diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java index 62518767a210..32d905291138 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java @@ -38,6 +38,7 @@ import java.awt.event.*; import java.awt.geom.Path2D; import java.awt.geom.Rectangle2D; import java.awt.geom.RoundRectangle2D; +import java.beans.PropertyChangeListener; import static com.intellij.ide.ui.laf.darcula.DarculaUIUtil.*; @@ -52,8 +53,9 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border, ErrorB return new DarculaComboBoxUI(); } - protected KeyListener editorKeyListener; - protected FocusListener editorFocusListener; + private KeyListener editorKeyListener; + private FocusListener editorFocusListener; + private PropertyChangeListener propertyListener; @Override protected void installDefaults() { @@ -61,6 +63,34 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border, ErrorB comboBox.setBorder(this); } + @Override protected void installListeners() { + super.installListeners(); + + propertyListener = createPropertyListener(); + comboBox.addPropertyChangeListener(propertyListener); + } + + @Override public void uninstallListeners() { + super.uninstallListeners(); + + if (propertyListener != null) { + comboBox.removePropertyChangeListener(propertyListener); + propertyListener = null; + } + } + + protected PropertyChangeListener createPropertyListener() { + return e -> { + if ("enabled".equals(e.getPropertyName())) { + EditorTextField etf = UIUtil.findComponentOfType((JComponent)editor, EditorTextField.class); + if (etf != null) { + Color color = e.getNewValue() == Boolean.FALSE ? UIManager.getColor("ComboBox.disabledBackground") : null; + etf.setBackground(color); + } + } + }; + } + protected JButton createArrowButton() { Color bg = comboBox.getBackground(); Color fg = comboBox.getForeground(); diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJComboBoxUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJComboBoxUI.java index 7a41e2e00f76..e5c68791568e 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJComboBoxUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJComboBoxUI.java @@ -57,7 +57,6 @@ public class WinIntelliJComboBoxUI extends DarculaComboBoxUI { private MouseListener buttonReleaseListener; private MouseListener buttonHoverListener; - private PropertyChangeListener propertyListener; private MouseListener editorHoverListener; @@ -72,33 +71,29 @@ public class WinIntelliJComboBoxUI extends DarculaComboBoxUI { if (!comboBox.isEditable()) { comboBox.addMouseListener(mouseListener = new ComboBoxMouseListener()); } + } - propertyListener = (evt) -> { - if("enabled".equals(evt.getPropertyName())) { + @Override public void uninstallListeners() { + super.uninstallListeners(); + comboBox.removeMouseListener(mouseListener); + } + + @Override + protected PropertyChangeListener createPropertyListener() { + return e -> { + if("enabled".equals(e.getPropertyName())) { EditorTextField etf = UIUtil.findComponentOfType((JComponent)editor, EditorTextField.class); if (etf != null) { etf.setBackground(getComboBackground(true)); } - } else if ("editable".equals(evt.getPropertyName())) { - if (evt.getNewValue() == Boolean.TRUE) { + } else if ("editable".equals(e.getPropertyName())) { + if (e.getNewValue() == Boolean.TRUE) { comboBox.removeMouseListener(mouseListener); } else { comboBox.addMouseListener(mouseListener); } } }; - - comboBox.addPropertyChangeListener(propertyListener); - } - - @Override public void uninstallListeners() { - super.uninstallListeners(); - comboBox.removeMouseListener(mouseListener); - - if (propertyListener != null) { - comboBox.removePropertyChangeListener(propertyListener); - propertyListener = null; - } } @Override public void paint(Graphics g, JComponent c) {