[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: JComboBox support from gcj gui branch
From: |
Mark Wielaard |
Subject: |
[cp-patches] FYI: JComboBox support from gcj gui branch |
Date: |
Sun, 05 Sep 2004 13:30:07 +0200 |
Hi,
This adds the JComboBox support the Olga has been working on from the
gcj gui branch. Also added a simple example to show that it really
works.
2004-09-05 Mark Wielaard <address@hidden>
* examples/gnu/classpath/examples/swing/Demo.java (mkComboBox):
New method.
2004-09-05 Olga Rodimina <address@hidden>
* javax/swing/ComboBoxEditor.java: Added javadocs.
* javax/swing/ComboBoxModel.java: Likewise.
* javax/swing/DefaultComboBoxModel.java: Implemented.
* javax/swing/DefaultListCellRenderer.java: Added javadocs
and ran through jalopy to fix formatting style.
(getListCellRendererComponent): Use appropriate border
if renderer has focus and use noFocusBorder when it doesn't.
* javax/swing/JComboBox.java: Implemented.
* javax/swing/JList.java:
(locationToIndex): New Method. Implemented.
(indexToLocation): New Method.
* javax/swing/JPopupMenu.java:
(visible): New field.
(isVisible): Changed to use new field above.
(setVisible): Likewise.
* javax/swing/MutableComboBoxModel.java: Added javadocs.
* javax/swing/plaf/basic/BasicArrowButton.java:
(shadow): Changed default color to Color.gray.
* javax/swing/plaf/basic/BasicComboBoxUI.java: New File.
UI delegate for JComboBox.
* javax/swing/plaf/basic/BasicComboPopup.java: New File.
Popup menu containing list of JComboBox's items.
* javax/swing/plaf/basic/BasicComboBoxEditor.java: New File.
* javax/swing/plaf/basic/BasicComboBoxRenderer.java: New File.
* javax/swing/plaf/basic/BasicComboBoxUI.java: New File.
* javax/swing/plaf/basic/BasicComboPopup.java: New File.
* javax/swing/plaf/basic/BasicPopupMenuUI.java:
(popupMenuWillBecomeVisible): Set selected path to the first
element only if it is of type MenuElement. Also fix formatting
style.
* javax/swing/plaf/basic/ComboPopup.java: Added javadocs and missing
methods signatures.
In the example I didn't enable editing yet since it gave strange errors.
If someone would like to debug that just add box.setEditable(true); to
the example and see if you can figure out what goes wrong.
Have fun,
Mark
Index: examples/gnu/classpath/examples/swing/Demo.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/examples/gnu/classpath/examples/swing/Demo.java,v
retrieving revision 1.4
diff -u -r1.4 Demo.java
--- examples/gnu/classpath/examples/swing/Demo.java 4 Sep 2004 20:31:20
-0000 1.4
+++ examples/gnu/classpath/examples/swing/Demo.java 5 Sep 2004 11:27:02
-0000
@@ -550,6 +550,12 @@
return tabs;
}
+ public static JComboBox mkComboBox(String[] names)
+ {
+ JComboBox box = new JComboBox(names);
+ return box;
+ }
+
public static JSpinner mkSpinner()
{
JSpinner spinner = new JSpinner();
@@ -767,6 +773,14 @@
mkColorChooser(),
panel);
+ new PopUpAction("ComboBox",
+ mkComboBox(new String[] {"Stop",
+ "Software",
+ "Hoarders",
+ "Support",
+ "GNU!"}),
+ panel);
+
JButton exitDisposer = mkDisposerButton(frame);
panel.add(exitDisposer);
Index: javax/swing/ComboBoxEditor.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/ComboBoxEditor.java,v
retrieving revision 1.3
diff -u -r1.3 ComboBoxEditor.java
--- javax/swing/ComboBoxEditor.java 9 Jan 2004 10:19:16 -0000 1.3
+++ javax/swing/ComboBoxEditor.java 5 Sep 2004 11:27:02 -0000
@@ -42,49 +42,56 @@
/**
* ComboBoxEditor
- * @author Andrew Selkirk
- * @version 1.0
+ *
+ * @author Andrew Selkirk
+ * @author Olga Rodimina
+ * @version 1.0
*/
-public interface ComboBoxEditor {
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * getEditorComponent
- * @returns Component
- */
- Component getEditorComponent();
-
- /**
- * setItem
- * @param item TODO
- */
- void setItem(Object item);
-
- /**
- * getItem
- * @returns Object
- */
- Object getItem();
-
- /**
- * selectAll
- */
- void selectAll();
-
- /**
- * addActionListener
- * @param listener TODO
- */
- void addActionListener(ActionListener listener);
-
- /**
- * removeActionListener
- * @param listener TODO
- */
- void removeActionListener(ActionListener listener);
-
-
+public interface ComboBoxEditor
+{
+ /**
+ * This method returns component that will be used by the combo box to
+ * display/edit currently selected item in the combo box.
+ *
+ * @return Component that will be used by the combo box to display/edit
+ * currently selected item
+ */
+ Component getEditorComponent();
+
+ /**
+ * 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
+ */
+ void setItem(Object item);
+
+ /**
+ * This method returns item that is currently editable.
+ *
+ * @return Item in the combo box that is currently editable
+ */
+ Object getItem();
+
+ /**
+ * selectAll
+ */
+ void selectAll();
+
+ /**
+ * This method adds specified ActionListener to this ComboBoxEditor.
+ *
+ * @param listener
+ */
+ void addActionListener(ActionListener listener);
+
+ /**
+ * This method removes given ActionListener from this ComboBoxEditor.
+ *
+ * @param listener TODO
+ */
+ void removeActionListener(ActionListener listener);
} // ComboBoxEditor
Index: javax/swing/ComboBoxModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/ComboBoxModel.java,v
retrieving revision 1.2
diff -u -r1.2 ComboBoxModel.java
--- javax/swing/ComboBoxModel.java 12 Oct 2003 16:44:39 -0000 1.2
+++ javax/swing/ComboBoxModel.java 5 Sep 2004 11:27:02 -0000
@@ -37,28 +37,32 @@
package javax.swing;
+
/**
- * ComboBoxModel
- * @author Andrew Selkirk
- * @version 1.0
+ * ComboBoxModel is a data model for JComboBox. This model keeps
+ * track of elements contained in the JComboBox as well as the current
+ * combo box selection. Whenever selection in the JComboBox changes, the
+ * ComboBoxModel should fire ListDataEvents to ComboBox's ListDataListeners.
+ *
+ * @author Andrew Selkirk
+ * @version 1.0
*/
-public interface ComboBoxModel extends ListModel {
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * setSelectedItem
- * @param item TODO
- */
- void setSelectedItem(Object item);
-
- /**
- * getSelectedItem
- * @returns Object
- */
- Object getSelectedItem();
-
+public interface ComboBoxModel extends ListModel
+{
+ /**
+ * This method sets the selected item in the combo box. Class
+ * implementing this interface should fire ListDataEvents to
+ * all registered ListDataListeners to indicated that the
+ * selection has changed.
+ *
+ * @param item item in the combo box that should be selected
+ */
+ void setSelectedItem(Object item);
+ /**
+ * The method returns currently selected item in the combo box
+ *
+ * @returns item that is currently selected in the combo box.
+ */
+ Object getSelectedItem();
} // ComboBoxModel
Index: javax/swing/DefaultComboBoxModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/DefaultComboBoxModel.java,v
retrieving revision 1.3
diff -u -r1.3 DefaultComboBoxModel.java
--- javax/swing/DefaultComboBoxModel.java 9 Jan 2004 10:19:16 -0000
1.3
+++ javax/swing/DefaultComboBoxModel.java 5 Sep 2004 11:27:02 -0000
@@ -38,146 +38,191 @@
package javax.swing;
import java.io.Serializable;
+import java.util.Arrays;
import java.util.Vector;
+
/**
- * DefaultComboBoxModel
- * @author Andrew Selkirk
- * @version 1.0
+ * DefaultComboBoxModel is a data model for JComboBox. This model keeps track
+ * of elements contained in the JComboBox as well as the current combo box
+ * selection. Whenever selection in the JComboBox changes, the ComboBoxModel
+ * will fire ListDataEvents to ComboBox's ListDataListeners.
+ *
+ * @author Andrew Selkirk
+ * @author Olga Rodimina
+ * @version 1.0
*/
-public class DefaultComboBoxModel extends AbstractListModel
- implements MutableComboBoxModel, Serializable
+public class DefaultComboBoxModel extends AbstractListModel
+ implements MutableComboBoxModel, Serializable
{
static final long serialVersionUID = 6698657703676921904L;
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * list
- */
- private Vector list;
-
- /**
- * selectedItem
- */
- private Object selectedItem;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor DefaultComboBoxModel
- */
- public DefaultComboBoxModel() {
- // TODO
- } // DefaultComboBoxModel()
-
- /**
- * Constructor DefaultComboBoxModel
- * @param items TODO
- */
- public DefaultComboBoxModel(Object[] items) {
- // TODO
- } // DefaultComboBoxModel()
-
- /**
- * Constructor DefaultComboBoxModel
- * @param vector TODO
- */
- public DefaultComboBoxModel(Vector vector) {
- // TODO
- } // DefaultComboBoxModel()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * addElement
- * @param object TODO
- */
- public void addElement(Object object) {
- // TODO
- } // addElement()
-
- /**
- * removeElementAt
- * @param index TODO
- */
- public void removeElementAt(int index) {
- // TODO
- } // removeElementAt()
-
- /**
- * insertElementAt
- * @param object TODO
- * @param index TODO
- */
- public void insertElementAt(Object object, int index) {
- // TODO
- } // insertElementAt()
-
- /**
- * removeElement
- * @param object TODO
- */
- public void removeElement(Object object) {
- // TODO
- } // removeElement()
-
- /**
- * removeAllElements
- */
- public void removeAllElements() {
- // TODO
- } // removeAllElements()
-
- /**
- * getSize
- * @returns int
- */
- public int getSize() {
- return 0; // TODO
- } // getSize()
-
- /**
- * setSelectedItem
- * @param object TODO
- */
- public void setSelectedItem(Object object) {
- // TODO
- } // setSelectedItem()
-
- /**
- * getSelectedItem
- * @returns Object
- */
- public Object getSelectedItem() {
- return null; // TODO
- } // getSelectedItem()
-
- /**
- * getElementAt
- * @param index TODO
- * @returns Object
- */
- public Object getElementAt(int index) {
- return null; // TODO
- } // getElementAt()
-
- /**
- * getIndexOf
- * @param object TODO
- * @returns int
- */
- public int getIndexOf(Object object) {
- return 0; // TODO
- } // getIndexOf()
-
-
-} // DefaultComboBoxModel
+ /**
+ * List containing items in the combo box
+ */
+ private Vector list;
+
+ /**
+ * Currently selected item in the combo box list
+ */
+ private Object selectedItem = null;
+
+ /**
+ * Constructor DefaultComboBoxModel. Create empty JComboBox.
+ */
+ public DefaultComboBoxModel()
+ {
+ list = new Vector();
+ }
+
+ /**
+ * Constructs new DefaultComboBoxModel object and initializes its item list
+ * to values in the given array.
+ *
+ * @param items array containing items of the combo box.
+ */
+ public DefaultComboBoxModel(Object[] items)
+ {
+ list = new Vector(Arrays.asList(items));
+ }
+
+ /**
+ * Consturcts new DefaultComboBoxModel object and initializes its item list
+ * to values in the given vector.
+ *
+ * @param vector Vector containing items for this combo box.
+ */
+ public DefaultComboBoxModel(Vector vector)
+ {
+ this.list = vector;
+ }
+
+ /**
+ * This method adds element to the combo box list. It fires ListDataEvent
+ * indicating that component was added to the combo box to all of the
+ * JComboBox's registered ListDataListeners.
+ *
+ * @param object item to add to the combo box list
+ */
+ public void addElement(Object object)
+ {
+ list.add(object);
+ fireIntervalAdded(this, list.size(), list.size());
+ }
+
+ /**
+ * This method removes element at the specified index from the combo box
+ * list. It fires ListDataEvent indicating that component was removed from
+ * the combo box list to all of the JComboBox's registered
+ * ListDataListeners.
+ *
+ * @param index index specifying location of the element to remove in the
+ * combo box list.
+ */
+ public void removeElementAt(int index)
+ {
+ list.remove(index);
+ fireIntervalRemoved(this, index, index);
+ }
+
+ /**
+ * This method inserts given object to the combo box list at the specified
+ * index. It fires ListDataEvent indicating that component was inserted to
+ * the combo box list to all of the JComboBox's registered
+ * ListDataListeners.
+ *
+ * @param object element to insert
+ * @param index index specifing position in the list where given element
+ * should be inserted.
+ */
+ public void insertElementAt(Object object, int index)
+ {
+ list.insertElementAt(object, index);
+ fireIntervalAdded(this, index, index);
+ }
+
+ /**
+ * Removes given object from the combo box list. It fires ListDataEvent
+ * indicating that component was removed from the combo box list to all of
+ * the JComboBox's registered ListDataListeners.
+ *
+ * @param object Element that will be removed from the combo box list
+ */
+ public void removeElement(Object object)
+ {
+ int index = getIndexOf(object);
+ if (index != -1)
+ removeElementAt(index);
+ }
+
+ /**
+ * Removes all the items from the JComboBox's item list. It fires
+ * ListDataEvent indicating that all the elements were removed from the
+ * combo box list to all of the JComboBox's registered ListDataListeners.
+ */
+ public void removeAllElements()
+ {
+ int listSize = getSize();
+ list.clear();
+ fireIntervalAdded(this, 0, listSize - 1);
+ }
+
+ /**
+ * Returns number of items in the combo box list
+ *
+ * @return number of items in the combo box list
+ */
+ public int getSize()
+ {
+ return list.size();
+ }
+
+ /**
+ * Selects given object in the combo box list. This method fires
+ * ListDataEvent to all registered ListDataListeners of the JComboBox. The
+ * start and end index of the event is set to -1 to indicate combo box's
+ * selection has changed, and not its contents.
+ *
+ * @param object item to select in the JComboBox
+ */
+ public void setSelectedItem(Object object)
+ {
+ selectedItem = object;
+ fireContentsChanged(this, -1, -1);
+ }
+
+ /**
+ * Returns currently selected item in the combo box list
+ *
+ * @return currently selected item in the combo box list
+ */
+ public Object getSelectedItem()
+ {
+ return selectedItem;
+ }
+
+ /**
+ * Returns element in the combo box list located at the given index
+ *
+ * @param index specifying location of the element in the list
+ *
+ * @return return element in the combo box list located at the given index
+ */
+ public Object getElementAt(int index)
+ {
+ return list.elementAt(index);
+ }
+
+ /**
+ * Returns index of the specified object in the combo box list.
+ *
+ * @param object element to look for in the combo box list .
+ *
+ * @return Index specifying position of the specified element in combo box
+ * list.
+ */
+ public int getIndexOf(Object object)
+ {
+ return list.indexOf(object);
+ }
+}
Index: javax/swing/DefaultListCellRenderer.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/DefaultListCellRenderer.java,v
retrieving revision 1.4
diff -u -r1.4 DefaultListCellRenderer.java
--- javax/swing/DefaultListCellRenderer.java 19 Mar 2004 21:22:24 -0000
1.4
+++ javax/swing/DefaultListCellRenderer.java 5 Sep 2004 11:27:02 -0000
@@ -41,16 +41,18 @@
import java.awt.Rectangle;
import java.io.Serializable;
import javax.swing.border.Border;
+import javax.swing.border.EmptyBorder;
/**
- * DefaultListCellRenderer
+ * DefaultListCellRenderer. This class is responsible for rendering list
+ * cells.
*
* @author Andrew Selkirk
* @version 1.0
*/
-public class DefaultListCellRenderer
- extends JLabel implements ListCellRenderer, Serializable
+public class DefaultListCellRenderer extends JLabel implements
ListCellRenderer,
+ Serializable
{
static final long serialVersionUID = 7708947179685189462L;
@@ -62,19 +64,22 @@
}
}
- /** noFocusBorder */
- protected static Border noFocusBorder = null; // TODO
+ /**
+ * This border is used whenever renderer doesn't have a focus.
+ */
+ protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
/**
* getListCellRendererComponent
*
- * @param list TODO
- * @param value TODO
- * @param index TODO
- * @param isSelected TODO
- * @param cellHasFocus TODO
+ * @param list JList list for the 'value'
+ * @param value object that should be rendered in the cell
+ * @param index index of the cell
+ * @param isSelected draw cell highlighted if isSelected is true
+ * @param cellHasFocus draw focus rectangle around cell if the cell has
+ * focus
*
- * @return Component
+ * @return Component that will be painted to the desired cell.
*/
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected,
@@ -86,31 +91,87 @@
if (isSelected)
{
- setBackground(list.getSelectionBackground());
- setForeground(list.getSelectionForeground());
+ setBackground(list.getSelectionBackground());
+ setForeground(list.getSelectionForeground());
}
else
{
- setBackground(list.getBackground());
- setForeground(list.getForeground());
+ 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 void validate() {}
- public void revalidate() {}
- public void repaint(long tm, int x, int y, int w, int h) {}
- public void repaint(Rectangle rect) {}
- protected void firePropertyChange(String propertyName, Object oldValue,
Object newValue){}
- public void firePropertyChange(String propertyName, byte oldValue, byte
newValue) {}
- public void firePropertyChange(String propertyName, char oldValue, char
newValue) {}
- public void firePropertyChange(String propertyName, short oldValue, short
newValue) {}
- public void firePropertyChange(String propertyName, int oldValue, int
newValue) {}
- public void firePropertyChange(String propertyName, long oldValue, long
newValue) {}
- public void firePropertyChange(String propertyName, float oldValue, float
newValue) {}
- public void firePropertyChange(String propertyName, double oldValue, double
newValue) {}
- public void firePropertyChange(String propertyName, boolean oldValue,
boolean newValue) {}
+ public void validate()
+ {
+ }
+
+ public void revalidate()
+ {
+ }
+
+ public void repaint(long tm, int x, int y, int w, int h)
+ {
+ }
+
+ public void repaint(Rectangle rect)
+ {
+ }
+
+ protected void firePropertyChange(String propertyName, Object oldValue,
+ Object newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, byte oldValue,
+ byte newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, char oldValue,
+ char newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, short oldValue,
+ short newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, int oldValue,
+ int newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, long oldValue,
+ long newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, float oldValue,
+ float newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, double oldValue,
+ double newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, boolean oldValue,
+ boolean newValue)
+ {
+ }
}
Index: javax/swing/JComboBox.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComboBox.java,v
retrieving revision 1.8
diff -u -r1.8 JComboBox.java
--- javax/swing/JComboBox.java 26 Jun 2004 16:06:48 -0000 1.8
+++ javax/swing/JComboBox.java 5 Sep 2004 11:27:02 -0000
@@ -35,761 +35,958 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing;
+import java.awt.Component;
+import java.awt.Dimension;
import java.awt.ItemSelectable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
+import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Vector;
-
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleAction;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleSelection;
+import javax.swing.JComponent;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.PopupMenuListener;
import javax.swing.plaf.ComboBoxUI;
+
/**
- * JComboBox
- * @author Andrew Selkirk
- * @version 1.0
+ * JComboBox. JComboBox is a container, that keeps track of elements added to
+ * it by the user. JComboBox allows user to select any item in its list and
+ * displays the selected item to the user. JComboBox also can show/hide popup
+ * menu containing its list of item whenever the mouse is pressed over it.
+ *
+ * @author Andrew Selkirk
+ * @author Olga Rodimina
*/
-public class JComboBox extends JComponent
- implements ItemSelectable, ListDataListener, ActionListener, Accessible
+public class JComboBox extends JComponent implements ItemSelectable,
+ ListDataListener,
+ ActionListener,
+ Accessible
{
private static final long serialVersionUID = 5654585963292734470L;
/**
- * AccessibleJComboBox
+ * KeySelectionManager interface. Class implementing this interface are
+ * responsible for matching key characters typed by the user with combo
+ * box's items.
*/
- protected class AccessibleJComboBox extends AccessibleJComponent
- implements AccessibleAction, AccessibleSelection
+ public static interface KeySelectionManager
{
- private static final long serialVersionUID = 8217828307256675666L;
+ int selectionForKey(char aKey, ComboBoxModel aModel);
+ }
+
+ /**
+ * Maximum number of rows that should be visible by default in the
+ * JComboBox's popup
+ */
+ public static final int DEFAULT_MAXIMUM_ROW_COUNT = 8;
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'editable' property changes.
+ */
+ public static final String EDITABLE_CHANGED_PROPERTY = "editable";
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'maximumRowCount' property
+ * changes.
+ */
+ public static final String MAXIMUM_ROW_COUNT_CHANGED_PROPERTY =
"maximumRowCount";
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'enabled' property changes.
+ */
+ public static final String ENABLED_CHANGED_PROPERTY = "enabled";
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'renderer' property changes.
+ */
+ public static final String RENDERER_CHANGED_PROPERTY = "renderer";
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'editor' property changes.
+ */
+ public static final String EDITOR_CHANGED_PROPERTY = "editor";
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'dataModel' property changes.
+ */
+ public static final String MODEL_CHANGED_PROPERTY = "dataModel";
+
+ /**
+ * name for the UI delegate for this combo box.
+ */
+ private static final String uiClassID = "ComboBoxUI";
+
+ /**
+ * dataModel used by JComboBox to keep track of its list data and currently
+ * selected element in the list.
+ */
+ protected ComboBoxModel dataModel;
+
+ /**
+ * Renderer renders(paints) every object in the combo box list in its
+ * associated list cell. This ListCellRenderer is used only when this
+ * JComboBox is uneditable.
+ */
+ protected ListCellRenderer renderer;
+
+ /**
+ * editor that is responsible for editting an object in a combo box list
+ */
+ protected ComboBoxEditor editor;
+
+ /**
+ * Number of rows that will be visible in the JComboBox's popup.
+ */
+ protected int maximumRowCount;
+
+ /**
+ * This field indicates if textfield of this JComboBox is editable or not.
+ */
+ protected boolean isEditable;
+
+ /**
+ * This field is reference to the current selection of the combo box.
+ */
+ protected Object selectedItemReminder;
+
+ /**
+ * keySelectionManager
+ */
+ protected KeySelectionManager keySelectionManager;
+
+ /**
+ * This actionCommand is used in ActionEvent that is fired to JComboBox's
+ * ActionListeneres.
+ */
+ protected String actionCommand;
+
+ /**
+ * This property indicates if heavyweight popup or lightweight popup will be
+ * used to diplay JComboBox's elements.
+ */
+ protected boolean lightWeightPopupEnabled;
+
+ /**
+ * The action taken when new item is selected in the JComboBox
+ */
+ private Action action;
+
+ /**
+ * since 1.4 If this field is set then comboBox's display area for the
+ * selected item will be set by default to this value.
+ */
+ private Object prototypeDisplayValue;
+
+ /**
+ * Constructs JComboBox object with specified data model for it. The first
+ * item in the specified data model is selected by default.
+ *
+ * @param model Data model that will be used by this JComboBox to keep track
+ * of its list of items.
+ */
+ public JComboBox(ComboBoxModel model)
+ {
+ setEditable(false);
+ setEnabled(true);
+ setMaximumRowCount(DEFAULT_MAXIMUM_ROW_COUNT);
+ setModel(model);
+ setActionCommand("comboBoxChanged");
+
+ // by default set selected item to the first element in the combo box
+ if (getItemCount() != 0)
+ setSelectedItem(getItemAt(0));
+
+ lightWeightPopupEnabled = true;
+ isEditable = false;
+
+ updateUI();
+ }
+
+ /**
+ * Constructs JComboBox with specified list of items.
+ *
+ * @param itemArray array containing list of items for this JComboBox
+ */
+ public JComboBox(Object[] itemArray)
+ {
+ this(new DefaultComboBoxModel(itemArray));
+ }
+
+ /**
+ * Constructs JComboBox object with specified list of items.
+ *
+ * @param itemVector vector containing list of items for this JComboBox.
+ */
+ public JComboBox(Vector itemVector)
+ {
+ this(new DefaultComboBoxModel(itemVector));
+ }
+
+ /**
+ * Constructor. Creates new empty JComboBox. ComboBox's data model is set to
+ * DefaultComboBoxModel.
+ */
+ public JComboBox()
+ {
+ this(new DefaultComboBoxModel());
+ }
+
+ private void writeObject(ObjectOutputStream stream) throws IOException
+ {
+ }
+
+ /**
+ * This method returns true JComboBox is editable and false otherwise
+ *
+ * @return boolean true if JComboBox is editable and false otherwise
+ */
+ public boolean isEditable()
+ {
+ return isEditable;
+ }
- /**
- * Constructor AccessibleJComboBox
- * @param component TODO
+ /*
+ * This method adds ancestor listener to this JComboBox.
+ */
+ protected void installAncestorListener()
+ {
+ /* FIXME: Need to implement.
+ *
+ * Need to add ancestor listener to this JComboBox. This listener
+ * should close combo box's popup list of items whenever it
+ * receives an AncestorEvent.
*/
- protected AccessibleJComboBox()
- {
- }
+ }
+
+ /**
+ * Set the "UI" property of the combo box, which is a look and feel class
+ * responsible for handling comboBox's input events and painting it.
+ *
+ * @param ui The new "UI" property
+ */
+ public void setUI(ComboBoxUI ui)
+ {
+ super.setUI(ui);
+ }
+
+ /**
+ * This method sets this comboBox's UI to the UIManager's default for the
+ * current look and feel.
+ */
+ public void updateUI()
+ {
+ setUI((ComboBoxUI) UIManager.getUI(this));
+ invalidate();
+ }
+
+ /**
+ * This method returns the String identifier for the UI class to the used
+ * with the JComboBox.
+ *
+ * @return The String identifier for the UI class.
+ */
+ public String getUIClassID()
+ {
+ return uiClassID;
+ }
+
+ /**
+ * This method returns the UI used to display the JComboBox.
+ *
+ * @return The UI used to display the JComboBox.
+ */
+ public ComboBoxUI getUI()
+ {
+ return (ComboBoxUI) ui;
+ }
+
+ /**
+ * Set the data model for this JComboBox. This un-registers all listeners
+ * associated with the current model, and re-registers them with the new
+ * model.
+ *
+ * @param newDataModel The new data model for this JComboBox
+ */
+ public void setModel(ComboBoxModel newDataModel)
+ {
+ if (this.dataModel == newDataModel)
+ return;
+
+ if (this.dataModel != null)
+ // remove all listeners currently registered with the model.
+ dataModel.removeListDataListener(this);
+
+ ComboBoxModel oldDataModel = this.dataModel;
+ this.dataModel = newDataModel;
+
+ if (this.dataModel != null)
+ // register all listeners with the new data model
+ dataModel.addListDataListener(this);
+
+ firePropertyChange(MODEL_CHANGED_PROPERTY, oldDataModel, this.dataModel);
+ }
+
+ /**
+ * This method returns data model for this comboBox.
+ *
+ * @return ComboBoxModel containing items for this combo box.
+ */
+ public ComboBoxModel getModel()
+ {
+ return dataModel;
+ }
+
+ /**
+ * This method sets JComboBox's popup to be either lightweight or
+ * heavyweight. If 'enabled' is true then lightweight popup is used and
+ * heavyweight otherwise. By default lightweight popup is used to display
+ * this JComboBox's elements.
+ *
+ * @param enabled indicates if lightweight popup or heavyweight popup should
+ * be used to display JComboBox's elements.
+ */
+ public void setLightWeightPopupEnabled(boolean enabled)
+ {
+ this.lightWeightPopupEnabled = enabled;
+ }
+
+ /**
+ * This method returns whether popup menu that is used to display list of
+ * combo box's item is lightWeight or not.
+ *
+ * @return boolean true if popup menu is lightweight and false otherwise.
+ */
+ public boolean isLightWeightPopupEnabled()
+ {
+ return lightWeightPopupEnabled;
+ }
+
+ /**
+ * This method sets editability of the combo box. If combo box is editable
+ * the user can choose component from the combo box list by typing
+ * component's name in the editor(JTextfield by default). Otherwise if not
+ * editable, the user should use the list to choose the component. This
+ * method fires PropertyChangeEvents to JComboBox's registered
+ * PropertyChangeListeners to indicate that 'editable' property of the
+ * JComboBox has changed.
+ *
+ * @param editable indicates if the JComboBox's textfield should be editable
+ * or not.
+ */
+ public void setEditable(boolean editable)
+ {
+ if (this.isEditable != editable)
+ {
+ this.isEditable = editable;
+ firePropertyChange(EDITABLE_CHANGED_PROPERTY, ! isEditable, isEditable);
+ }
+ }
+
+ /**
+ * Sets number of rows that should be visible in this JComboBox's popup. If
+ * this JComboBox's popup has more elements that maximum number or rows
+ * then popup will have a scroll pane to allow users to view other
+ * elements.
+ *
+ * @param rowCount number of rows that will be visible in JComboBox's popup.
+ */
+ public void setMaximumRowCount(int rowCount)
+ {
+ if (maximumRowCount != rowCount)
+ {
+ int oldMaximumRowCount = this.maximumRowCount;
+ this.maximumRowCount = rowCount;
+ firePropertyChange(MAXIMUM_ROW_COUNT_CHANGED_PROPERTY,
+ oldMaximumRowCount, this.maximumRowCount);
+ }
+ }
+
+ /**
+ * This method returns number of rows visible in the JComboBox's list of
+ * items.
+ *
+ * @return int maximun number of visible rows in the JComboBox's list.
+ */
+ public int getMaximumRowCount()
+ {
+ return maximumRowCount;
+ }
+
+ /**
+ * This method sets cell renderer for this JComboBox that will be used to
+ * paint combo box's items. The Renderer should only be used only when
+ * JComboBox is not editable. In the case when JComboBox is editable the
+ * editor must be used. This method also fires PropertyChangeEvent when
+ * cellRendered for this JComboBox has changed.
+ *
+ * @param aRenderer cell renderer that will be used by this JComboBox to
+ * paint its elements.
+ */
+ public void setRenderer(ListCellRenderer aRenderer)
+ {
+ if (this.renderer != aRenderer)
+ {
+ ListCellRenderer oldRenderer = this.renderer;
+ this.renderer = aRenderer;
+ firePropertyChange(RENDERER_CHANGED_PROPERTY, oldRenderer,
+ this.renderer);
+ }
+ }
+
+ /**
+ * This method returns renderer responsible for rendering selected item in
+ * the combo box
+ *
+ * @return ListCellRenderer
+ */
+ public ListCellRenderer getRenderer()
+ {
+ return renderer;
+ }
+
+ /**
+ * Sets editor for this JComboBox
+ *
+ * @param newEditor ComboBoxEditor for this JComboBox. This method fires
+ * PropertyChangeEvent when 'editor' property is changed.
+ */
+ public void setEditor(ComboBoxEditor newEditor)
+ {
+ if (editor == newEditor)
+ return;
+
+ if (editor != null)
+ editor.removeActionListener(this);
+
+ ComboBoxEditor oldEditor = editor;
+ editor = newEditor;
+
+ if (editor != null)
+ editor.addActionListener(this);
+
+ firePropertyChange(EDITOR_CHANGED_PROPERTY, oldEditor, editor);
+ }
+
+ /**
+ * Returns editor component that is responsible for displaying/editting
+ * selected item in the combo box.
+ *
+ * @return ComboBoxEditor
+ */
+ public ComboBoxEditor getEditor()
+ {
+ return editor;
+ }
+
+ /**
+ * Forces combo box to select given item
+ *
+ * @param item element in the combo box to select.
+ */
+ public void setSelectedItem(Object item)
+ {
+ dataModel.setSelectedItem(item);
+ }
+
+ /**
+ * Returns currently selected item in the combo box.
+ *
+ * @return element that is currently selected in this combo box.
+ */
+ public Object getSelectedItem()
+ {
+ Object item = dataModel.getSelectedItem();
+
+ if (item == null && getItemCount() != 0)
+ item = getItemAt(0);
+
+ return item;
+ }
+
+ /**
+ * Forces JComboBox to select component located in the given index in the
+ * combo box.
+ *
+ * @param index index specifying location of the component that should be
+ * selected.
+ */
+ public void setSelectedIndex(int index)
+ {
+ // FIXME: if index == -1 then nothing should be selected
+ setSelectedItem(dataModel.getElementAt(index));
+ }
+
+ /**
+ * Returns index of the item that is currently selected in the combo box.
+ * If no item is currently selected, then -1 is returned.
+ *
+ * @return int index specifying location of the currently selected item in
+ * the combo box or -1 if nothing is selected in the combo box.
+ */
+ public int getSelectedIndex()
+ {
+ Object selectedItem = getSelectedItem();
+ if (selectedItem != null && (dataModel instanceof DefaultComboBoxModel))
+ return ((DefaultComboBoxModel) dataModel).getIndexOf(selectedItem);
+
+ return -1;
+ }
+
+ public Object getPrototypeDisplayValue()
+ {
+ return prototypeDisplayValue;
+ }
+
+ public void setPrototypeDisplayValue(Object prototypeDisplayValue)
+ {
+ this.prototypeDisplayValue = prototypeDisplayValue;
+ }
+
+ /**
+ * This method adds given element to this JComboBox.
+ *
+ * @param element element to add
+ */
+ public void addItem(Object element)
+ {
+ ((MutableComboBoxModel) dataModel).addElement(element);
+ }
+
+ /**
+ * Inserts given element at the specified index to this JComboBox
+ *
+ * @param element element to insert
+ * @param index position where to insert the element
+ */
+ public void insertItemAt(Object element, int index)
+ {
+ ((MutableComboBoxModel) dataModel).insertElementAt(element, index);
+ }
+
+ /**
+ * This method removes given element from this JComboBox.
+ *
+ * @param element element to remove
+ */
+ public void removeItem(Object element)
+ {
+ ((MutableComboBoxModel) dataModel).removeElement(element);
+ }
+
+ /**
+ * This method remove element location in the specified index in the
+ * JComboBox.
+ *
+ * @param index index specifying position of the element to remove
+ */
+ public void removeItemAt(int index)
+ {
+ ((MutableComboBoxModel) dataModel).removeElementAt(index);
+ }
+
+ /**
+ * This method removes all elements from this JComboBox.
+ */
+ public void removeAllItems()
+ {
+ if (dataModel instanceof DefaultComboBoxModel)
+ ((DefaultComboBoxModel) dataModel).removeAllElements();
+ }
+
+ /**
+ * This method displays popup with list of combo box's items on the screen
+ */
+ public void showPopup()
+ {
+ setPopupVisible(true);
+ }
+
+ /**
+ * This method hides popup containing list of combo box's items
+ */
+ public void hidePopup()
+ {
+ setPopupVisible(false);
+ }
+
+ /**
+ * This method either displayes or hides the popup containing list of combo
+ * box's items.
+ *
+ * @param visible show popup if 'visible' is true and hide it otherwise
+ */
+ public void setPopupVisible(boolean visible)
+ {
+ getUI().setPopupVisible(this, visible);
+ }
+
+ /**
+ * Checks if popup is currently visible on the screen.
+ *
+ * @return boolean true if popup is visible and false otherwise
+ */
+ public boolean isPopupVisible()
+ {
+ return getUI().isPopupVisible(this);
+ }
+
+ /**
+ * This method sets actionCommand to the specified string. ActionEvent fired
+ * to this JComboBox registered ActionListeners will contain this
+ * actionCommand.
+ *
+ * @param aCommand new action command for the JComboBox's ActionEvent
+ */
+ public void setActionCommand(String aCommand)
+ {
+ actionCommand = aCommand;
+ }
+
+ /**
+ * Returns actionCommand associated with the ActionEvent fired by the
+ * JComboBox to its registered ActionListeners.
+ *
+ * @return String actionCommand for the ActionEvent
+ */
+ public String getActionCommand()
+ {
+ return actionCommand;
+ }
+
+ /**
+ * setAction
+ *
+ * @param a action to set
+ */
+ public void setAction(Action a)
+ {
+ Action old = action;
+ action = a;
+ configurePropertiesFromAction(action);
+ if (action != null)
+ // FIXME: remove from old action and add to new action
+ // PropertyChangeListener to listen to changes in the action
+ addActionListener(action);
+ }
+
+ /**
+ * This method returns Action that is invoked when selected item is changed
+ * in the JComboBox.
+ *
+ * @return Action
+ */
+ public Action getAction()
+ {
+ return action;
+ }
+
+ /**
+ * Configure properties of the JComboBox by reading properties of specified
+ * action. This method always sets the comboBox's "enabled" property to the
+ * value of the Action's "enabled" property.
+ *
+ * @param a An Action to configure the combo box from
+ */
+ protected void configurePropertiesFromAction(Action a)
+ {
+ if (a == null)
+ {
+ setEnabled(true);
+ setToolTipText(null);
+ }
+ else
+ {
+ setEnabled(a.isEnabled());
+ setToolTipText((String) (a.getValue(Action.SHORT_DESCRIPTION)));
+ }
+ }
+
+ /**
+ * Creates PropertyChangeListener to listen for the changes in comboBox's
+ * action properties.
+ *
+ * @param action action to listen to for property changes
+ *
+ * @return $PropertyChangeListener$ Listener that listens to changes in
+ * action properties.
+ */
+ protected PropertyChangeListener createActionPropertyChangeListener(Action
action)
+ {
+ return new PropertyChangeListener()
+ {
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ Action act = (Action) (e.getSource());
+ configurePropertiesFromAction(act);
+ }
+ };
+ }
+
+ /**
+ * This method fires ItemEvent to this JComboBox's registered ItemListeners.
+ * This method is invoked when currently selected item in this combo box
+ * has changed.
+ *
+ * @param e the ItemEvent describing the change in the combo box's
+ * selection.
+ */
+ protected void fireItemStateChanged(ItemEvent e)
+ {
+ ItemListener[] ll = getItemListeners();
+
+ for (int i = 0; i < ll.length; i++)
+ ll[i].itemStateChanged(e);
+ }
+
+ /**
+ * This method fires ActionEvent to this JComboBox's registered
+ * ActionListeners. This method is invoked when user explicitly changes
+ * currently selected item.
+ */
+ protected void fireActionEvent()
+ {
+ ActionListener[] ll = getActionListeners();
+
+ for (int i = 0; i < ll.length; i++)
+ ll[i].actionPerformed(new ActionEvent(this,
+ ActionEvent.ACTION_PERFORMED,
+ actionCommand));
+ }
+
+ /**
+ * This method is invoked whenever selected item changes in the combo box's
+ * data model. It fires ItemEvent and ActionEvent to all registered
+ * ComboBox's ItemListeners and ActionListeners respectively, indicating
+ * the change.
+ */
+ protected void selectedItemChanged()
+ {
+ // Fire ItemEvent to indicated that previously selected item is now
+ // deselected
+ if (selectedItemReminder != null)
+ fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
+ selectedItemReminder,
+ ItemEvent.DESELECTED));
+
+ // Fire ItemEvent to indicate that new item is selected
+ Object newSelection = getSelectedItem();
+ fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
+ newSelection, ItemEvent.SELECTED));
+
+ // Fire Action Event to JComboBox's registered listeners
+ fireActionEvent();
+
+ selectedItemReminder = newSelection;
+ }
+
+ /**
+ * Returns Object array of size 1 containing currently selected element in
+ * the JComboBox.
+ *
+ * @return Object[] Object array of size 1 containing currently selected
+ * element in the JComboBox.
+ */
+ public Object[] getSelectedObjects()
+ {
+ Object selectedObject = getSelectedItem();
+ return new Object[] { selectedObject };
+ }
+
+ /**
+ * This method handles actionEvents fired by the ComboBoxEditor. It changes
+ * this JComboBox's selection to the new value currently in the editor and
+ * hides list of combo box items.
+ *
+ * @param e the ActionEvent
+ */
+ public void actionPerformed(ActionEvent e)
+ {
+ setSelectedItem(((ComboBoxEditor) e.getSource()).getItem());
+ setPopupVisible(false);
+ }
+
+ /**
+ * This method selects item in this combo box that matches specified
+ * specified keyChar and returns true if such item is found. Otherwise
+ * false is returned.
+ *
+ * @param keyChar character indicating which item in the combo box should be
+ * selected.
+ *
+ * @return boolean true if item corresponding to the specified keyChar
+ * exists in the combo box. Otherwise false is returned.
+ */
+ public boolean selectWithKeyChar(char keyChar)
+ {
+ // FIXME: Need to implement
+ return false;
+ }
- /**
- * getAccessibleChildrenCount
- * @returns int
- */
- public int getAccessibleChildrenCount() {
- return 0; // TODO
- } // getAccessibleChildrenCount()
-
- /**
- * getAccessibleChild
- * @param value0 TODO
- * @returns Accessible
- */
- public Accessible getAccessibleChild(int value0) {
- return null; // TODO
- } // getAccessibleChild()
-
- /**
- * getAccessibleSelection
- * @returns AccessibleSelection
- */
- public AccessibleSelection getAccessibleSelection() {
- return null; // TODO
- } // getAccessibleSelection()
-
- /**
- * getAccessibleSelection
- * @param value0 TODO
- * @returns Accessible
- */
- public Accessible getAccessibleSelection(int value0) {
- return null; // TODO
- } // getAccessibleSelection()
-
- /**
- * isAccessibleChildSelected
- * @param value0 TODO
- * @returns boolean
- */
- public boolean isAccessibleChildSelected(int value0) {
- return false; // TODO
- } // isAccessibleChildSelected()
-
- /**
- * getAccessibleRole
- * @returns AccessibleRole
- */
- public AccessibleRole getAccessibleRole() {
- return AccessibleRole.COMBO_BOX;
- } // getAccessibleRole()
-
- /**
- * getAccessibleAction
- * @returns AccessibleAction
- */
- public AccessibleAction getAccessibleAction() {
- return null; // TODO
- } // getAccessibleAction()
-
- /**
- * getAccessibleActionDescription
- * @param value0 TODO
- * @returns String
- */
- public String getAccessibleActionDescription(int value0) {
- return null; // TODO
- } // getAccessibleActionDescription()
-
- /**
- * getAccessibleActionCount
- * @returns int
- */
- public int getAccessibleActionCount() {
- return 0; // TODO
- } // getAccessibleActionCount()
-
- /**
- * doAccessibleAction
- * @param value0 TODO
- * @returns boolean
- */
- public boolean doAccessibleAction(int value0) {
- return false; // TODO
- } // doAccessibleAction()
-
- /**
- * getAccessibleSelectionCount
- * @returns int
- */
- public int getAccessibleSelectionCount() {
- return 0; // TODO
- } // getAccessibleSelectionCount()
-
- /**
- * addAccessibleSelection
- * @param value0 TODO
- */
- public void addAccessibleSelection(int value0) {
- // TODO
- } // addAccessibleSelection()
-
- /**
- * removeAccessibleSelection
- * @param value0 TODO
- */
- public void removeAccessibleSelection(int value0) {
- // TODO
- } // removeAccessibleSelection()
-
- /**
- * clearAccessibleSelection
- */
- public void clearAccessibleSelection() {
- // TODO
- } // clearAccessibleSelection()
-
- /**
- * selectAllAccessibleSelection
- */
- public void selectAllAccessibleSelection() {
- // TODO
- } // selectAllAccessibleSelection()
-
-
- } // AccessibleJComboBox
-
- /**
- * KeySelectionManager
- */
- public static interface KeySelectionManager {
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * selectionForKey
- * @param value0 TODO
- * @param value1 TODO
- * @returns int
- */
- int selectionForKey(char value0, ComboBoxModel value1);
-
-
- } // KeySelectionManager
-
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * uiClassID
- */
- private static final String uiClassID = "ComboBoxUI";
-
- /**
- * dataModel
- */
- protected ComboBoxModel dataModel;
-
- /**
- * renderer
- */
- protected ListCellRenderer renderer;
-
- /**
- * editor
- */
- protected ComboBoxEditor editor;
-
- /**
- * maximumRowCount
- */
- protected int maximumRowCount;
-
- /**
- * isEditable
- */
- protected boolean isEditable;
-
- /**
- * selectedItemReminder
- */
- protected Object selectedItemReminder;
-
- /**
- * keySelectionManager
- */
- protected JComboBox.KeySelectionManager keySelectionManager;
-
- /**
- * actionCommand
- */
- protected String actionCommand;
-
- /**
- * lightWeightPopupEnabled
- */
- protected boolean lightWeightPopupEnabled;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor JComboBox
- * @param value0 TODO
- */
- public JComboBox(ComboBoxModel value0) {
- // TODO
- } // JComboBox()
-
- /**
- * Constructor JComboBox
- * @param value0 TODO
- */
- public JComboBox(Object[] value0) {
- // TODO
- } // JComboBox()
-
- /**
- * Constructor JComboBox
- * @param value0 TODO
- */
- public JComboBox(Vector value0) {
- // TODO
- } // JComboBox()
-
- /**
- * Constructor JComboBox
- */
- public JComboBox() {
- // TODO
- } // JComboBox()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * writeObject
- * @param stream TODO
- * @exception IOException TODO
- */
- private void writeObject(ObjectOutputStream stream) throws IOException {
- // TODO
- } // writeObject()
-
- /**
- * isEditable
- * @returns boolean
- */
- public boolean isEditable() {
- return false; // TODO
- } // isEditable()
-
- /**
- * installAncestorListener
- */
- protected void installAncestorListener() {
- // TODO
- } // installAncestorListener()
-
- /**
- * setUI
- * @param ui TODO
- */
- public void setUI(ComboBoxUI ui) {
- super.setUI(ui);
- } // setUI()
-
- /**
- * updateUI
- */
- public void updateUI() {
- setUI((ComboBoxUI) UIManager.get(this));
- invalidate();
- } // updateUI()
-
- /**
- * getUIClassID
- * @returns String
- */
- public String getUIClassID() {
- return uiClassID;
- } // getUIClassID()
-
- /**
- * getUI
- * @returns ComboBoxUI
- */
- public ComboBoxUI getUI() {
- return (ComboBoxUI) ui;
- } // getUI()
-
- /**
- * setModel
- * @param value0 TODO
- */
- public void setModel(ComboBoxModel value0) {
- // TODO
- } // setModel()
-
- /**
- * getModel
- * @returns ComboBoxModel
- */
- public ComboBoxModel getModel() {
- return null; // TODO
- } // getModel()
-
- /**
- * setLightWeightPopupEnabled
- * @param value0 TODO
- */
- public void setLightWeightPopupEnabled(boolean value0) {
- // TODO
- } // setLightWeightPopupEnabled()
-
- /**
- * isLightWeightPopupEnabled
- * @returns boolean
- */
- public boolean isLightWeightPopupEnabled() {
- return false; // TODO
- } // isLightWeightPopupEnabled()
-
- /**
- * setEditable
- * @param value0 TODO
- */
- public void setEditable(boolean value0) {
- // TODO
- } // setEditable()
-
- /**
- * setMaximumRowCount
- * @param value0 TODO
- */
- public void setMaximumRowCount(int value0) {
- // TODO
- } // setMaximumRowCount()
-
- /**
- * getMaximumRowCount
- * @returns int
- */
- public int getMaximumRowCount() {
- return 0; // TODO
- } // getMaximumRowCount()
-
- /**
- * setRenderer
- * @param value0 TODO
- */
- public void setRenderer(ListCellRenderer value0) {
- // TODO
- } // setRenderer()
-
- /**
- * getRenderer
- * @returns ListCellRenderer
- */
- public ListCellRenderer getRenderer() {
- return null; // TODO
- } // getRenderer()
-
- /**
- * setEditor
- * @param value0 TODO
- */
- public void setEditor(ComboBoxEditor value0) {
- // TODO
- } // setEditor()
-
- /**
- * getEditor
- * @returns ComboBoxEditor
- */
- public ComboBoxEditor getEditor() {
- return null; // TODO
- } // getEditor()
-
- /**
- * setSelectedItem
- * @param value0 TODO
- */
- public void setSelectedItem(Object value0) {
- // TODO
- } // setSelectedItem()
-
- /**
- * getSelectedItem
- * @returns Object
- */
- public Object getSelectedItem() {
- return null; // TODO
- } // getSelectedItem()
-
- /**
- * setSelectedIndex
- * @param value0 TODO
- */
- public void setSelectedIndex(int value0) {
- // TODO
- } // setSelectedIndex()
-
- /**
- * getSelectedIndex
- * @returns int
- */
- public int getSelectedIndex() {
- return 0; // TODO
- } // getSelectedIndex()
-
- /**
- * addItem
- * @param value0 TODO
- */
- public void addItem(Object value0) {
- // TODO
- } // addItem()
-
- /**
- * insertItemAt
- * @param value0 TODO
- * @param value1 TODO
- */
- public void insertItemAt(Object value0, int value1) {
- // TODO
- } // insertItemAt()
-
- /**
- * removeItem
- * @param value0 TODO
- */
- public void removeItem(Object value0) {
- // TODO
- } // removeItem()
-
- /**
- * removeItemAt
- * @param value0 TODO
- */
- public void removeItemAt(int value0) {
- // TODO
- } // removeItemAt()
-
- /**
- * removeAllItems
- */
- public void removeAllItems() {
- // TODO
- } // removeAllItems()
-
- /**
- * showPopup
- */
- public void showPopup() {
- // TODO
- } // showPopup()
-
- /**
- * hidePopup
- */
- public void hidePopup() {
- // TODO
- } // hidePopup()
-
- /**
- * setPopupVisible
- * @param value0 TODO
- */
- public void setPopupVisible(boolean value0) {
- // TODO
- } // setPopupVisible()
-
- /**
- * isPopupVisible
- * @returns boolean
- */
- public boolean isPopupVisible() {
- return false; // TODO
- } // isPopupVisible()
-
- /**
- * setActionCommand
- * @param value0 TODO
- */
- public void setActionCommand(String value0) {
- // TODO
- } // setActionCommand()
-
- /**
- * getActionCommand
- * @returns String
- */
- public String getActionCommand() {
- return null; // TODO
- } // getActionCommand()
-
- /**
- * setAction
- * @param value0 TODO
- */
- public void setAction(Action value0) {
- // TODO
- } // setAction()
-
- /**
- * isListener
- * @param value0 TODO
- * @param value1 TODO
- * @returns boolean
- */
- private boolean isListener(Class value0, ActionListener value1) {
- return false; // TODO
- } // isListener()
-
- /**
- * getAction
- * @returns Action
- */
- public Action getAction() {
- return null; // TODO
- } // getAction()
-
- /**
- * configurePropertiesFromAction
- * @param value0 TODO
- */
- protected void configurePropertiesFromAction(Action value0) {
- // TODO
- } // configurePropertiesFromAction()
-
- /**
- * createActionPropertyChangeListener
- * @param value0 TODO
- * @returns PropertyChangeListener
- */
- protected PropertyChangeListener
createActionPropertyChangeListener(Action value0) {
- return null; // TODO
- } // createActionPropertyChangeListener()
-
- /**
- * fireItemStateChanged
- * @param value0 TODO
- */
- protected void fireItemStateChanged(ItemEvent value0) {
- // TODO
- } // fireItemStateChanged()
-
- /**
- * fireActionEvent
- */
- protected void fireActionEvent() {
- // TODO
- } // fireActionEvent()
-
- /**
- * selectedItemChanged
- */
- protected void selectedItemChanged() {
- // TODO
- } // selectedItemChanged()
-
- /**
- * getSelectedObjects
- * @returns Object[]
- */
- public Object[] getSelectedObjects() {
- return null; // TODO
- } // getSelectedObjects()
-
- /**
- * actionPerformed
- * @param value0 TODO
- */
- public void actionPerformed(ActionEvent value0) {
- // TODO
- } // actionPerformed()
-
- /**
- * contentsChanged
- * @param value0 TODO
- */
- public void contentsChanged(ListDataEvent value0) {
- // TODO
- } // contentsChanged()
-
- /**
- * selectWithKeyChar
- * @param value0 TODO
- * @returns boolean
- */
- public boolean selectWithKeyChar(char value0) {
- return false; // TODO
- } // selectWithKeyChar()
-
- /**
- * intervalAdded
- * @param value0 TODO
- */
- public void intervalAdded(ListDataEvent value0) {
- // TODO
- } // intervalAdded()
-
- /**
- * intervalRemoved
- * @param value0 TODO
- */
- public void intervalRemoved(ListDataEvent value0) {
- // TODO
- } // intervalRemoved()
-
- /**
- * setEnabled
- * @param value0 TODO
- */
- public void setEnabled(boolean value0) {
- // TODO
- } // setEnabled()
-
- /**
- * configureEditor
- * @param value0 TODO
- * @param value1 TODO
- */
- public void configureEditor(ComboBoxEditor value0, Object value1) {
- // TODO
- } // configureEditor()
-
- /**
- * processKeyEvent
- * @param value0 TODO
- */
- public void processKeyEvent(KeyEvent value0) {
- // TODO
- } // processKeyEvent()
-
- /**
- * isFocusTraversable
- * @returns boolean
- * @deprecated
- */
- public boolean isFocusTraversable() {
- return false; // TODO
- } // isFocusTraversable()
-
- /**
- * setKeySelectionManager
- * @param value0 TODO
- */
- public void setKeySelectionManager(KeySelectionManager value0) {
- // TODO
- } // setKeySelectionManager()
-
- /**
- * getKeySelectionManager
- * @returns JComboBox.KeySelectionManager
- */
- public JComboBox.KeySelectionManager getKeySelectionManager() {
- return null; // TODO
- } // getKeySelectionManager()
-
- /**
- * getItemCount
- * @returns int
- */
- public int getItemCount() {
- return 0; // TODO
- } // getItemCount()
-
- /**
- * getItemAt
- * @param value0 TODO
- * @returns Object
- */
- public Object getItemAt(int value0) {
- return null; // TODO
- } // getItemAt()
-
- /**
- * createDefaultKeySelectionManager
- * @returns KeySelectionManager
- */
- protected KeySelectionManager createDefaultKeySelectionManager() {
- return null; // TODO
- } // createDefaultKeySelectionManager()
-
- /**
- * paramString
- * @returns String
- */
- protected String paramString() {
- return null; // TODO
- } // paramString()
+ /**
+ * The part of implementation of ListDataListener interface. This method is
+ * invoked when some items where added to the JComboBox's data model.
+ *
+ * @param event ListDataEvent describing the change
+ */
+ public void intervalAdded(ListDataEvent event)
+ {
+ // FIXME: Need to implement
+ repaint();
+ }
+
+ /**
+ * The part of implementation of ListDataListener interface. This method is
+ * invoked when some items where removed from the JComboBox's data model.
+ *
+ * @param event ListDataEvent describing the change.
+ */
+ public void intervalRemoved(ListDataEvent event)
+ {
+ // FIXME: Need to implement
+ repaint();
+ }
+
+ /**
+ * The part of implementation of ListDataListener interface. This method is
+ * invoked when contents of the JComboBox's data model changed.
+ *
+ * @param event ListDataEvent describing the change
+ */
+ public void contentsChanged(ListDataEvent event)
+ {
+ // if first and last index of the given ListDataEvent are both -1,
+ // then it indicates that selected item in the combo box data model
+ // have changed.
+ if (event.getIndex0() == -1 && event.getIndex1() == -1)
+ selectedItemChanged();
+ }
/**
- * getAccessibleContext
- * @returns AccessibleContext
+ * This method disables or enables JComboBox. If the JComboBox is enabled,
+ * then user is able to make item choice, otherwise if JComboBox is
+ * disabled then user is not able to make a selection.
+ *
+ * @param enabled if 'enabled' is true then enable JComboBox and disable it
*/
+ public void setEnabled(boolean enabled)
+ {
+ boolean oldEnabled = super.isEnabled();
+ if (enabled != oldEnabled)
+ {
+ super.setEnabled(enabled);
+ firePropertyChange(ENABLED_CHANGED_PROPERTY, oldEnabled,
+ (boolean) enabled);
+ }
+ }
+
+ /**
+ * This method initializes specified ComboBoxEditor to display given item.
+ *
+ * @param anEditor ComboBoxEditor to initialize
+ * @param anItem Item that should displayed in the specified editor
+ */
+ public void configureEditor(ComboBoxEditor anEditor, Object anItem)
+ {
+ anEditor.setItem(anItem);
+ }
+
+ /**
+ * This method hides combo box's popup whenever TAB key is pressed.
+ *
+ * @param e The KeyEvent indicating which key was pressed.
+ */
+ public void processKeyEvent(KeyEvent e)
+ {
+ }
+
+ /**
+ * This method always returns false to indicate that JComboBox itself is
+ * not focus traversable.
+ *
+ * @return false to indicate that JComboBox itself is not focus traversable.
+ *
+ * @deprecated
+ */
+ public boolean isFocusTraversable()
+ {
+ return false;
+ }
+
+ /**
+ * setKeySelectionManager
+ *
+ * @param aManager
+ */
+ public void setKeySelectionManager(KeySelectionManager aManager)
+ {
+ }
+
+ /**
+ * getKeySelectionManager
+ *
+ * @return JComboBox.KeySelectionManager
+ */
+ public KeySelectionManager getKeySelectionManager()
+ {
+ return null;
+ }
+
+ /**
+ * This method returns number of elements in this JComboBox
+ *
+ * @return int number of elements in this JComboBox
+ */
+ public int getItemCount()
+ {
+ return ((DefaultComboBoxModel) dataModel).getSize();
+ }
+
+ /**
+ * Returns elements located in the combo box at the given index.
+ *
+ * @param index index specifying location of the component to return.
+ *
+ * @return component in the combo box that is located in the given index.
+ */
+ public Object getItemAt(int index)
+ {
+ return ((MutableComboBoxModel) dataModel).getElementAt(index);
+ }
+
+ /**
+ * createDefaultKeySelectionManager
+ *
+ * @return KeySelectionManager
+ */
+ protected KeySelectionManager createDefaultKeySelectionManager()
+ {
+ return null;
+ }
+
+ /**
+ * A string that describes this JComboBox. Normally only used for debugging.
+ *
+ * @return A string describing this JComboBox
+ */
+ protected String paramString()
+ {
+ return "JComboBox";
+ }
+
public AccessibleContext getAccessibleContext()
{
if (accessibleContext == null)
@@ -797,74 +994,180 @@
return accessibleContext;
}
-
+
/**
- * addActionListener
- * @param listener TODO
+ * This methods adds specified ActionListener to this JComboBox.
+ *
+ * @param listener to add
*/
- public void addActionListener (ActionListener listener)
+ public void addActionListener(ActionListener listener)
{
- listenerList.add (ActionListener.class, listener);
+ listenerList.add(ActionListener.class, listener);
}
/**
- * removeActionListener
- * @param listener TODO
+ * This method removes specified ActionListener from this JComboBox.
+ *
+ * @param listener ActionListener
*/
- public void removeActionListener (ActionListener listener)
+ public void removeActionListener(ActionListener listener)
{
- listenerList.remove (ActionListener.class, listener);
+ listenerList.remove(ActionListener.class, listener);
}
/**
+ * This method returns array of ActionListeners that are registered with
+ * this JComboBox.
+ *
* @since 1.4
*/
public ActionListener[] getActionListeners()
{
- return (ActionListener[]) getListeners (ActionListener.class);
+ return (ActionListener[]) getListeners(ActionListener.class);
}
/**
- * addItemListener
- * @param listener TODO
+ * This method registers given ItemListener with this JComboBox
+ *
+ * @param listener to remove
*/
public void addItemListener(ItemListener listener)
{
- listenerList.add (ItemListener.class, listener);
+ listenerList.add(ItemListener.class, listener);
}
/**
- * removeItemListener
- * @param listener TODO
+ * This method unregisters given ItemListener from this JComboBox
+ *
+ * @param listener to remove
*/
public void removeItemListener(ItemListener listener)
{
- listenerList.remove (ItemListener.class, listener);
+ listenerList.remove(ItemListener.class, listener);
}
/**
+ * This method returns array of ItemListeners that are registered with this
+ * JComboBox.
+ *
* @since 1.4
*/
public ItemListener[] getItemListeners()
{
- return (ItemListener[]) getListeners (ItemListener.class);
+ return (ItemListener[]) getListeners(ItemListener.class);
}
- public void addPopupMenuListener (PopupMenuListener listener)
+ /**
+ * Adds PopupMenuListener to combo box to listen to the events fired by the
+ * combo box's popup menu containing its list of items
+ *
+ * @param listener to add
+ */
+ public void addPopupMenuListener(PopupMenuListener listener)
{
- listenerList.add (PopupMenuListener.class, listener);
+ listenerList.add(PopupMenuListener.class, listener);
}
- public void removePopupMenuListener (PopupMenuListener listener)
+ /**
+ * Removes PopupMenuListener to combo box to listen to the events fired by
+ * the combo box's popup menu containing its list of items
+ *
+ * @param listener to add
+ */
+ public void removePopupMenuListener(PopupMenuListener listener)
{
- listenerList.remove (PopupMenuListener.class, listener);
+ listenerList.remove(PopupMenuListener.class, listener);
}
/**
- * @since 1.4
+ * Returns array of PopupMenuListeners that are registered with combo box.
*/
public PopupMenuListener[] getPopupMenuListeners()
{
- return (PopupMenuListener[]) getListeners (PopupMenuListener.class);
+ return (PopupMenuListener[]) getListeners(PopupMenuListener.class);
+ }
+
+ /**
+ * AccessibleJComboBox
+ */
+ protected class AccessibleJComboBox extends AccessibleJComponent
+ implements AccessibleAction, AccessibleSelection
+ {
+ private static final long serialVersionUID = 8217828307256675666L;
+
+ protected AccessibleJComboBox()
+ {
+ }
+
+ public int getAccessibleChildrenCount()
+ {
+ return 0;
+ }
+
+ public Accessible getAccessibleChild(int value0)
+ {
+ return null;
+ }
+
+ public AccessibleSelection getAccessibleSelection()
+ {
+ return null;
+ }
+
+ public Accessible getAccessibleSelection(int value0)
+ {
+ return null;
+ }
+
+ public boolean isAccessibleChildSelected(int value0)
+ {
+ return false;
+ }
+
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.COMBO_BOX;
+ }
+
+ public AccessibleAction getAccessibleAction()
+ {
+ return null;
+ }
+
+ public String getAccessibleActionDescription(int value0)
+ {
+ return null;
+ }
+
+ public int getAccessibleActionCount()
+ {
+ return 0;
+ }
+
+ public boolean doAccessibleAction(int value0)
+ {
+ return false;
+ }
+
+ public int getAccessibleSelectionCount()
+ {
+ return 0;
+ }
+
+ public void addAccessibleSelection(int value0)
+ {
+ }
+
+ public void removeAccessibleSelection(int value0)
+ {
+ }
+
+ public void clearAccessibleSelection()
+ {
+ }
+
+ public void selectAllAccessibleSelection()
+ {
+ }
}
}
Index: javax/swing/JList.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JList.java,v
retrieving revision 1.16
diff -u -r1.16 JList.java
--- javax/swing/JList.java 22 Jul 2004 19:45:39 -0000 1.16
+++ javax/swing/JList.java 5 Sep 2004 11:27:02 -0000
@@ -588,6 +588,28 @@
return getUI().locationToIndex(this, r.getLocation());
}
+
+ /**
+ * Returns index of the cell to which specified location is closest to
+ * @param location for which to look for in the list
+ *
+ * @return index of the cell to which specified location is closest to.
+ */
+ public int locationToIndex(Point location) {
+ return getUI().locationToIndex(this, location);
+ }
+
+ /**
+ * Returns location of the cell located at the specified index in the list.
+ * @param index of the cell for which location will be determined
+ *
+ * @return location of the cell located at the specified index in the list.
+ */
+ public Point indexToLocation(int index){
+ //FIXME: Need to implement.
+ return null;
+ }
+
/**
* Returns the list index of the lower right or lower left corner of the
* address@hidden #visibleRect} property, depending on the address@hidden
Index: javax/swing/JPopupMenu.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JPopupMenu.java,v
retrieving revision 1.8
diff -u -r1.8 JPopupMenu.java
--- javax/swing/JPopupMenu.java 30 Jul 2004 20:21:19 -0000 1.8
+++ javax/swing/JPopupMenu.java 5 Sep 2004 11:27:02 -0000
@@ -144,6 +144,9 @@
/* Location of the popup */
private Point popupLocation;
+ /* Field indicating if popup menu is visible or not */
+ private boolean visible = false;
+
/* Bound Property indicating visibility of the popup menu*/
public static final String VISIBLE_CHANGED_PROPERTY = "visible";
@@ -564,7 +567,7 @@
*/
public boolean isVisible()
{
- return super.isVisible();
+ return visible;
}
/**
@@ -577,7 +580,7 @@
public void setVisible(boolean visible)
{
boolean old = isVisible();
- super.setVisible(visible);
+ this.visible = visible;
if (old != isVisible())
{
firePropertyChange(VISIBLE_CHANGED_PROPERTY, old, (boolean)
isVisible());
@@ -615,7 +618,7 @@
.getLayeredPane();
Point p = new Point(popupLocation.x, popupLocation.y);
SwingUtilities.convertPointFromScreen(p, layeredPane);
- popup.show(p.x, p.y, size.width, size.height);
+ popup.show(p.x, p.y, size.width, size.height);
}
else
{
Index: javax/swing/MutableComboBoxModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/MutableComboBoxModel.java,v
retrieving revision 1.2
diff -u -r1.2 MutableComboBoxModel.java
--- javax/swing/MutableComboBoxModel.java 12 Oct 2003 16:44:39 -0000
1.2
+++ javax/swing/MutableComboBoxModel.java 5 Sep 2004 11:27:03 -0000
@@ -38,40 +38,46 @@
package javax.swing;
/**
- * MutableComboBoxModel
- * @author Andrew Selkirk
- * @version 1.0
+ * MutableComboBoxModel is interface for data model that keeps track of the
+ * components data and provides methods to insert and remove elements from
+ * it. The Classes implementing this interface should fire appropriate
+ * events indicating the undergoing change in the data model.
+ *
+ * @author Andrew Selkirk
+ * @author Olga Rodimina
+ * @version 1.0
*/
-public interface MutableComboBoxModel extends ComboBoxModel {
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * addElement
- * @param object TODO
- */
- void addElement(Object object);
-
- /**
- * removeElementAt
- * @param index TODO
- */
- void removeElementAt(int index);
-
- /**
- * insertElementAt
- * @param object TODO
- * @param index TODO
- */
- void insertElementAt(Object object, int index);
-
- /**
- * removeElement
- * @param object TODO
- */
- void removeElement(Object object);
-
-
+public interface MutableComboBoxModel extends ComboBoxModel
+{
+ /**
+ * This method adds given object to its data model.
+ *
+ * @param object element to add to the data model.
+ */
+ void addElement(Object object);
+
+ /**
+ * This method removes elements located at the given index in the data
+ * model.
+ *
+ * @param index index specifying location of the element to remove.
+ */
+ void removeElementAt(int index);
+
+ /**
+ * This method inserts givent element to the data model, at the specified
+ * index.
+ *
+ * @param object element to insert
+ * @param index index specifying the position in the data model where the
+ * given element should be inserted.
+ */
+ void insertElementAt(Object object, int index);
+
+ /**
+ * This method removes given element from the data model
+ *
+ * @param element to remove.
+ */
+ void removeElement(Object object);
} // MutableComboBoxModel
Index: javax/swing/plaf/basic/BasicArrowButton.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicArrowButton.java,v
retrieving revision 1.5
diff -u -r1.5 BasicArrowButton.java
--- javax/swing/plaf/basic/BasicArrowButton.java 4 Sep 2004 20:31:20
-0000 1.5
+++ javax/swing/plaf/basic/BasicArrowButton.java 5 Sep 2004 11:27:03
-0000
@@ -163,7 +163,7 @@
/** The color the arrow is painted in if disabled and the bottom and
* right edges of the button. */
- private transient Color shadow = Color.BLACK;
+ private transient Color shadow = Color.gray;
/** The color the arrow is painted in if enabled and the bottom and
* right edges of the button. */
Index: javax/swing/plaf/basic/BasicComboBoxEditor.java
===================================================================
RCS file: javax/swing/plaf/basic/BasicComboBoxEditor.java
diff -N javax/swing/plaf/basic/BasicComboBoxEditor.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/plaf/basic/BasicComboBoxEditor.java 5 Sep 2004 11:27:03
-0000
@@ -0,0 +1,170 @@
+/* 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()
+ {
+ }
+ }
+}
Index: javax/swing/plaf/basic/BasicComboBoxRenderer.java
===================================================================
RCS file: javax/swing/plaf/basic/BasicComboBoxRenderer.java
diff -N javax/swing/plaf/basic/BasicComboBoxRenderer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/plaf/basic/BasicComboBoxRenderer.java 5 Sep 2004 11:27:03
-0000
@@ -0,0 +1,143 @@
+/* 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()
+ {
+ }
+ }
+}
Index: javax/swing/plaf/basic/BasicComboBoxUI.java
===================================================================
RCS file: javax/swing/plaf/basic/BasicComboBoxUI.java
diff -N javax/swing/plaf/basic/BasicComboBoxUI.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/plaf/basic/BasicComboBoxUI.java 5 Sep 2004 11:27:03 -0000
@@ -0,0 +1,1227 @@
+/* BasicComboBoxUI.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.Container;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.LayoutManager;
+import java.awt.Rectangle;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.EventListener;
+import javax.accessibility.Accessible;
+import javax.swing.CellRendererPane;
+import javax.swing.ComboBoxEditor;
+import javax.swing.ComboBoxModel;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+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.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
+import javax.swing.event.PopupMenuEvent;
+import javax.swing.event.PopupMenuListener;
+import javax.swing.plaf.ComboBoxUI;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicComboPopup;
+import javax.swing.plaf.basic.BasicGraphicsUtils;
+
+
+/**
+ * UI Delegate for JComboBox
+ *
+ * @author Olga Rodimina
+ */
+public class BasicComboBoxUI extends ComboBoxUI
+{
+ /**
+ * This arrow button that is displayed in the rigth side of JComboBox. This
+ * button is used to hide and show combo box's list of items
+ */
+ protected JButton arrowButton;
+
+ /**
+ * The combo box for which this UI delegate is for
+ */
+ protected JComboBox comboBox;
+
+ /**
+ * Component that is responsible for displaying/editting selected item of
+ * the combo box. By default JTextField is used as an editor for the
+ * JComboBox
+ */
+ protected Component editor;
+
+ /**
+ * Listener listening to focus events occuring in the JComboBox
+ */
+ protected FocusListener focusListener;
+
+ /**
+ * tells whether JComboBox currently has focus
+ */
+ protected boolean hasFocus;
+
+ /**
+ * Listener listening to item events fired by the JComboBox
+ */
+ protected ItemListener itemListener;
+
+ /**
+ * KeyListener listening to key events that occur while JComboBox has focus
+ */
+ protected KeyListener keyListener;
+
+ /**
+ * MouseListener listening to mouse events occuring in the combo box
+ */
+ private MouseListener mouseListener;
+
+ /**
+ * List used when rendering selected item of the combo box. The selection
+ * and foreground colors for combo box renderer are configured from this
+ * list
+ */
+ protected JList listBox;
+
+ /**
+ * ListDataListener listening to JComboBox model
+ */
+ protected ListDataListener listDataListener;
+
+ /**
+ * Popup list containing combo box's menu items
+ */
+ protected ComboPopup popup;
+ protected KeyListener popupKeyListener;
+ protected MouseListener popupMouseListener;
+ protected MouseMotionListener popupMouseMotionListener;
+
+ /**
+ * Listener listening to changes in the bound properties of JComboBox
+ */
+ protected PropertyChangeListener propertyChangeListener;
+
+ /**
+ * Colors that are used to render selected item in the combo box.
+ */
+ private Color shadow;
+ private Color darkShadow;
+ private Color highlight;
+ private Color lightHighlight;
+
+ /* Size of the largest item in the comboBox */
+ private Dimension largestItemSize;
+
+ // It seems that JComboBox doesn't have a border set explicitely. So we just
+ // paint the border everytime combo box is displayed.
+
+ /* border insets for this JComboBox*/
+ private static final Insets borderInsets = new Insets(2, 2, 2, 2);
+
+ // Width of the arrow button
+ private static int arrowButtonWidth = 15;
+
+ // FIXME: This fields aren't used anywhere at this moment.
+ protected Dimension cachedMinimumSize;
+ protected CellRendererPane currentValuePane;
+ protected boolean isMinimumSizeDirty;
+
+ /**
+ * Creates a new BasicComboBoxUI object.
+ */
+ public BasicComboBoxUI()
+ {
+ }
+
+ /**
+ * Factory method to create a BasicComboBoxUI for the given address@hidden
+ * JComponent}, which should be a address@hidden JComboBox}.
+ *
+ * @param c The address@hidden JComponent} a UI is being created for.
+ *
+ * @return A BasicComboBoxUI for the address@hidden JComponent}.
+ */
+ public static ComponentUI createUI(JComponent c)
+ {
+ return new BasicComboBoxUI();
+ }
+
+ /**
+ * This method installs the UI for the given JComponent.
+ *
+ * @param c The JComponent to install a UI for.
+ */
+ public void installUI(JComponent c)
+ {
+ super.installUI(c);
+
+ if (c instanceof JComboBox)
+ {
+ comboBox = (JComboBox) c;
+ comboBox.setOpaque(true);
+ comboBox.setLayout(createLayoutManager());
+ installDefaults();
+ installComponents();
+ installListeners();
+ installKeyboardActions();
+ }
+ }
+
+ /**
+ * This method uninstalls the UI.
+ *
+ * @param c The JComponent that is having this UI removed.
+ */
+ public void uninstallUI(JComponent c)
+ {
+ uninstallKeyboardActions();
+ uninstallListeners();
+ uninstallComponents();
+ uninstallDefaults();
+ comboBox = null;
+ }
+
+ /**
+ * This method installs the defaults that are defined in the Basic look and
+ * feel for this address@hidden JComboBox}.
+ */
+ protected void installDefaults()
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+
+ comboBox.setBackground(defaults.getColor("ComboBox.background"));
+ comboBox.setFont(defaults.getFont("ComboBox.font"));
+ comboBox.setForeground(defaults.getColor("ComboBox.foreground"));
+
+ // Set default color that should be used to to render selected item
+ // of the combo box.
+ shadow = defaults.getColor("Button.shadow");
+ darkShadow = defaults.getColor("Button.darkShadow");
+ lightHighlight = defaults.getColor("Button.light");
+ highlight = defaults.getColor("Button.highlight");
+ }
+
+ /**
+ * This method creates and installs the listeners for this UI.
+ */
+ protected void installListeners()
+ {
+ // install combo box's listeners
+ propertyChangeListener = createPropertyChangeListener();
+ comboBox.addPropertyChangeListener(propertyChangeListener);
+
+ focusListener = createFocusListener();
+ comboBox.addFocusListener(focusListener);
+
+ itemListener = createItemListener();
+ comboBox.addItemListener(itemListener);
+
+ keyListener = createKeyListener();
+ comboBox.addKeyListener(keyListener);
+
+ mouseListener = createMouseListener();
+ comboBox.addMouseListener(mouseListener);
+
+ // install listeners that listen to combo box model
+ listDataListener = createListDataListener();
+ comboBox.getModel().addListDataListener(listDataListener);
+
+ configureArrowButton();
+ }
+
+ /**
+ * This method uninstalls the defaults and sets any objects created during
+ * install to null
+ */
+ protected void uninstallDefaults()
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+
+ comboBox.setBackground(null);
+ comboBox.setFont(null);
+ comboBox.setForeground(null);
+
+ shadow = null;
+ darkShadow = null;
+ lightHighlight = null;
+ highlight = null;
+ }
+
+ /**
+ * Detaches all the listeners we attached in address@hidden
#installListeners}.
+ */
+ protected void uninstallListeners()
+ {
+ comboBox.removePropertyChangeListener(propertyChangeListener);
+ propertyChangeListener = null;
+
+ comboBox.removeFocusListener(focusListener);
+ focusListener = null;
+
+ comboBox.removeItemListener(itemListener);
+ itemListener = null;
+
+ comboBox.removeKeyListener(keyListener);
+ keyListener = null;
+
+ comboBox.removeMouseListener(mouseListener);
+ mouseListener = null;
+
+ comboBox.getModel().removeListDataListener(listDataListener);
+ listDataListener = null;
+
+ unconfigureArrowButton();
+ }
+
+ /**
+ * This method creates popup that will contain list of combo box's items
+ *
+ * @return popup containing list of combo box's items
+ */
+ protected ComboPopup createPopup()
+ {
+ return new BasicComboPopup(comboBox);
+ }
+
+ /**
+ * Creates KeyListener to listen to key events.
+ *
+ * @return KeyListener that listens to key events.
+ */
+ protected KeyListener createKeyListener()
+ {
+ return new KeyHandler();
+ }
+
+ /**
+ * This method create MouseListener that will listen to mouse event occuring
+ * in combo box.
+ *
+ * @return the MouseListener
+ */
+ private MouseListener createMouseListener()
+ {
+ return new MouseHandler();
+ }
+
+ /**
+ * This method create FocusListener that will listen to changes in this
+ * JComboBox's focus.
+ *
+ * @return theFocusListener
+ */
+ protected FocusListener createFocusListener()
+ {
+ return new FocusHandler();
+ }
+
+ /**
+ * This method create ListDataListener to listen to ComboBox's data model
+ *
+ * @return ListDataListener
+ */
+ protected ListDataListener createListDataListener()
+ {
+ return new ListDataHandler();
+ }
+
+ /**
+ * This method creates ItemListener that will listen to to the changes in
+ * the JComboBox's selection.
+ *
+ * @return the ItemListener
+ */
+ protected ItemListener createItemListener()
+ {
+ return new ItemHandler();
+ }
+
+ /**
+ * This method creates PropertyChangeListener to listen to the changes in
+ * the JComboBox's bound properties.
+ *
+ * @return the PropertyChangeListener
+ */
+ protected PropertyChangeListener createPropertyChangeListener()
+ {
+ return new PropertyChangeHandler();
+ }
+
+ /**
+ * This method returns layout manager for the combo box.
+ *
+ * @return layout manager for the combo box
+ */
+ protected LayoutManager createLayoutManager()
+ {
+ return new ComboBoxLayoutManager();
+ }
+
+ /**
+ * This method creates component that will be responsible for rendering the
+ * selected component in the combo box.
+ *
+ * @return render for the combo box
+ */
+ protected ListCellRenderer createRenderer()
+ {
+ return new BasicComboBoxRenderer();
+ }
+
+ /**
+ * Creates component that will be responsible for displaying/editting
+ * selected item in the combo box. This editor is used only when combo box
+ * is editable.
+ *
+ * @return component that will be responsible for displaying/editting
+ * selected item in the combo box.
+ */
+ protected ComboBoxEditor createEditor()
+ {
+ return new BasicComboBoxEditor();
+ }
+
+ /**
+ * This method installs components for this JComboBox. ArrowButton, main
+ * part of combo box (upper part) and popup list of items are created and
+ * configured here.
+ */
+ protected void installComponents()
+ {
+ // create and install arrow button
+ arrowButton = createArrowButton();
+
+ comboBox.add(arrowButton);
+
+ // Set list that will be used by BasicComboBoxRender
+ // in order to determine the right colors when rendering
+ listBox = new JList();
+
+ Color background = arrowButton.getBackground();
+ listBox.setBackground(background);
+ listBox.setSelectionBackground(background.darker());
+
+ Color foreground = arrowButton.getForeground();
+ listBox.setForeground(foreground);
+ listBox.setSelectionForeground(foreground);
+
+ // set editor and renderer for the combo box. Editor is used
+ // only if combo box becomes editable, otherwise renderer is used
+ // to paint the selected item; combobox is not editable by default.
+ comboBox.setRenderer(createRenderer());
+
+ comboBox.setEditor(createEditor());
+ editor = comboBox.getEditor().getEditorComponent();
+
+ // create drop down list of items
+ popup = createPopup();
+
+ comboBox.revalidate();
+ }
+
+ /**
+ * This method uninstalls components from this JComboBox
+ */
+ protected void uninstallComponents()
+ {
+ // uninstall arrow button
+ unconfigureArrowButton();
+ comboBox.remove(arrowButton);
+ arrowButton = null;
+
+ listBox = null;
+ popup = null;
+
+ comboBox.setRenderer(null);
+
+ comboBox.setEditor(null);
+ editor = null;
+ }
+
+ /**
+ * This method adds editor to the combo box
+ */
+ public void addEditor()
+ {
+ comboBox.add(editor);
+ }
+
+ /**
+ * This method removes editor from the combo box
+ */
+ public void removeEditor()
+ {
+ comboBox.remove(editor);
+ }
+
+ /**
+ * This method configures editor for this combo box.
+ */
+ protected void configureEditor()
+ {
+ // FIXME: Need to implement. Set font and add listeners.
+ }
+
+ /**
+ * This method removes all the listeners for the editor.
+ */
+ protected void unconfigureEditor()
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * This method adds listeners to the arrow button part of the combo box.
+ */
+ public void configureArrowButton()
+ {
+ arrowButton.addMouseListener(mouseListener);
+ }
+
+ /**
+ * This method removes listeners from the arrow button part of the combo
+ * box.
+ */
+ public void unconfigureArrowButton()
+ {
+ arrowButton.removeMouseListener(mouseListener);
+ }
+
+ /**
+ * This method create arrow button for this JComboBox. Arrow button is
+ * responsible for displaying / hiding drop down list of items when it is
+ * clicked.
+ *
+ * @return JButton arrow button for this JComboBox.
+ */
+ protected JButton createArrowButton()
+ {
+ return new BasicArrowButton(BasicArrowButton.SOUTH);
+ }
+
+ /**
+ * This method checks if popup part of the combo box is visible on the
+ * screen
+ *
+ * @param c The JComboBox to check
+ *
+ * @return true if popup part of the JComboBox is visible and false
+ * otherwise.
+ */
+ public boolean isPopupVisible(JComboBox c)
+ {
+ return popup.isVisible();
+ }
+
+ /**
+ * Displays/Hides JComboBox's list of items on the screen.
+ *
+ * @param c The combo box, for which list of items should be
+ * displayed/hidden
+ * @param v true if show popup part of the jcomboBox and false to hide.
+ */
+ public void setPopupVisible(JComboBox c, boolean v)
+ {
+ if (v)
+ popup.show();
+ else
+ popup.hide();
+ }
+
+ /**
+ * JComboBox is focus traversable if it is editable and not otherwise.
+ *
+ * @param c combo box for which to check whether it is focus traversable
+ *
+ * @return true if focus tranversable and false otherwise
+ */
+ public boolean isFocusTraversable(JComboBox c)
+ {
+ if (comboBox.isEditable())
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Paints given menu item using specified graphics context
+ *
+ * @param g The graphics context used to paint this combo box
+ * @param c comboBox which needs to be painted.
+ */
+ public void paint(Graphics g, JComponent c)
+ {
+ if (c instanceof JComboBox)
+ {
+ JComboBox cb = (JComboBox) c;
+
+ paintBorder(g, comboBox.getBounds(), hasFocus);
+
+ Rectangle rect = rectangleForCurrentValue();
+ paintCurrentValueBackground(g, rect, hasFocus);
+ paintCurrentValue(g, rect, hasFocus);
+ }
+ }
+
+ private void paintBorder(Graphics g, Rectangle bounds, boolean hasFocus)
+ {
+ int x = 0;
+ int y = 0;
+ int width = bounds.width;
+ int height = bounds.height;
+
+ Color oldColor = g.getColor();
+
+ if (! arrowButton.getModel().isPressed())
+ BasicGraphicsUtils.drawEtchedRect(g, x, y, width, height, Color.gray,
+ Color.white, Color.gray, Color.white);
+ else
+ {
+ g.setColor(darkShadow);
+ g.drawRect(x, y, width, height);
+ g.setColor(shadow);
+ g.drawRect(x + 1, y + 1, width - 3, height - 3);
+ }
+ g.setColor(oldColor);
+ }
+
+ /**
+ * Returns preferred size for the given menu item.
+ *
+ * @param c comboBox for which to get preferred size
+ *
+ * @return $Dimension$ preferred size for the given combo box
+ */
+ public Dimension getPreferredSize(JComponent c)
+ {
+ // return null to indicate that combo box's layout will determin its
+ // preferred size
+ return null;
+ }
+
+ /**
+ * This method returns the minimum size for this address@hidden JComboBox}
for this
+ * look and feel.
+ *
+ * @param c The address@hidden JComponent} to find the minimum size for.
+ *
+ * @return The dimensions of the minimum size.
+ */
+ public Dimension getMinimumSize(JComponent c)
+ {
+ return null;
+ }
+
+ /**
+ * This method returns the maximum size for this address@hidden JComboBox}
for this
+ * look and feel.
+ *
+ * @param c The address@hidden JComponent} to find the maximum size for
+ *
+ * @return The dimensions of the minimum size.
+ */
+ public Dimension getMaximumSize(JComponent c)
+ {
+ return null;
+ }
+
+ public int getAccessibleChildrenCount(JComponent c)
+ {
+ // FIXME: Need to implement
+ return 0;
+ }
+
+ public Accessible getAccessibleChild(JComponent c, int i)
+ {
+ // FIXME: Need to implement
+ return null;
+ }
+
+ /**
+ * Returns true if the specified key is a navigation key and false otherwise
+ *
+ * @param keyCode a key for which to check whether it is navigation key or
+ * not.
+ *
+ * @return true if the specified key is a navigation key and false otherwis
+ */
+ protected boolean isNavigationKey(int keyCode)
+ {
+ return false;
+ }
+
+ /**
+ * This method selects next possible item relative to the current selection
+ * to be next selected item in the combo box.
+ */
+ protected void selectNextPossibleValue()
+ {
+ int index = comboBox.getSelectedIndex();
+ if (index != comboBox.getItemCount() - 1)
+ comboBox.setSelectedIndex(index + 1);
+ }
+
+ /**
+ * This method selects previous item relative to current selection to be
+ * next selected item.
+ */
+ protected void selectPreviousPossibleValue()
+ {
+ int index = comboBox.getSelectedIndex();
+ if (index != 0)
+ comboBox.setSelectedIndex(index - 1);
+ }
+
+ /**
+ * This method displays combo box popup if the popup is not currently shown
+ * on the screen and hides it if it is currently shown
+ */
+ protected void toggleOpenClose()
+ {
+ setPopupVisible(comboBox, ! isPopupVisible(comboBox));
+ }
+
+ /**
+ * This method returns bounds in which comboBox's selected Item will be
+ * displayed
+ *
+ * @return rectangle bounds in which comboBox's selected Item will be
+ * displayed
+ */
+ protected Rectangle rectangleForCurrentValue()
+ {
+ Rectangle cbBounds = comboBox.getBounds();
+
+ // Subtract width or the arrow button and border insets
+ Rectangle rectForCurrentValue = new Rectangle(cbBounds.x
+ + borderInsets.left,
+ cbBounds.y
+ + borderInsets.top,
+ cbBounds.width
+ - arrowButtonWidth
+ - borderInsets.left
+ - borderInsets.right,
+ cbBounds.height
+ - borderInsets.top
+ - borderInsets.bottom);
+
+ return rectForCurrentValue;
+ }
+
+ /**
+ * This method returns insets of the current border.
+ *
+ * @return Insets representing space between combo box and its border
+ */
+ protected Insets getInsets()
+ {
+ return new Insets(0, 0, 0, 0);
+ }
+
+ /**
+ * This method paints currently selected value in the main part of the combo
+ * box (part without popup).
+ *
+ * @param g graphics context
+ * @param bounds Rectangle representing the size of the area in which
+ * selected item should be drawn
+ * @param hasFocus true if combo box has focus and false otherwise
+ */
+ public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
+ {
+ if (! comboBox.isEditable())
+ {
+ Object currentValue = comboBox.getSelectedItem();
+ boolean isPressed = arrowButton.getModel().isPressed();
+ if (currentValue != null)
+ {
+ Component comp = comboBox.getRenderer()
+ .getListCellRendererComponent(listBox,
+ currentValue,
+ -1,
+ isPressed,
+ isPressed);
+ if (! comboBox.isEnabled())
+ comp.setEnabled(false);
+
+ g.translate(borderInsets.left, borderInsets.top);
+ comp.setBounds(0, 0, bounds.width, bounds.height);
+ comp.paint(g);
+ g.translate(-borderInsets.left, -borderInsets.top);
+ }
+ comboBox.revalidate();
+ }
+ else
+ comboBox.getEditor().setItem(comboBox.getSelectedItem());
+ }
+
+ /**
+ * This method paints background of part of the combo box, where currently
+ * selected value is displayed. If the combo box has focus this method
+ * should also paint focus rectangle around the combo box.
+ *
+ * @param g graphics context
+ * @param bounds Rectangle representing the size of the largest item in the
+ * comboBox
+ * @param hasFocus true if combo box has fox and false otherwise
+ */
+ public void paintCurrentValueBackground(Graphics g, Rectangle bounds,
+ boolean hasFocus)
+ {
+ // background is painted by renderer, so it seems that nothing
+ // should be done here.
+ }
+
+ /**
+ * Returns default size for the combo box that doesn't contain any elements
+ * in it
+ *
+ * @return Default size of the combo box with no elements in it.
+ */
+ protected Dimension getDefaultSize()
+ {
+ return new Dimension(6, 17);
+ }
+
+ /**
+ * Returns size of the largest item in the combo box. This size will be the
+ * size of the combo box, not including the arrowButton.
+ *
+ * @return dimensions of the largest item in the combo box.
+ */
+ protected Dimension getLargestItemSize()
+ {
+ ComboBoxModel model = comboBox.getModel();
+ int numItems = model.getSize();
+
+ // if combo box doesn't have any items then simply
+ // return its default size
+ if (numItems == 0)
+ {
+ largestItemSize = getDefaultSize();
+ return largestItemSize;
+ }
+
+ Dimension size = new Dimension(0, 0);
+
+ // ComboBox's display size should be equal to the
+ // size of the largest item in the combo box.
+ ListCellRenderer renderer = comboBox.getRenderer();
+
+ for (int i = 0; i < numItems; i++)
+ {
+ Object item = model.getElementAt(i);
+ String s = item.toString();
+ Component comp = renderer.getListCellRendererComponent(listBox, item,
+ -1, false,
false);
+
+ if (comp.getPreferredSize().getWidth() > size.getWidth())
+ size = comp.getPreferredSize();
+ }
+
+ largestItemSize = size;
+ return largestItemSize;
+ }
+
+ /**
+ * This method installs the keyboard actions for the JComboBox as specified
+ * by the look and feel.
+ */
+ protected void installKeyboardActions()
+ {
+ // FIXME: Need to implement.
+ }
+
+ /**
+ * This method uninstalls the keyboard actions for the JComboBox there were
+ * installed by in address@hidden #installListeners}.
+ */
+ protected void uninstallKeyboardActions()
+ {
+ // FIXME: Need to implement.
+ }
+
+ /**
+ * This class is Layout Manager for this combo box.
+ */
+ public class ComboBoxLayoutManager extends Object implements LayoutManager
+ {
+ /**
+ * Creates a new ComboBoxLayoutManager object.
+ */
+ public ComboBoxLayoutManager()
+ {
+ }
+
+ public void addLayoutComponent(String name, Component comp)
+ {
+ // Do nothing
+ }
+
+ public void removeLayoutComponent(Component comp)
+ {
+ // Do nothing
+ }
+
+ /**
+ * Returns preferred layout size of the JComboBox.
+ *
+ * @param parent Container for which preferred size should be calculated
+ *
+ * @return preferred size for the given container
+ */
+ public Dimension preferredLayoutSize(Container parent)
+ {
+ Dimension d = new Dimension(0, 0);
+
+ if (largestItemSize == null)
+ largestItemSize = getLargestItemSize();
+
+ // add size for the area that will display selected item
+ d.width += largestItemSize.getWidth();
+ d.height += largestItemSize.getHeight();
+
+ // add size of the arrow button
+ d.width += arrowButtonWidth;
+
+ // add width and height of the border
+ d.width += borderInsets.left + borderInsets.right;
+ d.height += borderInsets.left + borderInsets.right;
+
+ // Add combo box's insets
+ Insets insets = parent.getInsets();
+ d.width += insets.left + insets.right;
+ d.width += insets.left + insets.right;
+
+ return d;
+ }
+
+ public Dimension minimumLayoutSize(Container parent)
+ {
+ return preferredLayoutSize(parent);
+ }
+
+ /**
+ * This method layouts out the components in the container. It puts arrow
+ * button right end part of the comboBox. If the comboBox is editable
+ * then editor is placed to the left of arrow button, starting from the
+ * beginning.
+ *
+ * @param parent Container that should be layed out.
+ */
+ public void layoutContainer(Container parent)
+ {
+ // Position editor component to the left of arrow button if combo box is
+ // editable
+ int editorWidth = comboBox.getBounds().width - arrowButtonWidth - 2;
+
+ if (comboBox.isEditable())
+ editor.setBounds(borderInsets.left, borderInsets.top, editorWidth,
+ comboBox.getBounds().height - borderInsets.left
+ - borderInsets.top);
+
+ arrowButton.setBounds(editorWidth, 2, arrowButtonWidth,
+ comboBox.getBounds().height - 4);
+ comboBox.revalidate();
+ }
+ }
+
+ /**
+ * This class handles focus changes occuring in the combo box. This class is
+ * responsible for repainting combo box whenever focus is gained or lost
+ * and also for hiding popup list of items whenever combo box loses its
+ * focus.
+ */
+ public class FocusHandler extends Object implements FocusListener
+ {
+ /**
+ * Creates a new FocusHandler object.
+ */
+ public FocusHandler()
+ {
+ }
+
+ /**
+ * This mehtod is invoked when combo box gains focus. It repaints main
+ * part of combo box accordingally.
+ *
+ * @param e the FocusEvent
+ */
+ public void focusGained(FocusEvent e)
+ {
+ hasFocus = true;
+ comboBox.repaint();
+ }
+
+ /**
+ * This method is invoked when combo box loses focus It repaint main part
+ * of combo box accordingally and hides popup list of items.
+ *
+ * @param e the FocusEvent
+ */
+ public void focusLost(FocusEvent e)
+ {
+ hasFocus = false;
+ comboBox.repaint();
+ popup.hide();
+ }
+ }
+
+ /**
+ * This class handles ItemEvent fired by the JComboBox when its selected
+ * item changes.
+ */
+ public class ItemHandler extends Object implements ItemListener
+ {
+ /**
+ * Creates a new ItemHandler object.
+ */
+ public ItemHandler()
+ {
+ }
+
+ /**
+ * This method is invoked when selected item becomes deselected or when
+ * new item becomes selected.
+ *
+ * @param e the ItemEvent representing item's state change.
+ */
+ public void itemStateChanged(ItemEvent e)
+ {
+ comboBox.repaint();
+ }
+ }
+
+ /**
+ * KeyHandler handles key events occuring while JComboBox has focus.
+ */
+ public class KeyHandler extends KeyAdapter
+ {
+ public KeyHandler()
+ {
+ }
+
+ /*
+ * This method is invoked whenever key is pressed while JComboBox is in
+ * focus.
+ */
+ public void keyPressed(KeyEvent e)
+ {
+ // FIXME: This method calls JComboBox.selectWithKeyChar if the key that
was
+ // pressed is not a navigation key.
+ }
+ }
+
+ /**
+ * This class handles to the changes occuring in the JComboBox's data model
+ */
+ public class ListDataHandler extends Object implements ListDataListener
+ {
+ /**
+ * Creates a new ListDataHandler object.
+ */
+ public ListDataHandler()
+ {
+ }
+
+ /**
+ * This method is invoked content's of JComboBox's data model are changed
+ *
+ * @param e ListDataEvent describing the change.
+ */
+ public void contentsChanged(ListDataEvent e)
+ {
+ // if the item is selected or deselected
+ }
+
+ /**
+ * This method is invoked when items were added to the JComboBox's data
+ * model.
+ *
+ * @param e ListDataEvent describing the change.
+ */
+ public void intervalAdded(ListDataEvent e)
+ {
+ // must determine if the size of the combo box should change
+ int start = e.getIndex0();
+ int end = e.getIndex1();
+
+ ComboBoxModel model = comboBox.getModel();
+ ListCellRenderer renderer = comboBox.getRenderer();
+
+ if (largestItemSize == null)
+ largestItemSize = new Dimension(0, 0);
+
+ for (int i = start - 1; i < end; i++)
+ {
+ Object item = model.getElementAt(i);
+ Component comp = renderer.getListCellRendererComponent(new JList(),
+ item, -1,
+ false, false);
+ if (comp.getPreferredSize().getWidth() > largestItemSize.getWidth())
+ largestItemSize = comp.getPreferredSize();
+ }
+ }
+
+ /**
+ * This method is invoked when items were removed from the JComboBox's
+ * data model.
+ *
+ * @param e ListDataEvent describing the change.
+ */
+ public void intervalRemoved(ListDataEvent e)
+ {
+ // must determine if the size of the combo box should change
+ // FIXME: need to implement
+ }
+ }
+
+ /**
+ * This class handles PropertyChangeEvents fired by JComboBox.
+ */
+ public class PropertyChangeHandler extends Object
+ implements PropertyChangeListener
+ {
+ public PropertyChangeHandler()
+ {
+ }
+
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ if (e.getPropertyName().equals(JComboBox.ENABLED_CHANGED_PROPERTY))
+ {
+ // disable arrow button
+ arrowButton.setEnabled(comboBox.isEnabled());
+
+ if (comboBox.isEditable())
+ comboBox.getEditor().getEditorComponent().setEnabled(comboBox
+ .isEnabled());
+ }
+ else if (e.getPropertyName().equals(JComboBox.EDITABLE_CHANGED_PROPERTY))
+ {
+ if (comboBox.isEditable())
+ {
+ configureEditor();
+ addEditor();
+ }
+ else
+ {
+ unconfigureEditor();
+ removeEditor();
+ }
+
+ comboBox.revalidate();
+ comboBox.repaint();
+ }
+
+ // FIXME: Need to handle changes in other bound properties.
+ }
+ }
+
+ /**
+ * MouseHandler listens to mouse events occuring in the combo box. This
+ * class is responsible for repainting this JComboBox whenever the mouse is
+ * being pressed or released over it.
+ */
+ private class MouseHandler extends MouseAdapter
+ {
+ /**
+ * This method is invoked when mouse is pressed over the combo box. It
+ * repaints the combo box accordinglly
+ *
+ * @param e the MouseEvent
+ */
+ public void mousePressed(MouseEvent e)
+ {
+ if (comboBox.isEnabled())
+ {
+ if (e.getSource() instanceof JComboBox)
+ {
+ arrowButton.getModel().setPressed(true);
+ arrowButton.getModel().setArmed(true);
+ }
+
+ comboBox.repaint();
+
+ if (e.getSource() instanceof BasicArrowButton)
+ toggleOpenClose();
+ }
+ }
+
+ /**
+ * This method is invoked when mouse is released over the combo box. It
+ * repaints the combo box accordinglly
+ *
+ * @param e the MouseEvent
+ */
+ public void mouseReleased(MouseEvent e)
+ {
+ if (comboBox.isEnabled())
+ {
+ if (e.getSource() instanceof JComboBox)
+ {
+ arrowButton.getModel().setPressed(false);
+ arrowButton.getModel().setArmed(false);
+ }
+
+ comboBox.repaint();
+ }
+ }
+ }
+}
Index: javax/swing/plaf/basic/BasicComboPopup.java
===================================================================
RCS file: javax/swing/plaf/basic/BasicComboPopup.java
diff -N javax/swing/plaf/basic/BasicComboPopup.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/plaf/basic/BasicComboPopup.java 5 Sep 2004 11:27:03 -0000
@@ -0,0 +1,933 @@
+/* BasicComboPopup.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.Dimension;
+import java.awt.Rectangle;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionAdapter;
+import java.awt.event.MouseMotionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import javax.swing.ComboBoxModel;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.ListCellRenderer;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingConstants;
+import javax.swing.Timer;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.PopupMenuEvent;
+import javax.swing.event.PopupMenuListener;
+
+
+/**
+ * UI Delegate for ComboPopup
+ *
+ * @author Olga Rodimina
+ */
+public class BasicComboPopup extends JPopupMenu implements ComboPopup
+{
+ protected Timer autoscrollTimer;
+
+ /**
+ * ComboBox associated with this popup
+ */
+ protected JComboBox comboBox;
+
+ /*
+ * FIXME: Document fields below
+ */
+ protected boolean hasEntered;
+ protected boolean isAutoScrolling;
+
+ /**
+ * ItemListener listening to the selection changes in the combo box
+ */
+ protected ItemListener itemListener;
+
+ /**
+ * This listener is not used
+ */
+ protected KeyListener keyListener;
+
+ /**
+ * JList which is used to display item is the combo box
+ */
+ protected JList list;
+
+ /**
+ * This listener is not used
+ */
+ protected ListDataListener listDataListener;
+
+ /**
+ * MouseListener listening to mouse events occuring in the combo box's
+ * list.
+ */
+ protected MouseListener listMouseListener;
+
+ /**
+ * MouseMotionListener listening to mouse motion events occuring in the
+ * combo box's list
+ */
+ protected MouseMotionListener listMouseMotionListener;
+
+ /**
+ * This listener is not used
+ */
+ protected ListSelectionListener listSelectionListener;
+
+ /**
+ * MouseListener listening to mouse events occuring in the combo box
+ */
+ protected MouseListener mouseListener;
+
+ /**
+ * MouseMotionListener listening to mouse motion events occuring in the
+ * combo box
+ */
+ protected MouseMotionListener mouseMotionListener;
+
+ /**
+ * PropertyChangeListener listening to changes occuring in the bound
+ * properties of the combo box
+ */
+ protected PropertyChangeListener propertyChangeListener;
+
+ /*
+ * FIXME: Document fields below
+ */
+ protected static int SCROLL_DOWN = 1;
+ protected static int SCROLL_UP = 0;
+ protected int scrollDirection;
+
+ /**
+ * JScrollPane that contains list portion of the combo box
+ */
+ protected JScrollPane scroller;
+
+ /**
+ * This field is not used
+ */
+ protected boolean valueIsAdjusting;
+
+ /**
+ * Creates a new BasicComboPopup object.
+ *
+ * @param comboBox the combo box with which this popup should be associated
+ */
+ public BasicComboPopup(JComboBox comboBox)
+ {
+ this.comboBox = comboBox;
+ installComboBoxListeners();
+
+ // initialize list that will be used to display elements of the combo box
+ this.list = createList();
+ ((JLabel)
list.getCellRenderer()).setHorizontalAlignment(SwingConstants.LEFT);
+ configureList();
+
+ // initialize scroller. Add list to the scroller.
+ scroller = createScroller();
+ configureScroller();
+
+ // add scroller with list inside of it to JPopupMenu
+ super.add(scroller);
+
+ setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled());
+ }
+
+ /**
+ * This method displays drow down list of combo box items on the screen.
+ */
+ public void show()
+ {
+ Rectangle cbBounds = comboBox.getBounds();
+
+ // popup should have same width as the comboBox and should be hight anough
+ // to display number of rows equal to 'maximumRowCount' property
+ int popupHeight = getPopupHeightForRowCount(comboBox.getMaximumRowCount())
+ + 4;
+
+ super.setPopupSize(cbBounds.width, popupHeight);
+
+ // location specified is relative to comboBox
+ super.show(comboBox, 0, cbBounds.height);
+ }
+
+ /**
+ * This method hides drop down list of items
+ */
+ public void hide()
+ {
+ super.setVisible(false);
+ }
+
+ /**
+ * Return list cointaining JComboBox's items
+ *
+ * @return list cointaining JComboBox's items
+ */
+ public JList getList()
+ {
+ return list;
+ }
+
+ /**
+ * Returns MouseListener that is listening to mouse events occuring in the
+ * combo box.
+ *
+ * @return MouseListener
+ */
+ public MouseListener getMouseListener()
+ {
+ return mouseListener;
+ }
+
+ /**
+ * Returns MouseMotionListener that is listening to mouse motion events
+ * occuring in the combo box.
+ *
+ * @return MouseMotionListener
+ */
+ public MouseMotionListener getMouseMotionListener()
+ {
+ return mouseMotionListener;
+ }
+
+ /**
+ * Returns KeyListener listening to key events occuring in the combo box.
+ * This method returns null because KeyHandler is not longer used.
+ *
+ * @return KeyListener
+ */
+ public KeyListener getKeyListener()
+ {
+ return keyListener;
+ }
+
+ /**
+ * This method uninstalls the UI for the given JComponent.
+ */
+ public void uninstallingUI()
+ {
+ uninstallComboBoxModelListeners(comboBox.getModel());
+
+ uninstallListeners();
+ uninstallKeyboardActions();
+ }
+
+ /**
+ * This method uninstalls listeners that were listening to changes occuring
+ * in the comb box's data model
+ *
+ * @param model data model for the combo box from which to uninstall
+ * listeners
+ */
+ protected void uninstallComboBoxModelListeners(ComboBoxModel model)
+ {
+ model.removeListDataListener(listDataListener);
+ }
+
+ /**
+ * This method uninstalls keyboard actions installed by the UI.
+ */
+ protected void uninstallKeyboardActions()
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * This method fires PopupMenuEvent indicating that combo box's popup list
+ * of items will become visible
+ */
+ protected void firePopupMenuWillBecomeVisible()
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * This method fires PopupMenuEvent indicating that combo box's popup list
+ * of items will become invisible.
+ */
+ protected void firePopupMenuWillBecomeInvisible()
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * This method fires PopupMenuEvent indicating that combo box's popup list
+ * of items was closed without selection.
+ */
+ protected void firePopupMenuCanceled()
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * Creates MouseListener to listen to mouse events occuring in the combo
+ * box. Note that this listener doesn't listen to mouse events occuring in
+ * the popup portion of the combo box, it only listens to main combo box
+ * part.
+ *
+ * @return new MouseMotionListener that listens to mouse events occuring in
+ * the combo box
+ */
+ protected MouseListener createMouseListener()
+ {
+ return new InvocationMouseHandler();
+ }
+
+ /**
+ * Create Mouse listener that listens to mouse dragging events occuring in
+ * the combo box. This listener is responsible for changing the selection
+ * in the combo box list to the component over which mouse is being
+ * currently dragged
+ *
+ * @return new MouseMotionListener that listens to mouse dragging events
+ * occuring in the combo box
+ */
+ protected MouseMotionListener createMouseMotionListener()
+ {
+ return new InvocationMouseMotionHandler();
+ }
+
+ /**
+ * KeyListener created in this method is not used anymore.
+ *
+ * @return KeyListener that does nothing
+ */
+ protected KeyListener createKeyListener()
+ {
+ return new InvocationKeyHandler();
+ }
+
+ /**
+ * ListSelectionListener created in this method is not used anymore
+ *
+ * @return ListSelectionListener that does nothing
+ */
+ protected ListSelectionListener createListSelectionListener()
+ {
+ return new ListSelectionHandler();
+ }
+
+ /**
+ * Creates ListDataListener. This method returns null, because
+ * ListDataHandler class is obsolete and is no longer used.
+ *
+ * @return null
+ */
+ protected ListDataListener createListDataListener()
+ {
+ return null;
+ }
+
+ /**
+ * This method creates ListMouseListener to listen to mouse events occuring
+ * in the combo box's item list.
+ *
+ * @return MouseListener to listen to mouse events occuring in the combo
+ * box's items list.
+ */
+ protected MouseListener createListMouseListener()
+ {
+ return new ListMouseHandler();
+ }
+
+ /**
+ * Creates ListMouseMotionlistener to listen to mouse motion events occuring
+ * in the combo box's list. This listener is responsible for highlighting
+ * items in the list when mouse is moved over them.
+ *
+ * @return MouseMotionListener that handles mouse motion events occuring in
+ * the list of the combo box.
+ */
+ protected MouseMotionListener createListMouseMotionListener()
+ {
+ return new ListMouseMotionHandler();
+ }
+
+ /**
+ * Creates PropertyChangeListener to handle changes in the JComboBox's bound
+ * properties.
+ *
+ * @return PropertyChangeListener to handle changes in the JComboBox's bound
+ * properties.
+ */
+ protected PropertyChangeListener createPropertyChangeListener()
+ {
+ return new PropertyChangeHandler();
+ }
+
+ /**
+ * Creates new ItemListener that will listen to ItemEvents occuring in the
+ * combo box.
+ *
+ * @return ItemListener to listen to ItemEvents occuring in the combo box.
+ */
+ protected ItemListener createItemListener()
+ {
+ return new ItemHandler();
+ }
+
+ /**
+ * Creates JList that will be used to display items in the combo box.
+ *
+ * @return JList that will be used to display items in the combo box.
+ */
+ protected JList createList()
+ {
+ JList l = new JList(comboBox.getModel());
+ l.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
+ return l;
+ }
+
+ /**
+ * This method configures the list of comboBox's items by setting default
+ * properties and installing listeners.
+ */
+ protected void configureList()
+ {
+ list.setModel(comboBox.getModel());
+
+ if (comboBox.getItemCount() < comboBox.getMaximumRowCount())
+ list.setVisibleRowCount(comboBox.getItemCount());
+ else
+ list.setVisibleRowCount(comboBox.getMaximumRowCount());
+ installListListeners();
+ }
+
+ /**
+ * This method installs list listeners.
+ */
+ protected void installListListeners()
+ {
+ // mouse listener listening to mouse events occuring in the
+ // combo box's list of items.
+ listMouseListener = createListMouseListener();
+ list.addMouseListener(listMouseListener);
+
+ // mouse listener listening to mouse motion events occuring in the
+ // combo box's list of items
+ listMouseMotionListener = createListMouseMotionListener();
+ list.addMouseMotionListener(listMouseMotionListener);
+
+ listSelectionListener = createListSelectionListener();
+ list.addListSelectionListener(listSelectionListener);
+ }
+
+ /**
+ * This method creates scroll pane that will contain the list of comboBox's
+ * items inside of it.
+ *
+ * @return JScrollPane
+ */
+ protected JScrollPane createScroller()
+ {
+ return new JScrollPane();
+ }
+
+ /**
+ * This method configures scroll pane to contain list of comboBox's items
+ */
+ protected void configureScroller()
+ {
+ scroller.getViewport().setView(list);
+
scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ }
+
+ /**
+ * This method configures popup menu that will be used to display Scrollpane
+ * with list of items inside of it.
+ */
+ protected void configurePopup()
+ {
+ // FIXME: Need to implement
+ }
+
+ /*
+ * This method installs listeners that will listen to changes occuring
+ * in the combo box.
+ */
+ protected void installComboBoxListeners()
+ {
+ // mouse listener that listens to mouse event in combo box
+ mouseListener = createMouseListener();
+ comboBox.addMouseListener(mouseListener);
+
+ // mouse listener that listens to mouse dragging events in the combo box
+ mouseMotionListener = createMouseMotionListener();
+ comboBox.addMouseMotionListener(mouseMotionListener);
+
+ // item listener listenening to selection events in the combo box
+ itemListener = createItemListener();
+ comboBox.addItemListener(itemListener);
+
+ propertyChangeListener = createPropertyChangeListener();
+ comboBox.addPropertyChangeListener(propertyChangeListener);
+ }
+
+ /**
+ * This method installs listeners that will listen to changes occuring in
+ * the comb box's data model
+ *
+ * @param model data model for the combo box for which to install listeners
+ */
+ protected void installComboBoxModelListeners(ComboBoxModel model)
+ {
+ // list data listener to listen for ListDataEvents in combo box.
+ // This listener is now obsolete and nothing is done here
+ listDataListener = createListDataListener();
+ comboBox.getModel().addListDataListener(listDataListener);
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ protected void installKeyboardActions()
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * This method always returns false to indicate that items in the combo box
+ * list are not focus traversable.
+ *
+ * @return false
+ */
+ public boolean isFocusTraversable()
+ {
+ return false;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param direction DOCUMENT ME!
+ */
+ protected void startAutoScrolling(int direction)
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ protected void stopAutoScrolling()
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ protected void autoScrollUp()
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ protected void autoScrollDown()
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * This method helps to delegate focus to the right component in the
+ * JComboBox. If the comboBox is editable then focus is sent to
+ * ComboBoxEditor, otherwise it is delegated to JComboBox.
+ *
+ * @param e MouseEvent
+ */
+ protected void delegateFocus(MouseEvent e)
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * This method displays combo box popup if the popup is not currently shown
+ * on the screen and hides it if it is currently visible
+ */
+ protected void togglePopup()
+ {
+ if (BasicComboPopup.this.isVisible())
+ hide();
+ else
+ show();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ protected MouseEvent convertMouseEvent(MouseEvent e)
+ {
+ return null;
+ }
+
+ /**
+ * Returns required height of the popup such that number of items visible in
+ * it are equal to the maximum row count. By default
+ * comboBox.maximumRowCount=8
+ *
+ * @param maxRowCount number of maximum visible rows in the combo box's
+ * popup list of items
+ *
+ * @return height of the popup required to fit number of items equal to
+ * JComboBox.maximumRowCount.
+ */
+ protected int getPopupHeightForRowCount(int maxRowCount)
+ {
+ int totalHeight = 0;
+ ListCellRenderer rend = list.getCellRenderer();
+
+ if (comboBox.getItemCount() < maxRowCount)
+ maxRowCount = comboBox.getItemCount();
+
+ for (int i = 0; i < maxRowCount; i++)
+ {
+ Component comp = rend.getListCellRendererComponent(list,
+ list.getModel()
+ .getElementAt(i),
+ -1, false, false);
+ Dimension dim = comp.getPreferredSize();
+ totalHeight += dim.height;
+ }
+
+ return totalHeight;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param px DOCUMENT ME!
+ * @param py DOCUMENT ME!
+ * @param pw DOCUMENT ME!
+ * @param ph DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ protected Rectangle computePopupBounds(int px, int py, int pw, int ph)
+ {
+ return new Rectangle(px, py, pw, ph);
+ }
+
+ /**
+ * This method changes the selection in the list to the item over which the
+ * mouse is currently located.
+ *
+ * @param anEvent MouseEvent
+ * @param shouldScroll DOCUMENT ME!
+ */
+ protected void updateListBoxSelectionForEvent(MouseEvent anEvent,
+ boolean shouldScroll)
+ {
+ // FIXME: Need to implement
+ }
+
+ /**
+ * InvocationMouseHandler is a listener that listens to mouse events
+ * occuring in the combo box. Note that this listener doesn't listen to
+ * mouse events occuring in the popup portion of the combo box, it only
+ * listens to main combo box part(area that displays selected item). This
+ * listener is responsible for showing and hiding popup portion of the
+ * combo box.
+ */
+ protected class InvocationMouseHandler extends MouseAdapter
+ {
+ /**
+ * Creates a new InvocationMouseHandler object.
+ */
+ protected InvocationMouseHandler()
+ {
+ }
+
+ /**
+ * This method is invoked whenever mouse is being pressed over the main
+ * part of the combo box. This method will show popup if the popup is
+ * not shown on the screen right now, and it will hide popup otherwise.
+ *
+ * @param e MouseEvent that should be handled
+ */
+ public void mousePressed(MouseEvent e)
+ {
+ if (comboBox.isEnabled())
+ togglePopup();
+ }
+
+ /**
+ * This method is invoked whenever mouse is released
+ *
+ * @param e MouseEvent that should be handled
+ */
+ public void mouseReleased(MouseEvent e)
+ {
+ // FIXME: should handle dragging events here, if
+ // mouse was dragged and released over the list of combobox's items,
+ // then item over which it was released should be selected.
+ }
+ }
+
+ /**
+ * InvocationMouseMotionListener is a mouse listener that listens to mouse
+ * dragging events occuring in the combo box.
+ */
+ protected class InvocationMouseMotionHandler extends MouseMotionAdapter
+ {
+ /**
+ * Creates a new InvocationMouseMotionHandler object.
+ */
+ protected InvocationMouseMotionHandler()
+ {
+ }
+
+ public void mouseDragged(MouseEvent e)
+ {
+ }
+ }
+
+ /**
+ * ItemHandler is an item listener that listens to selection event occuring
+ * in the combo box. FIXME: should specify here what it does when item is
+ * selected or deselected in the combo box list.
+ */
+ protected class ItemHandler extends Object implements ItemListener
+ {
+ /**
+ * Creates a new ItemHandler object.
+ */
+ protected ItemHandler()
+ {
+ }
+
+ /**
+ * This method responds to the selection events occuring in the combo box.
+ *
+ * @param e ItemEvent specifying the combo box's selection
+ */
+ public void itemStateChanged(ItemEvent e)
+ {
+ }
+ }
+
+ /**
+ * ListMouseHandler is a listener that listens to mouse events occuring in
+ * the combo box's list of items. This class is responsible for hiding
+ * popup portion of the combo box if the mouse is released inside the combo
+ * box's list.
+ */
+ protected class ListMouseHandler extends MouseAdapter
+ {
+ protected ListMouseHandler()
+ {
+ }
+
+ public void mousePressed(MouseEvent e)
+ {
+ }
+
+ public void mouseReleased(MouseEvent anEvent)
+ {
+ int index = list.locationToIndex(anEvent.getPoint());
+ comboBox.setSelectedIndex(index);
+ hide();
+ }
+ }
+
+ /**
+ * ListMouseMotionHandler listens to mouse motion events occuring in the
+ * combo box's list. This class is responsible for highlighting items in
+ * the list when mouse is moved over them
+ */
+ protected class ListMouseMotionHandler extends MouseMotionAdapter
+ {
+ protected ListMouseMotionHandler()
+ {
+ }
+
+ public void mouseMoved(MouseEvent anEvent)
+ {
+ // FIXME: Need to implement
+ // NOTE: the change isn't reflected in data model of the combo box.
+ // The items are only highlited, but not selected
+ }
+ }
+
+ /**
+ * This class listens to changes occuring in the bound properties of the
+ * combo box
+ */
+ protected class PropertyChangeHandler extends Object
+ implements PropertyChangeListener
+ {
+ protected PropertyChangeHandler()
+ {
+ }
+
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ if (e.getPropertyName().equals(JComboBox.RENDERER_CHANGED_PROPERTY))
+ {
+ list.setCellRenderer((ListCellRenderer) e.getNewValue());
+ revalidate();
+ repaint();
+ }
+ }
+ }
+
+ // ------ private helper methods --------------------
+
+ /**
+ * This method uninstalls listeners installed by the UI
+ */
+ private void uninstallListeners()
+ {
+ uninstallListListeners();
+ uninstallComboBoxListeners();
+ uninstallComboBoxModelListeners(comboBox.getModel());
+ }
+
+ /**
+ * This method uninstalls Listeners registered with combo boxes list of
+ * items
+ */
+ private void uninstallListListeners()
+ {
+ list.removeMouseListener(listMouseListener);
+ listMouseListener = null;
+
+ list.removeMouseMotionListener(listMouseMotionListener);
+ listMouseMotionListener = null;
+ }
+
+ /**
+ * This method uninstalls listeners listening to combo box associated with
+ * this popup menu
+ */
+ private void uninstallComboBoxListeners()
+ {
+ comboBox.removeMouseListener(mouseListener);
+ mouseListener = null;
+
+ comboBox.removeMouseMotionListener(mouseMotionListener);
+ mouseMotionListener = null;
+
+ comboBox.removeItemListener(itemListener);
+ itemListener = null;
+
+ comboBox.removePropertyChangeListener(propertyChangeListener);
+ propertyChangeListener = null;
+ }
+
+ // --------------------------------------------------------------------
+ // The following classes are here only for backwards API compatibility
+ // They aren't used.
+ // --------------------------------------------------------------------
+
+ /**
+ * This class is not used any more.
+ */
+ public class ListDataHandler extends Object implements ListDataListener
+ {
+ public ListDataHandler()
+ {
+ }
+
+ public void contentsChanged(ListDataEvent e)
+ {
+ }
+
+ public void intervalAdded(ListDataEvent e)
+ {
+ }
+
+ public void intervalRemoved(ListDataEvent e)
+ {
+ }
+ }
+
+ /**
+ * This class is not used anymore
+ */
+ protected class ListSelectionHandler extends Object
+ implements ListSelectionListener
+ {
+ protected ListSelectionHandler()
+ {
+ }
+
+ public void valueChanged(ListSelectionEvent e)
+ {
+ }
+ }
+
+ /**
+ * This class is not used anymore
+ */
+ public class InvocationKeyHandler extends KeyAdapter
+ {
+ public InvocationKeyHandler()
+ {
+ }
+
+ public void keyReleased(KeyEvent e)
+ {
+ }
+ }
+}
Index: javax/swing/plaf/basic/BasicPopupMenuUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicPopupMenuUI.java,v
retrieving revision 1.4
diff -u -r1.4 BasicPopupMenuUI.java
--- javax/swing/plaf/basic/BasicPopupMenuUI.java 31 Jul 2004 22:56:54
-0000 1.4
+++ javax/swing/plaf/basic/BasicPopupMenuUI.java 5 Sep 2004 11:27:03
-0000
@@ -163,6 +163,7 @@
popupMenu.setBorder(defaults.getBorder("PopupMenu.border"));
popupMenu.setFont(defaults.getFont("PopupMenu.font"));
popupMenu.setForeground(defaults.getColor("PopupMenu.foreground"));
+ popupMenu.setOpaque(true);
}
/**
@@ -228,12 +229,12 @@
}
/**
- * This method returns the minimum size of the JPopupMenu.
- *
- * @param c The JComponent to find a size for.
- *
- * @return The minimum size.
- */
+ * This method returns the minimum size of the JPopupMenu.
+ *
+ * @param c The JComponent to find a size for.
+ *
+ * @return The minimum size.
+ */
public Dimension getMinimumSize(JComponent c)
{
return null;
@@ -264,13 +265,13 @@
}
/**
- * Return true if given mouse event is a platform popup trigger,
- * and false otherwise
+ * Return true if given mouse event is a platform popup trigger, and false
+ * otherwise
*
* @param e MouseEvent that is to be checked for popup trigger event
*
- * @return true if given mouse event is a platform popup trigger,
- * and false otherwise
+ * @return true if given mouse event is a platform popup trigger, and false
+ * otherwise
*/
public boolean isPopupTrigger(MouseEvent e)
{
@@ -334,25 +335,25 @@
path[0] = popupMenu;
Component[] comps = popupMenu.getComponents();
if (comps.length != 0 && comps[0] instanceof MenuElement)
- path[1] = (MenuElement) comps[0];
- manager.setSelectedPath(path);
+ {
+ path[1] = (MenuElement) comps[0];
+ manager.setSelectedPath(path);
+ }
}
}
}
/**
- * ComponentListener that listens to Component Events fired by the
- * top - level window to which popup menu belongs. If top-level
- * window was resized, moved or hidded then popup menu will
- * be hidded and selected path of current menu hierarchy will be set
- * to null.
- *
+ * ComponentListener that listens to Component Events fired by the top -
+ * level window to which popup menu belongs. If top-level window was
+ * resized, moved or hidded then popup menu will be hidded and selected
+ * path of current menu hierarchy will be set to null.
*/
private class TopWindowListener implements ComponentListener
{
/**
- * This method is invoked when top-level window is resized.
- * This method closes current menu hierarchy.
+ * This method is invoked when top-level window is resized. This method
+ * closes current menu hierarchy.
*
* @param e The ComponentEvent
*/
@@ -363,8 +364,8 @@
}
/**
- * This method is invoked when top-level window is moved.
- * This method closes current menu hierarchy.
+ * This method is invoked when top-level window is moved. This method
+ * closes current menu hierarchy.
*
* @param e The ComponentEvent
*/
@@ -375,8 +376,8 @@
}
/**
- * This method is invoked when top-level window is shown
- * This method does nothing by default.
+ * This method is invoked when top-level window is shown This method does
+ * nothing by default.
*
* @param e The ComponentEvent
*/
@@ -387,8 +388,8 @@
}
/**
- * This method is invoked when top-level window is hidden
- * This method closes current menu hierarchy.
+ * This method is invoked when top-level window is hidden This method
+ * closes current menu hierarchy.
*
* @param e The ComponentEvent
*/
Index: javax/swing/plaf/basic/ComboPopup.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/ComboPopup.java,v
retrieving revision 1.1
diff -u -r1.1 ComboPopup.java
--- javax/swing/plaf/basic/ComboPopup.java 4 Sep 2004 17:14:01 -0000
1.1
+++ javax/swing/plaf/basic/ComboPopup.java 5 Sep 2004 11:27:03 -0000
@@ -35,12 +35,69 @@
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
{
- void hide();
+ /**
+ * 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();
}
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: JComboBox support from gcj gui branch,
Mark Wielaard <=