Browse Source

Fixed incorrect text color for boolean editor after tree has been unfocused.

Signed-off-by: weisj <weisj@arcor.de>
pull/27/head
weisj 5 years ago
parent
commit
0e58b50b54
  1. 4
      src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java
  2. 4
      src/main/java/com/github/weisj/darklaf/ui/checkbox/DarkCheckBoxUI.java
  3. 1
      src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java
  4. 7
      src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java
  5. 2
      src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRenderer.java
  6. 33
      src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java
  7. 1
      src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java

4
src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java

@ -114,6 +114,8 @@ public class DarkCellRendererToggleButton<T extends JToggleButton & CellEditorTo
public CellEditorCheckBox(final boolean opaque) { public CellEditorCheckBox(final boolean opaque) {
setOpaque(opaque); setOpaque(opaque);
putClientProperty("JToggleButton.isTreeCellEditor", true);
putClientProperty("JToggleButton.isTableCellEditor", true);
} }
public void setHasFocus(final boolean hasFocus) { public void setHasFocus(final boolean hasFocus) {
@ -137,6 +139,8 @@ public class DarkCellRendererToggleButton<T extends JToggleButton & CellEditorTo
public CellEditorRadioButton(final boolean opaque) { public CellEditorRadioButton(final boolean opaque) {
setOpaque(opaque); setOpaque(opaque);
putClientProperty("JToggleButton.isTreeCellEditor", true);
putClientProperty("JToggleButton.isTableCellEditor", true);
} }
public void setHasFocus(final boolean hasFocus) { public void setHasFocus(final boolean hasFocus) {

4
src/main/java/com/github/weisj/darklaf/ui/checkbox/DarkCheckBoxUI.java

@ -335,8 +335,12 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis
String key = evt.getPropertyName(); String key = evt.getPropertyName();
if ("componentOrientation".equals(key)) { if ("componentOrientation".equals(key)) {
checkBox.repaint(); checkBox.repaint();
hitArea.setRoundRect(0, 0, 0, 0, 0, 0);
} else if ("JToggleButton.isTreeCellEditor".equals(key) || "JToggleButton.isTableCellEditor".equals(key)) { } else if ("JToggleButton.isTreeCellEditor".equals(key) || "JToggleButton.isTableCellEditor".equals(key)) {
checkBox.repaint(); checkBox.repaint();
hitArea.setRoundRect(0, 0, 0, 0, 0, 0);
} else if ("JToggleButton.clearHitArea".equals(key)) {
hitArea.setRoundRect(0, 0, 0, 0, 0, 0);
} }
} }
} }

1
src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java

@ -125,6 +125,7 @@ public class DarkDefaultTreeEditor extends DefaultTreeCellEditor {
p.x -= bounds.x + button.getX(); p.x -= bounds.x + button.getX();
p.y -= bounds.y + button.getY(); p.y -= bounds.y + button.getY();
button.putClientProperty("JToggleButton.clearHitArea", true);
return button.contains(p); return button.contains(p);
} }
} }

7
src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java

