Commit 61341707 by Graydon Hoare

missing added files from merge

From-SVN: r86958
parent 9969aaf6
/* GThreadMutex.java -- Implements a mutex object for glib's gthread
abstraction, for use with GNU Classpath's --portable-native-sync option.
This is used in gthread-jni.c
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.awt.peer.gtk;
/** Implements a mutex object for glib's gthread
abstraction, for use with GNU Classpath's --portable-native-sync option.
This is used in gthread-jni.c.
We use this object to implement the POSIX semantics for Mutexes. They are
needed are needed for the function vector that is passed to glib's
g_thread subpackage's initialization function.
The GThreadMutex object itself serves as the Real Lock; if code has
entered the monitor for this GThreadMutex object (in Java language, if
it's synchronized on this object) then it holds the lock that this object
represents.
@author Steven Augart
May, 2004
*/
class GThreadMutex
{
/** Might "lock" be locked? Is anyone waiting
to get that lock? How long is the queue?
If zero, nobody holds a lock on this GThreadMutex object, and nobody is
trying to get one. Before someone attempts to acquire a lock on this
object, they must increment potentialLockers. After they release their
lock on this object, they must decrement potentialLockers.
Access to this field is guarded by synchronizing on the object
<code>lockForPotentialLockers</code>.
After construction, we only access this field via JNI.
*/
volatile int potentialLockers;
/** An object to synchronize to if you want to examine or modify the
<code>potentialLockers</code> field. Only hold this lock for brief
moments, just long enough to check or set the value of
<code>lockForPotentialLockers</code>.
We use this representation so that g_thread_mutex_trylock() will work
with the POSIX semantics. This is the only case in which you ever hold a
lock on <code>lockForPotentialLockers</code> while trying to get another
lock -- if you are the mutex_trylock() implementation, and you have just
checked that <code>potentialLockers</code> has the value zero. In that
case, mutex_trylock() holds the lock on lockForPotentialLockers so that
another thread calling mutex_trylock() or mutex_lock() won't increment
potentialLockers after we've checked it and before we've gained the lock
on the POSIX mutex. Of course, in that case the operation of gaining
the POSIX lock itself will succeed immediately, and once it has
succeeded, trylock releases lockForPotentialLockers right away,
incremented to 1 (one).
After construction, we only access this field via JNI.
*/
Object lockForPotentialLockers;
GThreadMutex()
{
potentialLockers = 0;
lockForPotentialLockers = new Object();
}
}
// Local Variables:
// c-file-style: "gnu"
// End:
/* AbstractSpinnerModel.java --
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing;
import java.util.EventListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
/**
* AbstractSpinnerModel
* @author Ka-Hing Cheung
* @version 1.0
*/
public abstract class AbstractSpinnerModel implements SpinnerModel
{
private ChangeEvent changeEvent = new ChangeEvent(this);
protected EventListenerList listenerList = new EventListenerList();
/**
* Creates an <code>AbstractSpinnerModel</code>.
*/
public AbstractSpinnerModel()
{
}
/**
* Adds a <code>ChangeListener</code>.
*
* @param listener the listener to add
*/
public void addChangeListener(ChangeListener listener)
{
listenerList.add(ChangeListener.class, listener);
}
/**
* Gets all the listeners that are of a particular type.
*
* @param c the type of listener
* @return the listeners that are of the specific type
*/
public EventListener[] getListeners(Class c)
{
return listenerList.getListeners(c);
}
/**
* Gets all the <code>ChangeListener</code>s.
*
* @return all the <code>ChangeListener</code>s
*/
public ChangeListener[] getChangeListeners()
{
return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
}
/**
* Remove a particular listener.
*
* @param listener the listener to remove
*/
public void removeChangeListener(ChangeListener listener)
{
listenerList.remove(ChangeListener.class, listener);
}
/**
* Fires a <code>ChangeEvent</code> to all the <code>ChangeListener</code>s
* added to this model
*/
protected void fireStateChanged()
{
ChangeListener[] listeners = getChangeListeners();
for(int i = 0; i < listeners.length; ++i)
listeners[i].stateChanged(changeEvent);
}
}
/* SpinnerNumberModel.java --
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing;
/**
* SpinnerNumberModel
*
* @author Ka-Hing Cheung
* @version 1.0
*/
public class SpinnerNumberModel extends AbstractSpinnerModel
{
/** DOCUMENT ME! */
private Number value;
/** DOCUMENT ME! */
private Comparable minimum;
/** DOCUMENT ME! */
private Comparable maximum;
/** DOCUMENT ME! */
private Number stepSize;
/**
* Creates a <code>SpinnerNumberModel</code> with initial value 0, step 1,
* and no maximum nor minimum.
*/
public SpinnerNumberModel()
{
this(new Integer(0), null, null, new Integer(1));
}
/**
* Creates a <code>SpinnerNumberModel</code> with double precision
*
* @param value the initial value
* @param minimum the minimum value
* @param maximum the maximum value
* @param stepSize the step size
*/
public SpinnerNumberModel(double value, double minimum, double maximum,
double stepSize)
{
this(new Double(value), new Double(minimum), new Double(maximum),
new Double(stepSize));
}
/**
* Creates a <code>SpinnerNumberModel</code> with integer precision
*
* @param value the initial value
* @param minimum the minimum value
* @param maximum the maximum value
* @param stepSize the step size
*/
public SpinnerNumberModel(int value, int minimum, int maximum, int stepSize)
{
this(new Integer(value), new Integer(minimum), new Integer(maximum),
new Integer(stepSize));
}
/**
* Creates a <code>SpinnerNumberModel</code> with <code>Number</code>s and
* <code>Comparable</code>s.
*
* @param value the initial value
* @param minimum the minimum value, if null there's no minimum
* @param maximum the maximum value, if null there's no maximum
* @param stepSize the step size
*
* @throws IllegalArgumentException if minimum &lt;= value &lt;= maximum
* does not hold
*/
public SpinnerNumberModel(Number value, Comparable minimum,
Comparable maximum, Number stepSize)
{
if (stepSize == null)
throw new IllegalArgumentException("stepSize may not be null");
if (value == null)
throw new IllegalArgumentException("value may not be null");
if (minimum != null)
{
if (minimum.compareTo(value) > 0)
throw new IllegalArgumentException("minimum is not <= value");
}
else
minimum = new Comparable()
{
public int compareTo(Object obj)
{
return -1;
}
};
if (maximum != null)
{
if (maximum.compareTo(value) < 0)
throw new IllegalArgumentException("maximum is not >= value");
}
else
maximum = new Comparable()
{
public int compareTo(Object obj)
{
return 1;
}
};
this.value = value;
this.stepSize = stepSize;
this.minimum = minimum;
this.maximum = maximum;
}
/**
* Sets the new value and fire a change event
*
* @param value the new value
*
* @throws IllegalArgumentException if minimum &lt;= value &lt;= maximum
* does not hold
*/
public void setValue(Object value)
{
if (! (value instanceof Number))
throw new IllegalArgumentException("value must be a Number");
this.value = (Number) value;
fireStateChanged();
}
/**
* Gets the current value
*
* @return the current value
*/
public Object getValue()
{
return value;
}
/**
* Gets the next value without changing the current value, or null if the
* current value is maximum.
*
* @return the next value
*/
public Object getNextValue()
{
Number num;
if (value instanceof Double)
num = new Double(value.doubleValue() + stepSize.doubleValue());
else if (value instanceof Float)
num = new Double(value.floatValue() + stepSize.floatValue());
else if (value instanceof Long)
num = new Long(value.longValue() + stepSize.longValue());
else if (value instanceof Integer)
num = new Integer(value.intValue() + stepSize.intValue());
else if (value instanceof Short)
num = new Short((short) (value.shortValue() + stepSize.shortValue()));
else
num = new Byte((byte) (value.byteValue() + stepSize.byteValue()));
return maximum.compareTo(num) >= 0 ? num : null;
}
/**
* Gets the previous value without changing the current value, or null if
* the current value is minimum.
*
* @return the previous value
*/
public Object getPreviousValue()
{
Number num;
if (value instanceof Double)
num = new Double(value.doubleValue() - stepSize.doubleValue());
else if (value instanceof Float)
num = new Double(value.floatValue() - stepSize.floatValue());
else if (value instanceof Long)
num = new Long(value.longValue() - stepSize.longValue());
else if (value instanceof Integer)
num = new Integer(value.intValue() - stepSize.intValue());
else if (value instanceof Short)
num = new Short((short) (value.shortValue() - stepSize.shortValue()));
else
num = new Byte((byte) (value.byteValue() - stepSize.byteValue()));
return minimum.compareTo(num) <= 0 ? num : null;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public Number getNumber()
{
return value;
}
}
/* TransferHandler.java --
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing;
import java.io.Serializable;
public class TransferHandler implements Serializable
{
private static final long serialVersionUID = -7908749299918704233L;
public static final int NONE = 0;
public static final int COPY = 1;
public static final int MOVE = 2;
public static final int COPY_OR_MOVE = 3;
protected TransferHandler()
{
// Do nothing here.
}
}
/* BasicComboBoxEditor.java --
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.plaf.basic;
import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.ComboBoxEditor;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.UIResource;
/**
* This is a component that is responsible for displaying/editting selected
* item in comboBox. By default, the JTextField is returned as
* BasicComboBoxEditor.
*
* @author Olga Rodimina
*/
public class BasicComboBoxEditor extends Object implements ComboBoxEditor,
FocusListener
{
protected JTextField editor;
/**
* Creates a new BasicComboBoxEditor object.
*/
public BasicComboBoxEditor()
{
editor = new JTextField();
editor.setBorder(new EmptyBorder(1, 1, 1, 1));
}
/**
* This method returns textfield that will be used by the combo box to
* display/edit currently selected item in the combo box.
*
* @return textfield that will be used by the combo box to display/edit
* currently selected item
*/
public Component getEditorComponent()
{
return editor;
}
/**
* Sets item that should be editted when any editting operation is performed
* by the user. The value is always equal to the currently selected value
* in the combo box. Thus whenever a different value is selected from the
* combo box list then this method should be called to change editting
* item to the new selected item.
*
* @param selectedItem item that is currently selected in the combo box
*/
public void setItem(Object item)
{
editor.setText(item.toString());
}
/**
* This method returns item that is currently editable.
*
* @return item in the combo box that is currently editable
*/
public Object getItem()
{
return editor.getText();
}
public void selectAll()
{
editor.selectAll();
}
/**
* This method is called when textfield gains focus. This will enable
* editing of the selected item.
*
* @param e the FocusEvent describing change in focus.
*/
public void focusGained(FocusEvent e)
{
// FIXME: Need to implement
}
/**
* This method is called when textfield loses focus. If during this time any
* editting operation was performed by the user, then it will be cancelled
* and selected item will not be changed.
*
* @param e the FocusEvent describing change in focus
*/
public void focusLost(FocusEvent e)
{
// FIXME: Need to implement
}
/**
* This method adds actionListener to the editor. If the user will edit
* currently selected item in the textfield and pressEnter, then action
* will be performed. The actionPerformed of this ActionListener should
* change the selected item of the comboBox to the newly editted selected
* item.
*
* @param l the ActionListener responsible for changing selected item of the
* combo box when it is editted by the user.
*/
public void addActionListener(ActionListener l)
{
// FIXME: Need to implement
}
/**
* This method removes actionListener from the textfield.
*
* @param l the ActionListener to remove from the textfield.
*/
public void removeActionListener(ActionListener l)
{
// FIXME: Need to implement
}
public static class UIResource extends BasicComboBoxEditor
implements javax.swing.plaf.UIResource
{
/**
* Creates a new UIResource object.
*/
public UIResource()
{
}
}
}
/* BasicComboBoxRenderer.java --
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.plaf.basic;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.io.Serializable;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.UIResource;
/**
* This class is renderer for the combo box.
*
* @author Olga Rodimina
*/
public class BasicComboBoxRenderer extends JLabel implements ListCellRenderer,
Serializable
{
/**
* This border is used whenever renderer doesn't have a focus.
*/
protected static Border noFocusBorder = new EmptyBorder(0, 0, 0, 0);
/**
* Creates a new BasicComboBoxRenderer object.
*/
public BasicComboBoxRenderer()
{
setHorizontalAlignment(SwingConstants.LEFT);
}
/**
* Returns preferredSize of the renderer
*
* @return preferredSize of the renderer
*/
public Dimension getPreferredSize()
{
return super.getPreferredSize();
}
/**
* getListCellRendererComponent
*
* @param list List of items for which to the background and foreground
* colors
* @param value object that should be rendered in the cell
* @param index index of the cell in the list of items.
* @param isSelected draw cell highlighted if isSelected is true
* @param cellHasFocus draw focus rectangle around cell if the cell has
* focus
*
* @return Component that will be used to draw the desired cell.
*/
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected,
boolean cellHasFocus)
{
String s = value.toString();
setText(s);
setOpaque(true);
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
if (isSelected)
{
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
}
else
{
setBackground(list.getBackground());
setForeground(list.getForeground());
}
setEnabled(list.isEnabled());
setFont(list.getFont());
// Use focusCellHighlightBorder when renderer has focus and
// noFocusBorder otherwise
if (cellHasFocus)
setBorder(UIManager.getBorder("List.focusCellHighlightBorder"));
else
setBorder(noFocusBorder);
return this;
}
public static class UIResource extends BasicComboBoxRenderer
implements javax.swing.plaf.UIResource
{
/**
* Creates a new UIResource object.
*/
public UIResource()
{
}
}
}
/* BasicFormattedTextFieldUI.java
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.plaf.basic;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
/**
* @since 1.4
*/
public class BasicFormattedTextFieldUI extends BasicTextFieldUI
{
public BasicFormattedTextFieldUI()
{
}
public static ComponentUI createUI(JComponent c)
{
return new BasicFormattedTextFieldUI();
}
protected String getPropertyPrefix()
{
return "FormattedTextField";
}
}
\ No newline at end of file
/* BasicPasswordFieldUI.java
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.plaf.basic;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.text.Element;
import javax.swing.text.View;
public class BasicPasswordFieldUI extends BasicTextFieldUI
{
public BasicPasswordFieldUI()
{
}
public static ComponentUI createUI(JComponent c)
{
return new BasicPasswordFieldUI();
}
protected String getPropertyPrefix()
{
return "PasswordField";
}
}
/* BasicTextAreaUI.java --
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.plaf.basic;
import java.beans.PropertyChangeEvent;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.text.Element;
import javax.swing.text.PlainView;
import javax.swing.text.View;
public class BasicTextAreaUI extends BasicTextUI
{
public static ComponentUI createUI(JComponent comp)
{
return new BasicTextAreaUI();
}
public BasicTextAreaUI()
{
}
public View create(Element elem)
{
return new PlainView(elem);
}
protected String getPropertyPrefix()
{
return "TextArea";
}
}
/* BasicToolTipUI.java --
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.plaf.basic;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import javax.swing.JComponent;
import javax.swing.JToolTip;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.ToolTipUI;
/**
* This is the Basic Look and Feel UI class for JToolTip.
*/
public class BasicToolTipUI extends ToolTipUI
{
/** The default Border around the JToolTip. */
private static Border defaultBorder = new Border()
{
// FIXME: This needs to go into Basic Look and Feel
// defaults.
/**
* This method returns the border insets.
*
* @param c The Component to find Border insets for.
*
* @return The Border insets.
*/
public Insets getBorderInsets(Component c)
{
return new Insets(4, 4, 4, 4);
}
/**
* This method returns whether the border is opaque.
*
* @return Whether the border is opaque.
*/
public boolean isBorderOpaque()
{
return false;
}
/**
* This method paints the border.
*
* @param c The Component to paint this border around.
* @param g The Graphics object to paint with.
* @param x The x coordinate to start painting at.
* @param y The y coordinate to start painting at.
* @param w The width of the Component.
* @param y The height of the Component.
*/
public void paintBorder(Component c, Graphics g, int x, int y, int w,
int h)
{
Color saved = g.getColor();
g.setColor(Color.BLACK);
g.drawRect(0, 0, w - 1, h - 1);
g.setColor(saved);
}
};
/** The shared instance of BasicToolTipUI used for all ToolTips. */
private static BasicToolTipUI shared;
/**
* Creates a new BasicToolTipUI object.
*/
public BasicToolTipUI()
{
super();
}
/**
* This method creates a new BasicToolTip UI for the given
* JComponent.
*
* @param c The JComponent to create a UI for.
*
* @return A BasicToolTipUI that can be used by the given JComponent.
*/
public static ComponentUI createUI(JComponent c)
{
if (shared == null)
shared = new BasicToolTipUI();
return shared;
}
/**
* This method returns the msximum size of the given JComponent.
*
* @param c The JComponent to find a maximum size for.
*
* @return The maximum size.
*/
public Dimension getMaximumSize(JComponent c)
{
return getPreferredSize(c);
}
/**
* This method returns the minimum size of the given JComponent.
*
* @param c The JComponent to find a minimum size for.
*
* @return The minimum size.
*/
public Dimension getMinimumSize(JComponent c)
{
return getPreferredSize(c);
}
/**
* This method returns the preferred size of the given JComponent.
*
* @param c The JComponent to find a preferred size for.
*
* @return The preferred size.
*/
public Dimension getPreferredSize(JComponent c)
{
JToolTip tip = (JToolTip) c;
Rectangle vr = new Rectangle();
Rectangle ir = new Rectangle();
Rectangle tr = new Rectangle();
Insets insets = tip.getInsets();
FontMetrics fm = tip.getToolkit().getFontMetrics(tip.getFont());
SwingUtilities.layoutCompoundLabel(tip, fm, tip.getTipText(), null,
SwingConstants.CENTER,
SwingConstants.CENTER,
SwingConstants.CENTER,
SwingConstants.CENTER, vr, ir, tr, 0);
return new Dimension(insets.left + tr.width + insets.right,
insets.top + tr.height + insets.bottom);
}
/**
* This method installs the defaults for the given JComponent.
*
* @param c The JComponent to install defaults for.
*/
protected void installDefaults(JComponent c)
{
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
c.setBackground(defaults.getColor("ToolTip.background"));
c.setForeground(defaults.getColor("ToolTip.foreground"));
c.setFont(defaults.getFont("ToolTip.font"));
c.setBorder(defaultBorder);
}
/**
* This method installs the listeners for the given JComponent.
*
* @param c The JComponent to install listeners for.
*/
protected void installListeners(JComponent c)
{
}
/**
* This method installs the UI for the given JComponent.
*
* @param c The JComponent to install the UI for.
*/
public void installUI(JComponent c)
{
c.setOpaque(true);
installDefaults(c);
installListeners(c);
}
/**
* This method paints the given JComponent with the given Graphics object.
*
* @param g The Graphics object to paint with.
* @param c The JComponent to paint.
*/
public void paint(Graphics g, JComponent c)
{
JToolTip tip = (JToolTip) c;
String text = tip.getTipText();
if (text == null)
return;
Rectangle vr = new Rectangle();
vr = SwingUtilities.calculateInnerArea(tip, vr);
Rectangle ir = new Rectangle();
Rectangle tr = new Rectangle();
FontMetrics fm = tip.getToolkit().getFontMetrics(tip.getFont());
SwingUtilities.layoutCompoundLabel(tip, fm, tip.getTipText(), null,
SwingConstants.CENTER,
SwingConstants.CENTER,
SwingConstants.CENTER,
SwingConstants.CENTER, vr, ir, tr, 0);
Color saved = g.getColor();
g.setColor(Color.BLACK);
g.drawString(text, vr.x, vr.y + fm.getAscent());
g.setColor(saved);
}
/**
* This method uninstalls the defaults for the given JComponent.
*
* @param c The JComponent to uninstall defaults for.
*/
protected void uninstallDefaults(JComponent c)
{
c.setForeground(null);
c.setBackground(null);
c.setFont(null);
c.setBorder(null);
}
/**
* This method uninstalls listeners for the given JComponent.
*
* @param c The JComponent to uninstall listeners for.
*/
protected void uninstallListeners(JComponent c)
{
}
/**
* This method uninstalls the UI for the given JComponent.
*
* @param c The JComponent to uninstall.
*/
public void uninstallUI(JComponent c)
{
uninstallDefaults(c);
uninstallListeners(c);
}
}
/* ComboPopup.java
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.plaf.basic;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JList;
public interface ComboPopup
{
/**
* This method display popup menu containing list of JComboBox's items to
* the screen
*/
void show();
/**
* This method hides popup menu with list of JComboBox's item from the
* screen
*/
void hide();
/**
* Retursn true if popup menu with JComboBOx's item is currently visible on
* the screen and false otherwise
*
* @return true if JComboBox's popup menu with list of items is currently
* visible on the screen and false otherwise.
*/
boolean isVisible();
/**
* Return JList that is used to draw cells of the JComboBox.
*
* @return JList that is used to draw cells of the JcomboBox
*/
JList getList();
/**
* This method returns MouseListener that listen's to mouse events occuring
* in the combo box
*
* @return MouseListenere
*/
MouseListener getMouseListener();
/**
* This method returns MouseListener that listen's to mouse events occuring
* in the combo box.
*
* @return MouseMotionListener
*/
MouseMotionListener getMouseMotionListener();
/**
* This method returns KeyListener that listen's to key events occuring in
* the combo box.
*
* @return KeyListener
*/
KeyListener getKeyListener();
/* This method removes any listeners that were installed */
void uninstallingUI();
}
/* SimpleAttributeSet.java --
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.text;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable;
import java.lang.Cloneable;
public class SimpleAttributeSet
implements MutableAttributeSet, Serializable, Cloneable
{
Hashtable tab;
static AttributeSet EMPTY = new SimpleAttributeSet();
public SimpleAttributeSet()
{
this(null);
}
public SimpleAttributeSet(AttributeSet a)
{
tab = new Hashtable();
addAttributes(a);
}
public void addAttribute(Object name, Object value)
{
tab.put(name, value);
}
public void addAttributes(AttributeSet attributes)
{
Enumeration e = attributes.getAttributeNames();
while (e.hasMoreElements())
{
Object name = e.nextElement();
Object val = attributes.getAttribute(name);
tab.put(name, val);
}
}
public Object clone()
{
SimpleAttributeSet s = new SimpleAttributeSet();
s.tab = (Hashtable) tab.clone();
return s;
}
public boolean containsAttribute(Object name, Object value)
{
return tab.containsKey(name)
&& tab.get(name).equals(value);
}
public boolean containsAttributes(AttributeSet attributes)
{
Enumeration e = attributes.getAttributeNames();
while (e.hasMoreElements())
{
Object name = e.nextElement();
Object val = attributes.getAttribute(name);
if (! containsAttribute(name, val))
return false;
}
return true;
}
public AttributeSet copyAttributes()
{
return (AttributeSet) clone();
}
public boolean equals(Object obj)
{
return (obj != null)
&& (obj instanceof SimpleAttributeSet)
&& ((SimpleAttributeSet)obj).tab.equals(this.tab);
}
public Object getAttribute(Object name)
{
Object val = tab.get(name);
if (val != null)
return val;
Object p = getResolveParent();
if (p != null && p instanceof AttributeSet)
return (((AttributeSet)p).getAttribute(name));
return null;
}
public int getAttributeCount()
{
return tab.size();
}
public Enumeration getAttributeNames()
{
return tab.keys();
}
public AttributeSet getResolveParent()
{
return (AttributeSet) tab.get(ResolveAttribute);
}
public int hashCode()
{
return tab.hashCode();
}
public boolean isDefined(Object attrName)
{
return tab.containsKey(attrName);
}
public boolean isEmpty()
{
return tab.isEmpty();
}
public boolean isEqual(AttributeSet attr)
{
return this.equals(attr);
}
public void removeAttribute(Object name)
{
tab.remove(name);
}
public void removeAttributes(AttributeSet attributes)
{
removeAttributes(attributes.getAttributeNames());
}
public void removeAttributes(Enumeration names)
{
while (names.hasMoreElements())
{
removeAttribute(names.nextElement());
}
}
public void setResolveParent(AttributeSet parent)
{
addAttribute(ResolveAttribute, parent);
}
public String toString()
{
return tab.toString();
}
}
/* TabSet.java --
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.text;
import java.io.Serializable;
public class TabSet implements Serializable
{
TabStop[] tabs;
public TabSet(TabStop[] t)
{
tabs = t;
}
public TabStop getTab(int i)
{
return tabs[i];
}
public TabStop getTabAfter(float location)
{
int idx = getTabIndexAfter(location);
if (idx == -1)
return null;
else
return tabs[idx];
}
public int getTabCount()
{
return tabs.length;
}
public int getTabIndex(TabStop tab)
{
for (int i = 0; i < tabs.length; ++i)
if (tabs[i] == tab)
return i;
return -1;
}
public int getTabIndexAfter(float location)
{
int idx = -1;
for (int i = 0; i < tabs.length; ++i)
{
if (location < tabs[i].getPosition())
idx = i;
}
return idx;
}
public String toString()
{
StringBuffer sb = new StringBuffer();
sb.append("[");
for (int i = 0; i < tabs.length; ++i)
{
if (i != 0)
sb.append(" - ");
sb.append(tabs[i].toString());
}
sb.append("]");
return sb.toString();
}
}
/* TabSet.java --
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.text;
import java.io.Serializable;
public class TabStop implements Serializable
{
public static final int ALIGN_LEFT = 0;
public static final int ALIGN_RIGHT = 1;
public static final int ALIGN_CENTER = 2;
public static final int ALIGN_DECIMAL = 4;
public static final int ALIGN_BAR = 5;
public static final int LEAD_NONE = 0;
public static final int LEAD_DOTS = 1;
public static final int LEAD_HYPHENS = 2;
public static final int LEAD_UNDERLINE = 3;
public static final int LEAD_THICKLINE = 4;
public static final int LEAD_EQUALS = 5;
float pos;
int align;
int leader;
public TabStop(float pos)
{
this(pos, ALIGN_LEFT, LEAD_NONE);
}
public TabStop(float pos, int align, int leader)
{
this.pos = pos;
this.align = align;
this.leader = leader;
}
public boolean equals(Object other)
{
return (other != null)
&& (other instanceof TabStop)
&& (((TabStop)other).getPosition() == this.getPosition())
&& (((TabStop)other).getLeader() == this.getLeader())
&& (((TabStop)other).getAlignment() == this.getAlignment());
}
public int getAlignment()
{
return align;
}
public int getLeader()
{
return leader;
}
public float getPosition()
{
return pos;
}
public int hashCode()
{
return (int) pos + (int) leader + (int) align;
}
public String toString()
{
String prefix = "";
switch (align)
{
case ALIGN_LEFT:
prefix = "left ";
break;
case ALIGN_RIGHT:
prefix = "right ";
break;
case ALIGN_CENTER:
prefix = "center ";
break;
case ALIGN_DECIMAL:
prefix = "decimal ";
break;
case ALIGN_BAR:
prefix = "bar ";
break;
default:
break;
}
return (prefix + "tab @" + pos + ((leader == LEAD_NONE) ? "" : "(w/leaders)"));
}
}
/* Utilities.java --
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.text;
import java.awt.FontMetrics;
import java.awt.Graphics;
/**
* A set of utilities to deal with text. This is used by several other classes
* inside this package.
*
* @author Roman Kennke <roman@ontographics.com>
*/
public class Utilities
{
/**
* The length of the char buffer that holds the characters to be drawn.
*/
private static final int BUF_LENGTH = 64;
/**
* Creates a new <code>Utilities</code> object.
*/
public Utilities()
{
// Nothing to be done here.
}
/**
* Draws the given text segment. Contained tabs and newline characters
* are taken into account. Tabs are expanded using the
* specified {@link TabExpander}.
*
* @param s the text fragment to be drawn.
* @param x the x position for drawing.
* @param y the y position for drawing.
* @param g the {@link Graphics} context for drawing.
* @param e the {@link TabExpander} which specifies the Tab-expanding
* technique.
* @param startOffset starting offset in the text.
* @return the x coordinate at the end of the drawn text.
*/
public static final int drawTabbedText(Segment s, int x, int y, Graphics g,
TabExpander e, int startOffset)
{
// This buffers the chars to be drawn.
char[] buffer = s.array;
// The current x and y pixel coordinates.
int pixelX = x;
int pixelY = y;
// The font metrics of the current selected font.
FontMetrics metrics = g.getFontMetrics();
int ascent = metrics.getAscent();
for (int offset = s.offset; offset < (s.offset + s.count); ++offset)
{
switch (buffer[offset])
{
case '\t':
// In case we have a tab, we just 'jump' over the tab.
// When we have no tab expander we just use the width of 'm'.
if (e != null)
pixelX = (int) e.nextTabStop((float) pixelX,
startOffset + offset - s.offset);
else
pixelX += metrics.charWidth(' ');
break;
case '\n':
// In case we have a newline, we must draw
// the buffer and jump on the next line.
g.drawChars(buffer, offset, 1, pixelX, y);
pixelY += metrics.getHeight();
pixelX = x;
break;
default:
// Here we draw the char.
g.drawChars(buffer, offset, 1, pixelX, pixelY + ascent);
pixelX += metrics.charWidth(buffer[offset]);
break;
}
}
return pixelX;
}
/**
* Determines the width, that the given text <code>s</code> would take
* if it was printed with the given {@link java.awt.FontMetrics} on the
* specified screen position.
* @param s the text fragment
* @param metrics the font metrics of the font to be used
* @param x the x coordinate of the point at which drawing should be done
* @param e the {@link TabExpander} to be used
* @param startOffset the index in <code>s</code> where to start
* @returns the width of the given text s. This takes tabs and newlines
* into account.
*/
public static final int getTabbedTextWidth(Segment s, FontMetrics metrics,
int x, TabExpander e,
int startOffset)
{
// This buffers the chars to be drawn.
char[] buffer = s.array;
// The current x coordinate.
int pixelX = x;
// The current maximum width.
int maxWidth = 0;
for (int offset = s.offset; offset < (s.offset + s.count); ++offset)
{
switch (buffer[offset])
{
case '\t':
// In case we have a tab, we just 'jump' over the tab.
// When we have no tab expander we just use the width of 'm'.
if (e != null)
pixelX = (int) e.nextTabStop((float) pixelX,
startOffset + offset - s.offset);
else
pixelX += metrics.charWidth(' ');
break;
case '\n':
// In case we have a newline, we must 'draw'
// the buffer and jump on the next line.
pixelX += metrics.charWidth(buffer[offset]);
maxWidth = Math.max(maxWidth, pixelX - x);
pixelX = x;
break;
default:
// Here we draw the char.
pixelX += metrics.charWidth(buffer[offset]);
break;
}
}
// Take the last line into account.
maxWidth = Math.max(maxWidth, pixelX - x);
return maxWidth;
}
}
/* Native implementation of functions in GThreadNativeMethodRunner
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
#include "gnu_java_awt_peer_gtk_GThreadNativeMethodRunner.h"
#include "gthread-jni.h"
/*
* Class: GThreadNativeMethodRunner
* Method: nativeRun
* Signature: (J)V
*
* Purpose: Run the C function whose function pointer is
*
*/
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GThreadNativeMethodRunner_nativeRun(JNIEnv *gdk_env, jobject lcl_obj,
jlong funcAddr, jlong funcArg)
{
/* Convert the function's address back into a pointer to a C function. */
void *(*funcPtr)(void *) = (void *(*)(void *)) funcAddr;
/* We do not need to worry about the return value from funcPtr(); it's
just thrown away. That is part of the g_threads spec, so no reason
to worry about returning it. */
(void) funcPtr((void *) funcArg);
/* Fall off the end and terminate the thread of control. */
}
/* Local Variables: */
/* c-file-style: "gnu" */
/* End: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment