[gui][PATCH] Various fixes to JComboBox
Olga Rodimina
rodimina@redhat.com
Fri Sep 17 02:34:00 GMT 2004
Hi,
Here is the patch that makes various fixes to JComboBox. I will be
committing this patch to java-gui-branch.
Olga.
-------------- next part --------------
? .snprj
? libjava.proj
? package-list
? patch
? resources
? javax/swing/.snprj
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2660.2.385
diff -c -p -u -r1.2660.2.385 ChangeLog
--- ChangeLog 13 Sep 2004 14:51:42 -0000 1.2660.2.385
+++ ChangeLog 14 Sep 2004 19:39:39 -0000
@@ -1,3 +1,27 @@
+2004-09-14 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/plaf/basic/BasicComboBoxUI.java:
+ (paintCurrentValue): Pass correct parameters to
+ getListCellRendererComponent().
+ (ListDataHandler.intervalRemoved): Implemented.
+ (PropertyChangeHandler.propertyChange): Handle changes in
+ MODEL_CHANGED_PROPERTY of the JComboBox
+ * javax/swing/plaf/basic/BasicComboPopup.java:
+ (BasicComboPopup): Moved code that configures popup to
+ configurePopup() and call it instead.
+ (firePopupMenuWillBecomeVisible): Implemented.
+ (firePopupMenuWillBecomeInvisible): Likewise.
+ (firePopupMenuCanceled): Likewise.
+ (configureList): Set list's visibleRowCount same as
+ comboBox's visibleRowCount.
+ (configurePopup): Implemented.
+ (getPopupHeightForRowCount): Get item's from JComboBox's model and
+ not from model of the JList.
+ (ListMouseMotionHandler.mouseMoved): Implemented.
+ (PropertyChangeHandler.propertyChange): Handles change in the
+ JComboBox's model.
+
+
2004-09-13 Michael Koch <konqueror@gmx.de>
* javax/swing/JComponent.java
Index: javax/swing/plaf/basic/BasicComboBoxUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicComboBoxUI.java,v
retrieving revision 1.1.2.1
diff -c -p -u -r1.1.2.1 BasicComboBoxUI.java
--- javax/swing/plaf/basic/BasicComboBoxUI.java 25 Aug 2004 17:52:11 -0000 1.1.2.1
+++ javax/swing/plaf/basic/BasicComboBoxUI.java 14 Sep 2004 19:39:41 -0000
@@ -796,7 +796,7 @@ public class BasicComboBoxUI extends Com
currentValue,
-1,
isPressed,
- isPressed);
+ hasFocus);
if (! comboBox.isEnabled())
comp.setEnabled(false);
@@ -1127,8 +1127,10 @@ public class BasicComboBoxUI extends Com
*/
public void intervalRemoved(ListDataEvent e)
{
- // must determine if the size of the combo box should change
- // FIXME: need to implement
+
+ // recalculate display size of the JComboBox.
+ largestItemSize = getLargestItemSize();
+ comboBox.repaint();
}
}
@@ -1142,11 +1144,13 @@ public class BasicComboBoxUI extends Com
{
}
+ /**
+ * This method is invoked whenever bound property of JComboBox changes.
+ */
public void propertyChange(PropertyChangeEvent e)
{
if (e.getPropertyName().equals(JComboBox.ENABLED_CHANGED_PROPERTY))
{
- // disable arrow button
arrowButton.setEnabled(comboBox.isEnabled());
if (comboBox.isEditable())
@@ -1169,6 +1173,16 @@ public class BasicComboBoxUI extends Com
comboBox.revalidate();
comboBox.repaint();
}
+ else if (e.getPropertyName().equals(JComboBox.MODEL_CHANGED_PROPERTY))
+ {
+ // remove ListDataListener from old model and add it to new model
+ ComboBoxModel oldModel = (ComboBoxModel) e.getOldValue();
+ if (oldModel != null)
+ oldModel.removeListDataListener(listDataListener);
+
+ if ((ComboBoxModel) e.getNewValue() != null)
+ comboBox.getModel().addListDataListener(listDataListener);
+ }
// FIXME: Need to handle changes in other bound properties.
}
Index: javax/swing/plaf/basic/BasicComboPopup.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicComboPopup.java,v
retrieving revision 1.1.2.1
diff -c -p -u -r1.1.2.1 BasicComboPopup.java
--- javax/swing/plaf/basic/BasicComboPopup.java 25 Aug 2004 17:52:11 -0000 1.1.2.1
+++ javax/swing/plaf/basic/BasicComboPopup.java 14 Sep 2004 19:39:41 -0000
@@ -171,19 +171,7 @@ public class BasicComboPopup extends JPo
{
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);
-
+ configurePopup();
setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled());
}
@@ -199,6 +187,8 @@ public class BasicComboPopup extends JPo
int popupHeight = getPopupHeightForRowCount(comboBox.getMaximumRowCount())
+ 4;
+ // FIXME: Uncomment this out once preferred size of JList will be working
+ // list.setPreferredSize(new Dimension(cbBounds.width, popupHeight));
super.setPopupSize(cbBounds.width, popupHeight);
// location specified is relative to comboBox
@@ -293,7 +283,10 @@ public class BasicComboPopup extends JPo
*/
protected void firePopupMenuWillBecomeVisible()
{
- // FIXME: Need to implement
+ PopupMenuListener[] ll = comboBox.getPopupMenuListeners();
+
+ for (int i = 0; i < ll.length; i++)
+ ll[i].popupMenuWillBecomeVisible(new PopupMenuEvent(comboBox));
}
/**
@@ -302,7 +295,10 @@ public class BasicComboPopup extends JPo
*/
protected void firePopupMenuWillBecomeInvisible()
{
- // FIXME: Need to implement
+ PopupMenuListener[] ll = comboBox.getPopupMenuListeners();
+
+ for (int i = 0; i < ll.length; i++)
+ ll[i].popupMenuWillBecomeInvisible(new PopupMenuEvent(comboBox));
}
/**
@@ -311,7 +307,10 @@ public class BasicComboPopup extends JPo
*/
protected void firePopupMenuCanceled()
{
- // FIXME: Need to implement
+ PopupMenuListener[] ll = comboBox.getPopupMenuListeners();
+
+ for (int i = 0; i < ll.length; i++)
+ ll[i].popupMenuCanceled(new PopupMenuEvent(comboBox));
}
/**
@@ -440,11 +439,7 @@ public class BasicComboPopup extends JPo
protected void configureList()
{
list.setModel(comboBox.getModel());
-
- if (comboBox.getItemCount() < comboBox.getMaximumRowCount())
- list.setVisibleRowCount(comboBox.getItemCount());
- else
- list.setVisibleRowCount(comboBox.getMaximumRowCount());
+ list.setVisibleRowCount(comboBox.getMaximumRowCount());
installListListeners();
}
@@ -493,7 +488,17 @@ public class BasicComboPopup extends JPo
*/
protected void configurePopup()
{
- // FIXME: Need to implement
+ // initialize list that will be used to display combo box's items
+ 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);
}
/*
@@ -643,8 +648,8 @@ public class BasicComboPopup extends JPo
for (int i = 0; i < maxRowCount; i++)
{
Component comp = rend.getListCellRendererComponent(list,
- list.getModel()
- .getElementAt(i),
+ comboBox.getModel()
+ .getElementAt(i),
-1, false, false);
Dimension dim = comp.getPreferredSize();
totalHeight += dim.height;
@@ -803,9 +808,11 @@ public class BasicComboPopup extends JPo
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
+ // 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();
}
}
@@ -828,6 +835,12 @@ public class BasicComboPopup extends JPo
revalidate();
repaint();
}
+ if (e.getPropertyName().equals(JComboBox.MODEL_CHANGED_PROPERTY))
+ {
+ list.setModel((ComboBoxModel) e.getNewValue());
+ revalidate();
+ repaint();
+ }
}
}
More information about the Java-patches
mailing list