@ -156,15 +156,14 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi
((JComboBox<?>) editorComponent).removeAllItems(); ((JComboBox<?>) editorComponent).removeAllItems();
((JComboBox<Object>) editorComponent).addItem(value); ((JComboBox<Object>) editorComponent).addItem(value);
((JComboBox<?>) editorComponent).setSelectedItem(value); ((JComboBox<?>) editorComponent).setSelectedItem(value);
} else if (editorComponent instanceof JToggleButton && adjustBoolValue) { } else if (editorComponent instanceof JToggleButton) {
((JToggleButton) editorComponent).setSelected(!(((JToggleButton) editorComponent).isSelected())); ((JToggleButton) editorComponent).setSelected(!(((JToggleButton) editorComponent).isSelected()));
SwingUtilities.invokeLater(tree::stopEditing); SwingUtilities.invokeLater(tree::stopEditing);
} }
editorComponent.setOpaque(false); editorComponent.setOpaque(false);
editorComponent.setComponentOrientation(tree.getComponentOrientation()); editorComponent.setComponentOrientation(tree.getComponentOrientation());
if (editorComponent instanceof JToggleButton) {
if (isSelected && editorComponent instanceof JToggleButton) { if (DarkUIUtil.hasFocus(tree) || DarkUIUtil.hasFocus(editorComponent)) {
if (DarkUIUtil.hasFocus(tree)) {
editorComponent.setForeground(UIManager.getColor("Tree.selectionForeground")); editorComponent.setForeground(UIManager.getColor("Tree.selectionForeground"));
} else { } else {
editorComponent.setForeground(UIManager.getColor("Tree.selectionForegroundInactive")); editorComponent.setForeground(UIManager.getColor("Tree.selectionForegroundInactive"));

2
src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRenderer.java

@ -59,7 +59,7 @@ public class DarkTreeCellRenderer extends DefaultTreeCellRenderer implements Tre
return rendererComponent; return rendererComponent;
} }
Component comp = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); Component comp = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (sel && !DarkUIUtil.hasFocus(tree)) { if (sel && !(DarkUIUtil.hasFocus(tree) || DarkUIUtil.hasFocus(comp))) {
comp.setForeground(UIManager.getColor("Tree.selectionForegroundInactive")); comp.setForeground(UIManager.getColor("Tree.selectionForegroundInactive"));
} }
return comp; return comp;

33
src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java

@ -23,6 +23,7 @@
*/ */
package com.github.weisj.darklaf.ui.tree; package com.github.weisj.darklaf.ui.tree;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.SystemInfo; import com.github.weisj.darklaf.util.SystemInfo;
import javax.swing.*; import javax.swing.*;
@ -53,7 +54,7 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
public static final String TREE_TABLE_TREE_KEY = "JTree.treeTableTree"; public static final String TREE_TABLE_TREE_KEY = "JTree.treeTableTree";
public static final String STRIPED_CLIENT_PROPERTY = "JTree.alternateRowColor"; public static final String STRIPED_CLIENT_PROPERTY = "JTree.alternateRowColor";
private final MouseListener mySelectionListener = new MouseAdapter() { private final MouseListener selectionListener = new MouseAdapter() {
boolean handled = false; boolean handled = false;
@Override @Override
@ -167,7 +168,7 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
tree.addPropertyChangeListener(this); tree.addPropertyChangeListener(this);
tree.addMouseListener(mySelectionListener); tree.addMouseListener(selectionListener);
} }
@Override @Override
@ -298,18 +299,40 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
@Override @Override
protected FocusListener createFocusListener() { protected FocusListener createFocusListener() {
return new FocusListener() { return new FocusListener() {
boolean focused = false;
@Override @Override
public void focusGained(final FocusEvent e) { public void focusGained(final FocusEvent e) {
tree.repaint(); if (!focused) {
tree.repaint();
}
focused = true;
} }
@Override @Override
public void focusLost(final FocusEvent e) { public void focusLost(final FocusEvent e) {
tree.repaint(); tree.stopEditing();
if (!hasFocus()) {
tree.repaint();
focused = false;
}
} }
}; };
} }
protected boolean hasFocus() {
if (!DarkUIUtil.hasFocus(tree)) {
Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
boolean treeEditor = owner instanceof JComponent
&& Boolean.TRUE.equals(((JComponent) owner).getClientProperty("JToggleButton.isTreeCellEditor"));
boolean treeRenderer = owner instanceof JComponent
&& Boolean.TRUE.equals(((JComponent) owner).getClientProperty("JToggleButton.isTreeCellRenderer"));
return owner == null || treeEditor || treeRenderer;
}
return true;
}
@Override @Override
protected TreeCellEditor createDefaultCellEditor() { protected TreeCellEditor createDefaultCellEditor() {
if (currentCellRenderer != null && (currentCellRenderer instanceof DarkTreeCellRenderer)) { if (currentCellRenderer != null && (currentCellRenderer instanceof DarkTreeCellRenderer)) {
@ -332,7 +355,7 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
@Override @Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
tree.removeMouseListener(mySelectionListener); tree.removeMouseListener(selectionListener);
tree.removePropertyChangeListener(this); tree.removePropertyChangeListener(this);
} }

1
src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java

@ -158,6 +158,7 @@ public final class DarkUIUtil {
} }
public static boolean hasFocus(final Component c) { public static boolean hasFocus(final Component c) {
if (c.hasFocus()) return true;
if (c instanceof Window) { if (c instanceof Window) {
return hasFocus(c); return hasFocus(c);
} }

Loading…
Cancel
Save