Browse Source

Simplified boolean client property checks.

pull/154/head
weisj 5 years ago
parent
commit
941e1fbdda
  1. 32
      core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java
  2. 29
      core/src/main/java/com/github/weisj/darklaf/ui/button/ButtonConstants.java
  3. 7
      core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java
  4. 7
      core/src/main/java/com/github/weisj/darklaf/ui/combobox/ComboBoxConstants.java
  5. 3
      core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java
  6. 5
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java
  7. 7
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java
  8. 3
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java
  9. 26
      core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java
  10. 10
      core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/MouseGrabber.java
  11. 5
      core/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarUI.java
  12. 3
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java
  13. 5
      core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollBarUtil.java
  14. 21
      core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java
  15. 9
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/SpinnerConstants.java
  16. 3
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkHandler.java
  17. 3
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java
  18. 4
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneLayout.java
  19. 6
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneScrollLayout.java
  20. 7
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java
  21. 4
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java
  22. 10
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellFocusBorder.java
  23. 6
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java
  24. 9
      core/src/main/java/com/github/weisj/darklaf/ui/table/TableUIBridge.java
  25. 4
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java
  26. 4
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java
  27. 3
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java
  28. 10
      core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/ToggleButtonConstants.java
  29. 4
      core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DropPreviewPanel.java
  30. 2
      core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java
  31. 4
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java
  32. 6
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRenderer.java
  33. 14
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java
  34. 3
      core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java
  35. 3
      core/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java
  36. 3
      core/src/test/java/ui/list/ListDemo.java
  37. 5
      core/src/test/java/ui/table/TableDemo.java
  38. 5
      core/src/test/java/ui/tree/TreeDemo.java
  39. 5
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java
  40. 64
      utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java

32
core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java

