Browse Source

Fixed tree not being able to start editing.

pull/127/head
weisj 5 years ago
parent
commit
9088b67358
  1. 10
      core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java
  2. 7
      core/src/main/java/com/github/weisj/darklaf/ui/combobox/ComboBoxConstants.java
  3. 1
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java
  4. 11
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/SpinnerConstants.java
  5. 9
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java
  6. 2
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java
  7. 15
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java
  8. 11
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java
  9. 10
      core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/ToggleButtonConstants.java
  10. 14
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java
  11. 16
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java
  12. 25
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java

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

@ -27,7 +27,7 @@ import com.github.weisj.darklaf.components.SelectableTreeNode;
import com.github.weisj.darklaf.decorators.CellRenderer; import com.github.weisj.darklaf.decorators.CellRenderer;
import com.github.weisj.darklaf.ui.table.DarkTableCellFocusBorder; import com.github.weisj.darklaf.ui.table.DarkTableCellFocusBorder;
import com.github.weisj.darklaf.ui.table.DarkTableUI; import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.togglebutton.DarkToggleButtonUI; import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonConstants;
import com.github.weisj.darklaf.ui.tree.DarkTreeCellRenderer; import com.github.weisj.darklaf.ui.tree.DarkTreeCellRenderer;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
@ -104,8 +104,8 @@ public class DarkCellRendererToggleButton<T extends JToggleButton & CellEditorTo
public CellEditorCheckBox(final boolean opaque) { public CellEditorCheckBox(final boolean opaque) {
setOpaque(opaque); setOpaque(opaque);
putClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR, true); putClientProperty(ToggleButtonConstants.KEY_IS_TREE_EDITOR, true);
putClientProperty(DarkToggleButtonUI.KEY_IS_TABLE_EDITOR, true); putClientProperty(ToggleButtonConstants.KEY_IS_TABLE_EDITOR, true);
} }
public void setHasFocus(final boolean hasFocus) { public void setHasFocus(final boolean hasFocus) {
@ -129,8 +129,8 @@ public class DarkCellRendererToggleButton<T extends JToggleButton & CellEditorTo
public CellEditorRadioButton(final boolean opaque) { public CellEditorRadioButton(final boolean opaque) {
setOpaque(opaque); setOpaque(opaque);
putClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR, true); putClientProperty(ToggleButtonConstants.KEY_IS_TREE_EDITOR, true);
putClientProperty(DarkToggleButtonUI.KEY_IS_TABLE_EDITOR, true); putClientProperty(ToggleButtonConstants.KEY_IS_TABLE_EDITOR, true);
} }
public void setHasFocus(final boolean hasFocus) { public void setHasFocus(final boolean hasFocus) {

7
core/src/main/java/com/github/weisj/darklaf/ui/combobox/ComboBoxConstants.java

@ -23,12 +23,15 @@
*/ */
package com.github.weisj.darklaf.ui.combobox; package com.github.weisj.darklaf.ui.combobox;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.tree.DarkTreeUI;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
public interface ComboBoxConstants { public interface ComboBoxConstants {
String KEY_IS_TREE_EDITOR = "JComboBox.isTreeCellEditor"; String KEY_IS_TREE_EDITOR = DarkTreeUI.KEY_IS_TREE_EDITOR;
String KEY_IS_TABLE_EDITOR = "JComboBox.isTableCellEditor"; String KEY_IS_TABLE_EDITOR = DarkTableUI.KEY_IS_TABLE_EDITOR;
static boolean isTreeOrTableCellEditor(final Component c) { static boolean isTreeOrTableCellEditor(final Component c) {
return isTreeCellEditor(c) || isTableCellEditor(c); return isTreeCellEditor(c) || isTableCellEditor(c);

1
core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java

@ -45,6 +45,7 @@ public class DarkListUI extends DarkListUIBridge {
public static final String KEY_IS_EDITING = KEY_PREFIX + "isEditing"; public static final String KEY_IS_EDITING = KEY_PREFIX + "isEditing";
public static final String RENDER_TYPE_CHECKBOX = "checkBox"; public static final String RENDER_TYPE_CHECKBOX = "checkBox";
public static final String RENDER_TYPE_RADIOBUTTON = "radioButton"; public static final String RENDER_TYPE_RADIOBUTTON = "radioButton";
public static final String KEY_IS_LIST_RENDERER = "JComponent.listCellEditor";
static { static {
UIManager.put("List.cellRenderer", new DarkListCellRenderer()); UIManager.put("List.cellRenderer", new DarkListCellRenderer());

11
core/src/main/java/com/github/weisj/darklaf/ui/spinner/SpinnerConstants.java

@ -23,15 +23,18 @@
*/ */
package com.github.weisj.darklaf.ui.spinner; package com.github.weisj.darklaf.ui.spinner;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.tree.DarkTreeUI;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
public interface SpinnerConstants { public interface SpinnerConstants {
String KEY_VARIANT = "JSpinner.variant"; String KEY_VARIANT = "JSpinner.variant";
String KEY_IS_TREE_EDITOR = "JSpinner.isTreeCellEditor"; String KEY_IS_TREE_EDITOR = DarkTreeUI.KEY_IS_TREE_EDITOR;
String KEY_IS_TREE_RENDER = "JSpinner.isTreeCellRenderer"; String KEY_IS_TREE_RENDER = DarkTreeUI.KEY_IS_TREE_RENDERER;
String KEY_IS_TABLE_EDITOR = "JSpinner.isTableCellEditor"; String KEY_IS_TABLE_EDITOR = DarkTableUI.KEY_IS_TABLE_EDITOR;
String KEY_IS_TABLE_RENDERER = "JSpinner.isTableCellRenderer"; String KEY_IS_TABLE_RENDERER = DarkTableUI.KEY_IS_TABLE_RENDERER;
String KEY_EDITOR_ALIGNMENT = "JSpinner.cellEditorAlignment"; String KEY_EDITOR_ALIGNMENT = "JSpinner.cellEditorAlignment";
String VARIANT_PLUS_MINUS = "plusMinus"; String VARIANT_PLUS_MINUS = "plusMinus";

9
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java

@ -24,9 +24,12 @@
package com.github.weisj.darklaf.ui.table; package com.github.weisj.darklaf.ui.table;
import com.github.weisj.darklaf.ui.cell.CellUtil; import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.ui.combobox.ComboBoxConstants;
import com.github.weisj.darklaf.ui.combobox.DarkComboBoxUI; import com.github.weisj.darklaf.ui.combobox.DarkComboBoxUI;
import com.github.weisj.darklaf.ui.spinner.DarkSpinnerUI; import com.github.weisj.darklaf.ui.spinner.DarkSpinnerUI;
import com.github.weisj.darklaf.ui.spinner.SpinnerConstants;
import com.github.weisj.darklaf.ui.text.DarkTextUI; import com.github.weisj.darklaf.ui.text.DarkTextUI;
import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonConstants;
import com.github.weisj.darklaf.util.PropertyValue; import com.github.weisj.darklaf.util.PropertyValue;
import javax.swing.*; import javax.swing.*;
@ -67,7 +70,7 @@ public class DarkTableCellEditor extends DefaultCellEditor {
public DarkTableCellEditor(final JTextField textField) { public DarkTableCellEditor(final JTextField textField) {
super(textField); super(textField);
textField.setBorder(new TextTableCellEditorBorder()); textField.setBorder(new TextTableCellEditorBorder());
textField.putClientProperty(DarkTextUI.KEY_IS_TABLE_EDITOR, Boolean.TRUE); textField.putClientProperty(DarkTextUI.KEY_IS_TABLE_EDITOR, true);
setClickCountToStart(2); setClickCountToStart(2);
} }
@ -89,13 +92,14 @@ public class DarkTableCellEditor extends DefaultCellEditor {
} }
}); });
comboBox.putClientProperty(ComboBoxConstants.KEY_IS_TABLE_EDITOR, true);
setClickCountToStart(2); setClickCountToStart(2);
} }
public DarkTableCellEditor(final JSpinner spinner) { public DarkTableCellEditor(final JSpinner spinner) {
super(dummyCheckBox); super(dummyCheckBox);
editorComponent = spinner; editorComponent = spinner;
spinner.putClientProperty("JSpinner.isTableCellEditor", Boolean.TRUE); spinner.putClientProperty(SpinnerConstants.KEY_IS_TABLE_EDITOR, Boolean.TRUE);
setClickCountToStart(2); setClickCountToStart(2);
delegate = new EditorDelegate() { delegate = new EditorDelegate() {
public Object getCellEditorValue() { public Object getCellEditorValue() {
@ -150,6 +154,7 @@ public class DarkTableCellEditor extends DefaultCellEditor {
toggleButton.setSelected(selected); toggleButton.setSelected(selected);
} }
}; };
toggleButton.putClientProperty(ToggleButtonConstants.KEY_IS_TABLE_EDITOR, true);
toggleButton.addActionListener(delegate); toggleButton.addActionListener(delegate);
toggleButton.setRequestFocusEnabled(false); toggleButton.setRequestFocusEnabled(false);
} }

2
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java

@ -46,6 +46,8 @@ import java.util.function.Supplier;
*/ */
public class DarkTableUI extends DarkTableUIBridge implements FocusListener { public class DarkTableUI extends DarkTableUIBridge implements FocusListener {
public static final String KEY_IS_TABLE_EDITOR = "JComponent.isTableEditor";
public static final String KEY_IS_TABLE_RENDERER = "JComponent.isTableRenderer";
protected static final String KEY_PREFIX = "JTable."; protected static final String KEY_PREFIX = "JTable.";
public static final String KEY_ALTERNATE_ROW_COLOR = KEY_PREFIX + "alternateRowColor"; public static final String KEY_ALTERNATE_ROW_COLOR = KEY_PREFIX + "alternateRowColor";
public static final String KEY_RENDER_BOOLEAN_AS_CHECKBOX = KEY_PREFIX + "renderBooleanAsCheckBox"; public static final String KEY_RENDER_BOOLEAN_AS_CHECKBOX = KEY_PREFIX + "renderBooleanAsCheckBox";

15
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java

@ -23,7 +23,6 @@
*/ */
package com.github.weisj.darklaf.ui.text; package com.github.weisj.darklaf.ui.text;
import com.github.weisj.darklaf.ui.table.TextTableCellEditorBorder;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsContext;
import com.github.weisj.darklaf.util.GraphicsUtil; import com.github.weisj.darklaf.util.GraphicsUtil;
@ -40,7 +39,6 @@ import java.awt.*;
*/ */
public class DarkTextBorder implements Border, UIResource { public class DarkTextBorder implements Border, UIResource {
private static final Border editorBorder = new TextTableCellEditorBorder();
protected final Color errorBorderColor; protected final Color errorBorderColor;
protected final Color focusErrorBorderColor; protected final Color focusErrorBorderColor;
protected final Color focusBorderColor; protected final Color focusBorderColor;
@ -76,12 +74,6 @@ public class DarkTextBorder implements Border, UIResource {
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTextUI.KEY_HAS_ERROR)); && Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTextUI.KEY_HAS_ERROR));
} }
protected static boolean isCellEditor(final Component c) {
return c instanceof JComponent
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTextUI.KEY_IS_CELL_EDITOR));
}
protected int getArcSize(final Component c) { protected int getArcSize(final Component c) {
return DarkTextFieldUI.isSearchField(c) ? searchArc : arc; return DarkTextFieldUI.isSearchField(c) ? searchArc : arc;
} }
@ -96,10 +88,6 @@ public class DarkTextBorder implements Border, UIResource {
public void paintBorder(final Component c, final Graphics g2, final int x, final int y, public void paintBorder(final Component c, final Graphics g2, final int x, final int y,
final int width, final int height) { final int width, final int height) {
if (isCellEditor(c)) {
editorBorder.paintBorder(c, g2, x, y, width, height);
return;
}
Graphics2D g = (Graphics2D) g2; Graphics2D g = (Graphics2D) g2;
g.translate(x, y); g.translate(x, y);
GraphicsContext config = GraphicsUtil.setupStrokePainting(g); GraphicsContext config = GraphicsUtil.setupStrokePainting(g);
@ -138,9 +126,6 @@ public class DarkTextBorder implements Border, UIResource {
@Override @Override
public Insets getBorderInsets(final Component c) { public Insets getBorderInsets(final Component c) {
if (isCellEditor(c)) {
return editorBorder.getBorderInsets(c);
}
Insets insets = new Insets(borderSize + padding.top, borderSize + padding.left, Insets insets = new Insets(borderSize + padding.top, borderSize + padding.left,
borderSize + padding.bottom, borderSize + padding.right); borderSize + padding.bottom, borderSize + padding.right);
if (DarkTextFieldUI.isSearchField(c)) { if (DarkTextFieldUI.isSearchField(c)) {

11
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java

@ -23,7 +23,10 @@
*/ */
package com.github.weisj.darklaf.ui.text; package com.github.weisj.darklaf.ui.text;
import com.github.weisj.darklaf.ui.list.DarkListUI;
import com.github.weisj.darklaf.ui.table.DarkTableCellBorder; import com.github.weisj.darklaf.ui.table.DarkTableCellBorder;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.tree.DarkTreeUI;
import com.github.weisj.darklaf.util.DarkSwingUtil; import com.github.weisj.darklaf.util.DarkSwingUtil;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsContext;
@ -53,9 +56,9 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
protected static final String KEY_PREFIX = "JTextComponent."; protected static final String KEY_PREFIX = "JTextComponent.";
public static final String KEY_ROUNDED_SELECTION = KEY_PREFIX + "roundedSelection"; public static final String KEY_ROUNDED_SELECTION = KEY_PREFIX + "roundedSelection";
public static final String KEY_HAS_ERROR = KEY_PREFIX + "hasError"; public static final String KEY_HAS_ERROR = KEY_PREFIX + "hasError";
public static final String KEY_IS_CELL_EDITOR = KEY_PREFIX + "cellEditor"; public static final String KEY_IS_TREE_EDITOR = DarkTreeUI.KEY_IS_TREE_EDITOR;
public static final String KEY_IS_TABLE_EDITOR = KEY_PREFIX + "isTableCellEditor"; public static final String KEY_IS_TABLE_EDITOR = DarkTableUI.KEY_IS_TABLE_EDITOR;
public static final String KEY_IS_LIST_RENDER = KEY_PREFIX + "listCellEditor"; public static final String KEY_IS_LIST_RENDER = DarkListUI.KEY_IS_LIST_RENDERER;
protected JTextComponent editor; protected JTextComponent editor;
private FocusListener focusListener = new FocusListener() { private FocusListener focusListener = new FocusListener() {
@ -151,7 +154,7 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
if (parent != null) { if (parent != null) {
g.setColor(parent.getBackground()); g.setColor(parent.getBackground());
} }
if (DarkTextBorder.isCellEditor(editor) || DarkUIUtil.isInCell(editor)) { if (DarkUIUtil.isInCell(editor)) {
g.setColor(getBackground(editor)); g.setColor(getBackground(editor));
} }
g.fillRect(0, 0, editor.getWidth(), editor.getHeight()); g.fillRect(0, 0, editor.getWidth(), editor.getHeight());

10
core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/ToggleButtonConstants.java

@ -23,6 +23,8 @@
*/ */
package com.github.weisj.darklaf.ui.togglebutton; package com.github.weisj.darklaf.ui.togglebutton;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.tree.DarkTreeUI;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import javax.swing.*; import javax.swing.*;
@ -30,10 +32,10 @@ import java.awt.*;
public interface ToggleButtonConstants { public interface ToggleButtonConstants {
String KEY_VARIANT = "JToggleButton.variant"; String KEY_VARIANT = "JToggleButton.variant";
String KEY_IS_TREE_EDITOR = "JToggleButton.isTreeCellEditor"; String KEY_IS_TREE_EDITOR = DarkTreeUI.KEY_IS_TREE_EDITOR;
String KEY_IS_TREE_RENDER = "JToggleButton.isTreeCellRenderer"; String KEY_IS_TREE_RENDERER = DarkTreeUI.KEY_IS_TREE_RENDERER;
String KEY_IS_TABLE_EDITOR = "JToggleButton.isTableCellEditor"; String KEY_IS_TABLE_EDITOR = DarkTableUI.KEY_IS_TABLE_EDITOR;
String KEY_IS_TABLE_RENDERER = "JToggleButton.isTableCellRenderer"; String KEY_IS_TABLE_RENDERER = DarkTableUI.KEY_IS_TABLE_RENDERER;
String KEY_CLEAR_HIT_AREA = "JToggleButton.clearHitArea"; String KEY_CLEAR_HIT_AREA = "JToggleButton.clearHitArea";
String VARIANT_SLIDER = "slider"; String VARIANT_SLIDER = "slider";

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

@ -24,9 +24,12 @@
package com.github.weisj.darklaf.ui.tree; package com.github.weisj.darklaf.ui.tree;
import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton; import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton;
import com.github.weisj.darklaf.ui.text.DarkTextUI;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.tree.DefaultTreeCellEditor; import javax.swing.tree.DefaultTreeCellEditor;
import javax.swing.tree.TreeCellEditor;
import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.awt.*; import java.awt.*;
@ -67,6 +70,17 @@ public class DarkDefaultTreeEditor extends DefaultTreeCellEditor {
}; };
} }
@Override
protected TreeCellEditor createTreeCellEditor() {
Border border = UIManager.getBorder("Tree.editorBorder");
JTextField textField = new JTextField();
textField.setBorder(border);
textField.putClientProperty(DarkTextUI.KEY_IS_TREE_EDITOR, true);
DefaultCellEditor editor = new DefaultCellEditor(textField);
editor.setClickCountToStart(1);
return editor;
}
@Override @Override
public Component getTreeCellEditorComponent(final JTree tree, final Object value, final boolean isSelected, public Component getTreeCellEditorComponent(final JTree tree, final Object value, final boolean isSelected,
final boolean expanded, final boolean leaf, final int row) { final boolean expanded, final boolean leaf, final int row) {

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

@ -24,7 +24,10 @@
package com.github.weisj.darklaf.ui.tree; package com.github.weisj.darklaf.ui.tree;
import com.github.weisj.darklaf.components.SelectableTreeNode; import com.github.weisj.darklaf.components.SelectableTreeNode;
import com.github.weisj.darklaf.ui.togglebutton.DarkToggleButtonUI; import com.github.weisj.darklaf.ui.combobox.ComboBoxConstants;
import com.github.weisj.darklaf.ui.spinner.SpinnerConstants;
import com.github.weisj.darklaf.ui.text.DarkTextUI;
import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonConstants;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import javax.swing.*; import javax.swing.*;
@ -52,6 +55,7 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi
super(textField); super(textField);
textField.setBorder(UIManager.getBorder("Tree.editorBorder")); textField.setBorder(UIManager.getBorder("Tree.editorBorder"));
textField.addFocusListener(this); textField.addFocusListener(this);
textField.putClientProperty(DarkTextUI.KEY_IS_TREE_EDITOR, true);
} }
public DarkTreeCellEditor(final JCheckBox checkBox) { public DarkTreeCellEditor(final JCheckBox checkBox) {
@ -75,7 +79,7 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi
} }
}; };
toggleButton.setFocusPainted(false); toggleButton.setFocusPainted(false);
toggleButton.putClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR, Boolean.TRUE); toggleButton.putClientProperty(ToggleButtonConstants.KEY_IS_TREE_EDITOR, Boolean.TRUE);
toggleButton.addActionListener(delegate); toggleButton.addActionListener(delegate);
toggleButton.setRequestFocusEnabled(false); toggleButton.setRequestFocusEnabled(false);
toggleButton.addFocusListener(this); toggleButton.addFocusListener(this);
@ -100,6 +104,7 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi
} }
}); });
comboBox.putClientProperty(ComboBoxConstants.KEY_IS_TREE_EDITOR, Boolean.TRUE);
comboBox.addFocusListener(this); comboBox.addFocusListener(this);
setClickCountToStart(2); setClickCountToStart(2);
} }
@ -107,8 +112,8 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi
public DarkTreeCellEditor(final JSpinner spinner) { public DarkTreeCellEditor(final JSpinner spinner) {
super(dummyCheckBox); super(dummyCheckBox);
editorComponent = spinner; editorComponent = spinner;
editorComponent.putClientProperty(SpinnerConstants.KEY_IS_TREE_EDITOR, Boolean.TRUE);
editorComponent.addFocusListener(this); editorComponent.addFocusListener(this);
spinner.putClientProperty("JSpinner.isTreeCellEditor", Boolean.TRUE);
setClickCountToStart(2); setClickCountToStart(2);
delegate = new EditorDelegate() { delegate = new EditorDelegate() {
public Object getCellEditorValue() { public Object getCellEditorValue() {
@ -144,11 +149,6 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi
return editorComponent instanceof JToggleButton && DarkTreeCellRenderer.isBooleanRenderingEnabled(tree); return editorComponent instanceof JToggleButton && DarkTreeCellRenderer.isBooleanRenderingEnabled(tree);
} }
@Override
public boolean isCellEditable(final EventObject anEvent) {
return super.isCellEditable(anEvent);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public Component getTreeCellEditorComponent(final JTree tree, final Object value, public Component getTreeCellEditorComponent(final JTree tree, final Object value,

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

@ -23,7 +23,6 @@
*/ */
package com.github.weisj.darklaf.ui.tree; package com.github.weisj.darklaf.ui.tree;
import com.github.weisj.darklaf.ui.togglebutton.DarkToggleButtonUI;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.SystemInfo; import com.github.weisj.darklaf.util.SystemInfo;
@ -59,6 +58,8 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
public static final String STYLE_LINE = "line"; public static final String STYLE_LINE = "line";
public static final String STYLE_DASHED = "dashed"; public static final String STYLE_DASHED = "dashed";
public static final String STYLE_NONE = "none"; public static final String STYLE_NONE = "none";
public static final String KEY_IS_TREE_EDITOR = "JComponent.isTreeEditor";
public static final String KEY_IS_TREE_RENDERER = "JComponent.isTreeRenderer";
private final MouseListener selectionListener = new MouseAdapter() { private final MouseListener selectionListener = new MouseAdapter() {
boolean handled = false; boolean handled = false;
@ -308,21 +309,16 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
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) {
if (!focused) {
tree.repaint(); tree.repaint();
} }
focused = true;
}
@Override @Override
public void focusLost(final FocusEvent e) { public void focusLost(final FocusEvent e) {
tree.stopEditing(); boolean focused = hasFocus(e != null ? e.getOppositeComponent() : null);
focused = hasFocus(e != null ? e.getOppositeComponent() : null);
if (!focused) { if (!focused) {
tree.stopEditing();
tree.repaint(); tree.repaint();
} }
} }
@ -341,10 +337,10 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
} }
boolean treeEditor = owner instanceof JComponent boolean treeEditor = owner instanceof JComponent
&& Boolean.TRUE.equals( && Boolean.TRUE.equals(
((JComponent) owner).getClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR)); ((JComponent) owner).getClientProperty(DarkTreeUI.KEY_IS_TREE_EDITOR));
boolean treeRenderer = owner instanceof JComponent boolean treeRenderer = !treeEditor && owner instanceof JComponent
&& Boolean.TRUE.equals( && Boolean.TRUE.equals(
((JComponent) owner).getClientProperty(DarkToggleButtonUI.KEY_IS_TREE_RENDER)); ((JComponent) owner).getClientProperty(DarkTreeUI.KEY_IS_TREE_RENDERER));
return treeEditor || treeRenderer; return treeEditor || treeRenderer;
} }
return true; return true;
@ -376,6 +372,13 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
tree.removePropertyChangeListener(this); tree.removePropertyChangeListener(this);
} }
@Override
protected boolean startEditing(final TreePath path, final MouseEvent event) {
boolean editing = super.startEditing(path, event);
if (editing) tree.repaint();
return editing;
}
@Override @Override
public void paint(final Graphics g, final JComponent c) { public void paint(final Graphics g, final JComponent c) {
if (tree != c) { if (tree != c) {

Loading…
Cancel
Save