Fix Darcula ComboBox with EditorTextField in disabled state

This commit is contained in:
Kirill Kirichenko
2018-01-26 13:03:37 +03:00
parent b12343d934
commit 7e332c161c
2 changed files with 44 additions and 19 deletions
@@ -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();
@@ -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) {