diff options
Diffstat (limited to 'libjava/classpath/javax/swing/plaf/basic/BasicComboPopup.java')
-rw-r--r-- | libjava/classpath/javax/swing/plaf/basic/BasicComboPopup.java | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicComboPopup.java b/libjava/classpath/javax/swing/plaf/basic/BasicComboPopup.java index 73aac8d4e65..73979bb89c1 100644 --- a/libjava/classpath/javax/swing/plaf/basic/BasicComboPopup.java +++ b/libjava/classpath/javax/swing/plaf/basic/BasicComboPopup.java @@ -38,6 +38,7 @@ exception statement from your version. */ package javax.swing.plaf.basic; +import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Point; @@ -55,6 +56,7 @@ import java.awt.event.MouseMotionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import javax.swing.BorderFactory; import javax.swing.ComboBoxModel; import javax.swing.JComboBox; import javax.swing.JLabel; @@ -178,8 +180,8 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup // to display number of rows equal to 'maximumRowCount' property int popupHeight = getPopupHeightForRowCount(comboBox.getMaximumRowCount()); - list.setPreferredSize(new Dimension(cbBounds.width, popupHeight)); - super.setPopupSize(cbBounds.width, popupHeight); + scroller.setPreferredSize(new Dimension(cbBounds.width, popupHeight)); + pack(); // Highlight selected item in the combo box's drop down list if (comboBox.getSelectedIndex() != -1) @@ -478,6 +480,7 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup */ protected void configureScroller() { + scroller.setBorder(null); scroller.getViewport().setView(list); scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); } @@ -488,6 +491,7 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup */ protected void configurePopup() { + setBorder(BorderFactory.createLineBorder(Color.BLACK)); // initialize list that will be used to display combo box's items this.list = createList(); ((JLabel) list.getCellRenderer()).setHorizontalAlignment(SwingConstants.LEFT); @@ -714,7 +718,11 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup protected void updateListBoxSelectionForEvent(MouseEvent anEvent, boolean shouldScroll) { - // FIXME: Need to implement + // TODO: We need to handle the shouldScroll parameter somehow. + int index = list.locationToIndex(anEvent.getPoint()); + // Check for valid index. + if (index >= 0) + list.setSelectedIndex(index); } /** @@ -732,6 +740,7 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup */ protected InvocationMouseHandler() { + // Nothing to do here. } /** @@ -744,7 +753,7 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup public void mousePressed(MouseEvent e) { if (comboBox.isEnabled()) - togglePopup(); + togglePopup(); } /** @@ -768,15 +777,15 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup // then change selection and close popup if (! (releasedComponent instanceof JComboBox)) { - // List model contains the item over which mouse is released, - // since it is updated every time the mouse is moved over a different - // item in the list. Now that the mouse is released we need to - // update model of the combo box as well. - comboBox.setSelectedIndex(list.getSelectedIndex()); - - if (isAutoScrolling) - stopAutoScrolling(); - hide(); + // List model contains the item over which mouse is released, + // since it is updated every time the mouse is moved over a different + // item in the list. Now that the mouse is released we need to + // update model of the combo box as well. + comboBox.setSelectedIndex(list.getSelectedIndex()); + + if (isAutoScrolling) + stopAutoScrolling(); + hide(); } } } @@ -792,6 +801,7 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup */ protected InvocationMouseMotionHandler() { + // Nothing to do here. } /** @@ -868,6 +878,7 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup */ protected ItemHandler() { + // Nothing to do here. } /** @@ -877,6 +888,7 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup */ public void itemStateChanged(ItemEvent e) { + // TODO: What should be done here? } } @@ -890,16 +902,20 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup { protected ListMouseHandler() { + // Nothing to do here. } public void mousePressed(MouseEvent e) { + // TODO: What should be do here? } public void mouseReleased(MouseEvent anEvent) { int index = list.locationToIndex(anEvent.getPoint()); - comboBox.setSelectedIndex(index); + // Check for valid index. + if (index >= 0) + comboBox.setSelectedIndex(index); hide(); } } @@ -913,15 +929,12 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup { protected ListMouseMotionHandler() { + // Nothing to do here. } public void mouseMoved(MouseEvent anEvent) { - // Highlight list cells over which the mouse is located. - // This changes list model, but has no effect on combo box's data model - int index = list.locationToIndex(anEvent.getPoint()); - list.setSelectedIndex(index); - list.repaint(); + updateListBoxSelectionForEvent(anEvent, false); } } @@ -934,6 +947,7 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup { protected PropertyChangeHandler() { + // Nothing to do here. } public void propertyChange(PropertyChangeEvent e) @@ -1009,18 +1023,22 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup { public ListDataHandler() { + // Nothing to do here. } public void contentsChanged(ListDataEvent e) { + // Nothing to do here. } public void intervalAdded(ListDataEvent e) { + // Nothing to do here. } public void intervalRemoved(ListDataEvent e) { + // Nothing to do here. } } @@ -1032,10 +1050,12 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup { protected ListSelectionHandler() { + // Nothing to do here. } public void valueChanged(ListSelectionEvent e) { + // Nothing to do here. } } @@ -1046,10 +1066,12 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup { public InvocationKeyHandler() { + // Nothing to do here. } public void keyReleased(KeyEvent e) { + // Nothing to do here. } } } |