Index: javax/swing/plaf/basic/BasicComboBoxUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboBoxUI.java,v retrieving revision 1.1 diff -u -r1.1 BasicComboBoxUI.java --- javax/swing/plaf/basic/BasicComboBoxUI.java 5 Sep 2004 11:31:06 -0000 1.1 +++ javax/swing/plaf/basic/BasicComboBoxUI.java 22 Sep 2004 12:39:00 -0000 @@ -796,7 +796,7 @@ currentValue, -1, isPressed, - isPressed); + hasFocus); if (! comboBox.isEnabled()) comp.setEnabled(false); @@ -1127,8 +1127,10 @@ */ 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 @@ { } + /** + * 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 @@ 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: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboPopup.java,v retrieving revision 1.1 diff -u -r1.1 BasicComboPopup.java --- javax/swing/plaf/basic/BasicComboPopup.java 5 Sep 2004 11:31:06 -0000 1.1 +++ javax/swing/plaf/basic/BasicComboPopup.java 22 Sep 2004 12:39:00 -0000 @@ -171,19 +171,7 @@ { 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 @@ 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 @@ */ 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 @@ */ 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 @@ */ 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 @@ 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 @@ */ 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 @@ 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 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 @@ revalidate(); repaint(); } + if (e.getPropertyName().equals(JComboBox.MODEL_CHANGED_PROPERTY)) + { + list.setModel((ComboBoxModel) e.getNewValue()); + revalidate(); + repaint(); + } } }