Browse Source

Make sure manually set properties aren't overridden when theme is changed.

pull/170/head
weisj 5 years ago
parent
commit
d58f56e38a
  1. 4
      core/src/main/java/com/github/weisj/darklaf/components/text/SearchTextField.java
  2. 2
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java
  3. 3
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUI.java
  4. 7
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java
  5. 3
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java
  6. 2
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java
  7. 9
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java
  8. 10
      utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java

4
core/src/main/java/com/github/weisj/darklaf/components/text/SearchTextField.java

@ -27,6 +27,8 @@ package com.github.weisj.darklaf.components.text;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.Document; import javax.swing.text.Document;
import com.github.weisj.darklaf.ui.text.DarkTextFieldUI;
public class SearchTextField extends JTextField { public class SearchTextField extends JTextField {
public static final int SEARCH = 0; public static final int SEARCH = 0;
@ -57,7 +59,7 @@ public class SearchTextField extends JTextField {
*/ */
public SearchTextField(final Document doc, final String text, final int columns) { public SearchTextField(final Document doc, final String text, final int columns) {
super(doc, text, columns); super(doc, text, columns);
putClientProperty("JTextField.variant", "search"); putClientProperty(DarkTextFieldUI.KEY_VARIANT, DarkTextFieldUI.VARIANT_SEARCH);
addActionListener(e -> { addActionListener(e -> {
SearchListener[] list = listenerList.getListeners(SearchListener.class); SearchListener[] list = listenerList.getListeners(SearchListener.class);
SearchEvent evt = new SearchEvent(SearchTextField.this, SEARCH, "search", getText()); SearchEvent evt = new SearchEvent(SearchTextField.this, SEARCH, "search", getText());

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

@ -61,7 +61,7 @@ public class DarkListUI extends DarkListUIBridge {
@Override @Override
protected void installDefaults() { protected void installDefaults() {
super.installDefaults(); super.installDefaults();
list.putClientProperty(KEY_ALTERNATE_ROW_COLOR, UIManager.getBoolean("List.alternateRowColor")); PropertyUtil.installBooleanProperty(list, KEY_ALTERNATE_ROW_COLOR, "List.alternateRowColor");
} }
@Override @Override

3
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUI.java

@ -28,7 +28,6 @@ import java.awt.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer; import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn; import javax.swing.table.TableColumn;
@ -78,10 +77,8 @@ public class DarkTableHeaderUI extends DarkTableHeaderUIBridge {
@Override @Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
super.uninstallDefaults(); super.uninstallDefaults();
if (header.getBorder() instanceof UIResource) {
LookAndFeel.uninstallBorder(header); LookAndFeel.uninstallBorder(header);
} }
}
@Override @Override
public void paint(final Graphics g2, final JComponent c) { public void paint(final Graphics g2, final JComponent c) {

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

@ -204,10 +204,9 @@ public class DarkTableUI extends DarkTableUIBridge implements FocusListener {
LookAndFeel.installProperty(table, "rowHeight", ROW_HEIGHT_FALLBACK); LookAndFeel.installProperty(table, "rowHeight", ROW_HEIGHT_FALLBACK);
} }
table.setDefaultEditor(Object.class, new DarkTableCellEditor()); table.setDefaultEditor(Object.class, new DarkTableCellEditor());
table.putClientProperty(KEY_RENDER_BOOLEAN_AS_CHECKBOX, PropertyUtil.installBooleanProperty(table, KEY_RENDER_BOOLEAN_AS_CHECKBOX, "Table.renderBooleanAsCheckBox");
UIManager.getBoolean("Table.renderBooleanAsCheckBox")); PropertyUtil.installBooleanProperty(table, KEY_ALTERNATE_ROW_COLOR, "Table.alternateRowColor");
table.putClientProperty(KEY_BOOLEAN_RENDER_TYPE, UIManager.getString("Table.booleanRenderType")); PropertyUtil.installProperty(table, KEY_BOOLEAN_RENDER_TYPE, UIManager.getString("Table.booleanRenderType"));
table.putClientProperty(KEY_ALTERNATE_ROW_COLOR, UIManager.getBoolean("Table.alternateRowColor"));
setupRendererComponents(table); setupRendererComponents(table);
borderColor = UIManager.getColor("TableHeader.borderColor"); borderColor = UIManager.getColor("TableHeader.borderColor");
selectionFocusBackground = UIManager.getColor("Table.focusSelectionBackground"); selectionFocusBackground = UIManager.getColor("Table.focusSelectionBackground");

3
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java

@ -51,7 +51,6 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
protected static final String KEY_PREFIX = "JTextField."; protected static final String KEY_PREFIX = "JTextField.";
public static final String KEY_VARIANT = KEY_PREFIX + "variant"; public static final String KEY_VARIANT = KEY_PREFIX + "variant";
public static final String KEY_SHOW_CLEAR = KEY_PREFIX + "showClear"; public static final String KEY_SHOW_CLEAR = KEY_PREFIX + "showClear";
public static final String KEY_KEEP_SELECTION_ON_FOCUS_LOST = KEY_PREFIX + "keepSelectionOnFocusLost";
public static final String KEY_FIND_POPUP = KEY_PREFIX + "Search.FindPopup"; public static final String KEY_FIND_POPUP = KEY_PREFIX + "Search.FindPopup";
public static final String VARIANT_SEARCH = "search"; public static final String VARIANT_SEARCH = "search";
protected static Icon clear; protected static Icon clear;
@ -264,8 +263,6 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
@Override @Override
protected void installDefaults() { protected void installDefaults() {
super.installDefaults(); super.installDefaults();
editor.putClientProperty(KEY_KEEP_SELECTION_ON_FOCUS_LOST,
UIManager.getBoolean("TextField.keepSelectionOnFocusLost"));
arcSize = UIManager.getInt("TextField.arc"); arcSize = UIManager.getInt("TextField.arc");
borderSize = UIManager.getInt("TextField.borderThickness"); borderSize = UIManager.getInt("TextField.borderThickness");
searchArcSize = UIManager.getInt("TextField.searchArc"); searchArcSize = UIManager.getInt("TextField.searchArc");

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

@ -108,7 +108,7 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
editor.setBorder(null); editor.setBorder(null);
} }
if (editor != null) { if (editor != null) {
editor.putClientProperty(KEY_ROUNDED_SELECTION, UIManager.getBoolean("TextComponent.roundedSelection")); PropertyUtil.installBooleanProperty(editor, KEY_ROUNDED_SELECTION, "TextComponent.roundedSelection");
} }
disabledColor = UIManager.getColor(getPropertyPrefix() + ".disabledBackground"); disabledColor = UIManager.getColor(getPropertyPrefix() + ".disabledBackground");
inactiveColor = UIManager.getColor(getPropertyPrefix() + ".inactiveBackground"); inactiveColor = UIManager.getColor(getPropertyPrefix() + ".inactiveBackground");

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

@ -168,11 +168,10 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
collapsedSelected = UIManager.getIcon("Tree.collapsed.selected.unfocused.icon"); collapsedSelected = UIManager.getIcon("Tree.collapsed.selected.unfocused.icon");
collapsedFocus = UIManager.getIcon("Tree.collapsed.unselected.focused.icon"); collapsedFocus = UIManager.getIcon("Tree.collapsed.unselected.focused.icon");
collapsed = UIManager.getIcon("Tree.collapsed.unselected.unfocused.icon"); collapsed = UIManager.getIcon("Tree.collapsed.unselected.unfocused.icon");
tree.putClientProperty(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX, PropertyUtil.installBooleanProperty(tree, KEY_RENDER_BOOLEAN_AS_CHECKBOX, "Tree.renderBooleanAsCheckBox");
UIManager.getBoolean("Tree.renderBooleanAsCheckBox")); PropertyUtil.installProperty(tree, KEY_BOOLEAN_RENDER_TYPE, UIManager.getString("Tree.booleanRenderType"));
tree.putClientProperty(DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE, UIManager.getString("Tree.booleanRenderType")); PropertyUtil.installProperty(tree, KEY_LINE_STYLE, UIManager.getString("Tree.defaultLineStyle"));
tree.setShowsRootHandles(true); LookAndFeel.installProperty(tree, JTree.SHOWS_ROOT_HANDLES_PROPERTY, true);
tree.putClientProperty(KEY_LINE_STYLE, UIManager.getString("Tree.defaultLineStyle"));
} }
@Override @Override

10
utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java

@ -31,6 +31,16 @@ import javax.swing.*;
public class PropertyUtil { public class PropertyUtil {
public static void installProperty(final JComponent c, final String key, final Object value) {
if (c.getClientProperty(key) == null) {
c.putClientProperty(key, value);
}
}
public static void installBooleanProperty(final JComponent c, final String key, final String valueKey) {
installProperty(c, key, UIManager.getBoolean(valueKey));
}
public static boolean getBooleanProperty(final Component c, final String property) { public static boolean getBooleanProperty(final Component c, final String property) {
return getBooleanProperty(c, property, false); return getBooleanProperty(c, property, false);
} }

Loading…
Cancel
Save