summaryrefslogtreecommitdiff
path: root/javax
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2007-01-06 15:43:21 +0000
committerRoman Kennke <roman@kennke.org>2007-01-06 15:43:21 +0000
commitdecd1972a517e1a88da29d2f5941e3e4d0a4a994 (patch)
tree558f1eba19eba3a13fd149e0babf17f5c6e20398 /javax
parentafb79f4fb907bcbd28609f33ca10a2dfc7e4103f (diff)
downloadclasspath-decd1972a517e1a88da29d2f5941e3e4d0a4a994.tar.gz
2007-01-06 Roman Kennke <roman@kennke.org>
PR 30337 * javax/swing/plaf/basic/BasicComboBoxUI.java (installUI): Install popup and list here. Don't configure the arrow button and editor here. (installComponents): Don't install popup and list here. (Moved to installUI). Configure arrow button here and check for null. (addEditor): Configure editor here. (configureArrowButton): Directly fetch listeners from popup. (paintCurrentValue): Removed unused local variables. (layoutContainer): Removed unused local variables. (PropertyChangeHandler.propertyChange): Don't invalidate minimumSize on each property change. Avoid calling getPropertyName() repeatedly. Clean up. Call addEditor() when editor changes. Configure and unconfigure editor when editable changes. Use 'model' instead of non-existing 'dataModel' property. * javax/swing/plaf/basic/BasicComboPopup.java (uninstallingUI): Remove property change listener and item listener here. Uninstall list listeners. Set model to null to prevent leakage. (configureList): Don't sync list selection there. (uninstallComboBoxListeners): Moved to uninstallingUI. (uninstallListeners): Moved to uninstallingUI. * javax/swing/plaf/metal/MetalComboBoxUI.java (createPopup): Call super. (getMinimumSize): Removed unused statement.
Diffstat (limited to 'javax')
-rw-r--r--javax/swing/plaf/basic/BasicComboBoxUI.java76
-rw-r--r--javax/swing/plaf/basic/BasicComboPopup.java34
-rw-r--r--javax/swing/plaf/metal/MetalComboBoxUI.java3
3 files changed, 53 insertions, 60 deletions
diff --git a/javax/swing/plaf/basic/BasicComboBoxUI.java b/javax/swing/plaf/basic/BasicComboBoxUI.java
index d98fd2afe..6a95b57a2 100644
--- a/javax/swing/plaf/basic/BasicComboBoxUI.java
+++ b/javax/swing/plaf/basic/BasicComboBoxUI.java
@@ -215,6 +215,8 @@ public class BasicComboBoxUI extends ComboBoxUI
isMinimumSizeDirty = true;
comboBox = (JComboBox) c;
installDefaults();
+ popup = createPopup();
+ listBox = popup.getList();
// Set editor and renderer for the combo box. Editor is used
// only if combo box becomes editable, otherwise renderer is used
@@ -229,14 +231,9 @@ public class BasicComboBoxUI extends ComboBoxUI
currentEditor = createEditor();
comboBox.setEditor(currentEditor);
}
- editor = currentEditor.getEditorComponent();
installComponents();
installListeners();
- if (arrowButton != null)
- configureArrowButton();
- if (editor != null)
- configureEditor();
comboBox.setLayout(createLayoutManager());
comboBox.setFocusable(true);
installKeyboardActions();
@@ -473,13 +470,11 @@ public class BasicComboBoxUI extends ComboBoxUI
*/
protected void installComponents()
{
- // create drop down list of items
- popup = createPopup();
- listBox = popup.getList();
-
// create and install arrow button
arrowButton = createArrowButton();
comboBox.add(arrowButton);
+ if (arrowButton != null)
+ configureArrowButton();
if (comboBox.isEditable())
addEditor();
@@ -521,7 +516,11 @@ public class BasicComboBoxUI extends ComboBoxUI
{
removeEditor();
editor = comboBox.getEditor().getEditorComponent();
- comboBox.add(editor);
+ if (editor != null)
+ {
+ configureEditor();
+ comboBox.add(editor);
+ }
}
/**
@@ -572,10 +571,8 @@ public class BasicComboBoxUI extends ComboBoxUI
{
arrowButton.setEnabled(comboBox.isEnabled());
arrowButton.setFocusable(false);
- if (popupMouseListener != null)
- arrowButton.addMouseListener(popupMouseListener);
- if (popupMouseMotionListener != null)
- arrowButton.addMouseMotionListener(popupMouseMotionListener);
+ arrowButton.addMouseListener(popup.getMouseListener());
+ arrowButton.addMouseMotionListener(popup.getMouseMotionListener());
// Mark the button as not closing the popup, we handle this ourselves.
arrowButton.putClientProperty(BasicLookAndFeel.DONT_CANCEL_POPUP,
@@ -855,9 +852,6 @@ public class BasicComboBoxUI extends ComboBoxUI
*/
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
{
- Object currentValue = comboBox.getSelectedItem();
- boolean isPressed = arrowButton.getModel().isPressed();
-
/* Gets the component to be drawn for the current value.
* If there is currently no selected item we will take an empty
* String as replacement.
@@ -1109,7 +1103,6 @@ public class BasicComboBoxUI extends ComboBoxUI
// editable
Insets i = getInsets();
int arrowSize = comboBox.getHeight() - (i.top + i.bottom);
- int editorWidth = comboBox.getBounds().width - arrowSize;
if (arrowButton != null)
arrowButton.setBounds(comboBox.getWidth() - (i.right + arrowSize),
@@ -1345,50 +1338,65 @@ public class BasicComboBoxUI extends ComboBoxUI
public void propertyChange(PropertyChangeEvent e)
{
// Lets assume every change invalidates the minimumsize.
- isMinimumSizeDirty = true;
-
- if (e.getPropertyName().equals("enabled"))
+ String propName = e.getPropertyName();
+ if (propName.equals("enabled"))
{
- arrowButton.setEnabled(comboBox.isEnabled());
+ boolean enabled = comboBox.isEnabled();
+ if (editor != null)
+ editor.setEnabled(enabled);
+ if (arrowButton != null)
+ arrowButton.setEnabled(enabled);
- if (comboBox.isEditable())
- comboBox.getEditor().getEditorComponent().setEnabled(
- comboBox.isEnabled());
+ comboBox.repaint();
+ }
+ else if (propName.equals("editor"))
+ {
+ addEditor();
+ comboBox.revalidate();
}
else if (e.getPropertyName().equals("editable"))
{
if (comboBox.isEditable())
{
- configureEditor();
addEditor();
}
else
{
- unconfigureEditor();
removeEditor();
}
comboBox.revalidate();
- comboBox.repaint();
}
- else if (e.getPropertyName().equals("dataModel"))
+ else if (e.getPropertyName().equals("model"))
{
// remove ListDataListener from old model and add it to new model
ComboBoxModel oldModel = (ComboBoxModel) e.getOldValue();
- if (oldModel != null)
+ if (oldModel != null && listDataListener != null)
oldModel.removeListDataListener(listDataListener);
- if ((ComboBoxModel) e.getNewValue() != null)
+ ComboBoxModel newModel = (ComboBoxModel) e.getNewValue();
+ if (newModel != null && listDataListener != null)
comboBox.getModel().addListDataListener(listDataListener);
+
+ if (editor != null)
+ {
+ comboBox.configureEditor(comboBox.getEditor(),
+ comboBox.getSelectedItem());
+ }
+ isMinimumSizeDirty = true;
+ comboBox.revalidate();
+ comboBox.repaint();
}
else if (e.getPropertyName().equals("font"))
{
Font font = (Font) e.getNewValue();
- editor.setFont(font);
+ if (editor != null)
+ {
+ editor.setFont(font);
+ }
listBox.setFont(font);
- arrowButton.setFont(font);
+ isMinimumSizeDirty = true;
comboBox.revalidate();
- comboBox.repaint();
}
// FIXME: Need to handle changes in other bound properties.
diff --git a/javax/swing/plaf/basic/BasicComboPopup.java b/javax/swing/plaf/basic/BasicComboPopup.java
index c29829d77..952df5ee7 100644
--- a/javax/swing/plaf/basic/BasicComboPopup.java
+++ b/javax/swing/plaf/basic/BasicComboPopup.java
@@ -271,9 +271,18 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup
*/
public void uninstallingUI()
{
+ if (propertyChangeListener != null)
+ {
+ comboBox.removePropertyChangeListener(propertyChangeListener);
+ }
+ if (itemListener != null)
+ {
+ comboBox.removeItemListener(itemListener);
+ }
uninstallComboBoxModelListeners(comboBox.getModel());
- uninstallListeners();
uninstallKeyboardActions();
+ uninstallListListeners();
+ list.setModel(null);
}
/**
@@ -466,7 +475,6 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup
list.setBorder(null);
list.setCellRenderer(comboBox.getRenderer());
list.setFocusable(false);
- syncListSelection();
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
installListListeners();
}
@@ -1010,15 +1018,6 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup
// ------ private helper methods --------------------
/**
- * This method uninstalls listeners installed by the UI
- */
- private void uninstallListeners()
- {
- uninstallComboBoxListeners();
- uninstallComboBoxModelListeners(comboBox.getModel());
- }
-
- /**
* This method uninstalls Listeners registered with combo boxes list of
* items
*/
@@ -1031,19 +1030,6 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup
listMouseMotionListener = null;
}
- /**
- * This method uninstalls listeners listening to combo box associated with
- * this popup menu
- */
- private void uninstallComboBoxListeners()
- {
- comboBox.removeItemListener(itemListener);
- itemListener = null;
-
- comboBox.removePropertyChangeListener(propertyChangeListener);
- propertyChangeListener = null;
- }
-
void syncListSelection()
{
int index = comboBox.getSelectedIndex();
diff --git a/javax/swing/plaf/metal/MetalComboBoxUI.java b/javax/swing/plaf/metal/MetalComboBoxUI.java
index c24c08505..7aafb715d 100644
--- a/javax/swing/plaf/metal/MetalComboBoxUI.java
+++ b/javax/swing/plaf/metal/MetalComboBoxUI.java
@@ -217,7 +217,7 @@ public class MetalComboBoxUI extends BasicComboBoxUI
*/
protected ComboPopup createPopup()
{
- return new MetalComboPopup(comboBox);
+ return super.createPopup();
}
/**
@@ -305,7 +305,6 @@ public class MetalComboBoxUI extends BasicComboBoxUI
{
MetalComboBoxButton b = (MetalComboBoxButton) arrowButton;
d = getDisplaySize();
- Insets insets = b.getInsets();
Insets arrowInsets = b.getInsets();
Insets comboInsets = comboBox.getInsets();
Icon icon = b.getComboIcon();