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. 29
      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) {
setOpaque(opaque);
putClientProperty("JToggleButton.isTreeCellEditor", true);
putClientProperty("JToggleButton.isTableCellEditor", true);
}
public void setHasFocus(final boolean hasFocus) {
@ -137,6 +139,8 @@ public class DarkCellRendererToggleButton<T extends JToggleButton & CellEditorTo
public CellEditorRadioButton(final boolean opaque) {
setOpaque(opaque);
putClientProperty("JToggleButton.isTreeCellEditor", true);
putClientProperty("JToggleButton.isTableCellEditor", true);
}
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();
if ("componentOrientation".equals(key)) {
checkBox.repaint();
hitArea.setRoundRect(0, 0, 0, 0, 0, 0);
} else if ("JToggleButton.isTreeCellEditor".equals(key) || "JToggleButton.isTableCellEditor".equals(key)) {
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.y -= bounds.y + button.getY();
button.putClientProperty("JToggleButton.clearHitArea", true);
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<Object>) editorComponent).addItem(value);
((JComboBox<?>) editorComponent).setSelectedItem(value);
} else if (editorComponent instanceof JToggleButton && adjustBoolValue) {
} else if (editorComponent instanceof JToggleButton) {
((JToggleButton) editorComponent).setSelected(!(((JToggleButton) editorComponent).isSelected()));
SwingUtilities.invokeLater(tree::stopEditing);
}
editorComponent.setOpaque(false);
editorComponent.setComponentOrientation(tree.getComponentOrientation());
if (isSelected && editorComponent instanceof JToggleButton) {
if (DarkUIUtil.hasFocus(tree)) {
if (editorComponent instanceof JToggleButton) {
if (DarkUIUtil.hasFocus(tree) || DarkUIUtil.hasFocus(editorComponent)) {
editorComponent.setForeground(UIManager.getColor("Tree.selectionForeground"));
} else {
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;
}
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"));
}
return comp;

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

@ -23,6 +23,7 @@
*/
package com.github.weisj.darklaf.ui.tree;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.SystemInfo;
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 STRIPED_CLIENT_PROPERTY = "JTree.alternateRowColor";
private final MouseListener mySelectionListener = new MouseAdapter() {
private final MouseListener selectionListener = new MouseAdapter() {
boolean handled = false;
@Override
@ -167,7 +168,7 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
protected void installListeners() {
super.installListeners();
tree.addPropertyChangeListener(this);
tree.addMouseListener(mySelectionListener);
tree.addMouseListener(selectionListener);
}
@Override
@ -298,18 +299,40 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
@Override
protected FocusListener createFocusListener() {
return new FocusListener() {
boolean focused = false;
@Override
public void focusGained(final FocusEvent e) {
if (!focused) {
tree.repaint();
}
focused = true;
}
@Override
public void focusLost(final FocusEvent e) {
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
protected TreeCellEditor createDefaultCellEditor() {
if (currentCellRenderer != null && (currentCellRenderer instanceof DarkTreeCellRenderer)) {
@ -332,7 +355,7 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
@Override
protected void uninstallListeners() {
super.uninstallListeners();
tree.removeMouseListener(mySelectionListener);
tree.removeMouseListener(selectionListener);
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) {
if (c.hasFocus()) return true;
if (c instanceof Window) {
return hasFocus(c);
}

Loading…
Cancel
Save