@ -32,6 +32,7 @@ import com.github.weisj.darklaf.platform.DecorationsHandler;
import com.github.weisj.darklaf.ui.rootpane.DarkRootPaneUI; import com.github.weisj.darklaf.ui.rootpane.DarkRootPaneUI;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.Pair; import com.github.weisj.darklaf.util.Pair;
import com.github.weisj.darklaf.util.PropertyUtil;
public class DarkPopupFactory extends PopupFactory { public class DarkPopupFactory extends PopupFactory {
@ -47,21 +48,19 @@ public class DarkPopupFactory extends PopupFactory {
@Override @Override
public Popup getPopup(final Component owner, final Component contents, public Popup getPopup(final Component owner, final Component contents,
final int x, final int y) throws IllegalArgumentException { final int x, final int y) throws IllegalArgumentException {
boolean isJComponent = contents instanceof JComponent; Pair<Popup, PopupType> result = getEffectivePopup(owner, contents, x, y);
Pair<Popup, PopupType> result = getEffectivePopup(owner, contents, x, y, isJComponent);
Popup popup = result.getFirst(); Popup popup = result.getFirst();
PopupType type = result.getSecond(); PopupType type = result.getSecond();
setupPopup(popup, type, contents, isJComponent); setupPopup(popup, type, contents);
return popup; return popup;
} }
protected Pair<Popup, PopupType> getEffectivePopup(final Component owner, final Component contents, protected Pair<Popup, PopupType> getEffectivePopup(final Component owner, final Component contents,
final int x, final int y, final int x, final int y) {
final boolean isJComponent) {
Popup popup = super.getPopup(owner, contents, x, y); Popup popup = super.getPopup(owner, contents, x, y);
PopupType type = getPopupType(popup); PopupType type = getPopupType(popup);
boolean forceHeavy = type != PopupType.HEAVY_WEIGHT && isJComponent boolean forceHeavy = type != PopupType.HEAVY_WEIGHT
&& Boolean.TRUE.equals(((JComponent) contents).getClientProperty(KEY_FORCE_HEAVYWEIGHT)); && PropertyUtil.getBooleanProperty(contents, KEY_FORCE_HEAVYWEIGHT);
if (forceHeavy) { if (forceHeavy) {
// null owner forces a heavyweight popup. // null owner forces a heavyweight popup.
Popup p = super.getPopup(getHeavyWeightParent(), contents, x, y); Popup p = super.getPopup(getHeavyWeightParent(), contents, x, y);
@ -77,8 +76,7 @@ public class DarkPopupFactory extends PopupFactory {
return PopupType.HEAVY_WEIGHT; return PopupType.HEAVY_WEIGHT;
} }
protected void setupPopup(final Popup popup, final PopupType type, final Component contents, protected void setupPopup(final Popup popup, final PopupType type, final Component contents) {
final boolean isJComponent) {
if (type == PopupType.MEDIUM_WEIGHT) { if (type == PopupType.MEDIUM_WEIGHT) {
JRootPane rootPane = SwingUtilities.getRootPane(contents); JRootPane rootPane = SwingUtilities.getRootPane(contents);
// Prevents decorations from being reinstalled. // Prevents decorations from being reinstalled.
@ -86,21 +84,17 @@ public class DarkPopupFactory extends PopupFactory {
} else if (type == PopupType.HEAVY_WEIGHT) { } else if (type == PopupType.HEAVY_WEIGHT) {
Window window = SwingUtilities.getWindowAncestor(contents); Window window = SwingUtilities.getWindowAncestor(contents);
if (window != null) { if (window != null) {
boolean isFocusable = isJComponent boolean isFocusable = PropertyUtil.getBooleanProperty(contents, KEY_FOCUSABLE_POPUP);
&& Boolean.TRUE.equals(((JComponent) contents).getClientProperty(KEY_FOCUSABLE_POPUP)); boolean startHidden = PropertyUtil.getBooleanProperty(contents, KEY_START_HIDDEN);
boolean startHidden = isJComponent setupWindow(window, contents, isFocusable, startHidden);
&& Boolean.TRUE.equals(((JComponent) contents).getClientProperty(KEY_START_HIDDEN));
setupWindow(window, contents, isJComponent, isFocusable, startHidden);
} }
} }
} }
protected void setupWindow(final Window window, final Component contents, final boolean isJComponent, protected void setupWindow(final Window window, final Component contents,
final boolean isFocusable, final boolean startHidden) { final boolean isFocusable, final boolean startHidden) {
boolean noDecorations = isJComponent boolean noDecorations = PropertyUtil.getBooleanProperty(contents, KEY_NO_DECORATION);
&& Boolean.TRUE.equals(((JComponent) contents).getClientProperty(KEY_NO_DECORATION)); boolean opaque = PropertyUtil.getBooleanProperty(contents, KEY_OPAQUE);
boolean opaque = isJComponent
&& Boolean.TRUE.equals(((JComponent) contents).getClientProperty(KEY_OPAQUE));
setupWindowBackground(window, opaque); setupWindowBackground(window, opaque);
setupWindowFocusableState(isFocusable, window); setupWindowFocusableState(isFocusable, window);
setupWindowDecorations(window, noDecorations); setupWindowDecorations(window, noDecorations);

29
core/src/main/java/com/github/weisj/darklaf/ui/button/ButtonConstants.java

@ -29,6 +29,8 @@ import java.awt.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import com.github.weisj.darklaf.util.PropertyUtil;
public interface ButtonConstants { public interface ButtonConstants {
String KEY_VARIANT = "JButton.variant"; String KEY_VARIANT = "JButton.variant";
String KEY_HOVER_COLOR = "JButton.borderless.hover"; String KEY_HOVER_COLOR = "JButton.borderless.hover";
@ -49,45 +51,38 @@ public interface ButtonConstants {
String VARIANT_NONE = "none"; String VARIANT_NONE = "none";
static boolean chooseAlternativeArc(final Component c) { static boolean chooseAlternativeArc(final Component c) {
return c instanceof AbstractButton return PropertyUtil.getBooleanProperty(c, KEY_ALT_ARC);
&& Boolean.TRUE.equals(((AbstractButton) c).getClientProperty(KEY_ALT_ARC));
} }
static boolean isLabelButton(final Component c) { static boolean isLabelButton(final Component c) {
return c instanceof AbstractButton return PropertyUtil.getBooleanProperty(c, KEY_VARIANT);
&& VARIANT_ONLY_LABEL.equals(((AbstractButton) c).getClientProperty(KEY_VARIANT));
} }
static boolean isNoArc(final Component c) { static boolean isNoArc(final Component c) {
return c instanceof AbstractButton return PropertyUtil.getBooleanProperty(c, KEY_NO_ARC);
&& Boolean.TRUE.equals(((AbstractButton) c).getClientProperty(KEY_NO_ARC));
} }
static boolean isSquare(final Component c) { static boolean isSquare(final Component c) {
return c instanceof AbstractButton && Boolean.TRUE.equals(((AbstractButton) c).getClientProperty(KEY_SQUARE)); return PropertyUtil.getBooleanProperty(c, KEY_SQUARE);
} }
static boolean isThin(final Component c) { static boolean isThin(final Component c) {
if (c instanceof AbstractButton) { return PropertyUtil.getBooleanProperty(c, KEY_THIN)
boolean isThin = Boolean.TRUE.equals(((AbstractButton) c).getClientProperty(KEY_THIN)); || (c instanceof AbstractButton && ButtonConstants.doConvertToBorderless((AbstractButton) c));
return isThin || ButtonConstants.doConvertToBorderless((AbstractButton) c);
}
return false;
} }
static boolean isBorderlessVariant(final Component c) { static boolean isBorderlessVariant(final Component c) {
if (isBorderlessRectangular(c)) return true; if (isBorderlessRectangular(c)) return true;
if (c instanceof JButton) { if (c instanceof JButton) {
JButton b = (JButton) c; JButton b = (JButton) c;
return doConvertToBorderless((AbstractButton) c) return PropertyUtil.isPropertyEqual(b, KEY_VARIANT, VARIANT_BORDERLESS)
|| VARIANT_BORDERLESS.equals(b.getClientProperty(KEY_VARIANT)); || doConvertToBorderless((AbstractButton) c);
} }
return false; return false;
} }
static boolean isBorderlessRectangular(final Component c) { static boolean isBorderlessRectangular(final Component c) {
return c instanceof AbstractButton return PropertyUtil.isPropertyEqual(c, KEY_VARIANT, VARIANT_BORDERLESS_RECTANGULAR);
&& VARIANT_BORDERLESS_RECTANGULAR.equals(((AbstractButton) c).getClientProperty(KEY_VARIANT));
} }
static boolean doConvertToBorderless(final AbstractButton b) { static boolean doConvertToBorderless(final AbstractButton b) {
@ -97,7 +92,7 @@ public interface ButtonConstants {
static boolean convertIconButtonToBorderless(final AbstractButton b) { static boolean convertIconButtonToBorderless(final AbstractButton b) {
return !(b instanceof UIResource) return !(b instanceof UIResource)
&& UIManager.getBoolean("Button.convertIconOnlyToBorderless") && UIManager.getBoolean("Button.convertIconOnlyToBorderless")
&& !Boolean.TRUE.equals(b.getClientProperty(KEY_NO_BORDERLESS_OVERWRITE)); && !PropertyUtil.getBooleanProperty(b, KEY_NO_BORDERLESS_OVERWRITE);
} }
static boolean isIconOnly(final AbstractButton b) { static boolean isIconOnly(final AbstractButton b) {

7
core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java

@ -32,6 +32,7 @@ import javax.swing.plaf.ListUI;
import com.github.weisj.darklaf.ui.list.DarkListUI; import com.github.weisj.darklaf.ui.list.DarkListUI;
import com.github.weisj.darklaf.ui.table.DarkTableCellEditor; import com.github.weisj.darklaf.ui.table.DarkTableCellEditor;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
public class CellUtil { public class CellUtil {
@ -107,7 +108,7 @@ public class CellUtil {
final boolean selected, final int row, final boolean selected, final int row,
final String altBgKey, final Color bgColor, final String altColorKey, final String altBgKey, final Color bgColor, final String altColorKey,
final Color selectionBackground, final String noFocusSelectionBgKey) { final Color selectionBackground, final String noFocusSelectionBgKey) {
boolean alternativeRow = Boolean.TRUE.equals(parent.getClientProperty(altBgKey)); boolean alternativeRow = PropertyUtil.getBooleanProperty(parent, altBgKey);
Color alternativeRowColor = UIManager.getColor(altColorKey); Color alternativeRowColor = UIManager.getColor(altColorKey);
Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : bgColor; Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : bgColor;
if (selected) { if (selected) {
@ -146,9 +147,7 @@ public class CellUtil {
} }
protected static boolean isListEditor(final Component c) { protected static boolean isListEditor(final Component c) {
return c instanceof JComponent return PropertyUtil.getBooleanProperty(c, DarkListUI.KEY_IS_LIST_RENDERER) && c.getParent() instanceof JList;
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkListUI.KEY_IS_LIST_RENDERER))
&& c.getParent() instanceof JList;
} }
public static Insets adjustEditorInsets(final Insets ins, final Component c) { public static Insets adjustEditorInsets(final Insets ins, final Component c) {

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

@ -30,6 +30,7 @@ import javax.swing.*;
import com.github.weisj.darklaf.ui.table.DarkTableUI; import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.tree.DarkTreeUI; import com.github.weisj.darklaf.ui.tree.DarkTreeUI;
import com.github.weisj.darklaf.util.PropertyUtil;
public interface ComboBoxConstants { public interface ComboBoxConstants {
String KEY_IS_TREE_EDITOR = DarkTreeUI.KEY_IS_TREE_EDITOR; String KEY_IS_TREE_EDITOR = DarkTreeUI.KEY_IS_TREE_EDITOR;
@ -41,12 +42,10 @@ public interface ComboBoxConstants {
} }
static boolean isTreeCellEditor(final Component c) { static boolean isTreeCellEditor(final Component c) {
return c instanceof JComponent return PropertyUtil.getBooleanProperty(c, KEY_IS_TREE_EDITOR);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_IS_TREE_EDITOR));
} }
static boolean isTableCellEditor(final Component c) { static boolean isTableCellEditor(final Component c) {
return c instanceof JComponent return PropertyUtil.getBooleanProperty(c, KEY_IS_TABLE_EDITOR);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_IS_TABLE_EDITOR));
} }
} }

3
core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java

@ -41,6 +41,7 @@ import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.ui.cell.CellUtil; import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Jannis Weis * @author Jannis Weis
@ -144,7 +145,7 @@ public class DarkLabelUI extends BasicLabelUI implements PropertyChangeListener
final int textX, final int textY) { final int textX, final int textY) {
int accChar = l.getDisplayedMnemonicIndex(); int accChar = l.getDisplayedMnemonicIndex();
if (DarkUIUtil.isInCell(l)) { if (DarkUIUtil.isInCell(l)) {
boolean selected = Boolean.TRUE.equals(l.getClientProperty(CellUtil.KEY_SELECTED_CELL_RENDERER)); boolean selected = PropertyUtil.getBooleanProperty(l, CellUtil.KEY_SELECTED_CELL_RENDERER);
boolean focused = hasFocusInCell(l); boolean focused = hasFocusInCell(l);
if (focused) { if (focused) {
if (selected) { if (selected) {

5
core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java

@ -30,6 +30,7 @@ import javax.swing.*;
import com.github.weisj.darklaf.ui.cell.CellUtil; import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
public class DarkListCellRenderer extends DefaultListCellRenderer { public class DarkListCellRenderer extends DefaultListCellRenderer {
@ -45,7 +46,7 @@ public class DarkListCellRenderer extends DefaultListCellRenderer {
} }
} }
Component comp = null; Component comp = null;
boolean isEditing = Boolean.TRUE.equals(list.getClientProperty(DarkListUI.KEY_IS_EDITING)); boolean isEditing = PropertyUtil.getBooleanProperty(list, DarkListUI.KEY_IS_EDITING);
if (isEditing) { if (isEditing) {
if (list.getSelectionModel().getLeadSelectionIndex() == index) { if (list.getSelectionModel().getLeadSelectionIndex() == index) {
comp = super.getListCellRendererComponent(list, value, index, false, false); comp = super.getListCellRendererComponent(list, value, index, false, false);
@ -62,9 +63,7 @@ public class DarkListCellRenderer extends DefaultListCellRenderer {
} else { } else {
if (DarkUIUtil.hasFocus(list) || DarkUIUtil.getParentOfType(JPopupMenu.class, list) != null) { if (DarkUIUtil.hasFocus(list) || DarkUIUtil.getParentOfType(JPopupMenu.class, list) != null) {
comp.setForeground(list.getSelectionForeground()); comp.setForeground(list.getSelectionForeground());
comp.setBackground(list.getSelectionBackground());
} else { } else {
comp.setBackground(UIManager.getColor("List.selectionNoFocusBackground"));
comp.setForeground(UIManager.getColor("List.selectionForegroundInactive")); comp.setForeground(UIManager.getColor("List.selectionForegroundInactive"));
} }
} }

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

@ -32,6 +32,7 @@ import javax.swing.*;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Jannis Weis * @author Jannis Weis
@ -156,7 +157,7 @@ public class DarkListUI extends DarkListUIBridge {
int ch = rowBounds.height; int ch = rowBounds.height;
if (empty || bgWidth > 0) { if (empty || bgWidth > 0) {
boolean alternativeRow = Boolean.TRUE.equals(list.getClientProperty(KEY_ALTERNATE_ROW_COLOR)); boolean alternativeRow = PropertyUtil.getBooleanProperty(list, KEY_ALTERNATE_ROW_COLOR);
Color alternativeRowColor = UIManager.getColor("List.alternateRowBackground"); Color alternativeRowColor = UIManager.getColor("List.alternateRowBackground");
Color normalColor = list.getBackground(); Color normalColor = list.getBackground();
Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor; Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor;
@ -168,7 +169,7 @@ public class DarkListUI extends DarkListUIBridge {
if (!empty) { if (!empty) {
Component rendererComponent = cellRenderer.getListCellRendererComponent(list, value, index, isSelected, Component rendererComponent = cellRenderer.getListCellRendererComponent(list, value, index, isSelected,
cellHasFocus); cellHasFocus);
if (Boolean.TRUE.equals(list.getClientProperty(KEY_SHRINK_WRAP))) { if (PropertyUtil.getBooleanProperty(list, KEY_SHRINK_WRAP)) {
// Shrink renderer to preferred size. This is mostly used on Windows // Shrink renderer to preferred size. This is mostly used on Windows
// where selection is only shown around the file name, instead of // where selection is only shown around the file name, instead of
// across the whole list cell. // across the whole list cell.
@ -199,7 +200,7 @@ public class DarkListUI extends DarkListUIBridge {
if (row < 0) { if (row < 0) {
// If shift is down in multi-select, we should do nothing. // If shift is down in multi-select, we should do nothing.
// For single select or non-shift-click, clear the selection // For single select or non-shift-click, clear the selection
if (isFileList && !Boolean.TRUE.equals(list.getClientProperty(KEY_FULL_ROW_SELECTION)) if (isFileList && !PropertyUtil.getBooleanProperty(list, KEY_FULL_ROW_SELECTION)
&& e.getID() == MouseEvent.MOUSE_PRESSED && && e.getID() == MouseEvent.MOUSE_PRESSED &&
(!e.isShiftDown() || list.getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)) { (!e.isShiftDown() || list.getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)) {
list.clearSelection(); list.clearSelection();

3
core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java

@ -48,6 +48,7 @@ import com.github.weisj.darklaf.ui.DragRecognitionSupport;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.LazyActionMap; import com.github.weisj.darklaf.util.LazyActionMap;
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* An extensible implementation of {@code ListUI}. * An extensible implementation of {@code ListUI}.
@ -514,7 +515,7 @@ public class DarkListUIBridge extends BasicListUI {
* Update is file list. * Update is file list.
*/ */
protected void updateIsFileList() { protected void updateIsFileList() {
boolean b = Boolean.TRUE.equals(list.getClientProperty("List.isFileList")); boolean b = PropertyUtil.getBooleanProperty(list, "List.isFileList");
if (b != isFileList) { if (b != isFileList) {
isFileList = b; isFileList = b;
Font oldFont = list.getFont(); Font oldFont = list.getFont();

26
core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java

@ -36,6 +36,7 @@ import javax.swing.plaf.basic.BasicPopupMenuUI;
import com.github.weisj.darklaf.components.ScrollPopupMenu; import com.github.weisj.darklaf.components.ScrollPopupMenu;
import com.github.weisj.darklaf.ui.DarkPopupFactory; import com.github.weisj.darklaf.ui.DarkPopupFactory;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* This implementation for PopupMenuUI is almost identical to the one of BasicPopupMenuUI. The key difference is that it * This implementation for PopupMenuUI is almost identical to the one of BasicPopupMenuUI. The key difference is that it
@ -48,7 +49,7 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI {
public static final String KEY_DO_NOT_CANCEL_POPUP = "doNotCancelPopup"; public static final String KEY_DO_NOT_CANCEL_POPUP = "doNotCancelPopup";
public static final String KEY_DO_NOT_CANCEL_ON_SCROLL = "doNotCancelOnScroll"; public static final String KEY_DO_NOT_CANCEL_ON_SCROLL = "doNotCancelOnScroll";
public static final StringBufferWrapper HIDE_POPUP_VALUE = new StringBufferWrapper(new StringBuffer("doNotCancelPopup")); public static final String HIDE_POPUP_VALUE = "doNotCancelPopup";
public static final String KEY_DEFAULT_LIGHTWEIGHT_POPUPS = "PopupMenu.defaultLightWeightPopups"; public static final String KEY_DEFAULT_LIGHTWEIGHT_POPUPS = "PopupMenu.defaultLightWeightPopups";
private PopupMenuContainer popupMenuContainer; private PopupMenuContainer popupMenuContainer;
@ -59,8 +60,7 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI {
@Override @Override
public void paint(final Graphics g, final JComponent c) { public void paint(final Graphics g, final JComponent c) {
Window window = SwingUtilities.getWindowAncestor(c); Window window = SwingUtilities.getWindowAncestor(c);
if (window != null if (window != null && PropertyUtil.getBooleanProperty(popupMenu, DarkPopupFactory.KEY_MAKE_VISIBLE)) {
&& Boolean.TRUE.equals(popupMenu.getClientProperty(DarkPopupFactory.KEY_MAKE_VISIBLE))) {
popupMenu.putClientProperty(DarkPopupFactory.KEY_MAKE_VISIBLE, false); popupMenu.putClientProperty(DarkPopupFactory.KEY_MAKE_VISIBLE, false);
window.setOpacity(1); window.setOpacity(1);
} }
@ -101,24 +101,4 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI {
int maxHeight = DarkUIUtil.getScreenBounds(popup, x, y, false).height; int maxHeight = DarkUIUtil.getScreenBounds(popup, x, y, false).height;
return popupMenuContainer.createPopup(popup, x, y, maxHeight); return popupMenuContainer.createPopup(popup, x, y, maxHeight);
} }
protected static class StringBufferWrapper {
private final StringBuffer buffer;
protected StringBufferWrapper(final StringBuffer buffer) {
this.buffer = buffer;
}
@Override
public String toString() {
return buffer.toString();
}
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@Override
public boolean equals(final Object obj) {
if (obj == null || buffer == null) return false;
return toString().equals(obj.toString());
}
}
} }

10
core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/MouseGrabber.java

@ -38,6 +38,7 @@ import sun.awt.SunToolkit;
import com.github.weisj.darklaf.components.OverlayScrollPane; import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
public class MouseGrabber implements ChangeListener, AWTEventListener, ComponentListener, WindowListener { public class MouseGrabber implements ChangeListener, AWTEventListener, ComponentListener, WindowListener {
@ -168,9 +169,8 @@ public class MouseGrabber implements ChangeListener, AWTEventListener, Component
(src instanceof JMenu && ((JMenu) src).isSelected())) { (src instanceof JMenu && ((JMenu) src).isSelected())) {
return; return;
} }
if (!(src instanceof JComponent) || if (!PropertyUtil.isPropertyEqual(src, DarkPopupMenuUI.KEY_DO_NOT_CANCEL_POPUP,
!DarkPopupMenuUI.HIDE_POPUP_VALUE.equals(((JComponent) src).getClientProperty( DarkPopupMenuUI.HIDE_POPUP_VALUE)) {
DarkPopupMenuUI.KEY_DO_NOT_CANCEL_POPUP))) {
// Cancel popup only if this property was not set. // Cancel popup only if this property was not set.
// If this property is set to TRUE component wants // If this property is set to TRUE component wants
// to deal with this event by himself. // to deal with this event by himself.
@ -246,9 +246,7 @@ public class MouseGrabber implements ChangeListener, AWTEventListener, Component
break; break;
} else if (c instanceof JPopupMenu) { } else if (c instanceof JPopupMenu) {
return true; return true;
} else if (c instanceof JComponent } else if (PropertyUtil.getBooleanProperty(c, DarkPopupMenuUI.KEY_DO_NOT_CANCEL_ON_SCROLL)) {
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(
DarkPopupMenuUI.KEY_DO_NOT_CANCEL_ON_SCROLL))) {
/* /*
* Change here: allows scrollable components that contain the popupMenu. * Change here: allows scrollable components that contain the popupMenu.
*/ */

5
core/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarUI.java

@ -39,6 +39,7 @@ import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.GraphicsUtil; import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Konstantin Bulenkov * @author Konstantin Bulenkov
@ -69,7 +70,7 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha
} }
protected static boolean hasFailed(final JComponent c) { protected static boolean hasFailed(final JComponent c) {
return Boolean.TRUE.equals(c.getClientProperty(KEY_FAILED)); return PropertyUtil.getBooleanProperty(c, KEY_FAILED);
} }
@Override @Override
@ -177,7 +178,7 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha
} }
protected static boolean hasPassed(final JComponent c) { protected static boolean hasPassed(final JComponent c) {
return Boolean.TRUE.equals(c.getClientProperty(KEY_PASSED)); return PropertyUtil.getBooleanProperty(c, KEY_PASSED);
} }
@Override @Override

3
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java

@ -37,6 +37,7 @@ import com.github.weisj.darklaf.platform.DecorationsHandler;
import com.github.weisj.darklaf.platform.decorations.CustomTitlePane; import com.github.weisj.darklaf.platform.decorations.CustomTitlePane;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Konstantin Bulenkov * @author Konstantin Bulenkov
@ -211,7 +212,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
} }
protected void updateClientDecoration() { protected void updateClientDecoration() {
if (!Boolean.TRUE.equals(rootPane.getClientProperty(KEY_NO_DECORATIONS_UPDATE))) { if (!PropertyUtil.getBooleanProperty(rootPane, KEY_NO_DECORATIONS_UPDATE)) {
uninstallClientDecorations(rootPane); uninstallClientDecorations(rootPane);
if (DecorationsHandler.getSharedInstance().isCustomDecorationSupported()) { if (DecorationsHandler.getSharedInstance().isCustomDecorationSupported()) {
installClientDecorations(rootPane); installClientDecorations(rootPane);

5
core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollBarUtil.java

@ -29,6 +29,8 @@ import java.awt.event.MouseWheelEvent;
import javax.swing.*; import javax.swing.*;
import com.github.weisj.darklaf.util.PropertyUtil;
public class ScrollBarUtil implements ScrollBarConstants { public class ScrollBarUtil implements ScrollBarConstants {
@SuppressWarnings("MagicConstant") @SuppressWarnings("MagicConstant")
@ -45,9 +47,8 @@ public class ScrollBarUtil implements ScrollBarConstants {
boolean limitScroll = Math.abs(e.getWheelRotation()) == 1; boolean limitScroll = Math.abs(e.getWheelRotation()) == 1;
Object fastWheelScroll = toScroll.getClientProperty(KEY_FAST_WHEEL_SCROLLING);
Component comp = vp == null ? null : vp.getView(); Component comp = vp == null ? null : vp.getView();
if (Boolean.TRUE.equals(fastWheelScroll) && comp instanceof Scrollable) { if (comp instanceof Scrollable && PropertyUtil.getBooleanProperty(toScroll, KEY_FAST_WHEEL_SCROLLING)) {
Scrollable scrollComp = (Scrollable) comp; Scrollable scrollComp = (Scrollable) comp;
Rectangle viewRect = vp.getViewRect(); Rectangle viewRect = vp.getViewRect();
int startingX = viewRect.x; int startingX = viewRect.x;

21
core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java

@ -40,7 +40,8 @@ import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.GraphicsUtil; import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.graphics.PaintUtil; import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.listener.MouseClickListener; import com.github.weisj.darklaf.listener.MouseClickListener;
import com.github.weisj.darklaf.util.*; import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Jannis Weis * @author Jannis Weis
@ -114,12 +115,11 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
} }
private static boolean showVolumeIcon(final JComponent c) { private static boolean showVolumeIcon(final JComponent c) {
return isVolumeSlider(c) return isVolumeSlider(c) && PropertyUtil.getBooleanProperty(c, KEY_SHOW_VOLUME_ICON);
&& Boolean.TRUE.equals(c.getClientProperty(KEY_SHOW_VOLUME_ICON));
} }
private static boolean isVolumeSlider(final JComponent c) { private static boolean isVolumeSlider(final JComponent c) {
return VARIANT_VOLUME.equals(c.getClientProperty(KEY_VARIANT)); return PropertyUtil.isPropertyEqual(c, KEY_VARIANT, VARIANT_VOLUME);
} }
@Override @Override
@ -307,8 +307,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
boolean ltr = (slider.getComponentOrientation().isLeftToRight() && !slider.getInverted()) boolean ltr = (slider.getComponentOrientation().isLeftToRight() && !slider.getInverted())
|| (!slider.getComponentOrientation().isLeftToRight() && slider.getInverted()); || (!slider.getComponentOrientation().isLeftToRight() && slider.getInverted());
Component minLabel = ltr ? getLowestValueLabel() : getHighestValueLabel(); Component minLabel = ltr ? getLowestValueLabel() : getHighestValueLabel();
boolean adjustMin = minLabel instanceof JComponent boolean adjustMin = PropertyUtil.getBooleanProperty(minLabel, KEY_MANUAL_LABEL_ALIGN);
&& Boolean.TRUE.equals(((JComponent) minLabel).getClientProperty(KEY_MANUAL_LABEL_ALIGN));
int minPrefWidth = minLabel.getPreferredSize().width; int minPrefWidth = minLabel.getPreferredSize().width;
float adj = (adjustMin ? minLabel.getAlignmentX() : Component.CENTER_ALIGNMENT); float adj = (adjustMin ? minLabel.getAlignmentX() : Component.CENTER_ALIGNMENT);
return (int) (minPrefWidth * adj) + 2 * (ltr ? focusInsets.left : focusInsets.right); return (int) (minPrefWidth * adj) + 2 * (ltr ? focusInsets.left : focusInsets.right);
@ -318,8 +317,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
boolean ltr = (slider.getComponentOrientation().isLeftToRight() && !slider.getInverted()) boolean ltr = (slider.getComponentOrientation().isLeftToRight() && !slider.getInverted())
|| (!slider.getComponentOrientation().isLeftToRight() && slider.getInverted()); || (!slider.getComponentOrientation().isLeftToRight() && slider.getInverted());
Component maxLabel = ltr ? getHighestValueLabel() : getLowestValueLabel(); Component maxLabel = ltr ? getHighestValueLabel() : getLowestValueLabel();
boolean adjustMax = maxLabel instanceof JComponent boolean adjustMax = PropertyUtil.getBooleanProperty(maxLabel, KEY_MANUAL_LABEL_ALIGN);
&& Boolean.TRUE.equals(((JComponent) maxLabel).getClientProperty(KEY_MANUAL_LABEL_ALIGN));
int maxPrefWidth = maxLabel.getPreferredSize().width; int maxPrefWidth = maxLabel.getPreferredSize().width;
float adj = (adjustMax ? maxLabel.getAlignmentX() : Component.CENTER_ALIGNMENT); float adj = (adjustMax ? maxLabel.getAlignmentX() : Component.CENTER_ALIGNMENT);
return (int) (maxPrefWidth * (1f - adj)) + 2 * (ltr ? focusInsets.right : focusInsets.left); return (int) (maxPrefWidth * (1f - adj)) + 2 * (ltr ? focusInsets.right : focusInsets.left);
@ -420,8 +418,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
checkDisabled(g); checkDisabled(g);
int labelCenter = xPositionForValue(value); int labelCenter = xPositionForValue(value);
float align = Component.CENTER_ALIGNMENT; float align = Component.CENTER_ALIGNMENT;
if (label instanceof JComponent if (PropertyUtil.getBooleanProperty(label, KEY_MANUAL_LABEL_ALIGN)) {
&& Boolean.TRUE.equals(((JComponent) label).getClientProperty(KEY_MANUAL_LABEL_ALIGN))) {
align = label.getAlignmentX(); align = label.getAlignmentX();
} }
int labelLeft = labelCenter - (int) (label.getPreferredSize().width * align); int labelLeft = labelCenter - (int) (label.getPreferredSize().width * align);
@ -665,7 +662,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
} }
private boolean paintFocus() { private boolean paintFocus() {
return slider.hasFocus() && Boolean.TRUE.equals(slider.getClientProperty(KEY_SHOW_FOCUS_GLOW)); return slider.hasFocus() && PropertyUtil.getBooleanProperty(slider, KEY_SHOW_FOCUS_GLOW);
} }
protected int getThumbWidth() { protected int getThumbWidth() {
@ -753,7 +750,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
} }
private boolean instantScrollEnabled(final JComponent c) { private boolean instantScrollEnabled(final JComponent c) {
return Boolean.TRUE.equals(c.getClientProperty(KEY_INSTANT_SCROLL)); return PropertyUtil.getBooleanProperty(c, KEY_INSTANT_SCROLL);
} }
public Rectangle getThumbRect() { public Rectangle getThumbRect() {

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

@ -30,6 +30,7 @@ import javax.swing.*;
import com.github.weisj.darklaf.ui.table.DarkTableUI; import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.tree.DarkTreeUI; import com.github.weisj.darklaf.ui.tree.DarkTreeUI;
import com.github.weisj.darklaf.util.PropertyUtil;
public interface SpinnerConstants { public interface SpinnerConstants {
String KEY_VARIANT = "JSpinner.variant"; String KEY_VARIANT = "JSpinner.variant";
@ -41,7 +42,7 @@ public interface SpinnerConstants {
String VARIANT_PLUS_MINUS = "plusMinus"; String VARIANT_PLUS_MINUS = "plusMinus";
static boolean usePlusMinusIcons(final JSpinner spinner) { static boolean usePlusMinusIcons(final JSpinner spinner) {
return VARIANT_PLUS_MINUS.equals(spinner.getClientProperty(KEY_VARIANT)); return PropertyUtil.isPropertyEqual(spinner, KEY_VARIANT, VARIANT_PLUS_MINUS);
} }
static boolean isTreeOrTableCellEditor(final Component c) { static boolean isTreeOrTableCellEditor(final Component c) {
@ -49,12 +50,10 @@ public interface SpinnerConstants {
} }
static boolean isTreeCellEditor(final Component c) { static boolean isTreeCellEditor(final Component c) {
return c instanceof JComponent return PropertyUtil.getBooleanProperty(c, KEY_IS_TREE_EDITOR);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_IS_TREE_EDITOR));
} }
static boolean isTableCellEditor(final Component c) { static boolean isTableCellEditor(final Component c) {
return c instanceof JComponent return PropertyUtil.getBooleanProperty(c, KEY_IS_TABLE_EDITOR);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_IS_TABLE_EDITOR));
} }
} }

3
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkHandler.java

@ -33,6 +33,7 @@ import javax.swing.*;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
public class DarkHandler extends TabbedPaneHandler { public class DarkHandler extends TabbedPaneHandler {
@ -108,7 +109,7 @@ public class DarkHandler extends TabbedPaneHandler {
} }
ui.tabPane.doLayout(); ui.tabPane.doLayout();
} else if (DarkTabbedPaneUI.KEY_DND.equals(key)) { } else if (DarkTabbedPaneUI.KEY_DND.equals(key)) {
ui.dndEnabled = Boolean.TRUE.equals(ui.tabPane.getClientProperty(DarkTabbedPaneUI.KEY_DND)); ui.dndEnabled = PropertyUtil.getBooleanProperty(ui.tabPane, DarkTabbedPaneUI.KEY_DND);
DropTarget dropTarget = ui.tabPane.getDropTarget(); DropTarget dropTarget = ui.tabPane.getDropTarget();
if (dropTarget != null) dropTarget.setActive(ui.dndEnabled); if (dropTarget != null) dropTarget.setActive(ui.dndEnabled);
} else if (PropertyKey.COMPONENT_ORIENTATION.equals(key)) { } else if (PropertyKey.COMPONENT_ORIENTATION.equals(key)) {

3
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java

@ -36,6 +36,7 @@ import javax.swing.event.PopupMenuListener;
import com.github.weisj.darklaf.components.ScrollPopupMenu; import com.github.weisj.darklaf.components.ScrollPopupMenu;
import com.github.weisj.darklaf.listener.PopupMenuAdapter; import com.github.weisj.darklaf.listener.PopupMenuAdapter;
import com.github.weisj.darklaf.util.PropertyUtil;
public class DarkScrollableTabSupport extends ScrollableTabSupport implements MouseWheelListener, ActionListener { public class DarkScrollableTabSupport extends ScrollableTabSupport implements MouseWheelListener, ActionListener {
@ -61,7 +62,7 @@ public class DarkScrollableTabSupport extends ScrollableTabSupport implements Mo
moreTabsButton.addActionListener(this); moreTabsButton.addActionListener(this);
newTabButton = ui.createNewTabButton(); newTabButton = ui.createNewTabButton();
newTabButton.setVisible(Boolean.TRUE.equals(ui.tabPane.getClientProperty(DarkTabbedPaneUI.KEY_SHOW_NEW_TAB_BUTTON))); newTabButton.setVisible(PropertyUtil.getBooleanProperty(ui.tabPane, DarkTabbedPaneUI.KEY_SHOW_NEW_TAB_BUTTON));
scrollPopupMenu = new ScrollPopupMenu(UIManager.getInt(DarkTabbedPaneUI.KEY_MAX_POPUP_HEIGHT)); scrollPopupMenu = new ScrollPopupMenu(UIManager.getInt(DarkTabbedPaneUI.KEY_MAX_POPUP_HEIGHT));
PopupMenuListener popupMenuListener = new PopupMenuAdapter() { PopupMenuListener popupMenuListener = new PopupMenuAdapter() {

4
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneLayout.java

@ -28,6 +28,8 @@ import java.awt.*;
import javax.swing.*; import javax.swing.*;
import com.github.weisj.darklaf.util.PropertyUtil;
public class DarkTabbedPaneLayout extends TabbedPaneLayout { public class DarkTabbedPaneLayout extends TabbedPaneLayout {
private final DarkTabbedPaneUI ui; private final DarkTabbedPaneUI ui;
@ -39,7 +41,7 @@ public class DarkTabbedPaneLayout extends TabbedPaneLayout {
@Override @Override
protected void centerTabs(final int tabPlacement, final int tabCount, final int returnAt) { protected void centerTabs(final int tabPlacement, final int tabCount, final int returnAt) {
if (ui.runCount == 1 && Boolean.TRUE.equals(ui.tabPane.getClientProperty(DarkTabbedPaneUI.KEY_CENTER_TABS))) { if (ui.runCount == 1 && PropertyUtil.getBooleanProperty(ui.tabPane, DarkTabbedPaneUI.KEY_CENTER_TABS)) {
if (ui.isHorizontalTabPlacement()) { if (ui.isHorizontalTabPlacement()) {
int shift = (returnAt - (ui.rects[tabCount - 1].x + ui.rects[tabCount - 1].width)) / 2; int shift = (returnAt - (ui.rects[tabCount - 1].x + ui.rects[tabCount - 1].width)) / 2;
for (int i = 0; i < tabCount; i++) { for (int i = 0; i < tabCount; i++) {

6
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneScrollLayout.java

@ -29,6 +29,8 @@ import java.util.function.Function;
import javax.swing.*; import javax.swing.*;
import com.github.weisj.darklaf.util.PropertyUtil;
public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout { public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout {
private final DarkTabbedPaneUI ui; private final DarkTabbedPaneUI ui;
@ -329,7 +331,7 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout {
restoreHiddenTabsX(leftMargin, returnAt, tabCount); restoreHiddenTabsX(leftMargin, returnAt, tabCount);
if (ui.minVisible == 0 && ui.maxVisible == tabCount - 1 if (ui.minVisible == 0 && ui.maxVisible == tabCount - 1
&& Boolean.TRUE.equals(ui.tabPane.getClientProperty(DarkTabbedPaneUI.KEY_CENTER_TABS))) { && PropertyUtil.getBooleanProperty(ui.tabPane, DarkTabbedPaneUI.KEY_CENTER_TABS)) {
adjustForCenterX(leftMargin, returnAt, tabCount); adjustForCenterX(leftMargin, returnAt, tabCount);
} }
@ -382,7 +384,7 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout {
restoreHiddenTabsY(topMargin, returnAt, tabCount); restoreHiddenTabsY(topMargin, returnAt, tabCount);
if (ui.minVisible == 0 && ui.maxVisible == tabCount - 1 if (ui.minVisible == 0 && ui.maxVisible == tabCount - 1
&& Boolean.TRUE.equals(ui.tabPane.getClientProperty(DarkTabbedPaneUI.KEY_CENTER_TABS))) { && PropertyUtil.getBooleanProperty(ui.tabPane, DarkTabbedPaneUI.KEY_CENTER_TABS)) {
adjustForCenterY(topMargin, returnAt, tabCount); adjustForCenterY(topMargin, returnAt, tabCount);
} }

7
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java

@ -41,6 +41,7 @@ import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.GraphicsUtil; import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.graphics.PaintUtil; import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Jannis Weis * @author Jannis Weis
@ -402,7 +403,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge {
} }
protected boolean shouldRotateTabRuns(final int tabPlacement) { protected boolean shouldRotateTabRuns(final int tabPlacement) {
return Boolean.TRUE.equals(tabPane.getClientProperty(KEY_ROTATE_TAB_RUNS)); return PropertyUtil.getBooleanProperty(tabPane, KEY_ROTATE_TAB_RUNS);
} }
@Override @Override
@ -478,7 +479,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge {
} }
protected boolean drawFocusBar() { protected boolean drawFocusBar() {
return !Boolean.FALSE.equals(tabPane.getClientProperty(KEY_DRAW_FOCUS_BAR)); return PropertyUtil.getBooleanProperty(tabPane, KEY_DRAW_FOCUS_BAR, true);
} }
protected Color getAccentColor() { protected Color getAccentColor() {
@ -737,7 +738,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge {
installComponent(KEY_SOUTH_COMP, c -> southComp = c); installComponent(KEY_SOUTH_COMP, c -> southComp = c);
installComponent(KEY_WEST_COMP, c -> westComp = c); installComponent(KEY_WEST_COMP, c -> westComp = c);
installComponent(KEY_EAST_COMP, c -> eastComp = c); installComponent(KEY_EAST_COMP, c -> eastComp = c);
dndEnabled = Boolean.TRUE.equals(tabPane.getClientProperty(KEY_DND)); dndEnabled = PropertyUtil.getBooleanProperty(tabPane, KEY_DND);
} }
protected void installComponent(final String key, final Consumer<Component> setter) { protected void installComponent(final String key, final Consumer<Component> setter) {

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

@ -46,6 +46,7 @@ import com.github.weisj.darklaf.ui.spinner.DarkSpinnerUI;
import com.github.weisj.darklaf.ui.spinner.SpinnerConstants; 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.ui.togglebutton.ToggleButtonConstants;
import com.github.weisj.darklaf.util.PropertyUtil;
import com.github.weisj.darklaf.util.PropertyValue; import com.github.weisj.darklaf.util.PropertyValue;
/** /**
@ -287,7 +288,8 @@ public class DarkTableCellEditor extends DefaultCellEditor {
} }
protected TableCellEditor getBooleanEditor(final JTable table) { protected TableCellEditor getBooleanEditor(final JTable table) {
if (DarkTableUI.RENDER_TYPE_RADIOBUTTON.equals(table.getClientProperty(DarkTableUI.KEY_BOOLEAN_RENDER_TYPE))) { if (PropertyUtil.isPropertyEqual(table, DarkTableUI.KEY_BOOLEAN_RENDER_TYPE,
DarkTableUI.RENDER_TYPE_RADIOBUTTON)) {
return radioButtonEditor; return radioButtonEditor;
} }
return checkBoxEditor; return checkBoxEditor;

10
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellFocusBorder.java

@ -30,6 +30,7 @@ import javax.swing.*;
import com.github.weisj.darklaf.graphics.PaintUtil; import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.ui.cell.DarkCellBorder; import com.github.weisj.darklaf.ui.cell.DarkCellBorder;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Jannis Weis * @author Jannis Weis
@ -65,17 +66,14 @@ public class DarkTableCellFocusBorder extends DarkCellBorder {
} }
public static boolean isRowFocusBorder(final Component c) { public static boolean isRowFocusBorder(final Component c) {
return c instanceof JComponent return PropertyUtil.getBooleanProperty(c, DarkTableUI.KEY_FULL_ROW_FOCUS_BORDER);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTableUI.KEY_FULL_ROW_FOCUS_BORDER));
} }
protected static boolean forcePaintLeft(final Component c) { protected static boolean forcePaintLeft(final Component c) {
return c instanceof JComponent return PropertyUtil.getBooleanProperty(c, DarkTableUI.KEY_FORCE_LEFT_BORDER);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTableUI.KEY_FORCE_LEFT_BORDER));
} }
protected static boolean forcePaintRight(final Component c) { protected static boolean forcePaintRight(final Component c) {
return c instanceof JComponent return PropertyUtil.getBooleanProperty(c, DarkTableUI.KEY_FORCE_RIGHT_BORDER);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTableUI.KEY_FORCE_RIGHT_BORDER));
} }
} }

6
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java

@ -35,6 +35,7 @@ import javax.swing.table.TableColumn;
import com.github.weisj.darklaf.ui.cell.CellUtil; import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton; import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author vincencopalazzo * @author vincencopalazzo
@ -47,7 +48,7 @@ public class DarkTableCellRenderer extends DefaultTableCellRenderer {
private final DarkCellRendererToggleButton<DarkCellRendererToggleButton.CellEditorRadioButton> radioRenderer = new DarkCellRendererToggleButton<>(new DarkCellRendererToggleButton.CellEditorRadioButton(true)); private final DarkCellRendererToggleButton<DarkCellRendererToggleButton.CellEditorRadioButton> radioRenderer = new DarkCellRendererToggleButton<>(new DarkCellRendererToggleButton.CellEditorRadioButton(true));
protected static boolean isBooleanRenderingEnabled(final JTable table) { protected static boolean isBooleanRenderingEnabled(final JTable table) {
return Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX)); return PropertyUtil.getBooleanProperty(table, DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX);
} }
@Override @Override
@ -101,7 +102,8 @@ public class DarkTableCellRenderer extends DefaultTableCellRenderer {
} }
protected TableCellRenderer getBooleanRenderer(final JTable table) { protected TableCellRenderer getBooleanRenderer(final JTable table) {
if (DarkTableUI.RENDER_TYPE_RADIOBUTTON.equals(table.getClientProperty(DarkTableUI.KEY_BOOLEAN_RENDER_TYPE))) { if (PropertyUtil.isPropertyEqual(table, DarkTableUI.KEY_BOOLEAN_RENDER_TYPE,
DarkTableUI.RENDER_TYPE_RADIOBUTTON)) {
return radioRenderer; return radioRenderer;
} }
return checkBoxRenderer; return checkBoxRenderer;

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

@ -52,6 +52,7 @@ import com.github.weisj.darklaf.ui.DragRecognitionSupport;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.LazyActionMap; import com.github.weisj.darklaf.util.LazyActionMap;
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* The type Table ui bridge. * The type Table ui bridge.
@ -343,7 +344,7 @@ public abstract class TableUIBridge extends TableUI {
} }
} }
isFileList = Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_IS_FILE_LIST)); isFileList = PropertyUtil.getBooleanProperty(table, DarkTableUI.KEY_IS_FILE_LIST);
} }
/** /**
@ -1841,8 +1842,8 @@ public abstract class TableUIBridge extends TableUI {
public boolean accept(final Object sender) { public boolean accept(final Object sender) {
String key = getName(); String key = getName();
if (sender instanceof JTable && if (sender instanceof JTable
Boolean.TRUE.equals(((JTable) sender).getClientProperty(DarkTableUI.KEY_IS_FILE_LIST))) { && PropertyUtil.getBooleanProperty((JTable) sender, DarkTableUI.KEY_IS_FILE_LIST)) {
if (Objects.equals(key, NEXT_COLUMN) || if (Objects.equals(key, NEXT_COLUMN) ||
Objects.equals(key, NEXT_COLUMN_CELL) || Objects.equals(key, NEXT_COLUMN_CELL) ||
Objects.equals(key, NEXT_COLUMN_EXTEND_SELECTION) || Objects.equals(key, NEXT_COLUMN_EXTEND_SELECTION) ||
@ -2582,7 +2583,7 @@ public abstract class TableUIBridge extends TableUI {
repaintDropLocation(oldValue); repaintDropLocation(oldValue);
repaintDropLocation(table.getDropLocation()); repaintDropLocation(table.getDropLocation());
} else if (DarkTableUI.KEY_IS_FILE_LIST.equals(changeName)) { } else if (DarkTableUI.KEY_IS_FILE_LIST.equals(changeName)) {
isFileList = Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_IS_FILE_LIST)); isFileList = PropertyUtil.getBooleanProperty(table, DarkTableUI.KEY_IS_FILE_LIST);
table.revalidate(); table.revalidate();
table.repaint(); table.repaint();
if (isFileList) { if (isFileList) {

4
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java

@ -38,6 +38,7 @@ import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.PaintUtil; import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.listener.MouseMovementListener; import com.github.weisj.darklaf.listener.MouseMovementListener;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Konstantin Bulenkov * @author Konstantin Bulenkov
@ -182,8 +183,7 @@ public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge {
} }
public static boolean hasShowIcon(final Component c) { public static boolean hasShowIcon(final Component c) {
return c instanceof JPasswordField return PropertyUtil.getBooleanProperty(c, KEY_SHOW_VIEW_BUTTON);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_SHOW_VIEW_BUTTON));
} }
private Point getShowIconCoord() { private Point getShowIconCoord() {

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

@ -35,6 +35,7 @@ import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.GraphicsUtil; import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.graphics.PaintUtil; import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Jannis Weis * @author Jannis Weis
@ -74,8 +75,7 @@ public class DarkTextBorder implements Border, UIResource {
} }
protected static boolean hasError(final Component c) { protected static boolean hasError(final Component c) {
return c instanceof JComponent return PropertyUtil.getBooleanProperty(c, DarkTextUI.KEY_HAS_ERROR);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTextUI.KEY_HAS_ERROR));
} }
protected int getArcSize(final Component c) { protected int getArcSize(final Component c) {

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

@ -41,6 +41,7 @@ import com.github.weisj.darklaf.listener.MouseClickListener;
import com.github.weisj.darklaf.listener.MouseMovementListener; import com.github.weisj.darklaf.listener.MouseMovementListener;
import com.github.weisj.darklaf.listener.PopupMenuAdapter; import com.github.weisj.darklaf.listener.PopupMenuAdapter;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Konstantin Bulenkov * @author Konstantin Bulenkov
@ -166,7 +167,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
} }
public static boolean isSearchField(final Component c) { public static boolean isSearchField(final Component c) {
return c instanceof JTextField && VARIANT_SEARCH.equals(((JTextField) c).getClientProperty(KEY_VARIANT)); return PropertyUtil.isPropertyEqual(c, KEY_VARIANT, VARIANT_SEARCH);
} }
protected void paintBackground(final Graphics graphics) { protected void paintBackground(final Graphics graphics) {

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

@ -31,6 +31,7 @@ import javax.swing.*;
import com.github.weisj.darklaf.ui.table.DarkTableUI; import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.tree.DarkTreeUI; import com.github.weisj.darklaf.ui.tree.DarkTreeUI;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
public interface ToggleButtonConstants { public interface ToggleButtonConstants {
String KEY_VARIANT = "JToggleButton.variant"; String KEY_VARIANT = "JToggleButton.variant";
@ -43,8 +44,7 @@ public interface ToggleButtonConstants {
String VARIANT_SLIDER = "slider"; String VARIANT_SLIDER = "slider";
static boolean isSlider(final JComponent c) { static boolean isSlider(final JComponent c) {
return c instanceof JToggleButton return PropertyUtil.isPropertyEqual(c, ToggleButtonConstants.KEY_VARIANT, VARIANT_SLIDER);
&& VARIANT_SLIDER.equals(c.getClientProperty(ToggleButtonConstants.KEY_VARIANT));
} }
static boolean isInCell(final Component c) { static boolean isInCell(final Component c) {
@ -56,12 +56,10 @@ public interface ToggleButtonConstants {
} }
static boolean isTreeCellEditor(final Component c) { static boolean isTreeCellEditor(final Component c) {
return c instanceof JComponent return PropertyUtil.getBooleanProperty(c, KEY_IS_TREE_EDITOR);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR));
} }
static boolean isTableCellEditor(final Component c) { static boolean isTableCellEditor(final Component c) {
return c instanceof JComponent return PropertyUtil.getBooleanProperty(c, KEY_IS_TABLE_EDITOR);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkToggleButtonUI.KEY_IS_TABLE_EDITOR));
} }
} }

4
core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DropPreviewPanel.java

@ -28,6 +28,8 @@ import java.awt.*;
import javax.swing.*; import javax.swing.*;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Jannis Weis * @author Jannis Weis
*/ */
@ -51,7 +53,7 @@ public class DropPreviewPanel extends JComponent {
} }
protected Color getBackgroundColor() { protected Color getBackgroundColor() {
boolean useToolbar = Boolean.TRUE.equals(toolBar.getClientProperty(DarkToolBarUI.KEY_USE_TOOL_BAR_BACKGROUND)); boolean useToolbar = PropertyUtil.getBooleanProperty(toolBar, DarkToolBarUI.KEY_USE_TOOL_BAR_BACKGROUND);
if (!useToolbar) { if (!useToolbar) {
Color c = dropBackground; Color c = dropBackground;
if (c == null) { if (c == null) {

2
core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java

@ -103,7 +103,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe
private boolean added; private boolean added;
public static ComponentUI createUI(final JComponent c) { public static ComponentUI createUI(final JComponent c) {
if (Boolean.TRUE.equals(c.getClientProperty(KEY_PLAIN_TOOLTIP))) { if (PropertyUtil.getBooleanProperty(c, KEY_PLAIN_TOOLTIP)) {
return BasicToolTipUI.createUI(c); return BasicToolTipUI.createUI(c);
} else { } else {
return new DarkTooltipUI(); return new DarkTooltipUI();

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

@ -37,6 +37,7 @@ import javax.swing.tree.TreePath;
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 com.github.weisj.darklaf.ui.text.DarkTextUI;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Jannis Weis * @author Jannis Weis
@ -99,7 +100,8 @@ public class DarkDefaultTreeEditor extends DefaultTreeCellEditor {
} }
protected DarkTreeCellEditor getBooleanEditor(final JTree table) { protected DarkTreeCellEditor getBooleanEditor(final JTree table) {
if (DarkTreeUI.RENDER_TYPE_RADIOBUTTON.equals(table.getClientProperty(DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE))) { if (PropertyUtil.isPropertyEqual(table, DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE,
DarkTreeUI.RENDER_TYPE_RADIOBUTTON)) {
return radioButtonEditor; return radioButtonEditor;
} }
return checkBoxEditor; return checkBoxEditor;

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

@ -33,6 +33,7 @@ import javax.swing.tree.TreeCellRenderer;
import com.github.weisj.darklaf.ui.cell.CellUtil; import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton; import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton;
import com.github.weisj.darklaf.util.PropertyUtil;
import com.github.weisj.darklaf.util.PropertyValue; import com.github.weisj.darklaf.util.PropertyValue;
/** /**
@ -93,11 +94,12 @@ public class DarkTreeCellRenderer extends DefaultTreeCellRenderer implements Tre
} }
protected static boolean isBooleanRenderingEnabled(final JTree tree) { protected static boolean isBooleanRenderingEnabled(final JTree tree) {
return Boolean.TRUE.equals(tree.getClientProperty(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX)); return PropertyUtil.getBooleanProperty(tree, DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX);
} }
protected DarkCellRendererToggleButton<?> getBooleanRenderer(final JTree table) { protected DarkCellRendererToggleButton<?> getBooleanRenderer(final JTree table) {
if (DarkTreeUI.RENDER_TYPE_RADIOBUTTON.equals(table.getClientProperty(DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE))) { if (PropertyUtil.isPropertyEqual(table, DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE,
DarkTreeUI.RENDER_TYPE_RADIOBUTTON)) {
return radioRenderer; return radioRenderer;
} }
return checkBoxRenderer; return checkBoxRenderer;

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

@ -40,6 +40,7 @@ import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
import com.github.weisj.darklaf.util.SystemInfo; import com.github.weisj.darklaf.util.SystemInfo;
/** /**
@ -185,7 +186,7 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
protected void installKeyboardActions() { protected void installKeyboardActions() {
super.installKeyboardActions(); super.installKeyboardActions();
if (Boolean.TRUE.equals(tree.getClientProperty(KEY_MAC_ACTIONS_INSTALLED))) return; if (PropertyUtil.getBooleanProperty(tree, KEY_MAC_ACTIONS_INSTALLED)) return;
tree.putClientProperty(KEY_MAC_ACTIONS_INSTALLED, Boolean.TRUE); tree.putClientProperty(KEY_MAC_ACTIONS_INSTALLED, Boolean.TRUE);
@ -337,10 +338,9 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
if (owner == null) { if (owner == null) {
owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
} }
boolean treeEditor = owner instanceof JComponent boolean treeEditor = PropertyUtil.getBooleanProperty(owner, DarkTreeUI.KEY_IS_TREE_EDITOR);
&& Boolean.TRUE.equals(((JComponent) owner).getClientProperty(DarkTreeUI.KEY_IS_TREE_EDITOR)); boolean treeRenderer = !treeEditor
boolean treeRenderer = !treeEditor && owner instanceof JComponent && PropertyUtil.getBooleanProperty(owner, DarkTreeUI.KEY_IS_TREE_RENDERER);
&& Boolean.TRUE.equals(((JComponent) owner).getClientProperty(DarkTreeUI.KEY_IS_TREE_RENDERER));
return treeEditor || treeRenderer; return treeEditor || treeRenderer;
} }
return true; return true;
@ -540,10 +540,10 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
protected Color getRowBackground(final int row, final boolean selected) { protected Color getRowBackground(final int row, final boolean selected) {
if (selected) { if (selected) {
boolean isTableTree = Boolean.TRUE.equals(tree.getClientProperty(KEY_TREE_TABLE_TREE)); boolean isTableTree = PropertyUtil.getBooleanProperty(tree, KEY_TREE_TABLE_TREE);
return getTreeSelectionBackground(hasFocus() || isTableTree || tree.isEditing()); return getTreeSelectionBackground(hasFocus() || isTableTree || tree.isEditing());
} }
if (Boolean.TRUE.equals(tree.getClientProperty(KEY_ALTERNATE_ROW_COLOR)) && row % 2 == 1) { if (row % 2 == 1 && PropertyUtil.getBooleanProperty(tree, KEY_ALTERNATE_ROW_COLOR)) {
return alternativeBackground; return alternativeBackground;
} else { } else {
return tree.getBackground(); return tree.getBackground();

3
core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java

@ -155,8 +155,7 @@ public final class DarkUIUtil {
} }
public static boolean isInCell(final Component c) { public static boolean isInCell(final Component c) {
boolean tableHeaderCell = c instanceof JComponent boolean tableHeaderCell = PropertyUtil.getBooleanProperty(c, DarkTableHeaderUI.KEY_IS_HEADER_RENDERER);
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTableHeaderUI.KEY_IS_HEADER_RENDERER));
boolean inCellRenderer = !tableHeaderCell boolean inCellRenderer = !tableHeaderCell
&& (getParentOfType(CellRendererPane.class, c) != null && (getParentOfType(CellRendererPane.class, c) != null
|| getParentOfType(TableCellRenderer.class, c) != null || getParentOfType(TableCellRenderer.class, c) != null

3
core/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java

@ -40,6 +40,7 @@ import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.GraphicsUtil; import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.ui.text.DarkTextUI; import com.github.weisj.darklaf.ui.text.DarkTextUI;
import com.github.weisj.darklaf.ui.text.StyleConstantsEx; import com.github.weisj.darklaf.ui.text.StyleConstantsEx;
import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* Note this class only sits inside this weird package because of a hack used in {@link * Note this class only sits inside this weird package because of a hack used in {@link
@ -409,7 +410,7 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai
private boolean isRounded(final JTextComponent c) { private boolean isRounded(final JTextComponent c) {
return !suppressRounded return !suppressRounded
&& (roundedEdges || Boolean.TRUE.equals(c.getClientProperty(DarkTextUI.KEY_ROUNDED_SELECTION))); && (roundedEdges || PropertyUtil.getBooleanProperty(c, DarkTextUI.KEY_ROUNDED_SELECTION));
} }
private Shape paintExtension(final Graphics2D g2d, final JTextComponent c, private Shape paintExtension(final Graphics2D g2d, final JTextComponent c,

3
core/src/test/java/ui/list/ListDemo.java

@ -34,6 +34,7 @@ import ui.ComponentDemo;
import ui.DemoPanel; import ui.DemoPanel;
import com.github.weisj.darklaf.ui.list.DarkListUI; import com.github.weisj.darklaf.ui.list.DarkListUI;
import com.github.weisj.darklaf.util.PropertyUtil;
public final class ListDemo implements ComponentDemo { public final class ListDemo implements ComponentDemo {
@ -52,7 +53,7 @@ public final class ListDemo implements ComponentDemo {
JPanel controlPanel = panel.addControls(); JPanel controlPanel = panel.addControls();
controlPanel.add(new JCheckBox(DarkListUI.KEY_ALTERNATE_ROW_COLOR) { controlPanel.add(new JCheckBox(DarkListUI.KEY_ALTERNATE_ROW_COLOR) {
{ {
setSelected(Boolean.TRUE.equals(list.getClientProperty(DarkListUI.KEY_ALTERNATE_ROW_COLOR))); setSelected(PropertyUtil.getBooleanProperty(list, DarkListUI.KEY_ALTERNATE_ROW_COLOR));
addActionListener(e -> list.putClientProperty(DarkListUI.KEY_ALTERNATE_ROW_COLOR, isSelected())); addActionListener(e -> list.putClientProperty(DarkListUI.KEY_ALTERNATE_ROW_COLOR, isSelected()));
} }
}, "span"); }, "span");

5
core/src/test/java/ui/table/TableDemo.java

@ -37,6 +37,7 @@ import ui.DemoPanel;
import com.github.weisj.darklaf.ui.table.DarkTableCellEditor; import com.github.weisj.darklaf.ui.table.DarkTableCellEditor;
import com.github.weisj.darklaf.ui.table.DarkTableUI; import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
public class TableDemo implements ComponentDemo { public class TableDemo implements ComponentDemo {
@ -112,7 +113,7 @@ public class TableDemo implements ComponentDemo {
}); });
controlPanel.add(new JCheckBox(DarkTableUI.KEY_ALTERNATE_ROW_COLOR) { controlPanel.add(new JCheckBox(DarkTableUI.KEY_ALTERNATE_ROW_COLOR) {
{ {
setSelected(Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_ALTERNATE_ROW_COLOR))); setSelected(PropertyUtil.getBooleanProperty(table, DarkTableUI.KEY_ALTERNATE_ROW_COLOR));
addActionListener(e -> table.putClientProperty(DarkTableUI.KEY_ALTERNATE_ROW_COLOR, isSelected())); addActionListener(e -> table.putClientProperty(DarkTableUI.KEY_ALTERNATE_ROW_COLOR, isSelected()));
} }
}); });
@ -144,7 +145,7 @@ public class TableDemo implements ComponentDemo {
}); });
controlPanel.add(new JCheckBox(DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX) { controlPanel.add(new JCheckBox(DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX) {
{ {
setSelected(Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX))); setSelected(PropertyUtil.getBooleanProperty(table, DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX));
addActionListener(e -> table.putClientProperty(DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX, addActionListener(e -> table.putClientProperty(DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX,
isSelected())); isSelected()));
} }

5
core/src/test/java/ui/tree/TreeDemo.java

@ -38,6 +38,7 @@ import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.components.SelectableTreeNode; import com.github.weisj.darklaf.components.SelectableTreeNode;
import com.github.weisj.darklaf.ui.tree.DarkTreeUI; import com.github.weisj.darklaf.ui.tree.DarkTreeUI;
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
public class TreeDemo implements ComponentDemo { public class TreeDemo implements ComponentDemo {
@ -96,13 +97,13 @@ public class TreeDemo implements ComponentDemo {
}); });
controlPanel.add(new JCheckBox(DarkTreeUI.KEY_ALTERNATE_ROW_COLOR) { controlPanel.add(new JCheckBox(DarkTreeUI.KEY_ALTERNATE_ROW_COLOR) {
{ {
setSelected(Boolean.TRUE.equals(tree.getClientProperty(DarkTreeUI.KEY_ALTERNATE_ROW_COLOR))); setSelected(PropertyUtil.getBooleanProperty(tree, DarkTreeUI.KEY_ALTERNATE_ROW_COLOR));
addActionListener(e -> tree.putClientProperty(DarkTreeUI.KEY_ALTERNATE_ROW_COLOR, isSelected())); addActionListener(e -> tree.putClientProperty(DarkTreeUI.KEY_ALTERNATE_ROW_COLOR, isSelected()));
} }
}); });
controlPanel.add(new JCheckBox(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX) { controlPanel.add(new JCheckBox(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX) {
{ {
setSelected(Boolean.TRUE.equals(tree.getClientProperty(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX))); setSelected(PropertyUtil.getBooleanProperty(tree, DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX));
addActionListener(e -> tree.putClientProperty(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX, isSelected())); addActionListener(e -> tree.putClientProperty(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX, isSelected()));
} }
}, "span"); }, "span");

5
macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java

@ -29,6 +29,7 @@ import java.awt.*;
import javax.swing.*; import javax.swing.*;
import com.github.weisj.darklaf.platform.macos.JNIDecorationsMacOS; import com.github.weisj.darklaf.platform.macos.JNIDecorationsMacOS;
import com.github.weisj.darklaf.util.PropertyUtil;
import com.github.weisj.darklaf.util.SystemInfo; import com.github.weisj.darklaf.util.SystemInfo;
public class MacOSDecorationsUtil { public class MacOSDecorationsUtil {
@ -80,11 +81,11 @@ public class MacOSDecorationsUtil {
} }
private static boolean isFullWindowContentEnabled(final JRootPane rootPane) { private static boolean isFullWindowContentEnabled(final JRootPane rootPane) {
return Boolean.TRUE.equals(rootPane.getClientProperty(FULL_WINDOW_CONTENT_KEY)); return PropertyUtil.getBooleanProperty(rootPane, FULL_WINDOW_CONTENT_KEY);
} }
private static boolean isTransparentTitleBarEnabled(final JRootPane rootPane) { private static boolean isTransparentTitleBarEnabled(final JRootPane rootPane) {
return Boolean.TRUE.equals(rootPane.getClientProperty(TRANSPARENT_TITLE_BAR_KEY)); return PropertyUtil.getBooleanProperty(rootPane, TRANSPARENT_TITLE_BAR_KEY);
} }
private static void setFullWindowContentEnabled(final JRootPane rootPane, private static void setFullWindowContentEnabled(final JRootPane rootPane,

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

@ -0,0 +1,64 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.weisj.darklaf.util;
import java.awt.*;
import java.util.Objects;
import javax.swing.*;
public class PropertyUtil {
public static boolean getBooleanProperty(final Component c, final String property) {
return getBooleanProperty(c, property, false);
}
public static boolean getBooleanProperty(final Component c, final String property, final boolean defaultValue) {
return c instanceof JComponent && getBooleanProperty((JComponent) c, property, defaultValue);
}
public static boolean getBooleanProperty(final JComponent c, final String property) {
return getBooleanProperty(c, property, false);
}
public static boolean getBooleanProperty(final JComponent c, final String property, final boolean defaultValue) {
if (c == null) return defaultValue;
Object obj = c.getClientProperty(property);
if (!defaultValue) {
return Boolean.TRUE.equals(obj);
} else {
return !Boolean.FALSE.equals(obj);
}
}
public static <T> boolean isPropertyEqual(final Component c, final String property, final T checkValue) {
return c instanceof JComponent && isPropertyEqual((JComponent) c, property, checkValue);
}
public static <T> boolean isPropertyEqual(final JComponent c, final String property, final T checkValue) {
if (c == null) return false;
Object obj = c.getClientProperty(property);
return Objects.equals(checkValue, obj);
}
}
Loading…
Cancel
Save