From ec5e3a4ab01c13347863c83463a17ef369c418c4 Mon Sep 17 00:00:00 2001 From: weisj Date: Wed, 11 Mar 2020 16:08:01 +0100 Subject: [PATCH] Replaced hard coded property names with constants. --- .../com/github/weisj/darklaf/DarkLaf.java | 3 +- .../darklaf/components/ScrollPopupMenu.java | 7 +- .../components/tabframe/JTabFrame.java | 6 +- .../components/tabframe/PanelPopup.java | 17 ++- .../components/tabframe/TabFramePopup.java | 9 ++ .../components/tabframe/TabFrameTab.java | 6 + .../tabframe/TabFrameTabContainer.java | 10 +- .../components/tabframe/TabFrameTabLabel.java | 10 +- .../components/text/NumberingPane.java | 23 ++- .../components/tooltip/DarkToolTip.java | 3 +- .../weisj/darklaf/platform/Decorations.java | 3 +- .../button/AbstractButtonLayoutDelegate.java | 4 +- .../weisj/darklaf/ui/button/DarkButtonUI.java | 131 ++++++++++-------- .../darklaf/ui/button/DarkToggleButtonUI.java | 17 ++- .../ui/cell/DarkCellRendererToggleButton.java | 12 +- .../ui/checkbox/DarkCheckBoxBorder.java | 5 +- .../darklaf/ui/checkbox/DarkCheckBoxUI.java | 11 +- .../colorchooser/DarkColorChooserPanel.java | 3 +- .../ui/colorchooser/DarkColorChooserUI.java | 3 +- .../darklaf/ui/combobox/DarkComboBoxUI.java | 32 +++-- .../darklaf/ui/combobox/DarkComboPopup.java | 2 +- .../ui/filechooser/DarkFileChooserUI.java | 4 +- .../filechooser/DarkFileChooserUIBridge.java | 13 +- .../darklaf/ui/filechooser/DarkFilePane.java | 9 +- .../ui/filechooser/DarkFilePaneUIBridge.java | 50 ++----- .../ui/internalframe/DarkInternalFrameUI.java | 4 +- .../weisj/darklaf/ui/label/DarkLabelUI.java | 3 +- .../darklaf/ui/list/DarkListCellRenderer.java | 4 +- .../weisj/darklaf/ui/list/DarkListUI.java | 24 +++- .../darklaf/ui/list/DarkListUIBridge.java | 24 ++-- .../ui/numberingpane/DarkNumberingPaneUI.java | 25 ++-- .../darklaf/ui/popupmenu/DarkPopupMenuUI.java | 14 +- .../ui/progressbar/DarkProgressBarUI.java | 60 ++++---- .../ui/radiobutton/DarkRadioButtonBorder.java | 5 +- .../ui/radiobutton/DarkRadioButtonUI.java | 9 +- .../darklaf/ui/rootpane/DarkRootPaneUI.java | 5 +- .../ui/scrollpane/DarkScrollBarUI.java | 10 +- .../ui/scrollpane/DarkScrollPaneUI.java | 8 +- .../weisj/darklaf/ui/slider/DarkSliderUI.java | 111 ++++++++------- .../darklaf/ui/spinner/DarkSpinnerUI.java | 72 +++++----- .../darklaf/ui/splitpane/DarkSplitPaneUI.java | 17 ++- .../darklaf/ui/tabbedpane/DarkHandler.java | 30 ++-- .../tabbedpane/DarkScrollableTabSupport.java | 4 +- .../ui/tabbedpane/DarkTabbedPaneUI.java | 78 ++++++----- .../ui/tabbedpane/DarkTabbedPaneUIBridge.java | 7 +- .../ui/tabbedpane/TabbedPaneHandler.java | 20 +-- .../darklaf/ui/tabframe/DarkPanelPopupUI.java | 19 +-- .../DarkTabFrameComponentPopupMenu.java | 5 +- .../tabframe/DarkTabFrameTabContainerUI.java | 19 +-- .../ui/tabframe/DarkTabFrameTabLabelUI.java | 21 +-- .../darklaf/ui/table/DarkTableCellEditor.java | 17 ++- .../DarkTableCellEditorToggleButton.java | 2 +- .../ui/table/DarkTableCellFocusBorder.java | 6 +- .../ui/table/DarkTableCellRenderer.java | 24 ++-- .../ui/table/DarkTableHeaderUIBridge.java | 3 +- .../weisj/darklaf/ui/table/DarkTableUI.java | 43 ++++-- .../darklaf/ui/table/DarkTableUIBridge.java | 6 +- .../weisj/darklaf/ui/table/TableUIBridge.java | 56 +++----- ...er.java => TextTableCellEditorBorder.java} | 28 ++-- .../darklaf/ui/taskpane/DarkTaskPaneUI.java | 5 +- .../darklaf/ui/text/DarkEditorPaneUI.java | 29 ++-- .../ui/text/DarkFormattedTextFieldUI.java | 4 +- .../darklaf/ui/text/DarkPasswordFieldUI.java | 6 +- .../weisj/darklaf/ui/text/DarkTextAreaUI.java | 21 +-- .../weisj/darklaf/ui/text/DarkTextBorder.java | 8 +- .../darklaf/ui/text/DarkTextFieldUI.java | 15 +- .../weisj/darklaf/ui/text/DarkTextUI.java | 15 +- .../darklaf/ui/toolbar/DarkToolBarLayout.java | 4 +- .../darklaf/ui/toolbar/DarkToolBarUI.java | 2 + .../ui/toolbar/DarkToolBarUIBridge.java | 15 +- .../darklaf/ui/toolbar/DropPreviewPanel.java | 2 +- .../darklaf/ui/tooltip/DarkTooltipBorder.java | 6 +- .../darklaf/ui/tooltip/DarkTooltipUI.java | 29 ++-- .../ui/tree/DarkDefaultTreeEditor.java | 2 +- .../darklaf/ui/tree/DarkTreeCellEditor.java | 3 +- .../darklaf/ui/tree/DarkTreeCellRenderer.java | 9 +- .../weisj/darklaf/ui/tree/DarkTreeUI.java | 50 ++++--- .../github/weisj/darklaf/util/DarkUIUtil.java | 6 +- .../weisj/darklaf/util/GraphicsUtil.java | 2 +- .../DarkHighlightPainter.java | 10 +- .../darklaf/properties/overwrites.properties | 1 + .../darklaf/properties/ui/tree.properties | 2 +- core/src/test/java/UIDemo.java | 21 +-- .../test/java/ui/button/ToggleButtonDemo.java | 9 +- .../test/java/ui/checkBox/CheckBoxDemo.java | 9 +- .../java/ui/checkBox/TriCheckBoxDemo.java | 9 +- .../test/java/ui/comboBox/ComboBoxDemo.java | 3 +- core/src/test/java/ui/list/ListDemo.java | 9 +- .../java/ui/radioButton/RadioButtonDemo.java | 9 +- core/src/test/java/ui/slider/SliderDemo.java | 15 +- core/src/test/java/ui/table/TableDemo.java | 3 +- .../test/java/ui/text/PasswordFieldDemo.java | 3 +- .../test/java/ui/text/TextComponentDemo.java | 3 +- core/src/test/java/ui/text/TextFieldDemo.java | 3 +- core/src/test/java/ui/tree/TreeDemo.java | 26 ++-- .../platform/macos/ui/MacOSTitlePane.java | 3 +- .../github/weisj/darklaf/PropertyLoader.java | 11 +- .../weisj/darklaf/util/PropertyKey.java | 46 ++++++ .../weisj/darklaf/util/PropertyValue.java | 30 ++++ .../platform/windows/ui/WindowsTitlePane.java | 16 ++- 100 files changed, 921 insertions(+), 729 deletions(-) rename core/src/main/java/com/github/weisj/darklaf/ui/table/{TextFieldTableCellEditorBorder.java => TextTableCellEditorBorder.java} (89%) create mode 100644 utils/src/main/java/com/github/weisj/darklaf/util/PropertyKey.java create mode 100644 utils/src/main/java/com/github/weisj/darklaf/util/PropertyValue.java diff --git a/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java b/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java index 8cd33813..9e118ffb 100644 --- a/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java +++ b/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java @@ -58,6 +58,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener public static final String SYSTEM_PROPERTY_PREFIX = "darklaf."; + public static final String LOOK_AND_FEEL_PROPERTY = "lookAndFeel"; private static final Logger LOGGER = Logger.getLogger(DarkLaf.class.getName()); private static final String NAME = "Darklaf"; private final BasicLookAndFeel base; @@ -425,7 +426,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener @Override public void propertyChange(final PropertyChangeEvent evt) { - if ("lookAndFeel".equals(evt.getPropertyName())) { + if (LOOK_AND_FEEL_PROPERTY.equals(evt.getPropertyName())) { if (UIManager.getLookAndFeel() == this) { PropertyLoader.finish(); } diff --git a/core/src/main/java/com/github/weisj/darklaf/components/ScrollPopupMenu.java b/core/src/main/java/com/github/weisj/darklaf/components/ScrollPopupMenu.java index 831b8571..a7010165 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/ScrollPopupMenu.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/ScrollPopupMenu.java @@ -24,6 +24,7 @@ package com.github.weisj.darklaf.components; import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.event.MenuKeyEvent; @@ -85,7 +86,7 @@ public class ScrollPopupMenu extends JPopupMenu { new OverlayScrollPane(view, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JScrollBar bar = overlayScrollPane.getVerticalScrollBar(); - bar.putClientProperty("ScrollBar.thin", Boolean.TRUE); + bar.putClientProperty("JScrollBar.thin", Boolean.TRUE); DarkUIUtil.doNotCancelPopupSetup(bar); DarkUIUtil.doNotCancelPopupSetup(overlayScrollPane.getScrollPane()); return overlayScrollPane; @@ -169,7 +170,7 @@ public class ScrollPopupMenu extends JPopupMenu { } firePopupMenuWillBecomeVisible(); showPopup(); - firePropertyChange("visible", Boolean.FALSE, Boolean.TRUE); + firePropertyChange(PropertyKey.VISIBLE, Boolean.FALSE, Boolean.TRUE); } else { hidePopup(); } @@ -180,7 +181,7 @@ public class ScrollPopupMenu extends JPopupMenu { firePopupMenuWillBecomeInvisible(); popWin.setVisible(false); popWin = null; - firePropertyChange("visible", Boolean.TRUE, Boolean.FALSE); + firePropertyChange(PropertyKey.VISIBLE, Boolean.TRUE, Boolean.FALSE); if (isPopupMenu()) { MenuSelectionManager.defaultManager().clearSelectedPath(); } diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/JTabFrame.java b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/JTabFrame.java index 0f0e6b4d..afbc8666 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/JTabFrame.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/JTabFrame.java @@ -41,6 +41,8 @@ import java.util.Objects; */ public class JTabFrame extends JComponent { + public static final String KEY_DND = "dndEnabled"; + private final JComponent bottomTabs = createTabContainer(); private final JComponent topTabs = createTabContainer(); private final JComponent leftTabs = createTabContainer(); @@ -537,7 +539,7 @@ public class JTabFrame extends JComponent { getPopupComponentAt(a).doLayout(); getPopupComponentAt(a).requestFocus(); } - firePropertyChange("visibleTab", new TabFramePosition(a, oldIndex), new TabFramePosition(a, index)); + firePropertyChange(TabFramePopup.KEY_VISIBLE_TAB, new TabFramePosition(a, oldIndex), new TabFramePosition(a, index)); } /** @@ -931,7 +933,7 @@ public class JTabFrame extends JComponent { if (getDropTarget() != null) { getDropTarget().setActive(dndEnabled); } - firePropertyChange("dndEnabled", old, dndEnabled); + firePropertyChange(KEY_DND, old, dndEnabled); } /** diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/PanelPopup.java b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/PanelPopup.java index 9ef71f1c..31b4b096 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/PanelPopup.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/PanelPopup.java @@ -35,7 +35,6 @@ import java.awt.*; * @since 2019 */ public class PanelPopup extends JPanel implements TabFramePopup { - private Component content; private boolean open; private JTabFrame parent; @@ -112,7 +111,7 @@ public class PanelPopup extends JPanel implements TabFramePopup { if (content == null) { content = new JPanel(); } - firePropertyChange("content", old, content); + firePropertyChange(KEY_CONTENT, old, content); } @Override @@ -127,7 +126,7 @@ public class PanelPopup extends JPanel implements TabFramePopup { boolean oldOpen = isOpen(); parent.closeTab(getAlignment(), getIndex()); open = false; - firePropertyChange("open", oldOpen, false); + firePropertyChange(KEY_OPEN, oldOpen, false); } } @@ -145,7 +144,7 @@ public class PanelPopup extends JPanel implements TabFramePopup { public void setTabFrame(final JTabFrame parent) { JTabFrame old = this.parent; this.parent = parent; - firePropertyChange("tabFrame", old, parent); + firePropertyChange(KEY_TAB_FRAME_PARENT, old, parent); } @Override @@ -161,7 +160,7 @@ public class PanelPopup extends JPanel implements TabFramePopup { } Alignment old = this.alignment; this.alignment = alignment; - firePropertyChange("alignment", old, alignment); + firePropertyChange(KEY_ALIGNMENT, old, alignment); } @Override @@ -171,7 +170,7 @@ public class PanelPopup extends JPanel implements TabFramePopup { boolean oldOpen = isOpen(); parent.openTab(getAlignment(), getIndex()); open = true; - firePropertyChange("open", oldOpen, true); + firePropertyChange(KEY_OPEN, oldOpen, true); requestFocus(); } } @@ -185,7 +184,7 @@ public class PanelPopup extends JPanel implements TabFramePopup { public void setTitle(final String title) { String old = this.title; this.title = title == null ? "" : title; - firePropertyChange("title", old, this.title); + firePropertyChange(KEY_TITLE, old, this.title); } @Override @@ -197,7 +196,7 @@ public class PanelPopup extends JPanel implements TabFramePopup { public void setIcon(final Icon icon) { Icon old = this.icon; this.icon = icon; - firePropertyChange("icon", old, icon); + firePropertyChange(KEY_ICON, old, icon); } @Override @@ -209,6 +208,6 @@ public class PanelPopup extends JPanel implements TabFramePopup { public void setIndex(final int index) { int old = this.index; this.index = index; - firePropertyChange("index", old, index); + firePropertyChange(KEY_INDEX, old, index); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFramePopup.java b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFramePopup.java index 83744f9b..8be12a62 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFramePopup.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFramePopup.java @@ -29,6 +29,15 @@ import javax.swing.*; import java.awt.*; public interface TabFramePopup { + String KEY_VISIBLE_TAB = "visibleTab"; + String KEY_CONTENT = "content"; + String KEY_TAB_FRAME_PARENT = "tabFrame"; + String KEY_ALIGNMENT = "alignment"; + String KEY_ICON = "icon"; + String KEY_INDEX = "index"; + String KEY_TITLE = "title"; + String KEY_OPEN = "open"; + String KEY_PEER_INSETS = "peerInsets"; /** * Get the current content pane. A popup may hold more than one content pane. In this case this method should return diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTab.java b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTab.java index 42a0ee7f..e2cb5bc1 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTab.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTab.java @@ -28,6 +28,12 @@ import com.github.weisj.darklaf.util.Alignment; import java.awt.*; public interface TabFrameTab { + String KEY_SELECTED = "selected"; + String KEY_CONTENT = "content"; + String KEY_TAB_FRAME_PARENT = "tabFrame"; + String KEY_ORIENTATION = "orientation"; + String KEY_ACCELERATOR = "accelerator"; + String KEY_TITLE = "title"; /** * Get the index of the tab. diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabContainer.java b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabContainer.java index 963dfc79..ab56d269 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabContainer.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabContainer.java @@ -74,7 +74,7 @@ public class TabFrameTabContainer extends JPanel implements TabFrameTab { remove(content); this.content = content; add(content, BorderLayout.CENTER); - firePropertyChange("content", old, content); + firePropertyChange(KEY_CONTENT, old, content); } @Override @@ -110,7 +110,7 @@ public class TabFrameTabContainer extends JPanel implements TabFrameTab { if (this.orientation == a) return; Alignment oldOrientation = this.orientation; this.orientation = a; - firePropertyChange("orientation", oldOrientation, orientation); + firePropertyChange(KEY_ORIENTATION, oldOrientation, orientation); } @Override @@ -123,7 +123,7 @@ public class TabFrameTabContainer extends JPanel implements TabFrameTab { if (selected == this.selected) return; boolean oldSelected = this.selected; this.selected = selected; - firePropertyChange("selected", oldSelected, selected); + firePropertyChange(KEY_SELECTED, oldSelected, selected); } @Override @@ -136,7 +136,7 @@ public class TabFrameTabContainer extends JPanel implements TabFrameTab { if (this.accelerator == accelerator) return; int oldAccelerator = this.accelerator; this.accelerator = accelerator; - firePropertyChange("accelerator", oldAccelerator, accelerator); + firePropertyChange(KEY_ACCELERATOR, oldAccelerator, accelerator); } @Override @@ -148,6 +148,6 @@ public class TabFrameTabContainer extends JPanel implements TabFrameTab { public void setTabFrame(final JTabFrame parent) { JTabFrame old = this.parent; this.parent = parent; - firePropertyChange("tabFrame", old, parent); + firePropertyChange(KEY_TAB_FRAME_PARENT, old, parent); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabLabel.java b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabLabel.java index bdb73810..099e669c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabLabel.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabLabel.java @@ -99,7 +99,7 @@ public class TabFrameTabLabel extends JLabel implements TabFrameTab { if (this.orientation == a) return; Alignment oldOrientation = this.orientation; this.orientation = a; - firePropertyChange("orientation", oldOrientation, orientation); + firePropertyChange(KEY_ORIENTATION, oldOrientation, orientation); } @Override @@ -112,7 +112,7 @@ public class TabFrameTabLabel extends JLabel implements TabFrameTab { if (selected == this.selected) return; boolean oldSelected = this.selected; this.selected = selected; - firePropertyChange("selected", oldSelected, selected); + firePropertyChange(KEY_SELECTED, oldSelected, selected); } @Override @@ -125,7 +125,7 @@ public class TabFrameTabLabel extends JLabel implements TabFrameTab { if (this.accelerator == accelerator) return; int oldAccelerator = this.accelerator; this.accelerator = accelerator; - firePropertyChange("accelerator", oldAccelerator, accelerator); + firePropertyChange(KEY_ACCELERATOR, oldAccelerator, accelerator); } @Override @@ -137,7 +137,7 @@ public class TabFrameTabLabel extends JLabel implements TabFrameTab { public void setTabFrame(final JTabFrame parent) { JTabFrame old = this.parent; this.parent = parent; - firePropertyChange("tabFrame", old, parent); + firePropertyChange(KEY_TAB_FRAME_PARENT, old, parent); } /** @@ -159,6 +159,6 @@ public class TabFrameTabLabel extends JLabel implements TabFrameTab { if (Objects.equals(title, this.title)) return; String oldTitle = this.title; this.title = title; - firePropertyChange("title", oldTitle, selected); + firePropertyChange(KEY_TITLE, oldTitle, selected); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/components/text/NumberingPane.java b/core/src/main/java/com/github/weisj/darklaf/components/text/NumberingPane.java index eba01318..24f049e6 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/text/NumberingPane.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/text/NumberingPane.java @@ -26,20 +26,15 @@ package com.github.weisj.darklaf.components.text; import com.github.weisj.darklaf.util.StringUtil; import javax.swing.*; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import javax.swing.text.JTextComponent; -import javax.swing.text.Position; -import javax.swing.text.Segment; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import javax.swing.text.*; +import java.util.*; import java.util.stream.Collectors; public class NumberingPane extends JComponent { + public static final String KEY_EDITOR = "editorPane"; + public static final String KEY_ICONS = "icons"; + public static final String KEY_MIN_ICON_WIDTH = "minimumIconWidth"; private JTextComponent textComponent; private Map iconMap; private Map> listenerMap; @@ -68,7 +63,7 @@ public class NumberingPane extends JComponent { public void setTextComponent(final JTextComponent textComponent) { JTextComponent old = this.textComponent; this.textComponent = textComponent; - firePropertyChange("editorPane", old, textComponent); + firePropertyChange(KEY_EDITOR, old, textComponent); } public int getIconCount() { @@ -114,7 +109,7 @@ public class NumberingPane extends JComponent { if (icon != null) { iconMap.put(pos, icon); } - firePropertyChange("icons", null, icon); + firePropertyChange(KEY_ICONS, null, icon); return pos; } @@ -174,7 +169,7 @@ public class NumberingPane extends JComponent { public void setMinimumIconWidth(final int width) { int old = this.width; this.width = Math.max(width, 0); - firePropertyChange("minimumIconWidth", old, width); + firePropertyChange(KEY_MIN_ICON_WIDTH, old, width); } public Collection getIcons() { @@ -187,7 +182,7 @@ public class NumberingPane extends JComponent { public void removeIconAt(final Position position) { Icon icon = iconMap.remove(position); - firePropertyChange("icons", icon, icon); + firePropertyChange(KEY_ICONS, icon, icon); } public List getIconListeners() { diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tooltip/DarkToolTip.java b/core/src/main/java/com/github/weisj/darklaf/components/tooltip/DarkToolTip.java index a47c283d..c4549a06 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tooltip/DarkToolTip.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tooltip/DarkToolTip.java @@ -39,6 +39,7 @@ import java.util.Objects; public class DarkToolTip extends JToolTip implements PropertyChangeListener { + public static final String TIP_TEXT_PROPERTY = "tiptext"; private static final long REPAINT_THRESHOLD = 150; private static final AlphaComposite COMPOSITE = AlphaComposite.getInstance(AlphaComposite.SRC_OVER); private static final float MAX_ALPHA = 1.0f; @@ -141,7 +142,7 @@ public class DarkToolTip extends JToolTip implements PropertyChangeListener { @Override public void propertyChange(final PropertyChangeEvent evt) { - if ("tiptext".equals(evt.getPropertyName())) { + if (TIP_TEXT_PROPERTY.equals(evt.getPropertyName())) { setPreferredSize(getUI().getPreferredSize(this)); if (!Objects.equals(evt.getNewValue(), evt.getOldValue())) { notifyToolTipListeners(ToolTipEvent.TEXT); diff --git a/core/src/main/java/com/github/weisj/darklaf/platform/Decorations.java b/core/src/main/java/com/github/weisj/darklaf/platform/Decorations.java index ab5813b5..f55bc5af 100644 --- a/core/src/main/java/com/github/weisj/darklaf/platform/Decorations.java +++ b/core/src/main/java/com/github/weisj/darklaf/platform/Decorations.java @@ -29,6 +29,7 @@ import com.github.weisj.darklaf.decorations.CustomTitlePane; import com.github.weisj.darklaf.decorations.DecorationsProvider; import com.github.weisj.darklaf.platform.macos.MacOSDecorationsProvider; import com.github.weisj.darklaf.platform.windows.WindowsDecorationsProvider; +import com.github.weisj.darklaf.util.PropertyValue; import com.github.weisj.darklaf.util.SystemInfo; import javax.swing.*; @@ -61,7 +62,7 @@ public final class Decorations { public static boolean isCustomDecorationSupported() { return decorationsProvider.isCustomDecorationSupported() - && !"false".equals(System.getProperty(DarkLaf.SYSTEM_PROPERTY_PREFIX + "decorations")) + && !PropertyValue.FALSE.equals(System.getProperty(DarkLaf.SYSTEM_PROPERTY_PREFIX + "decorations")) && LafManager.isDecorationsEnabled() && LafManager.getTheme().useCustomDecorations(); } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/button/AbstractButtonLayoutDelegate.java b/core/src/main/java/com/github/weisj/darklaf/ui/button/AbstractButtonLayoutDelegate.java index b2c46bd5..52a85059 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/button/AbstractButtonLayoutDelegate.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/button/AbstractButtonLayoutDelegate.java @@ -23,6 +23,8 @@ */ package com.github.weisj.darklaf.ui.button; +import com.github.weisj.darklaf.util.PropertyKey; + import javax.swing.*; import java.awt.*; @@ -32,7 +34,7 @@ public class AbstractButtonLayoutDelegate extends AbstractButton { public void setDelegate(final AbstractButton delegate) { this.delegate = delegate; - if (delegate != null) putClientProperty("html", delegate.getClientProperty("html")); + if (delegate != null) putClientProperty(PropertyKey.HTML, delegate.getClientProperty(PropertyKey.HTML)); } @Override diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java index fe540c72..2f18789f 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java @@ -23,10 +23,7 @@ */ package com.github.weisj.darklaf.ui.button; -import com.github.weisj.darklaf.util.DarkUIUtil; -import com.github.weisj.darklaf.util.GraphicsContext; -import com.github.weisj.darklaf.util.GraphicsUtil; -import com.github.weisj.darklaf.util.SystemInfo; +import com.github.weisj.darklaf.util.*; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -48,6 +45,18 @@ import java.beans.PropertyChangeListener; */ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListener { + public static final String KEY_PREFIX = "JButton."; + public static final String KEY_VARIANT = KEY_PREFIX + "variant"; + public static final String KEY_HOVER_COLOR = KEY_PREFIX + "shadow.hover"; + public static final String KEY_CLICK_COLOR = KEY_PREFIX + "shadow.click"; + public static final String KEY_ALT_ARC = KEY_PREFIX + "alternativeArc"; + public static final String KEY_NO_ARC = KEY_PREFIX + "noArc"; + public static final String KEY_SQUARE = KEY_PREFIX + "square"; + public static final String KEY_THIN = KEY_PREFIX + "thin"; + public static final String KEY_NO_SHADOW_OVERWRITE = KEY_PREFIX + "noShadowOverwrite"; + public static final String VARIANT_ONLY_LABEL = "onlyLabel"; + public static final String VARIANT_FULL_SHADOW = "fullShadow"; + public static final String VARIANT_SHADOW = "shadow"; protected static final Rectangle viewRect = new Rectangle(); protected static final Rectangle textRect = new Rectangle(); protected static final Rectangle iconRect = new Rectangle(); @@ -85,29 +94,12 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene public static boolean chooseAlternativeArc(final Component c) { return c instanceof JButton - && Boolean.TRUE.equals(((JButton) c).getClientProperty("JButton.alternativeArc")); + && Boolean.TRUE.equals(((JButton) c).getClientProperty(KEY_ALT_ARC)); } - @Override - protected void installDefaults(final AbstractButton b) { - super.installDefaults(b); - LookAndFeel.installProperty(b, "opaque", false); - b.setRolloverEnabled(UIManager.getBoolean("Button.rolloverEnabled")); - borderSize = UIManager.getInt("Button.borderThickness"); - shadowHeight = UIManager.getInt("Button.shadowHeight"); - inactiveForeground = UIManager.getColor("Button.disabledText"); - defaultForeground = UIManager.getColor("Button.selectedButtonForeground"); - defaultBackground = UIManager.getColor("Button.defaultFillColor"); - defaultHoverBackground = UIManager.getColor("Button.defaultFillColorRollOver"); - defaultClickBackground = UIManager.getColor("Button.defaultFillColorClick"); - background = UIManager.getColor("Button.activeFillColor"); - hoverBackground = UIManager.getColor("Button.activeFillColorRollOver"); - clickBackground = UIManager.getColor("Button.activeFillColorClick"); - inactiveBackground = UIManager.getColor("Button.inactiveFillColor"); - shadowHover = UIManager.getColor("Button.shadow.hover"); - shadowClick = UIManager.getColor("Button.shadow.click"); - arc = UIManager.getInt("Button.arc"); - squareArc = UIManager.getInt("Button.squareArc"); + public static boolean isLabelButton(final Component c) { + return c instanceof JButton + && VARIANT_ONLY_LABEL.equals(((JButton) c).getClientProperty(KEY_VARIANT)); } @Override @@ -122,9 +114,14 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene b.removePropertyChangeListener(this); } - public static boolean isLabelButton(final Component c) { - return c instanceof JButton - && "onlyLabel".equals(((JButton) c).getClientProperty("JButton.variant")); + public static boolean isShadowVariant(final Component c) { + if (isFullShadow(c)) return true; + if (c instanceof JButton) { + JButton b = (JButton) c; + return (isIconOnly(b) && convertIconButtonToShadow(b)) + || VARIANT_SHADOW.equals(b.getClientProperty(KEY_VARIANT)); + } + return false; } @Override @@ -146,14 +143,9 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene config.restore(); } - public static boolean isShadowVariant(final Component c) { - if (isFullShadow(c)) return true; - if (c instanceof JButton) { - JButton b = (JButton) c; - return (isIconOnly(b) && convertIconButtonToShadow(b)) - || "shadow".equals(b.getClientProperty("JButton.variant")); - } - return false; + public static boolean isFullShadow(final Component c) { + return c instanceof JButton + && VARIANT_FULL_SHADOW.equals(((JButton) c).getClientProperty(KEY_VARIANT)); } protected static boolean isIconOnly(final AbstractButton b) { @@ -172,9 +164,9 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene return fg; } - public static boolean isFullShadow(final Component c) { + public static boolean isNoArc(final Component c) { return c instanceof JButton - && "fullShadow".equals(((JButton) c).getClientProperty("JButton.variant")); + && Boolean.TRUE.equals(((JButton) c).getClientProperty(KEY_NO_ARC)); } private boolean shouldDrawBackground(final JComponent c) { @@ -184,11 +176,8 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene return c.isEnabled() && border != null && button.isContentAreaFilled(); } - protected Color getShadowColor(final AbstractButton c) { - Object colorHover = c.getClientProperty("JButton.shadow.hover"); - Object colorClick = c.getClientProperty("JButton.shadow.click"); - return c.getModel().isArmed() ? colorClick instanceof Color ? (Color) colorClick : shadowClick - : colorHover instanceof Color ? (Color) colorHover : shadowHover; + public static boolean isSquare(final Component c) { + return c instanceof JButton && Boolean.TRUE.equals(((JButton) c).getClientProperty(KEY_SQUARE)); } protected Color getBackgroundColor(final JComponent c) { @@ -267,24 +256,44 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene } } - public static boolean isNoArc(final Component c) { - return c instanceof JButton - && Boolean.TRUE.equals(((JButton) c).getClientProperty("JButton.noArc")); - } - - public static boolean isSquare(final Component c) { - return c instanceof JButton && Boolean.TRUE.equals(((JButton) c).getClientProperty("JButton.square")); - } - public static boolean isThin(final Component c) { return c instanceof JButton - && Boolean.TRUE.equals(((JButton) c).getClientProperty("JButton.thin")); + && Boolean.TRUE.equals(((JButton) c).getClientProperty(KEY_THIN)); } protected static boolean convertIconButtonToShadow(final AbstractButton b) { return !(b instanceof UIResource) && UIManager.getBoolean("Button.convertIconOnlyToShadow") - && !Boolean.TRUE.equals(b.getClientProperty("JButton.noShadowOverwrite")); + && !Boolean.TRUE.equals(b.getClientProperty(KEY_NO_SHADOW_OVERWRITE)); + } + + @Override + protected void installDefaults(final AbstractButton b) { + super.installDefaults(b); + LookAndFeel.installProperty(b, PropertyKey.OPAQUE, false); + b.setRolloverEnabled(UIManager.getBoolean("Button.rolloverEnabled")); + borderSize = UIManager.getInt("Button.borderThickness"); + shadowHeight = UIManager.getInt("Button.shadowHeight"); + inactiveForeground = UIManager.getColor("Button.disabledText"); + defaultForeground = UIManager.getColor("Button.selectedButtonForeground"); + defaultBackground = UIManager.getColor("Button.defaultFillColor"); + defaultHoverBackground = UIManager.getColor("Button.defaultFillColorRollOver"); + defaultClickBackground = UIManager.getColor("Button.defaultFillColorClick"); + background = UIManager.getColor("Button.activeFillColor"); + hoverBackground = UIManager.getColor("Button.activeFillColorRollOver"); + clickBackground = UIManager.getColor("Button.activeFillColorClick"); + inactiveBackground = UIManager.getColor("Button.inactiveFillColor"); + shadowHover = UIManager.getColor("Button.shadow.hover"); + shadowClick = UIManager.getColor("Button.shadow.click"); + arc = UIManager.getInt("Button.arc"); + squareArc = UIManager.getInt("Button.squareArc"); + } + + protected Color getShadowColor(final AbstractButton c) { + Object colorHover = c.getClientProperty(KEY_HOVER_COLOR); + Object colorClick = c.getClientProperty(KEY_CLICK_COLOR); + return c.getModel().isArmed() ? colorClick instanceof Color ? (Color) colorClick : shadowClick + : colorHover instanceof Color ? (Color) colorHover : shadowHover; } @Override @@ -302,14 +311,14 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene oldSquare = isSquare(button); oldAltArc = chooseAlternativeArc(button); button.setRolloverEnabled(true); - button.putClientProperty("JButton.square", true); - button.putClientProperty("JButton.thin", true); - button.putClientProperty("JButton.alternativeArc", true); + button.putClientProperty(KEY_SQUARE, true); + button.putClientProperty(KEY_THIN, true); + button.putClientProperty(KEY_ALT_ARC, true); } else { button.setRolloverEnabled(oldRolloverEnabled); - button.putClientProperty("JButton.square", oldSquare); - button.putClientProperty("JButton.thin", oldThin); - button.putClientProperty("JButton.alternativeArc", oldAltArc); + button.putClientProperty(KEY_SQUARE, oldSquare); + button.putClientProperty(KEY_THIN, oldThin); + button.putClientProperty(KEY_ALT_ARC, oldAltArc); } } @@ -401,7 +410,7 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if (key.startsWith("JButton.")) { + if (key.startsWith(KEY_PREFIX)) { button.repaint(); button.revalidate(); } else if (JButton.TEXT_CHANGED_PROPERTY.equals(key)) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkToggleButtonUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkToggleButtonUI.java index adc7da48..4d8e5a87 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkToggleButtonUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkToggleButtonUI.java @@ -26,6 +26,7 @@ package com.github.weisj.darklaf.ui.button; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; +import com.github.weisj.darklaf.util.PropertyKey; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -39,22 +40,30 @@ import java.beans.PropertyChangeListener; */ public class DarkToggleButtonUI extends DarkButtonUI { + public static final String KEY_PREFIX = "JToggleButton."; + public static final String KEY_VARIANT = KEY_PREFIX + "variant"; + public static final String KEY_IS_TREE_EDITOR = KEY_PREFIX + "isTreeCellEditor"; + public static final String KEY_IS_TREE_RENDER = KEY_PREFIX + "isTreeCellRenderer"; + public static final String KEY_IS_TABLE_EDITOR = KEY_PREFIX + "isTableCellEditor"; + public static final String KEY_IS_TABLE_RENDERER = KEY_PREFIX + "isTableCellRenderer"; + public static final String KEY_CLEAR_HIT_AREA = KEY_PREFIX + "clearHitArea"; + public static final String VARIANT_SLIDER = "slider"; private static final Rectangle rect = new Rectangle(); private final PropertyChangeListener propertyChangeListener = evt -> { String key = evt.getPropertyName(); - if ("JToggleButton.variant".equals(key)) { + if (KEY_VARIANT.equals(key)) { Object oldVal = evt.getOldValue(); Object newVal = evt.getNewValue(); if (oldVal != null && oldVal.equals(newVal)) { return; } - if ("slider".equals(newVal)) { + if (VARIANT_SLIDER.equals(newVal)) { button.setBorderPainted(false); } else { button.setBorderPainted(true); } - } else if ("componentOrientation".equals(key)) { + } else if (PropertyKey.COMPONENT_ORIENTATION.equals(key)) { button.repaint(); } }; @@ -159,7 +168,7 @@ public class DarkToggleButtonUI extends DarkButtonUI { private static boolean isSlider(final JComponent c) { return c instanceof JToggleButton - && "slider".equals(c.getClientProperty("JToggleButton.variant")); + && VARIANT_SLIDER.equals(c.getClientProperty(KEY_VARIANT)); } private void paintSlider(final Graphics2D g, final AbstractButton c) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java b/core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java index 44267e03..289ddc6c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java @@ -25,6 +25,8 @@ package com.github.weisj.darklaf.ui.cell; import com.github.weisj.darklaf.components.SelectableTreeNode; import com.github.weisj.darklaf.decorators.CellRenderer; +import com.github.weisj.darklaf.ui.button.DarkToggleButtonUI; +import com.github.weisj.darklaf.ui.table.DarkTableUI; import com.github.weisj.darklaf.ui.tree.DarkTreeCellRenderer; import com.github.weisj.darklaf.util.DarkUIUtil; @@ -58,7 +60,7 @@ public class DarkCellRendererToggleButton { - if ("value".equals(e.getPropertyName())) { + if (PropertyKey.VALUE.equals(e.getPropertyName())) { updatePreviewFromTextFields(); } }); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java index a828277f..8d20da65 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java @@ -27,6 +27,7 @@ import com.github.weisj.darklaf.color.DarkColorModel; import com.github.weisj.darklaf.color.DarkColorModelCMYK; import com.github.weisj.darklaf.color.DarkColorModelHSL; import com.github.weisj.darklaf.decorators.AncestorAdapter; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.colorchooser.AbstractColorChooserPanel; @@ -43,7 +44,7 @@ import java.beans.PropertyChangeListener; public class DarkColorChooserUI extends BasicColorChooserUI { private final PropertyChangeListener propertyChangeListener = e -> { - if ("ancestor".equals(e.getPropertyName())) { + if (PropertyKey.ANCESTOR.equals(e.getPropertyName())) { JComponent pane = (JComponent) e.getNewValue(); if (pane != null) { pane = (JComponent) pane.getRootPane().getContentPane(); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java index 5616f1e6..7cc45aac 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java @@ -27,6 +27,7 @@ import com.github.weisj.darklaf.components.ArrowButton; import com.github.weisj.darklaf.ui.list.DarkListCellRenderer; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.border.Border; @@ -47,6 +48,10 @@ import java.beans.PropertyChangeListener; */ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyChangeListener { + public static final String KEY_PREFIX = "JComboBox."; + public static final String KEY_IS_TREE_EDITOR = KEY_PREFIX + "isTreeCellEditor"; + public static final String KEY_IS_TABLE_EDITOR = KEY_PREFIX + "isTableCellEditor"; + private final MouseListener mouseListener = new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { @@ -91,11 +96,9 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC comboBox.setBorder(this); } - @Override - protected void installDefaults() { - super.installDefaults(); - LookAndFeel.installProperty(comboBox, "opaque", false); - arcSize = UIManager.getInt("ComboBox.arc"); + protected static boolean isTableCellEditor(final Component c) { + return c instanceof JComponent + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_IS_TABLE_EDITOR)); } @Override @@ -208,14 +211,16 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC return background; } - protected static boolean isTableCellEditor(final Component c) { + protected static boolean isTreeCellEditor(final Component c) { return c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JComboBox.isTableCellEditor")); + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_IS_TREE_EDITOR)); } - protected static boolean isTreeCellEditor(final Component c) { - return c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JComboBox.isTreeCellEditor")); + @Override + protected void installDefaults() { + super.installDefaults(); + LookAndFeel.installProperty(comboBox, PropertyKey.OPAQUE, false); + arcSize = UIManager.getInt("ComboBox.arc"); } private Color getForeground() { @@ -415,13 +420,14 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if ("componentOrientation".equals(key)) { + if (PropertyKey.COMPONENT_ORIENTATION.equals(key)) { comboBox.doLayout(); comboBox.repaint(); comboBox.getEditor().getEditorComponent().setComponentOrientation(comboBox.getComponentOrientation()); - } else if ("editable".equals(key)) { + } else if (PropertyKey.EDITABLE.equals(key)) { comboBox.repaint(); - } else if ("JComboBox.isTableCellEditor".equals(key) || "JComboBox.isTreeCellEditor".equals(key)) { + } else if (DarkComboBoxUI.KEY_IS_TABLE_EDITOR.equals(key) + || DarkComboBoxUI.KEY_IS_TREE_EDITOR.equals(key)) { comboBox.repaint(); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboPopup.java b/core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboPopup.java index b7a5179f..f4ca4c6b 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboPopup.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboPopup.java @@ -93,7 +93,7 @@ public class DarkComboPopup extends BasicComboPopup { protected JScrollPane createScroller() { overlayScrollPane = new OverlayScrollPane(list, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - overlayScrollPane.getVerticalScrollBar().putClientProperty("ScrollBar.thin", Boolean.TRUE); + overlayScrollPane.getVerticalScrollBar().putClientProperty("JScrollBar.thin", Boolean.TRUE); return overlayScrollPane.getScrollPane(); } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java index 59a4c379..b8fe183c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java @@ -41,6 +41,8 @@ import java.io.File; public class DarkFileChooserUI extends DarkFileChooserUIBridge { + public static final String KEY_VIEW_TYPE = "viewType"; + public DarkFileChooserUI(final JFileChooser b) { super(b); } @@ -187,7 +189,7 @@ public class DarkFileChooserUI extends DarkFileChooserUIBridge { topButtonPanel.add(Box.createGlue()); filePane.addPropertyChangeListener(e -> { - if ("viewType".equals(e.getPropertyName())) { + if (KEY_VIEW_TYPE.equals(e.getPropertyName())) { int viewType = filePane.getViewType(); switch (viewType) { case FilePane.VIEWTYPE_LIST: diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java index 76f8edfc..06afc195 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java @@ -23,6 +23,7 @@ */ package com.github.weisj.darklaf.ui.filechooser; +import com.github.weisj.darklaf.util.PropertyKey; import sun.awt.shell.ShellFolder; import sun.swing.FilePane; import sun.swing.SwingUtilities2; @@ -40,11 +41,7 @@ import javax.swing.plaf.basic.BasicDirectoryModel; import javax.swing.plaf.basic.BasicFileChooserUI; import javax.swing.plaf.metal.MetalFileChooserUI; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseListener; +import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; @@ -285,7 +282,7 @@ public class DarkFileChooserUIBridge extends BasicFileChooserUI { filePane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent e) { - if ("viewType".equals(e.getPropertyName())) { + if (DarkFileChooserUI.KEY_VIEW_TYPE.equals(e.getPropertyName())) { int viewType = filePane.getViewType(); switch (viewType) { case FilePane.VIEWTYPE_LIST: @@ -470,7 +467,7 @@ public class DarkFileChooserUIBridge extends BasicFileChooserUI { doApproveButtonMnemonicChanged(e); } else if (s.equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) { doControlButtonsChanged(e); - } else if (s.equals("componentOrientation")) { + } else if (s.equals(PropertyKey.COMPONENT_ORIENTATION)) { ComponentOrientation o = (ComponentOrientation) e.getNewValue(); JFileChooser cc = (JFileChooser) e.getSource(); if (o != e.getOldValue()) { @@ -478,7 +475,7 @@ public class DarkFileChooserUIBridge extends BasicFileChooserUI { } } else if (Objects.equals(s, "FileChooser.useShellFolder")) { doDirectoryChanged(e); - } else if (s.equals("ancestor")) { + } else if (PropertyKey.ANCESTOR.equals(s)) { if (e.getOldValue() == null && e.getNewValue() != null) { // Ancestor was added, set initial focus fileNameTextField.selectAll(); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java index 2e552847..b55d01d6 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePane.java @@ -24,7 +24,8 @@ package com.github.weisj.darklaf.ui.filechooser; import com.github.weisj.darklaf.components.OverlayScrollPane; -import com.github.weisj.darklaf.ui.table.TextFieldTableCellEditorBorder; +import com.github.weisj.darklaf.ui.table.DarkTableUI; +import com.github.weisj.darklaf.ui.table.TextTableCellEditorBorder; import com.github.weisj.darklaf.util.DarkUIUtil; import sun.awt.AWTAccessor; import sun.swing.SwingUtilities2; @@ -58,7 +59,7 @@ public class DarkFilePane extends DarkFilePaneUIBridge { megaByteString = UIManager.getString("FileChooser.fileSizeMegaBytes"); gigaByteString = UIManager.getString("FileChooser.fileSizeGigaBytes"); editCell = new JTextField(); - editCell.setBorder(new TextFieldTableCellEditorBorder()); + editCell.setBorder(new TextTableCellEditorBorder()); editCell.putClientProperty("JTextField.listCellEditor", true); } @@ -206,7 +207,7 @@ public class DarkFilePane extends DarkFilePaneUIBridge { detailsTable.addMouseListener(getMouseHandler()); // 4835633 : tell BasicTableUI that this is a file list - detailsTable.putClientProperty("Table.isFileList", Boolean.TRUE); + detailsTable.putClientProperty(DarkTableUI.KEY_IS_FILE_LIST, Boolean.TRUE); if (listViewWindowsStyle) { detailsTable.addFocusListener(repaintListener); @@ -435,4 +436,4 @@ public class DarkFilePane extends DarkFilePaneUIBridge { } } } -} \ No newline at end of file +} diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java index e53cdf43..998f0b48 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java @@ -26,7 +26,9 @@ package com.github.weisj.darklaf.ui.filechooser; import com.github.weisj.darklaf.ui.list.DarkListCellRenderer; import com.github.weisj.darklaf.ui.table.DarkTableCellEditor; import com.github.weisj.darklaf.ui.table.DarkTableCellRenderer; -import com.github.weisj.darklaf.ui.table.TextFieldTableCellEditorBorder; +import com.github.weisj.darklaf.ui.table.DarkTableUI; +import com.github.weisj.darklaf.ui.table.TextTableCellEditorBorder; +import com.github.weisj.darklaf.util.PropertyKey; import sun.awt.AWTAccessor; import sun.awt.shell.ShellFolder; import sun.awt.shell.ShellFolderColumnInfo; @@ -36,51 +38,21 @@ import sun.swing.SwingUtilities2; import javax.accessibility.AccessibleContext; import javax.swing.*; import javax.swing.border.Border; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; -import javax.swing.event.ListSelectionListener; -import javax.swing.event.RowSorterEvent; -import javax.swing.event.RowSorterListener; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; +import javax.swing.event.*; import javax.swing.filechooser.FileSystemView; import javax.swing.plaf.basic.BasicDirectoryModel; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.DefaultTableColumnModel; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumn; -import javax.swing.table.TableColumnModel; -import javax.swing.table.TableModel; -import javax.swing.table.TableRowSorter; +import javax.swing.table.*; import javax.swing.text.Position; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; +import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; import java.io.FileNotFoundException; import java.text.DateFormat; import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.Date; import java.util.List; -import java.util.Locale; -import java.util.Objects; +import java.util.*; import java.util.concurrent.Callable; /** @@ -471,7 +443,7 @@ public class DarkFilePaneUIBridge extends JPanel implements PropertyChangeListen revalidate(); repaint(); updateViewMenu(); - firePropertyChange("viewType", oldValue, viewType); + firePropertyChange(DarkFileChooserUI.KEY_VIEW_TYPE, oldValue, viewType); } public Action getViewTypeAction(final int viewType) { @@ -741,7 +713,7 @@ public class DarkFilePaneUIBridge extends JPanel implements PropertyChangeListen if (tableCellEditor == null) { tableCellEditor = new DetailsTableCellEditor(new JTextField() { { - super.setBorder(new TextFieldTableCellEditorBorder()); + super.setBorder(new TextTableCellEditorBorder()); } @Override @@ -805,7 +777,7 @@ public class DarkFilePaneUIBridge extends JPanel implements PropertyChangeListen // to our JList. // 4835633 : tell BasicTableUI that this is a file list - detailsTable.putClientProperty("Table.isFileList", Boolean.TRUE); + detailsTable.putClientProperty(DarkTableUI.KEY_IS_FILE_LIST, Boolean.TRUE); if (listViewWindowsStyle) { detailsTable.addFocusListener(repaintListener); @@ -1218,7 +1190,7 @@ public class DarkFilePaneUIBridge extends JPanel implements PropertyChangeListen applyEdit(); } else if (s.equals("busy")) { setCursor((Boolean) e.getNewValue() ? waitCursor : null); - } else if (s.equals("componentOrientation")) { + } else if (s.equals(PropertyKey.COMPONENT_ORIENTATION)) { ComponentOrientation o = (ComponentOrientation) e.getNewValue(); JFileChooser cc = (JFileChooser) e.getSource(); if (o != e.getOldValue()) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameUI.java index 70e5175a..eacf6cfe 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameUI.java @@ -23,6 +23,8 @@ */ package com.github.weisj.darklaf.ui.internalframe; +import com.github.weisj.darklaf.util.PropertyKey; + import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicInternalFrameUI; @@ -45,7 +47,7 @@ public class DarkInternalFrameUI extends BasicInternalFrameUI { @Override protected void installDefaults() { super.installDefaults(); - LookAndFeel.installProperty(frame, "opaque", false); + LookAndFeel.installProperty(frame, PropertyKey.OPAQUE, false); } @Override diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java index 95a93315..3795e15c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java @@ -26,6 +26,7 @@ package com.github.weisj.darklaf.ui.label; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; +import com.github.weisj.darklaf.util.PropertyKey; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -151,7 +152,7 @@ public class DarkLabelUI extends BasicLabelUI implements PropertyChangeListener public void propertyChange(final PropertyChangeEvent e) { super.propertyChange(e); String key = e.getPropertyName(); - if ("componentOrientation".equals(key)) { + if (PropertyKey.COMPONENT_ORIENTATION.equals(key)) { Object source = e.getSource(); if (source instanceof JLabel) { ((JLabel) source).doLayout(); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java b/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java index 0bd726c1..212f76aa 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java @@ -43,7 +43,7 @@ public class DarkListCellRenderer extends DefaultListCellRenderer { } } Component comp = null; - boolean isEditing = Boolean.TRUE.equals(list.getClientProperty("JList.isEditing")); + boolean isEditing = Boolean.TRUE.equals(list.getClientProperty(DarkListUI.KEY_IS_EDITING)); if (isEditing) { if (list.getSelectionModel().getLeadSelectionIndex() == index) { comp = super.getListCellRendererComponent(list, value, index, false, false); @@ -52,7 +52,7 @@ public class DarkListCellRenderer extends DefaultListCellRenderer { if (comp == null) { comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } - boolean alternativeRow = Boolean.TRUE.equals(list.getClientProperty("JList.alternateRowColor")); + boolean alternativeRow = Boolean.TRUE.equals(list.getClientProperty(DarkListUI.KEY_ALTERNATE_ROW_COLOR)); int layout = list.getLayoutOrientation(); if (layout == JList.VERTICAL) { alternativeRow = alternativeRow && index % 2 == 1; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java index d75da2f5..86075c3e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java @@ -36,6 +36,16 @@ import java.beans.PropertyChangeEvent; */ public class DarkListUI extends DarkListUIBridge { + public static final String KEY_PREFIX = "JList."; + 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_BOOLEAN_RENDER_TYPE = KEY_PREFIX + "booleanRenderType"; + public static final String KEY_SHRINK_WRAP = KEY_PREFIX + "shrinkWrap"; + public static final String KEY_FULL_ROW_SELECTION = KEY_PREFIX + "fullRowSelection"; + public static final String KEY_IS_EDITING = KEY_PREFIX + "isEditing"; + public static final String RENDER_TYPE_CHECKBOX = "checkBox"; + public static final String RENDER_TYPE_RADIOBUTTON = "radioButton"; + static { UIManager.put("List.cellRenderer", new DarkListCellRenderer()); } @@ -48,7 +58,7 @@ public class DarkListUI extends DarkListUIBridge { @Override protected void installDefaults() { super.installDefaults(); - list.putClientProperty("JList.alternateRowColor", UIManager.getBoolean("List.alternateRowColor")); + list.putClientProperty(KEY_ALTERNATE_ROW_COLOR, UIManager.getBoolean("List.alternateRowColor")); } @Override @@ -153,7 +163,7 @@ public class DarkListUI extends DarkListUIBridge { int ch = rowBounds.height; if (empty) { - boolean alternativeRow = Boolean.TRUE.equals(list.getClientProperty("JList.alternateRowColor")); + boolean alternativeRow = Boolean.TRUE.equals(list.getClientProperty(KEY_ALTERNATE_ROW_COLOR)); Color alternativeRowColor = UIManager.getColor("List.alternateRowBackground"); Color normalColor = list.getBackground(); Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor; @@ -165,7 +175,7 @@ public class DarkListUI extends DarkListUIBridge { Component rendererComponent = cellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (Boolean.TRUE.equals(list.getClientProperty("JList.shrinkWrap"))) { + if (Boolean.TRUE.equals(list.getClientProperty(KEY_SHRINK_WRAP))) { // Shrink renderer to preferred size. This is mostly used on Windows // where selection is only shown around the file name, instead of // across the whole list cell. @@ -186,7 +196,7 @@ public class DarkListUI extends DarkListUIBridge { public void propertyChange(final PropertyChangeEvent e) { super.propertyChange(e); String key = e.getPropertyName(); - if ("JList.alternateRowColor".equals(key)) { + if (KEY_ALTERNATE_ROW_COLOR.equals(key)) { list.repaint(); } } @@ -197,9 +207,9 @@ public class DarkListUI extends DarkListUIBridge { if (row < 0) { // If shift is down in multi-select, we should do nothing. // For single select or non-shift-click, clear the selection - if (isFileList && !Boolean.TRUE.equals(list.getClientProperty("JList.fullRowSelection")) - && e.getID() == MouseEvent.MOUSE_PRESSED && - (!e.isShiftDown() || list.getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)) { + if (isFileList && !Boolean.TRUE.equals(list.getClientProperty(KEY_FULL_ROW_SELECTION)) + && e.getID() == MouseEvent.MOUSE_PRESSED && + (!e.isShiftDown() || list.getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)) { list.clearSelection(); } } else { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java index e694e6c4..a74cbd44 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java @@ -28,28 +28,20 @@ import com.github.weisj.darklaf.ui.DragRecognitionSupport; import com.github.weisj.darklaf.util.DarkSwingUtil; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.LazyActionMap; +import com.github.weisj.darklaf.util.PropertyKey; import sun.swing.DefaultLookup; import sun.swing.SwingUtilities2; import sun.swing.UIAction; import javax.swing.*; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.event.MouseInputListener; +import javax.swing.event.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicListUI; import javax.swing.text.Position; import java.awt.*; import java.awt.datatransfer.Transferable; -import java.awt.event.ActionEvent; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; +import java.awt.event.*; import java.awt.geom.Point2D; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -656,7 +648,7 @@ public class DarkListUIBridge extends BasicListUI { LookAndFeel.installColorsAndFont(list, "List.background", "List.foreground", "List.font"); - LookAndFeel.installProperty(list, "opaque", Boolean.TRUE); + LookAndFeel.installProperty(list, PropertyKey.OPAQUE, Boolean.TRUE); if (list.getCellRenderer() == null) { @SuppressWarnings("unchecked") @@ -2694,8 +2686,8 @@ public class DarkListUIBridge extends BasicListUI { } else if (Objects.equals(propertyName, "cellRenderer")) { updateLayoutStateNeeded |= cellRendererChanged; redrawList(); - } else if (Objects.equals(propertyName, "font") - || DarkSwingUtil.isScaleChanged(e)) { + } else if (Objects.equals(propertyName, PropertyKey.FONT) + || DarkSwingUtil.isScaleChanged(e)) { updateLayoutStateNeeded |= fontChanged; redrawList(); } else if (Objects.equals(propertyName, "prototypeCellValue")) { @@ -2711,7 +2703,7 @@ public class DarkListUIBridge extends BasicListUI { list.repaint(); } else if (Objects.equals(propertyName, "selectionBackground")) { list.repaint(); - } else if ("layoutOrientation".equals(propertyName)) { + } else if (PropertyKey.LAYOUT_ORIENTATION.equals(propertyName)) { updateLayoutStateNeeded |= layoutOrientationChanged; layoutOrientation = list.getLayoutOrientation(); redrawList(); @@ -2720,7 +2712,7 @@ public class DarkListUIBridge extends BasicListUI { updateLayoutStateNeeded |= layoutOrientationChanged; redrawList(); } - } else if ("componentOrientation".equals(propertyName)) { + } else if (PropertyKey.COMPONENT_ORIENTATION.equals(propertyName)) { isLeftToRight = list.getComponentOrientation().isLeftToRight(); updateLayoutStateNeeded |= componentOrientationChanged; redrawList(); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java index d413e47e..43d40f35 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java @@ -30,17 +30,13 @@ import com.github.weisj.darklaf.components.text.NumberingPane; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.plaf.ComponentUI; -import javax.swing.text.BadLocationException; -import javax.swing.text.Caret; -import javax.swing.text.Document; -import javax.swing.text.Element; -import javax.swing.text.JTextComponent; -import javax.swing.text.Position; +import javax.swing.text.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -86,7 +82,7 @@ public class DarkNumberingPaneUI extends ComponentUI { "NumberingPane.font"); foregroundHighlight = UIManager.getColor("NumberingPane.currentLineForeground"); backgroundHighlight = UIManager.getColor("NumberingPane.currentLineBackground"); - LookAndFeel.installProperty(c, "opaque", true); + LookAndFeel.installProperty(c, PropertyKey.OPAQUE, true); LookAndFeel.installBorder(c, "NumberingPane.border"); } @@ -322,7 +318,7 @@ public class DarkNumberingPaneUI extends ComponentUI { @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if ("caret".equals(key)) { + if (PropertyKey.CARET.equals(key)) { if (evt.getNewValue() instanceof Caret) { Object oldCaret = evt.getOldValue(); if (oldCaret instanceof Caret) { @@ -335,10 +331,10 @@ public class DarkNumberingPaneUI extends ComponentUI { ((Caret) newCaret).addChangeListener(currentLinePainter); } } - } else if ("font".equals(key)) { + } else if (PropertyKey.FONT.equals(key)) { Font font = textComponent.getFont(); numberingPane.setFont(font.deriveFont(Math.max(font.getSize() - 1, 1.0f))); - } else if ("editorPane".equals(key)) { + } else if (NumberingPane.KEY_EDITOR.equals(key)) { Object newPane = evt.getNewValue(); if (textComponent != null) { currentLinePainter.setComponent(null); @@ -354,7 +350,8 @@ public class DarkNumberingPaneUI extends ComponentUI { currentHighlight = textComponent.getHighlighter().addHighlight(0, 0, currentLinePainter); textComponent.getCaret().addChangeListener(currentLinePainter); currentLinePainter.setComponent(textComponent); - } catch (BadLocationException ignored) {} + } catch (BadLocationException ignored) { + } textComponent.addPropertyChangeListener(getPropertyChangeListener()); textComponent.getCaret().addChangeListener(getChangeListener()); Font font = textComponent.getFont(); @@ -362,7 +359,7 @@ public class DarkNumberingPaneUI extends ComponentUI { oldBackground = textComponent.getBackground(); textComponent.setBackground(UIManager.getColor("NumberingPane.textBackground")); } - } else if ("icons".equals(key)) { + } else if (NumberingPane.KEY_ICONS.equals(key)) { Object oldVal = evt.getOldValue(); Object newVal = evt.getNewValue(); if (oldVal instanceof Icon) { @@ -371,7 +368,7 @@ public class DarkNumberingPaneUI extends ComponentUI { if (newVal instanceof Icon) { maxIconWidth = Math.max(maxIconWidth, ((Icon) newVal).getIconWidth()); } - } else if ("ancestor".equals(key)) { + } else if (PropertyKey.ANCESTOR.equals(key)) { if (evt.getSource() == numberingPane) { JScrollPane parent = DarkUIUtil.getParentOfType(JScrollPane.class, (Component) evt.getNewValue()); if (parent != null) { @@ -380,7 +377,7 @@ public class DarkNumberingPaneUI extends ComponentUI { viewport = null; } } - } else if ("minimumIconWidth".equals(key)) { + } else if (NumberingPane.KEY_MIN_ICON_WIDTH.equals(key)) { maxIconWidth = calculateMaxIconWidth(); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java index dac9f59d..85374ae5 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java @@ -51,10 +51,12 @@ import java.util.List; */ public class DarkPopupMenuUI extends BasicPopupMenuUI { - public static final StringBufferWrapper HIDE_POPUP_KEY = new StringBufferWrapper(new StringBuffer( - "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 StringBufferWrapper HIDE_POPUP_VALUE = new StringBufferWrapper(new StringBuffer( + "doNotCancelPopup")); public static final StringBuilder MOUSE_GRABBER_KEY = new StringBuilder( - "javax.swing.plaf.basic.BasicPopupMenuUI.MouseGrabber"); + "javax.swing.plaf.basic.BasicPopupMenuUI.MouseGrabber"); public static ComponentUI createUI(final JComponent x) { @@ -230,11 +232,11 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI { */ case MouseEvent.MOUSE_PRESSED: if (isInPopup(src) || - (src instanceof JMenu && ((JMenu) src).isSelected())) { + (src instanceof JMenu && ((JMenu) src).isSelected())) { return; } if (!(src instanceof JComponent) || - !HIDE_POPUP_KEY.equals(((JComponent) src).getClientProperty("doNotCancelPopup"))) { + !HIDE_POPUP_VALUE.equals(((JComponent) src).getClientProperty(KEY_DO_NOT_CANCEL_POPUP))) { // Cancel popup only if this property was not set. // If this property is set to TRUE component wants // to deal with this event by himself. @@ -311,7 +313,7 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI { } else if (c instanceof JPopupMenu) { return true; } else if (c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("doNotCancelOnScroll"))) { + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_DO_NOT_CANCEL_ON_SCROLL))) { /* * Change here: allows scrollable components that contain the popupMenu. */ diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarUI.java index 381c5344..4e2551db 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarUI.java @@ -26,6 +26,7 @@ package com.github.weisj.darklaf.ui.progressbar; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -43,11 +44,14 @@ import java.beans.PropertyChangeListener; */ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyChangeListener { + public static final String KEY_PREFIX = "JProgressBar."; + public static final String KEY_FAILED = KEY_PREFIX + "failed"; + public static final String KEY_PASSED = KEY_PREFIX + "passed"; + private static final int CYCLE_TIME_DEFAULT = 800; private static final int REPAINT_INTERVAL_DEFAULT = 50; private static final int CYCLE_TIME_SIMPLIFIED = 1000; private static final int REPAINT_INTERVAL_SIMPLIFIED = 500; - private static final int DEFAULT_WIDTH = 4; private Color trackColor; private Color progressColor; private Color indeterminateStartColor; @@ -56,26 +60,15 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha private Color failedEndColor; private Color passedColor; private Color passedEndColor; + private int stripeWidth; public static ComponentUI createUI(final JComponent c) { return new DarkProgressBarUI(); } - @Override - protected void installDefaults() { - super.installDefaults(); - UIManager.put("ProgressBar.repaintInterval", isSimplified() ? REPAINT_INTERVAL_SIMPLIFIED : REPAINT_INTERVAL_DEFAULT); - UIManager.put("ProgressBar.cycleTime", isSimplified() ? CYCLE_TIME_SIMPLIFIED : CYCLE_TIME_DEFAULT); - trackColor = UIManager.getColor("ProgressBar.trackColor"); - progressColor = UIManager.getColor("ProgressBar.progressColor"); - indeterminateStartColor = UIManager.getColor("ProgressBar.indeterminateStartColor"); - indeterminateEndColor = UIManager.getColor("ProgressBar.indeterminateEndColor"); - - failedColor = UIManager.getColor("ProgressBar.failedColor"); - failedEndColor = UIManager.getColor("ProgressBar.failedEndColor"); - passedColor = UIManager.getColor("ProgressBar.passedColor"); - passedEndColor = UIManager.getColor("ProgressBar.passedEndColor"); + protected static boolean hasFailed(final JComponent c) { + return Boolean.TRUE.equals(c.getClientProperty(KEY_FAILED)); } @Override @@ -180,12 +173,24 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha } } - protected static boolean hasFailed(final JComponent c) { - return Boolean.TRUE.equals(c.getClientProperty("JProgressBar.failed")); + protected static boolean hasPassed(final JComponent c) { + return Boolean.TRUE.equals(c.getClientProperty(KEY_PASSED)); } - protected static boolean hasPassed(final JComponent c) { - return Boolean.TRUE.equals(c.getClientProperty("JProgressBar.passed")); + @Override + protected void installDefaults() { + super.installDefaults(); + UIManager.put("ProgressBar.repaintInterval", isSimplified() ? REPAINT_INTERVAL_SIMPLIFIED : REPAINT_INTERVAL_DEFAULT); + UIManager.put("ProgressBar.cycleTime", isSimplified() ? CYCLE_TIME_SIMPLIFIED : CYCLE_TIME_DEFAULT); + trackColor = UIManager.getColor("ProgressBar.trackColor"); + progressColor = UIManager.getColor("ProgressBar.progressColor"); + indeterminateStartColor = UIManager.getColor("ProgressBar.indeterminateStartColor"); + indeterminateEndColor = UIManager.getColor("ProgressBar.indeterminateEndColor"); + stripeWidth = UIManager.getInt("ProgressBar.stripeWidth"); + failedColor = UIManager.getColor("ProgressBar.failedColor"); + failedEndColor = UIManager.getColor("ProgressBar.failedEndColor"); + passedColor = UIManager.getColor("ProgressBar.passedColor"); + passedEndColor = UIManager.getColor("ProgressBar.passedEndColor"); } protected Color getStartColor() { @@ -321,16 +326,7 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha } private int getStripeWidth() { - Object ho = progressBar.getClientProperty("ProgressBar.stripeWidth"); - if (ho != null) { - try { - return Integer.parseInt(ho.toString()); - } catch (NumberFormatException nfe) { - return DEFAULT_WIDTH; - } - } else { - return DEFAULT_WIDTH; - } + return stripeWidth; } @@ -341,11 +337,11 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if ("JProgressBar.failed".equals(key)) { + if (KEY_FAILED.equals(key)) { progressBar.repaint(); - } else if ("JProgressBar.passed".equals(key)) { + } else if (KEY_PASSED.equals(key)) { progressBar.repaint(); - } else if ("componentOrientation".equals(key)) { + } else if (PropertyKey.COMPONENT_ORIENTATION.equals(key)) { progressBar.repaint(); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonBorder.java b/core/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonBorder.java index 2e127342..13203ed7 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonBorder.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonBorder.java @@ -24,6 +24,7 @@ package com.github.weisj.darklaf.ui.radiobutton; +import com.github.weisj.darklaf.ui.button.DarkToggleButtonUI; import com.github.weisj.darklaf.util.DarkUIUtil; import javax.swing.*; @@ -64,12 +65,12 @@ public class DarkRadioButtonBorder implements Border, UIResource { protected static boolean isTreeCellEditor(final Component c) { return c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JToggleButton.isTreeCellEditor")); + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR)); } protected static boolean isTableCellEditor(final Component c) { return c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JToggleButton.isTreeCellEditor")); + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR)); } @Override diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java index d99bbb8b..47b4bd48 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java @@ -24,10 +24,12 @@ package com.github.weisj.darklaf.ui.radiobutton; import com.github.weisj.darklaf.icons.EmptyIcon; +import com.github.weisj.darklaf.ui.button.DarkToggleButtonUI; import com.github.weisj.darklaf.ui.checkbox.DarkCheckBoxUI; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; +import com.github.weisj.darklaf.util.PropertyKey; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -93,7 +95,7 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha @Override public void installDefaults(final AbstractButton b) { super.installDefaults(b); - LookAndFeel.installProperty(b, "opaque", false); + LookAndFeel.installProperty(b, PropertyKey.OPAQUE, false); radioIcon = UIManager.getIcon("RadioButton.unchecked.icon"); radioDisabledIcon = UIManager.getIcon("RadioButton.uncheckedDisabled.icon"); radioFocusedIcon = UIManager.getIcon("RadioButton.uncheckedFocused.icon"); @@ -274,9 +276,10 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if ("componentOrientation".equals(key)) { + if (PropertyKey.COMPONENT_ORIENTATION.equals(key)) { radioButton.repaint(); - } else if ("JToggleButton.isTreeCellEditor".equals(key) || "JToggleButton.isTableCellEditor".equals(key)) { + } else if (DarkToggleButtonUI.KEY_IS_TREE_EDITOR.equals(key) + || DarkToggleButtonUI.KEY_IS_TABLE_EDITOR.equals(key)) { radioButton.repaint(); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java index 38e62ec8..368eec9e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java @@ -27,6 +27,7 @@ package com.github.weisj.darklaf.ui.rootpane; import com.github.weisj.darklaf.decorations.CustomTitlePane; import com.github.weisj.darklaf.platform.Decorations; import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -79,7 +80,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener public void propertyChange(final PropertyChangeEvent e) { super.propertyChange(e); String propertyName = e.getPropertyName(); - if ("windowDecorationStyle".equals(propertyName)) { + if (PropertyKey.WINDOW_DECORATIONS_STYLE.equals(propertyName)) { if (!decorationStyleLock) { windowDecorationsStyle = rootPane.getWindowDecorationStyle(); updateClientDecoration(); @@ -93,7 +94,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener decorationStyleLock = false; } } - } else if ("ancestor".equals(propertyName)) { + } else if (PropertyKey.ANCESTOR.equals(propertyName)) { updateWindow(rootPane.getParent()); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarUI.java index f9794aa6..07645c9f 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarUI.java @@ -41,6 +41,10 @@ import java.awt.event.*; */ public class DarkScrollBarUI extends BasicScrollBarUI { + public static final String KEY_PREFIX = "JScrollBar."; + public static final String KEY_SCROLL_PANE_PARENT = KEY_PREFIX + "scrollPaneParent"; + public static final String KEY_FAST_WHEEL_SCROLLING = KEY_PREFIX + "fastWheelScrolling"; + public static final String KEY_THIN = KEY_PREFIX + "thin"; private static final float THUMB_ALPHA = 0.6f; private static final float MAX_TRACK_ALPHA = 0.3f; private static final float MAX_THUMB_ALPHA = 1; @@ -62,7 +66,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { if (scrollbar.getOrientation() == JScrollBar.VERTICAL && !e.isShiftDown() || scrollbar.getOrientation() == JScrollBar.HORIZONTAL && e.isShiftDown()) { scrollbar.setValueIsAdjusting(true); - Object sp = scrollbar.getClientProperty("JScrollBar.scrollPaneParent"); + Object sp = scrollbar.getClientProperty(KEY_SCROLL_PANE_PARENT); if (scrollbar.getParent() instanceof JScrollPane) { doScroll(scrollbar, ((JScrollPane) scrollbar.getParent()).getViewport(), e, scrollbar.getParent().getComponentOrientation().isLeftToRight()); @@ -177,7 +181,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { boolean limitScroll = Math.abs(e.getWheelRotation()) == 1; - Object fastWheelScroll = toScroll.getClientProperty("JScrollBar.fastWheelScrolling"); + Object fastWheelScroll = toScroll.getClientProperty(KEY_FAST_WHEEL_SCROLLING); Component comp = vp == null ? null : vp.getView(); if (Boolean.TRUE.equals(fastWheelScroll) && comp instanceof Scrollable) { Scrollable scrollComp = (Scrollable) comp; @@ -502,7 +506,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { } protected boolean isThin() { - return scrollbar.getClientProperty("ScrollBar.thin") == Boolean.TRUE; + return scrollbar.getClientProperty(KEY_THIN) == Boolean.TRUE; } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java index 92d55a6a..d764490e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java @@ -35,9 +35,11 @@ import java.beans.PropertyChangeListener; */ public class DarkScrollPaneUI extends BasicScrollPaneUI { + public static final String KEY_VERTICALS_SCROLL_BAR = "verticalScrollBar"; + public static final String KEY_HORIZONTAL_SCROLL_BAR = "horizontalScrollBar"; private final MouseWheelListener verticalMouseWheelListener = e -> { if (!scrollpane.isWheelScrollingEnabled() - || e.getModifiersEx() == 0 || !horizontalScrollBarEnabled()) { + || e.getModifiersEx() == 0 || !horizontalScrollBarEnabled()) { return; } JScrollBar scrollbar = scrollpane.getHorizontalScrollBar(); @@ -70,7 +72,7 @@ public class DarkScrollPaneUI extends BasicScrollPaneUI { private final PropertyChangeListener propertyChangeListener = e -> { if (e.getSource() == scrollpane) { String propertyName = e.getPropertyName(); - if ("verticalScrollBar".equals(propertyName)) { + if (KEY_VERTICALS_SCROLL_BAR.equals(propertyName)) { Object old = e.getOldValue(); Object newVal = e.getNewValue(); if (old instanceof JScrollBar) { @@ -79,7 +81,7 @@ public class DarkScrollPaneUI extends BasicScrollPaneUI { if (newVal instanceof JScrollBar) { ((JScrollBar) newVal).addMouseWheelListener(verticalMouseWheelListener); } - } else if ("horizontalScrollBar".equals(propertyName)) { + } else if (KEY_HORIZONTAL_SCROLL_BAR.equals(propertyName)) { Object old = e.getOldValue(); Object newVal = e.getNewValue(); if (old instanceof JScrollBar) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java index 55902609..1a220535 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java @@ -27,6 +27,7 @@ import com.github.weisj.darklaf.decorators.MouseClickListener; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -34,11 +35,7 @@ import javax.swing.plaf.basic.BasicSliderUI; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.awt.geom.Area; -import java.awt.geom.Ellipse2D; -import java.awt.geom.Path2D; -import java.awt.geom.Rectangle2D; -import java.awt.geom.RoundRectangle2D; +import java.awt.geom.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -47,6 +44,14 @@ import java.beans.PropertyChangeListener; */ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListener { + public static final String KEY_PREFIX = "JSlider."; + public static final String KEY_THUMB_ARROW_SHAPE = KEY_PREFIX + "paintThumbArrowShape"; + public static final String KEY_SHOW_VOLUME_ICON = KEY_PREFIX + "volume.showIcon"; + public static final String KEY_VARIANT = KEY_PREFIX + "variant"; + public static final String KEY_INSTANT_SCROLL = KEY_PREFIX + "instantScrollEnabled"; + public static final String KEY_SHOW_FOCUS_GLOW = KEY_PREFIX + "paintFocusGlow"; + public static final String VARIANT_VOLUME = "volume"; + private static final int ICON_BAR_EXT = 5; private static final int ICON_PAD = 10; private final Rectangle iconRect = new Rectangle(0, 0, 0, 0); @@ -105,43 +110,13 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene return new DarkSliderUI((JSlider) c); } - @Override - public void installUI(final JComponent c) { - super.installUI(c); - slider.putClientProperty("Slider.paintFocusGlow", UIManager.getBoolean("Slider.paintFocusGlow")); + private static boolean showVolumeIcon(final JComponent c) { + return isVolumeSlider(c) + && Boolean.TRUE.equals(c.getClientProperty(KEY_SHOW_VOLUME_ICON)); } - @Override - protected void installDefaults(final JSlider slider) { - super.installDefaults(slider); - LookAndFeel.installProperty(slider, "opaque", false); - arcSize = UIManager.getInt("Slider.arc"); - trackSize = UIManager.getInt("Slider.trackThickness"); - plainThumbRadius = UIManager.getInt("Slider.plainThumbRadius"); - thumbSize = UIManager.getDimension("Slider.thumbSize"); - inactiveTickForeground = UIManager.getColor("Slider.disabledTickColor"); - trackBackground = UIManager.getColor("Slider.trackBackground"); - selectedTrackBackground = UIManager.getColor("Slider.selectedTrackColor"); - selectedTrackInactiveBackground = UIManager.getColor("Slider.disabledTrackColor"); - selectedVolumeTrackBackground = UIManager.getColor("Slider.volume.selectedTrackColor"); - selectedVolumeTrackInactiveBackground = UIManager.getColor("Slider.volume.disabledTrackColor"); - thumbBackground = UIManager.getColor("Slider.activeThumbFill"); - thumbInactiveBackground = UIManager.getColor("Slider.inactiveThumbFill"); - volumeThumbBackground = UIManager.getColor("Slider.volume.activeThumbFill"); - volumeThumbInactiveBackground = UIManager.getColor("Slider.volume.inactiveThumbFill"); - thumbBorderColor = UIManager.getColor("Slider.thumbBorderColor"); - thumbInactiveBorderColor = UIManager.getColor("Slider.thumbBorderColorDisabled"); - - volume0 = UIManager.getIcon("Slider.volume.enabled_level_0.icon"); - volume1 = UIManager.getIcon("Slider.volume.enabled_level_1.icon"); - volume2 = UIManager.getIcon("Slider.volume.enabled_level_2.icon"); - volume3 = UIManager.getIcon("Slider.volume.enabled_level_3.icon"); - volume4 = UIManager.getIcon("Slider.volume.enabled_level_4.icon"); - volume0Inactive = UIManager.getIcon("Slider.volume.disabled_level_0.icon"); - volume1Inactive = UIManager.getIcon("Slider.volume.disabled_level_1.icon"); - volume2Inactive = UIManager.getIcon("Slider.volume.disabled_level_2.icon"); - volume3Inactive = UIManager.getIcon("Slider.volume.disabled_level_3.icon"); - volume4Inactive = UIManager.getIcon("Slider.volume.disabled_level_4.icon"); + private static boolean isVolumeSlider(final JComponent c) { + return VARIANT_VOLUME.equals(c.getClientProperty(KEY_VARIANT)); } @Override @@ -328,15 +303,43 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene return inactiveTickForeground; } - protected boolean isPlainThumb() { - Boolean paintThumbArrowShape = (Boolean) slider.getClientProperty("Slider.paintThumbArrowShape"); - return (!slider.getPaintTicks() && paintThumbArrowShape == null) || - paintThumbArrowShape == Boolean.FALSE; + @Override + public void installUI(final JComponent c) { + super.installUI(c); + slider.putClientProperty(KEY_SHOW_FOCUS_GLOW, UIManager.getBoolean("Slider.paintFocusGlow")); } - private static boolean showVolumeIcon(final JComponent c) { - return isVolumeSlider(c) - && Boolean.TRUE.equals(c.getClientProperty("Slider.volume.showIcon")); + @Override + protected void installDefaults(final JSlider slider) { + super.installDefaults(slider); + LookAndFeel.installProperty(slider, PropertyKey.OPAQUE, false); + arcSize = UIManager.getInt("Slider.arc"); + trackSize = UIManager.getInt("Slider.trackThickness"); + plainThumbRadius = UIManager.getInt("Slider.plainThumbRadius"); + thumbSize = UIManager.getDimension("Slider.thumbSize"); + inactiveTickForeground = UIManager.getColor("Slider.disabledTickColor"); + trackBackground = UIManager.getColor("Slider.trackBackground"); + selectedTrackBackground = UIManager.getColor("Slider.selectedTrackColor"); + selectedTrackInactiveBackground = UIManager.getColor("Slider.disabledTrackColor"); + selectedVolumeTrackBackground = UIManager.getColor("Slider.volume.selectedTrackColor"); + selectedVolumeTrackInactiveBackground = UIManager.getColor("Slider.volume.disabledTrackColor"); + thumbBackground = UIManager.getColor("Slider.activeThumbFill"); + thumbInactiveBackground = UIManager.getColor("Slider.inactiveThumbFill"); + volumeThumbBackground = UIManager.getColor("Slider.volume.activeThumbFill"); + volumeThumbInactiveBackground = UIManager.getColor("Slider.volume.inactiveThumbFill"); + thumbBorderColor = UIManager.getColor("Slider.thumbBorderColor"); + thumbInactiveBorderColor = UIManager.getColor("Slider.thumbBorderColorDisabled"); + + volume0 = UIManager.getIcon("Slider.volume.enabled_level_0.icon"); + volume1 = UIManager.getIcon("Slider.volume.enabled_level_1.icon"); + volume2 = UIManager.getIcon("Slider.volume.enabled_level_2.icon"); + volume3 = UIManager.getIcon("Slider.volume.enabled_level_3.icon"); + volume4 = UIManager.getIcon("Slider.volume.enabled_level_4.icon"); + volume0Inactive = UIManager.getIcon("Slider.volume.disabled_level_0.icon"); + volume1Inactive = UIManager.getIcon("Slider.volume.disabled_level_1.icon"); + volume2Inactive = UIManager.getIcon("Slider.volume.disabled_level_2.icon"); + volume3Inactive = UIManager.getIcon("Slider.volume.disabled_level_3.icon"); + volume4Inactive = UIManager.getIcon("Slider.volume.disabled_level_4.icon"); } protected void calculateIconRect() { @@ -468,8 +471,10 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene g.translate(-x, -y); } - private static boolean isVolumeSlider(final JComponent c) { - return "volume".equals(c.getClientProperty("Slider.variant")); + protected boolean isPlainThumb() { + Boolean paintThumbArrowShape = (Boolean) slider.getClientProperty(KEY_THUMB_ARROW_SHAPE); + return (!slider.getPaintTicks() && paintThumbArrowShape == null) || + paintThumbArrowShape == Boolean.FALSE; } private void paintSliderThumb(final Graphics2D g) { @@ -489,7 +494,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene } private boolean paintFocus() { - return slider.hasFocus() && Boolean.TRUE.equals(slider.getClientProperty("Slider.paintFocusGlow")); + return slider.hasFocus() && Boolean.TRUE.equals(slider.getClientProperty(KEY_SHOW_FOCUS_GLOW)); } private Path2D getThumbShape() { @@ -576,15 +581,15 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene } private boolean instantScrollEnabled(final JComponent c) { - return Boolean.TRUE.equals(c.getClientProperty("Slider.instantScrollEnabled")); + return Boolean.TRUE.equals(c.getClientProperty(KEY_INSTANT_SCROLL)); } @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if ("Slider.variant".equals(key)) { + if (KEY_VARIANT.equals(key)) { slider.repaint(); - } else if ("Slider.volume.showIcon".equals(key)) { + } else if (DarkSliderUI.KEY_SHOW_VOLUME_ICON.equals(key)) { calculateGeometry(); slider.repaint(); } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java index f19f3203..2c29e913 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java @@ -26,6 +26,7 @@ package com.github.weisj.darklaf.ui.spinner; import com.github.weisj.darklaf.components.ArrowButton; import com.github.weisj.darklaf.decorators.LayoutManagerDelegate; import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.border.Border; @@ -47,6 +48,14 @@ import java.beans.PropertyChangeListener; */ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener { + public static final String KEY_PREFIX = "JSpinner."; + public static final String KEY_VARIANT = KEY_PREFIX + "variant"; + public static final String KEY_IS_TREE_EDITOR = KEY_PREFIX + "isTreeCellEditor"; + public static final String KEY_IS_TREE_RENDER = KEY_PREFIX + "isTreeCellRenderer"; + public static final String KEY_IS_TABLE_EDITOR = KEY_PREFIX + "isTableCellEditor"; + public static final String KEY_IS_TABLE_RENDERER = KEY_PREFIX + "isTableCellRenderer"; + public static final String KEY_EDITOR_ALIGNMENT = KEY_PREFIX + "cellEditorAlignment"; + public static final String VARIANT_PLUS_MINUS = "plusMinus"; private final FocusListener focusListener = new FocusAdapter() { @Override public void focusGained(final FocusEvent e) { @@ -80,7 +89,6 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe protected Icon plusInactiveIcon; protected Icon minusInactiveIcon; private JComponent editor; - private Color compColor; private JButton prevButton; private Component editorComponent; @@ -90,7 +98,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe } protected static boolean usePlusMinusIcons(final JSpinner spinner) { - return "plusMinus".equals(spinner.getClientProperty("JSpinner.variant")); + return VARIANT_PLUS_MINUS.equals(spinner.getClientProperty(KEY_VARIANT)); } @Override @@ -107,26 +115,9 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe spinner.removePropertyChangeListener(this); } - @Override - protected void installDefaults() { - super.installDefaults(); - arc = UIManager.getInt("Spinner.arc"); - borderSize = UIManager.getInt("Spinner.borderThickness"); - background = UIManager.getColor("Spinner.activeBackground"); - inactiveBackground = UIManager.getColor("Spinner.inactiveBackground"); - arrowBackgroundStart = UIManager.getColor("Spinner.arrowBackgroundStart"); - arrowBackgroundEnd = UIManager.getColor("Spinner.arrowBackgroundEnd"); - - arrowDownIcon = UIManager.getIcon("Spinner.arrowDown.icon"); - arrowUpIcon = UIManager.getIcon("Spinner.arrowUp.icon"); - minusIcon = UIManager.getIcon("Spinner.minus.icon"); - plusIcon = UIManager.getIcon("Spinner.plus.icon"); - - arrowDownInactiveIcon = UIManager.getIcon("Spinner.arrowDownInactive.icon"); - arrowUpInactiveIcon = UIManager.getIcon("Spinner.arrowUpInactive.icon"); - minusInactiveIcon = UIManager.getIcon("Spinner.minusInactive.icon"); - plusInactiveIcon = UIManager.getIcon("Spinner.plusInactive.icon"); - LookAndFeel.installProperty(spinner, "opaque", false); + protected static boolean isTableCellEditor(final Component c) { + return c instanceof JComponent + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_IS_TABLE_EDITOR)); } protected LayoutManager createLayout() { @@ -266,14 +257,31 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe return c == null || !c.isEnabled() ? inactiveBackground : background; } - protected static boolean isTableCellEditor(final Component c) { + protected static boolean isTreeCellEditor(final Component c) { return c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JSpinner.isTableCellEditor")); + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_IS_TREE_EDITOR)); } - protected static boolean isTreeCellEditor(final Component c) { - return c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JSpinner.isTreeCellEditor")); + @Override + protected void installDefaults() { + super.installDefaults(); + arc = UIManager.getInt("Spinner.arc"); + borderSize = UIManager.getInt("Spinner.borderThickness"); + background = UIManager.getColor("Spinner.activeBackground"); + inactiveBackground = UIManager.getColor("Spinner.inactiveBackground"); + arrowBackgroundStart = UIManager.getColor("Spinner.arrowBackgroundStart"); + arrowBackgroundEnd = UIManager.getColor("Spinner.arrowBackgroundEnd"); + + arrowDownIcon = UIManager.getIcon("Spinner.arrowDown.icon"); + arrowUpIcon = UIManager.getIcon("Spinner.arrowUp.icon"); + minusIcon = UIManager.getIcon("Spinner.minus.icon"); + plusIcon = UIManager.getIcon("Spinner.plus.icon"); + + arrowDownInactiveIcon = UIManager.getIcon("Spinner.arrowDownInactive.icon"); + arrowUpInactiveIcon = UIManager.getIcon("Spinner.arrowUpInactive.icon"); + minusInactiveIcon = UIManager.getIcon("Spinner.minusInactive.icon"); + plusInactiveIcon = UIManager.getIcon("Spinner.plusInactive.icon"); + LookAndFeel.installProperty(spinner, PropertyKey.OPAQUE, false); } private void paintSpinBackground(final Graphics2D g, final int width, final int height, @@ -307,13 +315,13 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if ("opaque".equals(key)) { + if (PropertyKey.OPAQUE.equals(key)) { boolean val = Boolean.TRUE.equals(evt.getNewValue()); spinner.getEditor().setOpaque(val); if (editorComponent instanceof JComponent) { ((JComponent) editorComponent).setOpaque(val); } - } else if ("JSpinner.isTableCellEditor".equals(key)) { + } else if (KEY_IS_TABLE_EDITOR.equals(key)) { if (Boolean.FALSE.equals(evt.getNewValue())) { if (editor instanceof JSpinner.DefaultEditor) { // if editor alignment isn't set in LAF, we get 0 (CENTER) here @@ -323,14 +331,14 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe } } spinner.repaint(); - } else if ("JSpinner.cellEditorAlignment".equals(key) && isTableCellEditor(spinner)) { + } else if (KEY_EDITOR_ALIGNMENT.equals(key) && isTableCellEditor(spinner)) { if (editorComponent instanceof JTextField && evt.getNewValue() instanceof Integer) { ((JTextField) editorComponent).setHorizontalAlignment((Integer) evt.getNewValue()); } spinner.repaint(); - } else if ("JSpinner.variant".equals(key)) { + } else if (KEY_VARIANT.equals(key)) { spinner.repaint(); - } else if ("JSpinner.isTreeCellEditor".equals(key)) { + } else if (KEY_IS_TREE_EDITOR.equals(key)) { spinner.repaint(); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneUI.java index bc00668f..3ee51502 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneUI.java @@ -24,6 +24,7 @@ package com.github.weisj.darklaf.ui.splitpane; import com.github.weisj.darklaf.decorators.LayoutManagerDelegate; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -38,6 +39,12 @@ import java.beans.PropertyChangeListener; */ public class DarkSplitPaneUI extends BasicSplitPaneUI implements PropertyChangeListener { + public static final String KEY_PREFIX = "JSplitPane."; + public static final String KEY_STYLE = KEY_PREFIX + "style"; + public static final String STYLE_GRIP = "grip"; + public static final String STYLE_LINE = "line"; + public static final String STYLE_INVISIBLE = "invisible"; + private static final int DIVIDER_DRAG_SIZE = 10; private static final int DIVIDER_DRAG_OFFSET = 5; private Style style; @@ -120,7 +127,7 @@ public class DarkSplitPaneUI extends BasicSplitPaneUI implements PropertyChangeL @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if ("JSplitPane.style".equals(key)) { + if (KEY_STYLE.equals(key)) { Object val = evt.getNewValue(); Style oldStyle = style; if (Style.INVISIBLE.name.equals(val)) { @@ -137,7 +144,7 @@ public class DarkSplitPaneUI extends BasicSplitPaneUI implements PropertyChangeL splitPane.doLayout(); } } - } else if ("orientation".equals(key)) { + } else if (PropertyKey.ORIENTATION.equals(key)) { splitPane.doLayout(); } } @@ -147,9 +154,9 @@ public class DarkSplitPaneUI extends BasicSplitPaneUI implements PropertyChangeL } private enum Style { - GRIP("grip"), - LINE("line"), - INVISIBLE("invisible"); + GRIP(STYLE_GRIP), + LINE(STYLE_LINE), + INVISIBLE(STYLE_INVISIBLE); final private String name; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkHandler.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkHandler.java index 07c6d18f..5d236a36 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkHandler.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkHandler.java @@ -23,6 +23,8 @@ */ package com.github.weisj.darklaf.ui.tabbedpane; +import com.github.weisj.darklaf.util.PropertyKey; + import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.plaf.UIResource; @@ -48,32 +50,32 @@ public class DarkHandler extends TabbedPaneHandler { public void propertyChange(final PropertyChangeEvent e) { super.propertyChange(e); String key = e.getPropertyName(); - if ("TabbedPane.maxPopupHeight".equals(key)) { + if (DarkTabbedPaneUI.KEY_MAX_POPUP_HEIGHT.equals(key)) { Integer newVal = (Integer) e.getNewValue(); if (newVal != null && newVal >= 0) { ui.scrollableTabSupport.scrollPopupMenu.setMaxHeight(newVal); } - } else if ("JTabbedPane.tabAreaInsets".equals(key)) { + } else if (DarkTabbedPaneUI.KEY_TAB_AREA_INSETS.equals(key)) { Object ins = e.getNewValue(); if (ins instanceof Insets) { ui.tabAreaInsets = (Insets) ins; } else if (ins == null) { ui.tabAreaInsets = new Insets(0, 0, 0, 0); } - } else if ("JTabbedPane.contentBorderInsets".equals(key)) { + } else if (DarkTabbedPaneUI.KEY_CONTENT_BORDER_INSETS.equals(key)) { Object ins = e.getNewValue(); if (ins instanceof Insets) { ui.contentBorderInsets = (Insets) ins; } else if (ins == null) { ui.contentBorderInsets = new Insets(0, 0, 0, 0); } - } else if ("tabPlacement".equals(key)) { + } else if (DarkTabbedPaneUI.KEY_TAB_PLACEMENT.equals(key)) { if (ui.scrollableTabLayoutEnabled()) { ui.currentShiftX = 0; ui.currentShiftY = 0; ui.scrollLayout.calculateTabRects(ui.tabPane.getTabPlacement(), ui.tabPane.getTabCount()); } - } else if ("JTabbedPane.showNewTabButton".equals(key)) { + } else if (DarkTabbedPaneUI.KEY_SHOW_NEW_TAB_BUTTON.equals(key)) { Object val = e.getNewValue(); if (val instanceof Boolean && ui.scrollableTabLayoutEnabled()) { boolean show = (Boolean) val; @@ -84,7 +86,7 @@ public class DarkHandler extends TabbedPaneHandler { } ui.tabPane.doLayout(); ui.tabPane.repaint(); - } else if ("JTabbedPane.leadingComponent".equals(key)) { + } else if (DarkTabbedPaneUI.KEY_LEADING_COMP.equals(key)) { ui.tabPane.remove(ui.leadingComp); Object val = e.getNewValue(); if (val instanceof Component) { @@ -94,7 +96,7 @@ public class DarkHandler extends TabbedPaneHandler { ui.leadingComp = null; } ui.tabPane.doLayout(); - } else if ("JTabbedPane.trailingComponent".equals(key)) { + } else if (DarkTabbedPaneUI.KEY_TRAILING_COMP.equals(key)) { ui.tabPane.remove(ui.trailingComp); Object val = e.getNewValue(); if (val instanceof Component) { @@ -104,13 +106,13 @@ public class DarkHandler extends TabbedPaneHandler { ui.trailingComp = null; } ui.tabPane.doLayout(); - } else if ("JTabbedPane.dndEnabled".equals(key)) { - ui.dndEnabled = Boolean.TRUE.equals(ui.tabPane.getClientProperty("JTabbedPane.dndEnabled")); + } else if (DarkTabbedPaneUI.KEY_DND.equals(key)) { + ui.dndEnabled = Boolean.TRUE.equals(ui.tabPane.getClientProperty(DarkTabbedPaneUI.KEY_DND)); ui.tabPane.getDropTarget().setActive(ui.dndEnabled); - } else if ("componentOrientation".equals(key)) { + } else if (PropertyKey.COMPONENT_ORIENTATION.equals(key)) { ui.tabPane.doLayout(); ui.tabPane.repaint(); - } else if ("JTabbedPane.northComponent".equals(key)) { + } else if (DarkTabbedPaneUI.KEY_NORTH_COMP.equals(key)) { ui.tabPane.remove(ui.northComp); Object val = e.getNewValue(); if (val instanceof Component) { @@ -120,7 +122,7 @@ public class DarkHandler extends TabbedPaneHandler { ui.northComp = null; } ui.tabPane.doLayout(); - } else if ("JTabbedPane.southComponent".equals(key)) { + } else if (DarkTabbedPaneUI.KEY_SOUTH_COMP.equals(key)) { ui.tabPane.remove(ui.southComp); Object val = e.getNewValue(); if (val instanceof Component) { @@ -130,7 +132,7 @@ public class DarkHandler extends TabbedPaneHandler { ui.southComp = null; } ui.tabPane.doLayout(); - } else if ("JTabbedPane.eastComponent".equals(key)) { + } else if (DarkTabbedPaneUI.KEY_EAST_COMP.equals(key)) { ui.tabPane.remove(ui.eastComp); Object val = e.getNewValue(); if (val instanceof Component) { @@ -140,7 +142,7 @@ public class DarkHandler extends TabbedPaneHandler { ui.eastComp = null; } ui.tabPane.doLayout(); - } else if ("JTabbedPane.westComponent".equals(key)) { + } else if (DarkTabbedPaneUI.KEY_WEST_COMP.equals(key)) { ui.tabPane.remove(ui.westComp); Object val = e.getNewValue(); if (val instanceof Component) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java index 00142f40..7676e579 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java @@ -59,9 +59,9 @@ public class DarkScrollableTabSupport extends ScrollableTabSupport implements Mo moreTabsButton.addActionListener(this); newTabButton = ui.createNewTabButton(); - newTabButton.setVisible(Boolean.TRUE.equals(ui.tabPane.getClientProperty("JTabbedPane.showNewTabButton"))); + newTabButton.setVisible(Boolean.TRUE.equals(ui.tabPane.getClientProperty(DarkTabbedPaneUI.KEY_SHOW_NEW_TAB_BUTTON))); - scrollPopupMenu = new ScrollPopupMenu(UIManager.getInt("TabbedPane.maxPopupHeight")); + scrollPopupMenu = new ScrollPopupMenu(UIManager.getInt(DarkTabbedPaneUI.KEY_MAX_POPUP_HEIGHT)); PopupMenuListener popupMenuListener = new PopupMenuAdapter() { @Override public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java index 0f2820f4..467d7280 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java @@ -37,12 +37,30 @@ import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.MouseEvent; import java.util.TooManyListenersException; +import java.util.function.Consumer; /** * @author Jannis Weis */ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { + public static final String KEY_PREFIX = "JTabbedPane."; + public static final String KEY_DND = KEY_PREFIX + "dndEnabled"; + public static final String KEY_NORTH_COMP = KEY_PREFIX + "northComponent"; + public static final String KEY_WEST_COMP = KEY_PREFIX + "westComponent"; + public static final String KEY_EAST_COMP = KEY_PREFIX + "eastComponent"; + public static final String KEY_SOUTH_COMP = KEY_PREFIX + "southComponent"; + public static final String KEY_LEADING_COMP = KEY_PREFIX + "leadingComponent"; + public static final String KEY_TRAILING_COMP = KEY_PREFIX + "trailingComponent"; + public static final String KEY_SHOW_NEW_TAB_BUTTON = KEY_PREFIX + "showNewTabButton"; + public static final String KEY_DRAW_FOCUS_BAR = KEY_PREFIX + "drawFocusBar"; + public static final String KEY_TAB_PLACEMENT = "tabPlacement"; + public static final String KEY_CONTENT_BORDER_INSETS = KEY_PREFIX + "contentBorderInsets"; + public static final String KEY_TAB_AREA_INSETS = KEY_PREFIX + "tabAreaInsets"; + public static final String KEY_MAX_POPUP_HEIGHT = KEY_PREFIX + "maxPopupHeight"; + public static final String KEY_NEW_TAB_ACTION = KEY_PREFIX + "newTabAction"; + public static final String KEY_ROTATE_TAB_RUNS = KEY_PREFIX + "rotateTabRuns"; + protected static final TabbedPaneTransferHandler TRANSFER_HANDLER = new TabbedPaneTransferHandler.UIResource(); protected final FocusListener focusListener = new FocusListener() { @Override @@ -79,6 +97,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { protected int dropSourceIndex = -1; protected boolean sourceEqualsTarget; protected boolean drawDropRect; + protected int focusSize; protected boolean dragging; protected Rectangle dragRect = new Rectangle(); @@ -115,7 +134,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { } protected Action getNewTabAction() { - Object action = tabPane.getClientProperty("JTabbedPane.newTabAction"); + Object action = tabPane.getClientProperty(KEY_NEW_TAB_ACTION); return action instanceof Action ? (Action) action : null; } @@ -234,7 +253,6 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { if (isSelected) { if (!drawFocusBar()) return; g.setColor(getAccentColor()); - int focusSize = UIManager.getInt("TabbedPane.focusBarHeight"); switch (tabPlacement) { case LEFT: g.fillRect(r.x + r.width - focusSize, r.y, focusSize, r.height); @@ -382,7 +400,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { } protected boolean shouldRotateTabRuns(final int tabPlacement) { - return Boolean.TRUE.equals(tabPane.getClientProperty("JTabbedPane.rotateTabRuns")); + return Boolean.TRUE.equals(tabPane.getClientProperty(KEY_ROTATE_TAB_RUNS)); } @Override @@ -458,7 +476,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { } protected boolean drawFocusBar() { - return !Boolean.FALSE.equals(tabPane.getClientProperty("JTabbedPane.drawFocusBar")); + return !Boolean.FALSE.equals(tabPane.getClientProperty(KEY_DRAW_FOCUS_BAR)); } protected Color getAccentColor() { @@ -698,55 +716,41 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { hoverBackground = UIManager.getColor("TabbedPane.hoverBackground"); tabAreaBackground = UIManager.getColor("TabbedPane.tabAreaBackground"); + focusSize = UIManager.getInt("TabbedPane.focusBarHeight"); moreTabsIcon = UIManager.getIcon("TabbedPane.moreTabs.icon"); newTabIcon = UIManager.getIcon("TabbedPane.newTab.icon"); - Object ins = tabPane.getClientProperty("JTabbedPane.tabAreaInsets"); + Object ins = tabPane.getClientProperty(KEY_TAB_AREA_INSETS); if (ins instanceof Insets) { tabAreaInsets = (Insets) ins; } - ins = tabPane.getClientProperty("JTabbedPane.contentBorderInsets"); + ins = tabPane.getClientProperty(KEY_CONTENT_BORDER_INSETS); if (ins instanceof Insets) { contentBorderInsets = (Insets) ins; } - Object lead = tabPane.getClientProperty("JTabbedPane.leadingComponent"); - if (lead instanceof Component) { - leadingComp = wrapClientComponent((Component) lead); - tabPane.add(leadingComp); - } - Object trail = tabPane.getClientProperty("JTabbedPane.trailingComponent"); - if (trail instanceof Component) { - trailingComp = wrapClientComponent((Component) trail); - tabPane.add(trailingComp); - } - Object north = tabPane.getClientProperty("JTabbedPane.northComponent"); - if (north instanceof Component) { - northComp = wrapClientComponent((Component) north); - tabPane.add(northComp); - } - Object south = tabPane.getClientProperty("JTabbedPane.southComponent"); - if (south instanceof Component) { - southComp = wrapClientComponent((Component) south); - tabPane.add(southComp); - } - Object west = tabPane.getClientProperty("JTabbedPane.westComponent"); - if (west instanceof Component) { - westComp = wrapClientComponent((Component) west); - tabPane.add(westComp); - } - Object east = tabPane.getClientProperty("JTabbedPane.eastComponent"); - if (east instanceof Component) { - eastComp = wrapClientComponent((Component) east); - tabPane.add(eastComp); + installComponent(KEY_LEADING_COMP, c -> leadingComp = c); + installComponent(KEY_TRAILING_COMP, c -> trailingComp = c); + installComponent(KEY_NORTH_COMP, c -> northComp = c); + installComponent(KEY_SOUTH_COMP, c -> southComp = c); + installComponent(KEY_WEST_COMP, c -> westComp = c); + installComponent(KEY_EAST_COMP, c -> eastComp = c); + dndEnabled = Boolean.TRUE.equals(tabPane.getClientProperty(KEY_DND)); + } + + protected void installComponent(final String key, final Consumer setter) { + Object comp = tabPane.getClientProperty(key); + if (comp instanceof Component) { + Component wrapped = wrapClientComponent((Component) comp); + setter.accept(wrapped); + tabPane.add(wrapped); } - dndEnabled = Boolean.TRUE.equals(tabPane.getClientProperty("JTabbedPane.dndEnabled")); } @Override public Rectangle getTabBounds(final JTabbedPane pane, final int i) { Rectangle rect = super.getTabBounds(pane, i); if (scrollableTabLayoutEnabled() && rect != null - && dropTargetIndex >= 0 && i == dropTargetIndex) { + && dropTargetIndex >= 0 && i == dropTargetIndex) { int tabPlacement = pane.getTabPlacement(); if (tabPlacement == TOP || tabPlacement == BOTTOM) { if (pane.getComponentOrientation().isLeftToRight()) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java index 46bdd3bd..4e1d6ff5 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java @@ -25,6 +25,7 @@ package com.github.weisj.darklaf.ui.tabbedpane; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.LazyActionMap; +import com.github.weisj.darklaf.util.PropertyKey; import sun.swing.DefaultLookup; import sun.swing.SwingUtilities2; import sun.swing.UIAction; @@ -659,7 +660,7 @@ public abstract class DarkTabbedPaneUIBridge extends TabbedPaneUI implements Swi View v = getTextViewForTab(tabIndex); if (v != null) { - tabPane.putClientProperty("html", v); + tabPane.putClientProperty(PropertyKey.HTML, v); } SwingUtilities.layoutCompoundLabel(tabPane, @@ -673,7 +674,7 @@ public abstract class DarkTabbedPaneUIBridge extends TabbedPaneUI implements Swi textRect, textIconGap); - tabPane.putClientProperty("html", null); + tabPane.putClientProperty(PropertyKey.HTML, null); int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected); int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected); @@ -908,7 +909,7 @@ public abstract class DarkTabbedPaneUIBridge extends TabbedPaneUI implements Swi if (opaque == null) { opaque = Boolean.FALSE; } - LookAndFeel.installProperty(tabPane, "opaque", opaque); + LookAndFeel.installProperty(tabPane, PropertyKey.OPAQUE, opaque); // Fix for 6711145 BasicTabbedPanuUI should not throw a NPE if these // keys are missing. So we are setting them to there default values here diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneHandler.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneHandler.java index 1cbc7acd..fca641ad 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneHandler.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneHandler.java @@ -24,6 +24,7 @@ package com.github.weisj.darklaf.ui.tabbedpane; import com.github.weisj.darklaf.util.DarkSwingUtil; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -32,13 +33,7 @@ import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicHTML; import javax.swing.text.View; import java.awt.*; -import java.awt.event.ContainerEvent; -import java.awt.event.ContainerListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; +import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Objects; @@ -78,11 +73,11 @@ public class TabbedPaneHandler implements ChangeListener, ContainerListener, Foc ui.tabScroller.createButtons(ui); } ui.calculatedBaseline = false; - } else if (Objects.equals(name, "opaque") && isScrollLayout) { + } else if (Objects.equals(name, PropertyKey.OPAQUE) && isScrollLayout) { boolean newVal = (Boolean) e.getNewValue(); ui.tabScroller.tabPanel.setOpaque(newVal); ui.tabScroller.viewport.setOpaque(newVal); - } else if (Objects.equals(name, "background") && isScrollLayout) { + } else if (Objects.equals(name, PropertyKey.BACKGROUND) && isScrollLayout) { Color newVal = (Color) e.getNewValue(); ui.tabScroller.tabPanel.setBackground(newVal); ui.tabScroller.viewport.setBackground(newVal); @@ -91,7 +86,7 @@ public class TabbedPaneHandler implements ChangeListener, ContainerListener, Foc ui.tabContainer.removeUnusedTabComponents(); } Component c = ui.tabPane.getTabComponentAt( - (Integer) e.getNewValue()); + (Integer) e.getNewValue()); if (c != null) { if (ui.tabContainer == null) { ui.installTabContainer(); @@ -105,7 +100,7 @@ public class TabbedPaneHandler implements ChangeListener, ContainerListener, Foc } else if (Objects.equals(name, "indexForNullComponent")) { ui.isRunsDirty = true; updateHtmlViews((Integer) e.getNewValue(), true); - } else if (Objects.equals(name, "font") || DarkSwingUtil.isScaleChanged(e)) { + } else if (Objects.equals(name, PropertyKey.FONT) || DarkSwingUtil.isScaleChanged(e)) { ui.calculatedBaseline = false; } } @@ -270,8 +265,7 @@ public class TabbedPaneHandler implements ChangeListener, ContainerListener, Foc // currently no IndexPropertyChangeEvent. Once // IndexPropertyChangeEvents have been added this code should be // modified to use it. - Integer indexObj = - (Integer) tp.getClientProperty("__index_to_remove__"); + Integer indexObj = (Integer) tp.getClientProperty("__index_to_remove__"); if (indexObj != null) { int index = indexObj; if (ui.htmlViews != null && ui.htmlViews.size() > index) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java index bdb6ef65..4e7d06f2 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java @@ -26,6 +26,7 @@ package com.github.weisj.darklaf.ui.tabframe; import com.github.weisj.darklaf.components.border.MutableLineBorder; import com.github.weisj.darklaf.components.tabframe.JTabFrame; import com.github.weisj.darklaf.components.tabframe.PanelPopup; +import com.github.weisj.darklaf.components.tabframe.TabFramePopup; import com.github.weisj.darklaf.components.tooltip.ToolTipContext; import com.github.weisj.darklaf.components.uiresource.JLabelUIResource; import com.github.weisj.darklaf.ui.panel.DarkPanelUI; @@ -229,29 +230,29 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if ("open".equals(key)) { + if (TabFramePopup.KEY_OPEN.equals(key)) { if (Boolean.TRUE.equals(evt.getNewValue())) { setHeaderBackground(true); } - } else if ("content".equals(key)) { + } else if (TabFramePopup.KEY_CONTENT.equals(key)) { if (content == null) return; content.add((Component) evt.getNewValue(), BorderLayout.CENTER); content.invalidate(); - } else if ("title".equals(key)) { + } else if (TabFramePopup.KEY_TITLE.equals(key)) { if (label == null) return; label.setText(evt.getNewValue().toString()); label.repaint(); - } else if ("icon".equals(key)) { + } else if (TabFramePopup.KEY_ICON.equals(key)) { if (label == null) return; label.setIcon((Icon) evt.getNewValue()); label.repaint(); - } else if ("visibleTab".equals(key)) { + } else if (TabFramePopup.KEY_VISIBLE_TAB.equals(key)) { if (evt.getNewValue() instanceof JTabFrame.TabFramePosition) { if (((JTabFrame.TabFramePosition) evt.getNewValue()).getAlignment() == popupComponent.getAlignment()) { updateBorder(true); } } - } else if ("tabFrame".equals(key)) { + } else if (TabFramePopup.KEY_TAB_FRAME_PARENT.equals(key)) { Object oldVal = evt.getOldValue(); Object newVal = evt.getNewValue(); if (oldVal instanceof JTabFrame) { @@ -260,10 +261,10 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe if (newVal instanceof JTabFrame) { ((JTabFrame) newVal).addPropertyChangeListener(this); } - } else if ("peerInsets".equals(key)) { + } else if (TabFramePopup.KEY_PEER_INSETS.equals(key)) { updateBorder(false); updateTooltip(); - } else if ("alignment".equals(key)) { + } else if (TabFramePopup.KEY_ALIGNMENT.equals(key)) { updateTooltip(); } } @@ -281,7 +282,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe if (notifyPeer) { try { Component peer = tabFrame.getPopupComponentAt(tabFrame.getPeer(popupComponent.getAlignment())); - peer.firePropertyChange("peerInsets", 0, 1); + peer.firePropertyChange(TabFramePopup.KEY_PEER_INSETS, 0, 1); } catch (IndexOutOfBoundsException ignored) {/*may happen during transfer*/} } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameComponentPopupMenu.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameComponentPopupMenu.java index df8ccec2..857095db 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameComponentPopupMenu.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameComponentPopupMenu.java @@ -27,6 +27,7 @@ import com.github.weisj.darklaf.components.JXPopupMenu; import com.github.weisj.darklaf.components.tabframe.TabFrameTab; import com.github.weisj.darklaf.icons.EmptyIcon; import com.github.weisj.darklaf.util.Alignment; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.plaf.UIResource; @@ -135,7 +136,7 @@ public class DarkTabFrameComponentPopupMenu extends JXPopupMenu implements Prope @Override public void propertyChange(final PropertyChangeEvent evt) { - if ("orientation".equals(evt.getPropertyName())) { + if (TabFrameTab.KEY_ORIENTATION.equals(evt.getPropertyName())) { Object a = evt.getNewValue(); if (a instanceof Alignment) { if (disabled >= 0) { @@ -144,7 +145,7 @@ public class DarkTabFrameComponentPopupMenu extends JXPopupMenu implements Prope disabled = ((Alignment) a).ordinal(); actions[disabled].setEnabled(false); } - } else if ("componentPopupMenu".equals(evt.getPropertyName())) { + } else if (PropertyKey.COMPONENT_POPUP_MENU.equals(evt.getPropertyName())) { if (evt.getNewValue() != this) { tab.getComponent().removePropertyChangeListener(this); } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabContainerUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabContainerUI.java index 631cc971..09d38081 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabContainerUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabContainerUI.java @@ -24,11 +24,13 @@ package com.github.weisj.darklaf.ui.tabframe; import com.github.weisj.darklaf.components.tabframe.JTabFrame; +import com.github.weisj.darklaf.components.tabframe.TabFrameTab; import com.github.weisj.darklaf.components.tabframe.TabFrameTabContainer; import com.github.weisj.darklaf.decorators.HoverListener; import com.github.weisj.darklaf.ui.panel.DarkPanelUI; import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -42,6 +44,7 @@ import java.beans.PropertyChangeListener; public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyChangeListener { + private static final String ACCELERATOR_PREFIX = "accelerator_"; protected TabFrameTabContainer tabContainer; private final MouseListener mouseListener = new MouseAdapter() { @Override @@ -95,8 +98,8 @@ public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyC if (acc < 0) return; tabFrame.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(UIManager.getString("TabFrame.acceleratorKeyCode") + " " + acc), - "accelerator_" + acc); - tabFrame.getActionMap().put("accelerator_" + acc, createAcceleratorAction(tabFrame)); + ACCELERATOR_PREFIX + acc); + tabFrame.getActionMap().put(ACCELERATOR_PREFIX + acc, createAcceleratorAction(tabFrame)); } protected Action createAcceleratorAction(final JTabFrame tabFrame) { @@ -147,7 +150,7 @@ public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyC protected void uninstallAccelerator(final JTabFrame tabFrame) { if (tabFrame == null) return; int acc = tabContainer.getAccelerator(); - String accAction = "accelerator_" + acc; + String accAction = ACCELERATOR_PREFIX + acc; tabFrame.getActionMap().remove(accAction); } @@ -161,7 +164,7 @@ public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyC @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if ("content".equals(key)) { + if (TabFrameTab.KEY_CONTENT.equals(key)) { Object oldVal = evt.getOldValue(); Object newVal = evt.getNewValue(); if (oldVal instanceof Component) { @@ -176,21 +179,21 @@ public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyC ((Component) newVal).addMouseListener(dragListener); ((Component) newVal).addMouseMotionListener(dragListener); } - } else if ("selected".equals(key)) { + } else if (TabFrameTab.KEY_SELECTED.equals(key)) { if (tabContainer == null) return; tabContainer.repaint(); - } else if ("accelerator".equals(key)) { + } else if (TabFrameTab.KEY_ACCELERATOR.equals(key)) { if (tabContainer == null) return; uninstallAccelerator(tabContainer.getTabFrame()); installAccelerator(tabContainer.getTabFrame()); - } else if ("tabFrame".equals(key)) { + } else if (TabFrameTab.KEY_TAB_FRAME_PARENT.equals(key)) { if (evt.getOldValue() instanceof JTabFrame) { uninstallAccelerator((JTabFrame) evt.getOldValue()); } if (evt.getNewValue() instanceof JTabFrame) { installAccelerator((JTabFrame) evt.getNewValue()); } - } else if ("paintingForPrint".equals(key)) { + } else if (PropertyKey.PAINTING_FOR_PRINT.equals(key)) { printing = Boolean.TRUE.equals(evt.getNewValue()); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java index 8ef4f013..180d75ab 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java @@ -24,12 +24,14 @@ package com.github.weisj.darklaf.ui.tabframe; import com.github.weisj.darklaf.components.tabframe.JTabFrame; +import com.github.weisj.darklaf.components.tabframe.TabFrameTab; import com.github.weisj.darklaf.components.tabframe.TabFrameTabLabel; import com.github.weisj.darklaf.decorators.HoverListener; import com.github.weisj.darklaf.icons.RotatableIcon; import com.github.weisj.darklaf.ui.label.DarkLabelUI; import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.darklaf.util.PropertyKey; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -47,6 +49,7 @@ import java.beans.PropertyChangeListener; public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChangeListener { + private static final String ACCELERATOR_PREFIX = "accelerator_"; private TabFrameTabLabel tabComponent; private final MouseListener mouseListener = new MouseAdapter() { @Override @@ -165,27 +168,27 @@ public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChang public void propertyChange(final PropertyChangeEvent e) { super.propertyChange(e); String key = e.getPropertyName(); - if ("selected".equals(key)) { + if (TabFrameTab.KEY_SELECTED.equals(key)) { tabComponent.setForeground(Boolean.TRUE.equals(e.getNewValue()) ? selectedFontColor : defaultFontColor); tabComponent.repaint(); - } else if ("title".equals(key)) { + } else if (TabFrameTab.KEY_TITLE.equals(key)) { updateText(); - } else if ("accelerator".equals(key)) { + } else if (TabFrameTab.KEY_ACCELERATOR.equals(key)) { updateText(); if (tabComponent == null) return; uninstallAccelerator(tabComponent.getTabFrame()); installAccelerator(tabComponent.getTabFrame()); - } else if ("orientation".equals(key)) { + } else if (TabFrameTab.KEY_ORIENTATION.equals(key)) { rotatableIcon.setOrientation(mapOrientation(tabComponent.getOrientation())); - } else if ("tabFrame".equals(key)) { + } else if (TabFrameTab.KEY_TAB_FRAME_PARENT.equals(key)) { if (e.getOldValue() instanceof JTabFrame) { uninstallAccelerator((JTabFrame) e.getOldValue()); } if (e.getNewValue() instanceof JTabFrame) { installAccelerator((JTabFrame) e.getNewValue()); } - } else if ("paintingForPrint".equals(key)) { + } else if (PropertyKey.PAINTING_FOR_PRINT.equals(key)) { printing = Boolean.TRUE.equals(e.getNewValue()); } } @@ -209,8 +212,8 @@ public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChang if (acc < 0) return; tabFrame.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(UIManager.getString("TabFrame.acceleratorKeyCode") + " " + acc), - "accelerator_" + acc); - tabFrame.getActionMap().put("accelerator_" + acc, createAcceleratorAction(tabFrame)); + ACCELERATOR_PREFIX + acc); + tabFrame.getActionMap().put(ACCELERATOR_PREFIX + acc, createAcceleratorAction(tabFrame)); } protected Action createAcceleratorAction(final JTabFrame tabFrame) { @@ -236,7 +239,7 @@ public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChang protected void uninstallAccelerator(final JTabFrame tabFrame) { if (tabFrame == null) return; int acc = tabComponent.getAccelerator(); - String accAction = "accelerator_" + acc; + String accAction = ACCELERATOR_PREFIX + acc; tabFrame.getActionMap().remove(accAction); } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java index d2783890..1b422d01 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java @@ -24,6 +24,9 @@ package com.github.weisj.darklaf.ui.table; import com.github.weisj.darklaf.ui.combobox.DarkComboBoxUI; +import com.github.weisj.darklaf.ui.spinner.DarkSpinnerUI; +import com.github.weisj.darklaf.ui.text.DarkTextUI; +import com.github.weisj.darklaf.util.PropertyValue; import javax.swing.*; import javax.swing.border.Border; @@ -61,8 +64,8 @@ public class DarkTableCellEditor extends DefaultCellEditor { public DarkTableCellEditor(final JTextField textField) { super(textField); - textField.setBorder(new TextFieldTableCellEditorBorder()); - textField.putClientProperty("JTextField.isCellEditor", Boolean.TRUE); + textField.setBorder(new TextTableCellEditorBorder()); + textField.putClientProperty(DarkTextUI.KEY_IS_TABLE_EDITOR, Boolean.TRUE); setClickCountToStart(2); } @@ -140,7 +143,7 @@ public class DarkTableCellEditor extends DefaultCellEditor { if (value instanceof Boolean) { selected = (Boolean) value; } else if (value instanceof String) { - selected = value.equals("true"); + selected = value.equals(PropertyValue.TRUE); } toggleButton.setSelected(selected); } @@ -232,15 +235,15 @@ public class DarkTableCellEditor extends DefaultCellEditor { Component rendererComp = table.getCellRenderer(row, column) .getTableCellRendererComponent(table, value, isSelected, false, row, column); if (rendererComp instanceof JTextField) { - editorComponent.putClientProperty("JSpinner.cellEditorAlignment", + editorComponent.putClientProperty(DarkSpinnerUI.KEY_EDITOR_ALIGNMENT, ((JTextField) rendererComp).getHorizontalAlignment()); } else if (rendererComp instanceof JLabel) { - editorComponent.putClientProperty("JSpinner.cellEditorAlignment", + editorComponent.putClientProperty(DarkSpinnerUI.KEY_EDITOR_ALIGNMENT, ((JLabel) rendererComp).getHorizontalAlignment()); } } - boolean alternativeRow = Boolean.TRUE.equals(table.getClientProperty("JTable.alternateRowColor")); + boolean alternativeRow = Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_ALTERNATE_ROW_COLOR)); Color alternativeRowColor = UIManager.getColor("Table.alternateRowBackground"); Color normalColor = table.getBackground(); Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor; @@ -270,7 +273,7 @@ public class DarkTableCellEditor extends DefaultCellEditor { } protected TableCellEditor getBooleanEditor(final JTable table) { - if ("radioButton".equals(table.getClientProperty("JTable.booleanRenderType"))) { + if (DarkTableUI.RENDER_TYPE_RADIOBUTTON.equals(table.getClientProperty(DarkTableUI.KEY_BOOLEAN_RENDER_TYPE))) { return radioButtonEditor; } return checkBoxEditor; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditorToggleButton.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditorToggleButton.java index a38294e5..0653140d 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditorToggleButton.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditorToggleButton.java @@ -55,7 +55,7 @@ public class DarkTableCellEditorToggleButton extends AbstractCellEditor implemen } toggleButton.setHorizontalAlignment(table.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT); - boolean alternativeRow = Boolean.TRUE.equals(table.getClientProperty("JTable.alternateRowColor")); + boolean alternativeRow = Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_ALTERNATE_ROW_COLOR)); Color alternativeRowColor = UIManager.getColor("Table.alternateRowBackground"); Color normalColor = table.getBackground(); Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellFocusBorder.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellFocusBorder.java index ecfdfbc6..afa7d945 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellFocusBorder.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellFocusBorder.java @@ -64,16 +64,16 @@ public class DarkTableCellFocusBorder extends DarkCellBorder { protected static boolean isRowFocusBorder(final Component c) { return c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JTable.rowFocusBorder")); + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTableUI.KEY_SHOW_ROW_FOCUS_BORDER)); } protected static boolean forcePaintLeft(final Component c) { return c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JTable.forcePaintLeft")); + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTableUI.KEY_FORCE_LEFT_BORDER)); } protected static boolean forcePaintRight(final Component c) { return c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JTable.forcePaintRight")); + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTableUI.KEY_FORCE_RIGHT_BORDER)); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java index 93f879b4..1358f197 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java @@ -41,9 +41,13 @@ import java.awt.*; public class DarkTableCellRenderer extends DefaultTableCellRenderer { private final DarkCellRendererToggleButton checkBoxRenderer = - new DarkCellRendererToggleButton<>(new DarkCellRendererToggleButton.CellEditorCheckBox(true)); + new DarkCellRendererToggleButton<>(new DarkCellRendererToggleButton.CellEditorCheckBox(true)); private final DarkCellRendererToggleButton radioRenderer = - new DarkCellRendererToggleButton<>(new DarkCellRendererToggleButton.CellEditorRadioButton(true)); + new DarkCellRendererToggleButton<>(new DarkCellRendererToggleButton.CellEditorRadioButton(true)); + + protected static boolean isBooleanRenderingEnabled(final JTable table) { + return Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX)); + } @Override public Component getTableCellRendererComponent(final JTable table, final Object value, @@ -64,7 +68,7 @@ public class DarkTableCellRenderer extends DefaultTableCellRenderer { && !table.isEditing() && DarkUIUtil.hasFocus(table)) { component.setBorder(UIManager.getBorder("Table.focusSelectedCellHighlightBorder")); - component.putClientProperty("JTable.rowFocusBorder", true); + component.putClientProperty(DarkTableUI.KEY_SHOW_ROW_FOCUS_BORDER, true); JTableHeader header = table.getTableHeader(); TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn(); boolean forceLeft = false; @@ -74,13 +78,13 @@ public class DarkTableCellRenderer extends DefaultTableCellRenderer { forceLeft = column == index + 1 || column == index; forceRight = column == index - 1 || column == index; } - component.putClientProperty("JTable.forcePaintRight", forceRight); - component.putClientProperty("JTable.forcePaintLeft", forceLeft); + component.putClientProperty(DarkTableUI.KEY_FORCE_RIGHT_BORDER, forceRight); + component.putClientProperty(DarkTableUI.KEY_FORCE_LEFT_BORDER, forceLeft); } else { - component.putClientProperty("JTable.rowFocusBorder", false); + component.putClientProperty(DarkTableUI.KEY_SHOW_ROW_FOCUS_BORDER, false); } - boolean alternativeRow = Boolean.TRUE.equals(table.getClientProperty("JTable.alternateRowColor")); + boolean alternativeRow = Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_ALTERNATE_ROW_COLOR)); Color alternativeRowColor = UIManager.getColor("Table.alternateRowBackground"); Color normalColor = table.getBackground(); Color background = alternativeRow && row % 2 == 1 ? alternativeRowColor : normalColor; @@ -98,12 +102,8 @@ public class DarkTableCellRenderer extends DefaultTableCellRenderer { return component; } - protected static boolean isBooleanRenderingEnabled(final JTable table) { - return Boolean.TRUE.equals(table.getClientProperty("JTable.renderBooleanAsCheckBox")); - } - protected TableCellRenderer getBooleanRenderer(final JTable table) { - if ("radioButton".equals(table.getClientProperty("JTable.booleanRenderType"))) { + if (DarkTableUI.RENDER_TYPE_RADIOBUTTON.equals(table.getClientProperty(DarkTableUI.KEY_BOOLEAN_RENDER_TYPE))) { return radioRenderer; } return checkBoxRenderer; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUIBridge.java index 80b3c6e4..1b51e54f 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUIBridge.java @@ -24,6 +24,7 @@ package com.github.weisj.darklaf.ui.table; import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.darklaf.util.PropertyKey; import sun.swing.SwingUtilities2; import sun.swing.UIAction; @@ -357,7 +358,7 @@ public class DarkTableHeaderUIBridge extends BasicTableHeaderUI { protected void installDefaults() { LookAndFeel.installColorsAndFont(header, "TableHeader.background", "TableHeader.foreground", "TableHeader.font"); - LookAndFeel.installProperty(header, "opaque", Boolean.TRUE); + LookAndFeel.installProperty(header, PropertyKey.OPAQUE, Boolean.TRUE); } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java index 23d8b014..976b0cd3 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java @@ -25,6 +25,7 @@ package com.github.weisj.darklaf.ui.table; import com.github.weisj.darklaf.components.OverlayScrollPane; import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.darklaf.util.PropertyKey; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -47,16 +48,32 @@ import java.util.function.Supplier; */ public class DarkTableUI extends DarkTableUIBridge { - private static final int ROW_HEIGHT = 22; + public static final String KEY_PREFIX = "JTable."; + 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_BOOLEAN_RENDER_TYPE = KEY_PREFIX + "booleanRenderType"; + public static final String KEY_SHOW_ROW_FOCUS_BORDER = KEY_PREFIX + "rowFocusBorder"; + public static final String KEY_FORCE_LEFT_BORDER = KEY_PREFIX + "forcePaintLeft"; + public static final String KEY_FORCE_RIGHT_BORDER = KEY_PREFIX + "forcePaintRight"; + public static final String KEY_FILE_CHOOSER_PARENT = KEY_PREFIX + "fileChooserParent"; + public static final String KEY_FILENAME_COLUMN_INDEX = KEY_PREFIX + "fileNameColumnIndex"; + public static final String KEY_HORIZONTAL_LINES = "showHorizontalLines"; + public static final String KEY_VERTICAL_LINES = "showVerticalLines"; + public static final String KEY_IS_FILE_LIST = "Table.isFileList"; + public static final String KEY_IS_PRINT_MODE = "Table.printMode"; + public static final String RENDER_TYPE_CHECKBOX = "checkBox"; + public static final String RENDER_TYPE_RADIOBUTTON = "radioButton"; + + private static final int ROW_HEIGHT_FALLBACK = 22; private final PropertyChangeListener propertyChangeListener = e -> { String key = e.getPropertyName(); - if ("showHorizontalLines".equals(key)) { + if (KEY_HORIZONTAL_LINES.equals(key)) { boolean b = Boolean.TRUE.equals(e.getNewValue()); table.setRowMargin(b ? 1 : 0); - } else if ("showVerticalLines".equals(key)) { + } else if (KEY_VERTICAL_LINES.equals(key)) { boolean b = Boolean.TRUE.equals(e.getNewValue()); table.getColumnModel().setColumnMargin(b ? 1 : 0); - } else if ("ancestor".equals(key)) { + } else if (PropertyKey.ANCESTOR.equals(key)) { Object oldVal = e.getOldValue(); Object newVal = e.getNewValue(); if (oldVal instanceof Component) { @@ -72,7 +89,7 @@ public class DarkTableUI extends DarkTableUIBridge { LookAndFeel.installBorder((JComponent) newUnwrapped, "Table.scrollPaneBorder"); } } - } else if ("componentOrientation".equals(key)) { + } else if (PropertyKey.COMPONENT_ORIENTATION.equals(key)) { table.doLayout(); table.repaint(); } @@ -181,13 +198,13 @@ public class DarkTableUI extends DarkTableUIBridge { super.installDefaults(); int rowHeight = UIManager.getInt("Table.rowHeight"); if (rowHeight > 0) { - table.setRowHeight(ROW_HEIGHT); + table.setRowHeight(ROW_HEIGHT_FALLBACK); } table.setDefaultEditor(Object.class, new DarkTableCellEditor()); - table.putClientProperty("JTable.renderBooleanAsCheckBox", + table.putClientProperty(KEY_RENDER_BOOLEAN_AS_CHECKBOX, UIManager.getBoolean("Table.renderBooleanAsCheckBox")); - table.putClientProperty("JTable.booleanRenderType", UIManager.getString("Table.booleanRenderType")); - table.putClientProperty("JTable.alternateRowColor", UIManager.getBoolean("Table.alternateRowColor")); + table.putClientProperty(KEY_BOOLEAN_RENDER_TYPE, UIManager.getString("Table.booleanRenderType")); + table.putClientProperty(KEY_ALTERNATE_ROW_COLOR, UIManager.getBoolean("Table.alternateRowColor")); setupRendererComponents(table); borderColor = UIManager.getColor("TableHeader.borderColor"); selectionFocusBackground = UIManager.getColor("Table.focusSelectionBackground"); @@ -430,16 +447,16 @@ public class DarkTableUI extends DarkTableUIBridge { } protected JFileChooser getFileChooser() { - Object obj = table.getClientProperty("JTable.fileChooserParent"); - if (obj instanceof Supplier) { - Object supplied = ((Supplier) obj).get(); + Object obj = table.getClientProperty(DarkTableUI.KEY_FILE_CHOOSER_PARENT); + if (obj instanceof Supplier) { + Object supplied = ((Supplier) obj).get(); return supplied instanceof JFileChooser ? (JFileChooser) supplied : null; } return null; } protected Integer getFileNameColumnIndex() { - Object obj = table.getClientProperty("JTable.fileNameColumnIndex"); + Object obj = table.getClientProperty(DarkTableUI.KEY_FILENAME_COLUMN_INDEX); return obj instanceof Integer ? (Integer) obj : 0; } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUIBridge.java index 93dcc6aa..24b17115 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUIBridge.java @@ -93,10 +93,10 @@ public class DarkTableUIBridge extends TableUIBridge { // For FIT_WIDTH, all columns should be printed irrespective of // how many columns are visible. So, we used clip which is already set to // total col width instead of visible region - // Since JTable.PrintMode is not accessible - // from here, we aet "Table.printMode" in TablePrintable#print and + // Since JDarkTableUI.KEY_IS_PRINT_MODE is not accessible + // from here, we aet DarkTableUI.KEY_IS_PRINT_MODE in TablePrintable#print and // access from here. - Object printMode = table.getClientProperty("Table.printMode"); + Object printMode = table.getClientProperty(DarkTableUI.KEY_IS_PRINT_MODE); if ((printMode == JTable.PrintMode.FIT_WIDTH)) { upperLeft = clip.getLocation(); lowerRight = new Point(clip.x + clip.width - 1, diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/TableUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/TableUIBridge.java index b2e25aea..c4ec5177 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/TableUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/TableUIBridge.java @@ -27,6 +27,7 @@ import com.github.weisj.darklaf.ui.BasicTransferable; import com.github.weisj.darklaf.ui.DragRecognitionSupport; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.LazyActionMap; +import com.github.weisj.darklaf.util.PropertyKey; import sun.swing.DefaultLookup; import sun.swing.SwingUtilities2; import sun.swing.UIAction; @@ -40,21 +41,10 @@ import javax.swing.plaf.TableHeaderUI; import javax.swing.plaf.TableUI; import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicTableUI; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.JTableHeader; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumn; -import javax.swing.table.TableColumnModel; +import javax.swing.table.*; import java.awt.*; import java.awt.datatransfer.Transferable; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; +import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Enumeration; @@ -109,7 +99,7 @@ public abstract class TableUIBridge extends TableUI { // Helper class for keyboard actions // /** - * Local cache of Table's client property "Table.isFileList" + * Local cache of Table's client property DarkTableUI.KEY_IS_FILE_LIST */ protected boolean isFileList = false; @@ -280,7 +270,7 @@ public abstract class TableUIBridge extends TableUI { /* * Returns true if the given point is outside the preferredSize of the * item at the given row of the table. (Column must be 0). - * Returns false if the "Table.isFileList" client property is not set. + * Returns false if the DarkTableUI.KEY_IS_FILE_LIST client property is not set. */ protected boolean pointOutsidePrefSize(final int row, final int column, final Point p) { if (!isFileList) { @@ -323,7 +313,7 @@ public abstract class TableUIBridge extends TableUI { // developer changes the font, it's there responsability to update // the row height. - LookAndFeel.installProperty(table, "opaque", Boolean.TRUE); + LookAndFeel.installProperty(table, PropertyKey.OPAQUE, Boolean.TRUE); Color sbg = table.getSelectionBackground(); if (sbg == null || sbg instanceof UIResource) { @@ -352,7 +342,7 @@ public abstract class TableUIBridge extends TableUI { } } - isFileList = Boolean.TRUE.equals(table.getClientProperty("Table.isFileList")); + isFileList = Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_IS_FILE_LIST)); } /** @@ -566,9 +556,9 @@ public abstract class TableUIBridge extends TableUI { // how many columns are visible. So, we used clip which is already set to // total col width instead of visible region // Since JTable.PrintMode is not accessible - // from here, we aet "Table.printMode" in TablePrintable#print and + // from here, we aet DarkTableUI.KEY_IS_PRINT_MODE in TablePrintable#print and // access from here. - Object printMode = table.getClientProperty("Table.printMode"); + Object printMode = table.getClientProperty(DarkTableUI.KEY_IS_PRINT_MODE); if ((printMode == JTable.PrintMode.FIT_WIDTH)) { upperLeft = clip.getLocation(); lowerRight = new Point(clip.x + clip.width - 1, @@ -1881,17 +1871,17 @@ public abstract class TableUIBridge extends TableUI { String key = getName(); if (sender instanceof JTable && - Boolean.TRUE.equals(((JTable) sender).getClientProperty("Table.isFileList"))) { + Boolean.TRUE.equals(((JTable) sender).getClientProperty(DarkTableUI.KEY_IS_FILE_LIST))) { if (Objects.equals(key, NEXT_COLUMN) || - Objects.equals(key, NEXT_COLUMN_CELL) || - Objects.equals(key, NEXT_COLUMN_EXTEND_SELECTION) || - Objects.equals(key, NEXT_COLUMN_CHANGE_LEAD) || - Objects.equals(key, PREVIOUS_COLUMN) || - Objects.equals(key, PREVIOUS_COLUMN_CELL) || - Objects.equals(key, PREVIOUS_COLUMN_EXTEND_SELECTION) || - Objects.equals(key, PREVIOUS_COLUMN_CHANGE_LEAD) || - Objects.equals(key, SCROLL_LEFT_CHANGE_SELECTION) || - Objects.equals(key, SCROLL_LEFT_EXTEND_SELECTION) || + Objects.equals(key, NEXT_COLUMN_CELL) || + Objects.equals(key, NEXT_COLUMN_EXTEND_SELECTION) || + Objects.equals(key, NEXT_COLUMN_CHANGE_LEAD) || + Objects.equals(key, PREVIOUS_COLUMN) || + Objects.equals(key, PREVIOUS_COLUMN_CELL) || + Objects.equals(key, PREVIOUS_COLUMN_EXTEND_SELECTION) || + Objects.equals(key, PREVIOUS_COLUMN_CHANGE_LEAD) || + Objects.equals(key, SCROLL_LEFT_CHANGE_SELECTION) || + Objects.equals(key, SCROLL_LEFT_EXTEND_SELECTION) || Objects.equals(key, SCROLL_RIGHT_CHANGE_SELECTION) || Objects.equals(key, SCROLL_RIGHT_EXTEND_SELECTION) || Objects.equals(key, FIRST_COLUMN) || @@ -2621,9 +2611,9 @@ public abstract class TableUIBridge extends TableUI { public void propertyChange(final PropertyChangeEvent event) { String changeName = event.getPropertyName(); - if ("componentOrientation".equals(changeName)) { + if (PropertyKey.COMPONENT_ORIENTATION.equals(changeName)) { InputMap inputMap = getInputMap( - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); SwingUtilities.replaceUIInputMap(table, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, @@ -2638,8 +2628,8 @@ public abstract class TableUIBridge extends TableUI { JTable.DropLocation oldValue = (JTable.DropLocation) event.getOldValue(); repaintDropLocation(oldValue); repaintDropLocation(table.getDropLocation()); - } else if ("Table.isFileList".equals(changeName)) { - isFileList = Boolean.TRUE.equals(table.getClientProperty("Table.isFileList")); + } else if (DarkTableUI.KEY_IS_FILE_LIST.equals(changeName)) { + isFileList = Boolean.TRUE.equals(table.getClientProperty(DarkTableUI.KEY_IS_FILE_LIST)); table.revalidate(); table.repaint(); if (isFileList) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/table/TextFieldTableCellEditorBorder.java b/core/src/main/java/com/github/weisj/darklaf/ui/table/TextTableCellEditorBorder.java similarity index 89% rename from core/src/main/java/com/github/weisj/darklaf/ui/table/TextFieldTableCellEditorBorder.java rename to core/src/main/java/com/github/weisj/darklaf/ui/table/TextTableCellEditorBorder.java index e7acc32e..a5692391 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/table/TextFieldTableCellEditorBorder.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/table/TextTableCellEditorBorder.java @@ -23,6 +23,7 @@ */ package com.github.weisj.darklaf.ui.table; +import com.github.weisj.darklaf.ui.text.DarkTextUI; import com.github.weisj.darklaf.util.DarkUIUtil; import javax.swing.*; @@ -31,11 +32,11 @@ import java.awt.*; /** * @author Jannis Weis */ -public class TextFieldTableCellEditorBorder extends DarkTableCellBorder { +public class TextTableCellEditorBorder extends DarkTableCellBorder { protected Color borderColor; - public TextFieldTableCellEditorBorder() { + public TextTableCellEditorBorder() { borderColor = UIManager.getColor("TextField.border.enabled"); } @@ -68,6 +69,16 @@ public class TextFieldTableCellEditorBorder extends DarkTableCellBorder { } } + protected static boolean isListEditor(final Component c) { + return c instanceof JComponent + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTextUI.KEY_IS_LIST_RENDER)) + && c.getParent() instanceof JList; + } + + protected static boolean isInWrapper(final Component c) { + return c.getParent() instanceof DarkTableCellEditor.IconWrapper; + } + @Override public Insets getBorderInsets(final Component c) { Insets ins = super.getBorderInsets(); @@ -78,7 +89,7 @@ public class TextFieldTableCellEditorBorder extends DarkTableCellBorder { ins.right -= ((DarkTableCellEditor.IconWrapper) c.getParent()).getIconCompGap(); } } else if (isListEditor(c)) { - ListCellRenderer renderer = ((JList) c.getParent()).getCellRenderer(); + ListCellRenderer renderer = ((JList) c.getParent()).getCellRenderer(); if (renderer instanceof JLabel) { if (parentLTR(c)) { ins.left -= ((JLabel) renderer).getIconTextGap() - 1; @@ -90,15 +101,4 @@ public class TextFieldTableCellEditorBorder extends DarkTableCellBorder { return ins; } - protected static boolean isInWrapper(final Component c) { - return c.getParent() instanceof DarkTableCellEditor.IconWrapper; - } - - - protected static boolean isListEditor(final Component c) { - return c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JTextField.listCellEditor")) - && c.getParent() instanceof JList; - } - } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneUI.java index 2eb8d1e1..48fbe9c0 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneUI.java @@ -38,6 +38,8 @@ import java.awt.*; public class DarkTaskPaneUI extends MetalTaskPaneUI { + public static final String KEY_COLLAPSED = "collapsed"; + protected boolean isCollapsed; protected Color borderColor; protected Icon collapsedIcon; @@ -66,7 +68,8 @@ public class DarkTaskPaneUI extends MetalTaskPaneUI { @Override protected void installListeners() { super.installListeners(); - group.addPropertyChangeListener(JXCollapsiblePane.ANIMATION_STATE_KEY, e -> isCollapsed = "collapsed".equals(e.getNewValue())); + group.addPropertyChangeListener(JXCollapsiblePane.ANIMATION_STATE_KEY, + e -> isCollapsed = KEY_COLLAPSED.equals(e.getNewValue())); } @Override diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkEditorPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkEditorPaneUI.java index 07dde764..99b5839f 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkEditorPaneUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkEditorPaneUI.java @@ -23,17 +23,13 @@ */ package com.github.weisj.darklaf.ui.text; +import com.github.weisj.darklaf.util.PropertyKey; + import javax.swing.*; import javax.swing.plaf.ActionMapUIResource; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.UIResource; -import javax.swing.text.Document; -import javax.swing.text.EditorKit; -import javax.swing.text.JTextComponent; -import javax.swing.text.Style; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyleContext; -import javax.swing.text.StyledDocument; +import javax.swing.text.*; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.StyleSheet; import java.awt.*; @@ -142,8 +138,7 @@ public class DarkEditorPaneUI extends DarkTextUI { String cssRule = sun.swing.SwingUtilities2.displayPropertiesToCSS(font, fg); styleSheet.addRule(cssRule); documentStyleSheet.addStyleSheet(styleSheet); - documentStyleSheet.addRule("BASE_SIZE " + - component.getFont().getSize()); + documentStyleSheet.addRule("BASE_SIZE " + component.getFont().getSize()); Style style = ((StyledDocument) document).getStyle(StyleContext.DEFAULT_STYLE); if (!font.equals(style.getAttribute(FONT_ATTRIBUTE_KEY))) { style.addAttribute(FONT_ATTRIBUTE_KEY, font); @@ -313,21 +308,21 @@ public class DarkEditorPaneUI extends DarkTextUI { } } updateFocusTraversalKeys(); - } else if ("editable".equals(name)) { + } else if (PropertyKey.EDITABLE.equals(name)) { updateFocusTraversalKeys(); - } else if ("foreground".equals(name) - || "font".equals(name) - || "document".equals(name) - || JEditorPane.W3C_LENGTH_UNITS.equals(name) - || JEditorPane.HONOR_DISPLAY_PROPERTIES.equals(name) + } else if (PropertyKey.FOREGROUND.equals(name) + || PropertyKey.FONT.equals(name) + || PropertyKey.DOCUMENT.equals(name) + || JEditorPane.W3C_LENGTH_UNITS.equals(name) + || JEditorPane.HONOR_DISPLAY_PROPERTIES.equals(name) ) { JComponent c = getComponent(); updateDisplayProperties(c.getFont(), c.getForeground()); if (JEditorPane.W3C_LENGTH_UNITS.equals(name) - || JEditorPane.HONOR_DISPLAY_PROPERTIES.equals(name)) { + || JEditorPane.HONOR_DISPLAY_PROPERTIES.equals(name)) { modelChanged(); } - if ("foreground".equals(name)) { + if (PropertyKey.FOREGROUND.equals(name)) { Object honorDisplayPropertiesObject = c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES); boolean honorDisplayProperties = false; if (honorDisplayPropertiesObject instanceof Boolean) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkFormattedTextFieldUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkFormattedTextFieldUI.java index 5e87aa2f..be2a5fe7 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkFormattedTextFieldUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkFormattedTextFieldUI.java @@ -23,6 +23,8 @@ */ package com.github.weisj.darklaf.ui.text; +import com.github.weisj.darklaf.util.PropertyKey; + import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -63,7 +65,7 @@ public class DarkFormattedTextFieldUI extends DarkTextFieldUI implements Propert @Override public void propertyChange(final PropertyChangeEvent evt) { super.propertyChange(evt); - if ("document".equals(evt.getPropertyName())) { + if (PropertyKey.DOCUMENT.equals(evt.getPropertyName())) { Object oldDoc = evt.getOldValue(); Object newDoc = evt.getNewValue(); if (oldDoc instanceof Document) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java index 2fb20612..30d2044e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java @@ -42,6 +42,8 @@ import java.util.Arrays; */ public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge { + public static final String KEY_PREFIX = "JPasswordField."; + public static final String KEY_SHOW_VIEW_BUTTON = "JPasswordField.showViewIcon"; protected Icon show; protected Icon showPressed; private final FocusListener focusListener = new FocusAdapter() { @@ -179,7 +181,7 @@ public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge { public static boolean hasShowIcon(final Component c) { return c instanceof JPasswordField - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JPasswordField.showViewIcon")); + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_SHOW_VIEW_BUTTON)); } @@ -218,7 +220,7 @@ public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge { public void propertyChange(final PropertyChangeEvent evt) { super.propertyChange(evt); String key = evt.getPropertyName(); - if ("JPasswordField.showViewIcon".equals(key)) { + if (KEY_SHOW_VIEW_BUTTON.equals(key)) { editor.doLayout(); Component parent = editor.getParent(); if (parent instanceof JComponent) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextAreaUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextAreaUI.java index ce5f40e0..4b445197 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextAreaUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextAreaUI.java @@ -24,23 +24,12 @@ package com.github.weisj.darklaf.ui.text; import com.github.weisj.darklaf.ui.html.DarkHTML; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.plaf.ComponentUI; -import javax.swing.text.AbstractDocument; -import javax.swing.text.BoxView; -import javax.swing.text.CompositeView; -import javax.swing.text.Document; -import javax.swing.text.Element; -import javax.swing.text.GlyphView; -import javax.swing.text.JTextComponent; -import javax.swing.text.ParagraphView; -import javax.swing.text.PlainView; -import javax.swing.text.StyleConstants; -import javax.swing.text.View; -import javax.swing.text.ViewFactory; -import javax.swing.text.WrappedPlainView; +import javax.swing.text.*; import java.awt.*; import java.beans.PropertyChangeEvent; @@ -68,11 +57,11 @@ public class DarkTextAreaUI extends DarkTextUI { public void propertyChange(final PropertyChangeEvent evt) { super.propertyChange(evt); if (evt.getPropertyName().equals("lineWrap") || - evt.getPropertyName().equals("wrapStyleWord") || - evt.getPropertyName().equals("tabSize")) { + evt.getPropertyName().equals("wrapStyleWord") || + evt.getPropertyName().equals("tabSize")) { // rebuild the view modelChanged(); - } else if ("editable".equals(evt.getPropertyName())) { + } else if (PropertyKey.EDITABLE.equals(evt.getPropertyName())) { updateFocusTraversalKeys(); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java index 2fed6a4e..bd48262e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.ui.text; -import com.github.weisj.darklaf.ui.table.TextFieldTableCellEditorBorder; +import com.github.weisj.darklaf.ui.table.TextTableCellEditorBorder; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; @@ -40,7 +40,7 @@ import java.awt.*; */ public class DarkTextBorder implements Border, UIResource { - private static final Border editorBorder = new TextFieldTableCellEditorBorder(); + private static final Border editorBorder = new TextTableCellEditorBorder(); protected Color errorBorderColor; protected Color focusErrorBorderColor; protected Color focusBorderColor; @@ -73,13 +73,13 @@ public class DarkTextBorder implements Border, UIResource { protected static boolean hasError(final Component c) { return c instanceof JComponent - && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JTextComponent.hasError")); + && 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("JTextField.cellEditor")); + && Boolean.TRUE.equals(((JComponent) c).getClientProperty(DarkTextUI.KEY_IS_CELL_EDITOR)); } protected int getArcSize(final Component c) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java index a060f660..5a970d38 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java @@ -45,13 +45,18 @@ import java.beans.PropertyChangeListener; */ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyChangeListener { + public static final String KEY_PREFIX = "JTextField."; + public static final String KEY_VARIANT = KEY_PREFIX + "variant"; + 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 VARIANT_SEARCH = "search"; protected static Icon clear; protected static Icon clearHover; protected static Icon search; protected static Icon searchWithHistory; private final FocusListener focusListener = new FocusAdapter() { public void focusLost(final FocusEvent e) { - if (!Boolean.TRUE.equals(getComponent().getClientProperty("JTextField.keepSelectionOnFocusLost"))) { + if (!Boolean.TRUE.equals(getComponent().getClientProperty(KEY_KEEP_SELECTION_ON_FOCUS_LOST))) { getComponent().select(0, 0); } } @@ -149,7 +154,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh private static JPopupMenu getSearchPopup(final JComponent c) { - Object value = c.getClientProperty("JTextField.Search.FindPopup"); + Object value = c.getClientProperty(KEY_FIND_POPUP); return value instanceof JPopupMenu ? (JPopupMenu) value : null; } @@ -170,7 +175,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh public static boolean isSearchField(final Component c) { - return c instanceof JTextField && "search".equals(((JTextField) c).getClientProperty("JTextField.variant")); + return c instanceof JTextField && VARIANT_SEARCH.equals(((JTextField) c).getClientProperty(KEY_VARIANT)); } protected void paintBackground(final Graphics graphics) { @@ -252,7 +257,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh public void propertyChange(final PropertyChangeEvent evt) { super.propertyChange(evt); String key = evt.getPropertyName(); - if ("JTextField.Search.FindPopup".equals(key)) { + if (KEY_FIND_POPUP.equals(key)) { Object oldVal = evt.getOldValue(); Object newVal = evt.getNewValue(); if (oldVal instanceof JPopupMenu) { @@ -261,7 +266,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh if (newVal instanceof JPopupMenu) { ((JPopupMenu) newVal).addPopupMenuListener(searchPopupListener); } - } else if ("JTextField.variant".equals(key)) { + } else if (KEY_VARIANT.equals(key)) { editor.doLayout(); Component parent = editor.getParent(); if (parent instanceof JComponent) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java index b5eec336..251c9abe 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java @@ -49,6 +49,13 @@ import java.util.Set; */ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeListener { + public static final String KEY_PREFIX = "JTextComponent."; + 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_IS_CELL_EDITOR = KEY_PREFIX + "cellEditor"; + public static final String KEY_IS_TABLE_EDITOR = KEY_PREFIX + "isTableCellEditor"; + public static final String KEY_IS_LIST_RENDER = KEY_PREFIX + "listCellEditor"; + protected JTextComponent editor; private FocusListener focusListener = new FocusListener() { @Override @@ -75,7 +82,7 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi @Override protected void installDefaults() { super.installDefaults(); - editor.putClientProperty("JTextComponent.roundedSelection", + editor.putClientProperty(KEY_ROUNDED_SELECTION, UIManager.getBoolean("TextComponent.roundedSelection")); disabledColor = UIManager.getColor(getPropertyPrefix() + ".disabledBackground"); inactiveColor = UIManager.getColor(getPropertyPrefix() + ".inactiveBackground"); @@ -84,15 +91,15 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi @Override protected void uninstallDefaults() { super.uninstallDefaults(); - editor.putClientProperty("JTextComponent.roundedSelection", null); + editor.putClientProperty(KEY_ROUNDED_SELECTION, null); } @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if ("JTextComponent.roundedSelection".equals(key)) { + if (KEY_ROUNDED_SELECTION.equals(key)) { editor.repaint(); - } else if ("JTextComponent.hasError".equals(key)) { + } else if (KEY_HAS_ERROR.equals(key)) { editor.repaint(); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarLayout.java b/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarLayout.java index 7f267821..c9cad0eb 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarLayout.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarLayout.java @@ -23,6 +23,8 @@ */ package com.github.weisj.darklaf.ui.toolbar; +import com.github.weisj.darklaf.util.PropertyKey; + import javax.swing.*; import javax.swing.plaf.UIResource; import java.awt.*; @@ -99,7 +101,7 @@ public class DarkToolBarLayout implements LayoutManager2, Serializable, Property public void propertyChange(final PropertyChangeEvent e) { String name = e.getPropertyName(); - if (name.equals("orientation")) { + if (name.equals(PropertyKey.ORIENTATION)) { int o = (Integer) e.getNewValue(); if (o == JToolBar.VERTICAL) { lm = new BoxLayout(toolBar, BoxLayout.PAGE_AXIS); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUI.java index c951bcde..92bccf1e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUI.java @@ -38,6 +38,8 @@ import java.awt.event.WindowEvent; */ public class DarkToolBarUI extends DarkToolBarUIBridge { + public static final String KEY_PREFIX = "JToolBar."; + public static final String KEY_USE_TOOL_BAR_BACKGROUND = KEY_PREFIX + "drag.useToolbarBackground"; private static final Robot robot = createRobot(); private final DropPreviewPanel previewPanel = new DropPreviewPanel(); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUIBridge.java index 517d8851..ca37c8ad 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUIBridge.java @@ -25,6 +25,7 @@ package com.github.weisj.darklaf.ui.toolbar; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.LazyActionMap; +import com.github.weisj.darklaf.util.PropertyKey; import sun.swing.DefaultLookup; import sun.swing.UIAction; @@ -38,15 +39,7 @@ import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicBorders; import javax.swing.plaf.basic.BasicToolBarUI; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ContainerEvent; -import java.awt.event.ContainerListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; +import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.HashMap; @@ -180,7 +173,7 @@ public abstract class DarkToolBarUIBridge extends ToolBarUI implements SwingCons floatingToolBar = null; setOrientation(toolBar.getOrientation()); - LookAndFeel.installProperty(c, "opaque", Boolean.TRUE); + LookAndFeel.installProperty(c, PropertyKey.OPAQUE, Boolean.TRUE); if (c.getClientProperty(FOCUSED_COMP_INDEX) != null) { focusedCompIndex = (Integer) (c.getClientProperty(FOCUSED_COMP_INDEX)); @@ -1044,7 +1037,7 @@ public abstract class DarkToolBarUIBridge extends ToolBarUI implements SwingCons String propertyName = evt.getPropertyName(); if (Objects.equals(propertyName, "lookAndFeel")) { toolBar.updateUI(); - } else if (Objects.equals(propertyName, "orientation")) { + } else if (Objects.equals(propertyName, PropertyKey.ORIENTATION)) { // Search for JSeparator components and change it's orientation // to match the toolbar and flip it's orientation. Component[] components = toolBar.getComponents(); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DropPreviewPanel.java b/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DropPreviewPanel.java index e3af54b1..eb0b527d 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DropPreviewPanel.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DropPreviewPanel.java @@ -49,7 +49,7 @@ public class DropPreviewPanel extends JComponent { } protected Color getBackgroundColor() { - boolean useToolbar = Boolean.TRUE.equals(toolBar.getClientProperty("JToolBar.drag.useToolbarBackground")); + boolean useToolbar = Boolean.TRUE.equals(toolBar.getClientProperty(DarkToolBarUI.KEY_USE_TOOL_BAR_BACKGROUND)); if (!useToolbar) { Color c = dropBackground; if (c == null) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java index 2490f87d..ac5b802a 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java @@ -139,7 +139,7 @@ public class DarkTooltipBorder implements Border { protected Insets getUserInsets(final Component c) { if (c instanceof JComponent) { - Object obj = ((JComponent) c).getClientProperty("JToolTip.insets"); + Object obj = ((JComponent) c).getClientProperty(DarkTooltipUI.KEY_INSETS); if (obj instanceof Insets) { return (Insets) obj; } @@ -166,8 +166,8 @@ public class DarkTooltipBorder implements Border { protected boolean isPlain(final Component c) { if (!(c instanceof JComponent)) return false; - Object prop = ((JComponent) c).getClientProperty("JToolTip.style"); - return prop == ToolTipStyle.PLAIN || "plain".equals(prop); + Object prop = ((JComponent) c).getClientProperty(DarkTooltipUI.KEY_STYLE); + return prop == ToolTipStyle.PLAIN || DarkTooltipUI.VARIANT_PLAIN.equals(prop); } public int getShadowSize(final Component c) { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java index 4347fc6e..38a2fe48 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java @@ -25,6 +25,7 @@ package com.github.weisj.darklaf.ui.tooltip; import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import javax.swing.border.Border; @@ -42,6 +43,16 @@ import java.beans.PropertyChangeListener; */ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListener, HierarchyListener { + public static final String KEY_PREFIX = "JToolTip."; + public static final String KEY_STYLE = KEY_PREFIX + "style"; + public static final String KEY_INSETS = KEY_PREFIX + "insets"; + public static final String KEY_POINTER_LOCATION = KEY_PREFIX + "pointerLocation"; + public static final String KEY_POINTER_WIDTH = KEY_PREFIX + "pointerWidth"; + public static final String KEY_POINTER_HEIGHT = KEY_PREFIX + "pointerHeight"; + public static final String KEY_PLAIN_TOOLTIP = "JComponent.plainTooltip"; + public static final String VARIANT_PLAIN = "plain"; + public static final String VARIANT_BALLOON = "balloon"; + protected JToolTip toolTip; protected MouseListener exitListener = new MouseAdapter() { @Override @@ -84,7 +95,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe public static ComponentUI createUI(final JComponent c) { - if (Boolean.TRUE.equals(c.getClientProperty("JComponent.plainTooltip"))) { + if (Boolean.TRUE.equals(c.getClientProperty(KEY_PLAIN_TOOLTIP))) { return BasicToolTipUI.createUI(c); } else { return new DarkTooltipUI(); @@ -132,7 +143,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe super.installDefaults(c); c.setOpaque(false); if (c.getBorder() instanceof DarkTooltipBorder) { - Alignment align = (Alignment) c.getClientProperty("JToolTip.pointerLocation"); + Alignment align = (Alignment) c.getClientProperty(KEY_POINTER_LOCATION); ((DarkTooltipBorder) c.getBorder()).setPointerLocation(align == null ? Alignment.CENTER : align); } } @@ -181,7 +192,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe String text = ((JToolTip) c).getTipText(); if ((text != null) && !text.equals("")) { - View v = (View) c.getClientProperty("html"); + View v = (View) c.getClientProperty(PropertyKey.HTML); if (v != null) { prefSize.width += (int) v.getPreferredSpan(View.X_AXIS) + 6; prefSize.height += (int) v.getPreferredSpan(View.Y_AXIS); @@ -223,26 +234,26 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe if (tooltip.getBorder() instanceof DarkTooltipBorder) { DarkTooltipBorder border = (DarkTooltipBorder) tooltip.getBorder(); Object newVal = evt.getNewValue(); - if ("JToolTip.pointerLocation".equals(key)) { + if (KEY_POINTER_LOCATION.equals(key)) { if (newVal instanceof Alignment) { border.setPointerLocation((Alignment) newVal); } else { border.setPointerLocation(Alignment.CENTER); } updateSize(); - } else if ("JToolTip.pointerHeight".equals(key)) { + } else if (KEY_POINTER_HEIGHT.equals(key)) { if (newVal instanceof Integer) { border.setPointerHeight((Integer) newVal); } updateSize(); - } else if ("JToolTip.pointerWidth".equals(key)) { + } else if (KEY_POINTER_WIDTH.equals(key)) { if (newVal instanceof Integer) { border.setPointerWidth((Integer) newVal); } updateSize(); - } else if ("JToolTip.insets".equals(key)) { + } else if (KEY_INSETS.equals(key)) { updateSize(); - } else if ("component".equals(key)) { + } else if (PropertyKey.COMPONENT.equals(key)) { Object oldComp = evt.getOldValue(); if (oldComp instanceof Component) { ((Component) oldComp).removeMouseListener(mouseListener); @@ -253,7 +264,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe } } } - if ("JToolTip.style".equals(key)) { + if (KEY_STYLE.equals(key)) { tooltip.setPreferredSize(getPreferredSize(tooltip)); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java index a6272575..75821a7a 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java @@ -83,7 +83,7 @@ public class DarkDefaultTreeEditor extends DefaultTreeCellEditor { } protected DarkTreeCellEditor getBooleanEditor(final JTree table) { - if ("radioButton".equals(table.getClientProperty("JTree.booleanRenderType"))) { + if (DarkTreeUI.RENDER_TYPE_RADIOBUTTON.equals(table.getClientProperty(DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE))) { return radioButtonEditor; } return checkBoxEditor; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java index 6fb16bb0..4024eb8f 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java @@ -24,6 +24,7 @@ package com.github.weisj.darklaf.ui.tree; import com.github.weisj.darklaf.components.SelectableTreeNode; +import com.github.weisj.darklaf.ui.button.DarkToggleButtonUI; import com.github.weisj.darklaf.util.DarkUIUtil; import javax.swing.*; @@ -76,7 +77,7 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi } }; toggleButton.setFocusPainted(false); - toggleButton.putClientProperty("JToggleButton.isTreeCellEditor", Boolean.TRUE); + toggleButton.putClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR, Boolean.TRUE); toggleButton.addActionListener(delegate); toggleButton.setRequestFocusEnabled(false); toggleButton.addFocusListener(this); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRenderer.java b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRenderer.java index cd4cec28..d78f0dcf 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRenderer.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRenderer.java @@ -25,6 +25,7 @@ package com.github.weisj.darklaf.ui.tree; import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton; import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.darklaf.util.PropertyValue; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; @@ -72,18 +73,18 @@ public class DarkTreeCellRenderer extends DefaultTreeCellRenderer implements Tre } if (!(val instanceof Boolean)) { String str = String.valueOf(val); - if ("true".equals(str)) val = true; - if ("false".equals(str)) val = false; + if (PropertyValue.TRUE.equals(str)) val = true; + if (PropertyValue.FALSE.equals(str)) val = false; } return val; } protected static boolean isBooleanRenderingEnabled(final JTree tree) { - return Boolean.TRUE.equals(tree.getClientProperty("JTree.renderBooleanAsCheckBox")); + return Boolean.TRUE.equals(tree.getClientProperty(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX)); } protected DarkCellRendererToggleButton getBooleanRenderer(final JTree table) { - if ("radioButton".equals(table.getClientProperty("JTree.booleanRenderType"))) { + if (DarkTreeUI.RENDER_TYPE_RADIOBUTTON.equals(table.getClientProperty(DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE))) { return radioRenderer; } return checkBoxRenderer; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java index 5a0d60a4..2f9c5b29 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java @@ -23,6 +23,7 @@ */ package com.github.weisj.darklaf.ui.tree; +import com.github.weisj.darklaf.ui.button.DarkToggleButtonUI; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.SystemInfo; @@ -46,8 +47,18 @@ import java.util.Enumeration; */ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { - public static final String TREE_TABLE_TREE_KEY = "JTree.treeTableTree"; - public static final String STRIPED_CLIENT_PROPERTY = "JTree.alternateRowColor"; + public static final String KEY_PREFIX = "JTree."; + public static final String KEY_TREE_TABLE_TREE = KEY_PREFIX + "treeTableTree"; + 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_BOOLEAN_RENDER_TYPE = KEY_PREFIX + "booleanRenderType"; + public static final String KEY_LINE_STYLE = KEY_PREFIX + "lineStyle"; + public static final String KEY_MAC_ACTIONS_INSTALLED = "MacTreeUi.actionsInstalled"; + public static final String RENDER_TYPE_CHECKBOX = "checkBox"; + public static final String RENDER_TYPE_RADIOBUTTON = "radioButton"; + public static final String STYLE_LINE = "line"; + public static final String STYLE_DASHED = "dashed"; + public static final String STYLE_NONE = "none"; private final MouseListener selectionListener = new MouseAdapter() { boolean handled = false; @@ -132,7 +143,8 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { super.completeUIInstall(); myOldRepaintAllRowValue = UIManager.getBoolean("Tree.repaintWholeRow"); UIManager.put("Tree.repaintWholeRow", true); - tree.putClientProperty("JTree.alternateRowColor", UIManager.getBoolean("Tree.alternateRowColor")); + tree.putClientProperty(DarkTreeUI.KEY_ALTERNATE_ROW_COLOR, + UIManager.getBoolean("Tree.alternateRowColor")); } @Override @@ -152,11 +164,11 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { collapsedSelected = UIManager.getIcon("Tree.collapsed.selected.unfocused.icon"); collapsedFocus = UIManager.getIcon("Tree.collapsed.unselected.focused.icon"); collapsed = UIManager.getIcon("Tree.collapsed.unselected.unfocused.icon"); - tree.putClientProperty("JTree.renderBooleanAsCheckBox", + tree.putClientProperty(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX, UIManager.getBoolean("Tree.renderBooleanAsCheckBox")); - tree.putClientProperty("JTree.booleanRenderType", UIManager.getString("Tree.booleanRenderType")); + tree.putClientProperty(DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE, UIManager.getString("Tree.booleanRenderType")); tree.setShowsRootHandles(true); - tree.putClientProperty("JTree.lineStyle", "Line"); + tree.putClientProperty(KEY_LINE_STYLE, UIManager.getString("Tree.defaultLineStyle")); } @Override @@ -170,9 +182,9 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { protected void installKeyboardActions() { super.installKeyboardActions(); - if (Boolean.TRUE.equals(tree.getClientProperty("MacTreeUi.actionsInstalled"))) return; + if (Boolean.TRUE.equals(tree.getClientProperty(KEY_MAC_ACTIONS_INSTALLED))) return; - tree.putClientProperty("MacTreeUi.actionsInstalled", Boolean.TRUE); + tree.putClientProperty(KEY_MAC_ACTIONS_INSTALLED, Boolean.TRUE); final InputMap inputMap = tree.getInputMap(JComponent.WHEN_FOCUSED); inputMap.put(KeyStroke.getKeyStroke("pressed LEFT"), "collapse_or_move_up"); @@ -320,9 +332,9 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { if (!DarkUIUtil.hasFocus(tree)) { Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); boolean treeEditor = owner instanceof JComponent - && Boolean.TRUE.equals(((JComponent) owner).getClientProperty("JToggleButton.isTreeCellEditor")); + && Boolean.TRUE.equals(((JComponent) owner).getClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR)); boolean treeRenderer = owner instanceof JComponent - && Boolean.TRUE.equals(((JComponent) owner).getClientProperty("JToggleButton.isTreeCellRenderer")); + && Boolean.TRUE.equals(((JComponent) owner).getClientProperty(DarkToggleButtonUI.KEY_IS_TREE_RENDER)); return treeEditor || treeRenderer; } return true; @@ -499,10 +511,10 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { protected Color getRowBackground(final int row, final boolean selected) { if (selected) { - boolean isTableTree = Boolean.TRUE.equals(tree.getClientProperty(TREE_TABLE_TREE_KEY)); + boolean isTableTree = Boolean.TRUE.equals(tree.getClientProperty(KEY_TREE_TABLE_TREE)); return getTreeSelectionBackground(hasFocus() || isTableTree || tree.isEditing()); } - if (Boolean.TRUE.equals(tree.getClientProperty(STRIPED_CLIENT_PROPERTY)) && row % 2 == 1) { + if (Boolean.TRUE.equals(tree.getClientProperty(KEY_ALTERNATE_ROW_COLOR)) && row % 2 == 1) { return alternativeBackground; } else { return tree.getBackground(); @@ -510,7 +522,7 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { } protected boolean shouldPaintLines() { - return !"None".equals(getLineStyle()); + return !STYLE_NONE.equals(getLineStyle()); } protected Color getLineColor(final TreePath path) { @@ -545,7 +557,7 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { } protected String getLineStyle() { - return String.valueOf(tree.getClientProperty("JTree.lineStyle")); + return String.valueOf(tree.getClientProperty(KEY_LINE_STYLE)); } protected boolean selectedChildOf(final TreePath path) { @@ -557,7 +569,7 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { } protected boolean isDashedLine() { - return UIManager.getBoolean("Tree.lineTypeDashed") || "Dashed".equals(getLineStyle()); + return STYLE_DASHED.equals(getLineStyle()); } private void drawDashedLine(final Graphics g, final int x, int y1, final int y2) { @@ -703,13 +715,13 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { @Override public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); - if (STRIPED_CLIENT_PROPERTY.equals(key)) { + if (KEY_ALTERNATE_ROW_COLOR.equals(key)) { tree.repaint(); - } else if ("JTree.renderBooleanAsCheckBox".equals(key)) { + } else if (DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX.equals(key)) { tree.repaint(); - } else if ("JTree.booleanRenderType".equals(key)) { + } else if (DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE.equals(key)) { tree.repaint(); - } else if ("JTree.lineStyle".equals(key)) { + } else if (KEY_LINE_STYLE.equals(key)) { tree.repaint(); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java b/core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java index f73bb43e..c18d79da 100644 --- a/core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java +++ b/core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java @@ -51,7 +51,7 @@ public final class DarkUIUtil { public final static AlphaComposite GLOW_ALPHA = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f); public final static AlphaComposite DROP_ALPHA = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f); public final static AlphaComposite SHADOW_COMPOSITE = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f); - public static final boolean USE_QUARTZ = "true".equals(System.getProperty("apple.awt.graphics.UseQuartz")); + public static final boolean USE_QUARTZ = PropertyValue.TRUE.equals(System.getProperty("apple.awt.graphics.UseQuartz")); private static final Rectangle iconRect = new Rectangle(); private static final Rectangle textRect = new Rectangle(); @@ -196,8 +196,8 @@ public final class DarkUIUtil { } public static void doNotCancelPopupSetup(final JComponent component) { - component.putClientProperty("doNotCancelPopup", DarkPopupMenuUI.HIDE_POPUP_KEY); - component.putClientProperty("doNotCancelOnScroll", Boolean.TRUE); + component.putClientProperty(DarkPopupMenuUI.KEY_DO_NOT_CANCEL_POPUP, DarkPopupMenuUI.HIDE_POPUP_VALUE); + component.putClientProperty(DarkPopupMenuUI.KEY_DO_NOT_CANCEL_ON_SCROLL, Boolean.TRUE); } public static boolean isInCell(final Component c) { diff --git a/core/src/main/java/com/github/weisj/darklaf/util/GraphicsUtil.java b/core/src/main/java/com/github/weisj/darklaf/util/GraphicsUtil.java index e00ddfd2..80128869 100644 --- a/core/src/main/java/com/github/weisj/darklaf/util/GraphicsUtil.java +++ b/core/src/main/java/com/github/weisj/darklaf/util/GraphicsUtil.java @@ -92,6 +92,6 @@ public final class GraphicsUtil { } public static boolean isHighDpiEnabled() { - return "true".equalsIgnoreCase(System.getProperty("hidpi")); + return PropertyValue.TRUE.equalsIgnoreCase(System.getProperty("hidpi")); } } diff --git a/core/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java b/core/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java index 6f6086d2..06b34e51 100644 --- a/core/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java +++ b/core/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java @@ -24,6 +24,7 @@ package javax.swing.text.DefaultHighlighterDark; import com.github.weisj.darklaf.color.ColorWrapper; +import com.github.weisj.darklaf.ui.text.DarkTextUI; import com.github.weisj.darklaf.ui.text.StyleConstantsEx; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; @@ -31,12 +32,7 @@ import sun.swing.SwingUtilities2; import javax.swing.*; import javax.swing.plaf.TextUI; -import javax.swing.text.BadLocationException; -import javax.swing.text.DefaultHighlighter; -import javax.swing.text.Highlighter; -import javax.swing.text.JTextComponent; -import javax.swing.text.Position; -import javax.swing.text.View; +import javax.swing.text.*; import java.awt.*; import java.awt.geom.Arc2D; import java.awt.geom.Area; @@ -415,7 +411,7 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai private boolean isRounded(final JTextComponent c) { return !suppressRounded - && (roundedEdges || Boolean.TRUE.equals(c.getClientProperty("JTextComponent.roundedSelection"))); + && (roundedEdges || Boolean.TRUE.equals(c.getClientProperty(DarkTextUI.KEY_ROUNDED_SELECTION))); } private Shape paintExtension(final Graphics2D g2d, final JTextComponent c, diff --git a/core/src/main/resources/com/github/weisj/darklaf/properties/overwrites.properties b/core/src/main/resources/com/github/weisj/darklaf/properties/overwrites.properties index 7c78b37f..53887f3d 100644 --- a/core/src/main/resources/com/github/weisj/darklaf/properties/overwrites.properties +++ b/core/src/main/resources/com/github/weisj/darklaf/properties/overwrites.properties @@ -26,3 +26,4 @@ Table.renderBooleanAsCheckBox = tableBooleanRenderer Tree.renderBooleanAsCheckBox = treeBooleanRenderer TextComponent.roundedSelection = roundedSelection Button.convertIconOnlyToShadow = shadowIconButtons +Tree.defaultLineStyle = treeLineStyle diff --git a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tree.properties b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tree.properties index bfd0c6e3..9827150e 100644 --- a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tree.properties +++ b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tree.properties @@ -38,7 +38,6 @@ Tree.lineUnselected = %gridLine Tree.selectionForegroundInactive = %textSelectionForegroundInactive -Tree.lineTypeDashed = false Tree.textBackground = %textBackground Tree.rowHeight = 22 Tree.dropLineColor = %dropForeground @@ -48,6 +47,7 @@ Tree.alternateRowBackground = %backgroundAlternative Tree.renderBooleanAsCheckBox = true Tree.booleanRenderType = checkBox +Tree.defaultLineStyle = line Tree.editorBorderInsets = 2,5,2,5 diff --git a/core/src/test/java/UIDemo.java b/core/src/test/java/UIDemo.java index d9dfb079..978d0b03 100644 --- a/core/src/test/java/UIDemo.java +++ b/core/src/test/java/UIDemo.java @@ -3,6 +3,7 @@ import com.github.weisj.darklaf.components.text.SearchTextField; import com.github.weisj.darklaf.components.text.SearchTextFieldWithHistory; import com.github.weisj.darklaf.components.tristate.TristateCheckBox; import com.github.weisj.darklaf.icons.IconLoader; +import com.github.weisj.darklaf.ui.slider.DarkSliderUI; import org.jdesktop.swingx.JXStatusBar; import org.jdesktop.swingx.JXTaskPane; import org.jdesktop.swingx.JXTaskPaneContainer; @@ -208,19 +209,19 @@ public final class UIDemo { setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }}); add(new JSlider() {{ - putClientProperty("Slider.variant", "volume"); - putClientProperty("Slider.instantScrollEnabled", Boolean.TRUE); + putClientProperty(DarkSliderUI.KEY_VARIANT, DarkSliderUI.VARIANT_VOLUME); + putClientProperty(DarkSliderUI.KEY_INSTANT_SCROLL, Boolean.TRUE); }}); add(new JSlider() {{ putClientProperty("Slider.variant", "volume"); putClientProperty("Slider.instantScrollEnabled", Boolean.TRUE); - putClientProperty("Slider.volume.showIcon", Boolean.TRUE); + putClientProperty(DarkSliderUI.KEY_SHOW_VOLUME_ICON, Boolean.TRUE); }}); add(new JSlider() {{ setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); putClientProperty("Slider.variant", "volume"); putClientProperty("Slider.instantScrollEnabled", Boolean.TRUE); - putClientProperty("Slider.volume.showIcon", Boolean.TRUE); + putClientProperty(DarkSliderUI.KEY_SHOW_VOLUME_ICON, Boolean.TRUE); }}); }}); panel.add(new JPanel() {{ @@ -277,7 +278,7 @@ public final class UIDemo { setPaintLabels(true); putClientProperty("Slider.variant", "volume"); putClientProperty("Slider.instantScrollEnabled", Boolean.TRUE); - putClientProperty("Slider.volume.showIcon", Boolean.TRUE); + putClientProperty(DarkSliderUI.KEY_SHOW_VOLUME_ICON, Boolean.TRUE); }}); add(new JSlider() {{ setSnapToTicks(true); @@ -288,7 +289,7 @@ public final class UIDemo { setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); putClientProperty("Slider.variant", "volume"); putClientProperty("Slider.instantScrollEnabled", Boolean.TRUE); - putClientProperty("Slider.volume.showIcon", Boolean.TRUE); + putClientProperty(DarkSliderUI.KEY_SHOW_VOLUME_ICON, Boolean.TRUE); }}); }}); panel.add(new JPanel() {{ @@ -309,14 +310,14 @@ public final class UIDemo { setOrientation(VERTICAL); putClientProperty("Slider.variant", "volume"); putClientProperty("Slider.instantScrollEnabled", Boolean.TRUE); - putClientProperty("Slider.volume.showIcon", Boolean.TRUE); + putClientProperty(DarkSliderUI.KEY_SHOW_VOLUME_ICON, Boolean.TRUE); }}); add(new JSlider() {{ setOrientation(VERTICAL); setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); putClientProperty("Slider.variant", "volume"); putClientProperty("Slider.instantScrollEnabled", Boolean.TRUE); - putClientProperty("Slider.volume.showIcon", Boolean.TRUE); + putClientProperty(DarkSliderUI.KEY_SHOW_VOLUME_ICON, Boolean.TRUE); }}); }}); panel.add(new JPanel() {{ @@ -379,7 +380,7 @@ public final class UIDemo { setPaintLabels(true); putClientProperty("Slider.variant", "volume"); putClientProperty("Slider.instantScrollEnabled", Boolean.TRUE); - putClientProperty("Slider.volume.showIcon", Boolean.TRUE); + putClientProperty(DarkSliderUI.KEY_SHOW_VOLUME_ICON, Boolean.TRUE); }}); add(new JSlider() {{ setOrientation(VERTICAL); @@ -391,7 +392,7 @@ public final class UIDemo { setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); putClientProperty("Slider.variant", "volume"); putClientProperty("Slider.instantScrollEnabled", Boolean.TRUE); - putClientProperty("Slider.volume.showIcon", Boolean.TRUE); + putClientProperty(DarkSliderUI.KEY_SHOW_VOLUME_ICON, Boolean.TRUE); }}); }}); diff --git a/core/src/test/java/ui/button/ToggleButtonDemo.java b/core/src/test/java/ui/button/ToggleButtonDemo.java index c91379d9..b64adfa5 100644 --- a/core/src/test/java/ui/button/ToggleButtonDemo.java +++ b/core/src/test/java/ui/button/ToggleButtonDemo.java @@ -24,6 +24,7 @@ package ui.button; import com.github.weisj.darklaf.icons.IconLoader; +import com.github.weisj.darklaf.ui.button.DarkToggleButtonUI; import ui.ComponentDemo; import ui.DemoPanel; @@ -52,13 +53,13 @@ public class ToggleButtonDemo implements ComponentDemo { addActionListener(e -> button.setComponentOrientation(isSelected() ? ComponentOrientation.LEFT_TO_RIGHT : ComponentOrientation.RIGHT_TO_LEFT)); }}); - controlPanel.add(new JCheckBox("JToggleButton.isTreeCellEditor") {{ + controlPanel.add(new JCheckBox(DarkToggleButtonUI.KEY_IS_TREE_EDITOR) {{ setSelected(false); - addActionListener(e -> button.putClientProperty("JToggleButton.isTreeCellEditor", isSelected())); + addActionListener(e -> button.putClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR, isSelected())); }}); - controlPanel.add(new JCheckBox("JToggleButton.isTableCellEditor") {{ + controlPanel.add(new JCheckBox(DarkToggleButtonUI.KEY_IS_TABLE_EDITOR) {{ setSelected(false); - addActionListener(e -> button.putClientProperty("JToggleButton.isTableCellEditor", isSelected())); + addActionListener(e -> button.putClientProperty(DarkToggleButtonUI.KEY_IS_TABLE_EDITOR, isSelected())); }}); controlPanel.add(new JCheckBox("Rollover") {{ setSelected(button.isRolloverEnabled()); diff --git a/core/src/test/java/ui/checkBox/CheckBoxDemo.java b/core/src/test/java/ui/checkBox/CheckBoxDemo.java index 395ce755..1f1a92f3 100644 --- a/core/src/test/java/ui/checkBox/CheckBoxDemo.java +++ b/core/src/test/java/ui/checkBox/CheckBoxDemo.java @@ -23,6 +23,7 @@ */ package ui.checkBox; +import com.github.weisj.darklaf.ui.button.DarkToggleButtonUI; import ui.ComponentDemo; import ui.DemoPanel; @@ -54,13 +55,13 @@ public class CheckBoxDemo implements ComponentDemo { setSelected(button.isRolloverEnabled()); addActionListener(e -> button.setRolloverEnabled(isSelected())); }}); - controlPanel.add(new JCheckBox("JToggleButton.isTreeCellEditor") {{ + controlPanel.add(new JCheckBox(DarkToggleButtonUI.KEY_IS_TREE_EDITOR) {{ setSelected(false); - addActionListener(e -> button.putClientProperty("JToggleButton.isTreeCellEditor", isSelected())); + addActionListener(e -> button.putClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR, isSelected())); }}); - controlPanel.add(new JCheckBox("JToggleButton.isTableCellEditor") {{ + controlPanel.add(new JCheckBox(DarkToggleButtonUI.KEY_IS_TABLE_EDITOR) {{ setSelected(false); - addActionListener(e -> button.putClientProperty("JToggleButton.isTableCellEditor", isSelected())); + addActionListener(e -> button.putClientProperty(DarkToggleButtonUI.KEY_IS_TABLE_EDITOR, isSelected())); }}); return panel; } diff --git a/core/src/test/java/ui/checkBox/TriCheckBoxDemo.java b/core/src/test/java/ui/checkBox/TriCheckBoxDemo.java index 7f3fb9d2..b739eba5 100644 --- a/core/src/test/java/ui/checkBox/TriCheckBoxDemo.java +++ b/core/src/test/java/ui/checkBox/TriCheckBoxDemo.java @@ -24,6 +24,7 @@ package ui.checkBox; import com.github.weisj.darklaf.components.tristate.TristateCheckBox; +import com.github.weisj.darklaf.ui.button.DarkToggleButtonUI; import ui.ComponentDemo; import ui.DemoPanel; @@ -55,13 +56,13 @@ public class TriCheckBoxDemo implements ComponentDemo { setSelected(button.isRolloverEnabled()); addActionListener(e -> button.setRolloverEnabled(isSelected())); }}); - controlPanel.add(new JCheckBox("JToggleButton.isTreeCellEditor") {{ + controlPanel.add(new JCheckBox(DarkToggleButtonUI.KEY_IS_TREE_EDITOR) {{ setSelected(false); - addActionListener(e -> button.putClientProperty("JToggleButton.isTreeCellEditor", isSelected())); + addActionListener(e -> button.putClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR, isSelected())); }}); - controlPanel.add(new JCheckBox("JToggleButton.isTableCellEditor") {{ + controlPanel.add(new JCheckBox(DarkToggleButtonUI.KEY_IS_TABLE_EDITOR) {{ setSelected(false); - addActionListener(e -> button.putClientProperty("JToggleButton.isTableCellEditor", isSelected())); + addActionListener(e -> button.putClientProperty(DarkToggleButtonUI.KEY_IS_TABLE_EDITOR, isSelected())); }}); return panel; } diff --git a/core/src/test/java/ui/comboBox/ComboBoxDemo.java b/core/src/test/java/ui/comboBox/ComboBoxDemo.java index f28f6a38..5722b664 100644 --- a/core/src/test/java/ui/comboBox/ComboBoxDemo.java +++ b/core/src/test/java/ui/comboBox/ComboBoxDemo.java @@ -23,6 +23,7 @@ */ package ui.comboBox; +import com.github.weisj.darklaf.util.PropertyKey; import ui.ComponentDemo; import ui.DemoPanel; @@ -48,7 +49,7 @@ public class ComboBoxDemo implements ComponentDemo { setSelected(comboBox.isEnabled()); addActionListener(e -> comboBox.setEnabled(isSelected())); }}); - controlPanel.add(new JCheckBox("editable") {{ + controlPanel.add(new JCheckBox(PropertyKey.EDITABLE) {{ setSelected(comboBox.isEditable()); addActionListener(e -> comboBox.setEditable(isSelected())); }}); diff --git a/core/src/test/java/ui/list/ListDemo.java b/core/src/test/java/ui/list/ListDemo.java index 9dddc3b6..b6fce939 100644 --- a/core/src/test/java/ui/list/ListDemo.java +++ b/core/src/test/java/ui/list/ListDemo.java @@ -23,6 +23,7 @@ */ package ui.list; +import com.github.weisj.darklaf.ui.list.DarkListUI; import ui.ComponentDemo; import ui.DemoPanel; @@ -40,15 +41,15 @@ public final class ListDemo implements ComponentDemo { @Override public JComponent createComponent() { String[] week = {"Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday", "Sunday"}; + "Thursday", "Friday", "Saturday", "Sunday"}; JList list = new JList<>(week); list.setSelectedIndex(2); DemoPanel panel = new DemoPanel(list, new BorderLayout(), 0); JPanel controlPanel = panel.addControls(); - controlPanel.add(new JCheckBox("JList.alternateRowColor") {{ - setSelected(Boolean.TRUE.equals(list.getClientProperty("JList.alternateRowColor"))); - addActionListener(e -> list.putClientProperty("JList.alternateRowColor", isSelected())); + controlPanel.add(new JCheckBox(DarkListUI.KEY_ALTERNATE_ROW_COLOR) {{ + setSelected(Boolean.TRUE.equals(list.getClientProperty(DarkListUI.KEY_ALTERNATE_ROW_COLOR))); + addActionListener(e -> list.putClientProperty(DarkListUI.KEY_ALTERNATE_ROW_COLOR, isSelected())); }}, "span"); controlPanel = panel.addControls(); diff --git a/core/src/test/java/ui/radioButton/RadioButtonDemo.java b/core/src/test/java/ui/radioButton/RadioButtonDemo.java index 2d60497b..4e9c8a7a 100644 --- a/core/src/test/java/ui/radioButton/RadioButtonDemo.java +++ b/core/src/test/java/ui/radioButton/RadioButtonDemo.java @@ -23,6 +23,7 @@ */ package ui.radioButton; +import com.github.weisj.darklaf.ui.button.DarkToggleButtonUI; import ui.ComponentDemo; import ui.DemoPanel; @@ -54,13 +55,13 @@ public class RadioButtonDemo implements ComponentDemo { setSelected(button.isRolloverEnabled()); addActionListener(e -> button.setRolloverEnabled(isSelected())); }}); - controlPanel.add(new JCheckBox("JToggleButton.isTreeCellEditor") {{ + controlPanel.add(new JCheckBox(DarkToggleButtonUI.KEY_IS_TREE_EDITOR) {{ setSelected(false); - addActionListener(e -> button.putClientProperty("JToggleButton.isTreeCellEditor", isSelected())); + addActionListener(e -> button.putClientProperty(DarkToggleButtonUI.KEY_IS_TREE_EDITOR, isSelected())); }}); - controlPanel.add(new JCheckBox("JToggleButton.isTableCellEditor") {{ + controlPanel.add(new JCheckBox(DarkToggleButtonUI.KEY_IS_TABLE_EDITOR) {{ setSelected(false); - addActionListener(e -> button.putClientProperty("JToggleButton.isTableCellEditor", isSelected())); + addActionListener(e -> button.putClientProperty(DarkToggleButtonUI.KEY_IS_TABLE_EDITOR, isSelected())); }}); return panel; } diff --git a/core/src/test/java/ui/slider/SliderDemo.java b/core/src/test/java/ui/slider/SliderDemo.java index 09518bcc..c3cb67e6 100644 --- a/core/src/test/java/ui/slider/SliderDemo.java +++ b/core/src/test/java/ui/slider/SliderDemo.java @@ -23,6 +23,7 @@ */ package ui.slider; +import com.github.weisj.darklaf.ui.slider.DarkSliderUI; import ui.ComponentDemo; import ui.DemoPanel; @@ -83,14 +84,16 @@ public class SliderDemo implements ComponentDemo { setSelected(slider.getPaintTrack()); addActionListener(e -> slider.setPaintTrack(isSelected())); }}); - controlPanel.add(new JCheckBox("Slider.variant = volume") {{ - addActionListener(e -> slider.putClientProperty("Slider.variant", isSelected() ? "volume" : null)); + controlPanel.add(new JCheckBox(DarkSliderUI.KEY_VARIANT + " = " + DarkSliderUI.VARIANT_VOLUME) {{ + addActionListener(e -> slider.putClientProperty(DarkSliderUI.KEY_VARIANT, isSelected() + ? DarkSliderUI.VARIANT_VOLUME + : null)); }}); - controlPanel.add(new JCheckBox("Slider.instantScrollEnabled") {{ - addActionListener(e -> slider.putClientProperty("Slider.instantScrollEnabled", isSelected())); + controlPanel.add(new JCheckBox(DarkSliderUI.KEY_INSTANT_SCROLL) {{ + addActionListener(e -> slider.putClientProperty(DarkSliderUI.KEY_INSTANT_SCROLL, isSelected())); }}); - controlPanel.add(new JCheckBox("Slider.volume.showIcon") {{ - addActionListener(e -> slider.putClientProperty("Slider.volume.showIcon", isSelected())); + controlPanel.add(new JCheckBox(DarkSliderUI.KEY_SHOW_VOLUME_ICON) {{ + addActionListener(e -> slider.putClientProperty(DarkSliderUI.KEY_SHOW_VOLUME_ICON, isSelected())); }}); return panel; } diff --git a/core/src/test/java/ui/table/TableDemo.java b/core/src/test/java/ui/table/TableDemo.java index 8d578867..01b8a8e0 100644 --- a/core/src/test/java/ui/table/TableDemo.java +++ b/core/src/test/java/ui/table/TableDemo.java @@ -24,6 +24,7 @@ package ui.table; import com.github.weisj.darklaf.ui.table.DarkTableCellEditor; +import com.github.weisj.darklaf.util.PropertyKey; import ui.ComponentDemo; import ui.DemoPanel; @@ -80,7 +81,7 @@ public class TableDemo implements ComponentDemo { setSelected(table.isEnabled()); addActionListener(e -> table.setEnabled(isSelected())); }}); - controlPanel.add(new JCheckBox("editable") {{ + controlPanel.add(new JCheckBox(PropertyKey.EDITABLE) {{ setSelected(editable.get()); addActionListener(e -> editable.set(isSelected())); }}); diff --git a/core/src/test/java/ui/text/PasswordFieldDemo.java b/core/src/test/java/ui/text/PasswordFieldDemo.java index 99c9c317..80280079 100644 --- a/core/src/test/java/ui/text/PasswordFieldDemo.java +++ b/core/src/test/java/ui/text/PasswordFieldDemo.java @@ -23,6 +23,7 @@ */ package ui.text; +import com.github.weisj.darklaf.util.PropertyKey; import ui.ComponentDemo; import ui.DemoPanel; @@ -45,7 +46,7 @@ public class PasswordFieldDemo implements ComponentDemo { setSelected(textField.isEnabled()); addActionListener(e -> textField.setEnabled(isSelected())); }}); - controlPanel.add(new JCheckBox("editable") {{ + controlPanel.add(new JCheckBox(PropertyKey.EDITABLE) {{ setSelected(textField.isEditable()); addActionListener(e -> textField.setEditable(isSelected())); }}); diff --git a/core/src/test/java/ui/text/TextComponentDemo.java b/core/src/test/java/ui/text/TextComponentDemo.java index 63fb07fc..176ee900 100644 --- a/core/src/test/java/ui/text/TextComponentDemo.java +++ b/core/src/test/java/ui/text/TextComponentDemo.java @@ -24,6 +24,7 @@ package ui.text; import com.github.weisj.darklaf.ui.text.DarkTextBorder; +import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.StringUtil; import ui.ComponentDemo; import ui.DemoPanel; @@ -47,7 +48,7 @@ public abstract class TextComponentDemo implements Com setSelected(text.isEnabled()); addActionListener(e -> text.setEnabled(isSelected())); }}); - controlPanel.add(new JCheckBox("editable") {{ + controlPanel.add(new JCheckBox(PropertyKey.EDITABLE) {{ setSelected(text.isEditable()); addActionListener(e -> text.setEditable(isSelected())); }}); diff --git a/core/src/test/java/ui/text/TextFieldDemo.java b/core/src/test/java/ui/text/TextFieldDemo.java index 1651203e..4ce163cd 100644 --- a/core/src/test/java/ui/text/TextFieldDemo.java +++ b/core/src/test/java/ui/text/TextFieldDemo.java @@ -23,6 +23,7 @@ */ package ui.text; +import com.github.weisj.darklaf.util.PropertyKey; import ui.ComponentDemo; import ui.DemoPanel; @@ -45,7 +46,7 @@ public class TextFieldDemo implements ComponentDemo { setSelected(textField.isEnabled()); addActionListener(e -> textField.setEnabled(isSelected())); }}); - controlPanel.add(new JCheckBox("editable") {{ + controlPanel.add(new JCheckBox(PropertyKey.EDITABLE) {{ setSelected(textField.isEditable()); addActionListener(e -> textField.setEditable(isSelected())); }}); diff --git a/core/src/test/java/ui/tree/TreeDemo.java b/core/src/test/java/ui/tree/TreeDemo.java index a2db088a..6c27a9a4 100644 --- a/core/src/test/java/ui/tree/TreeDemo.java +++ b/core/src/test/java/ui/tree/TreeDemo.java @@ -25,6 +25,8 @@ package ui.tree; import com.github.weisj.darklaf.components.OverlayScrollPane; import com.github.weisj.darklaf.components.SelectableTreeNode; +import com.github.weisj.darklaf.ui.tree.DarkTreeUI; +import com.github.weisj.darklaf.util.PropertyKey; import net.miginfocom.swing.MigLayout; import ui.ComponentDemo; import ui.DemoPanel; @@ -58,7 +60,7 @@ public class TreeDemo implements ComponentDemo { DemoPanel panel = new DemoPanel(new OverlayScrollPane(tree), new BorderLayout(), 0); JPanel controlPanel = panel.addControls(); controlPanel.setLayout(new MigLayout("fillx, wrap 2", "[][grow]")); - controlPanel.add(new JCheckBox("editable") {{ + controlPanel.add(new JCheckBox(PropertyKey.EDITABLE) {{ setSelected(tree.isEditable()); addActionListener(e -> tree.setEditable(isSelected())); }}); @@ -71,20 +73,20 @@ public class TreeDemo implements ComponentDemo { setSelected(tree.getShowsRootHandles()); addActionListener(e -> tree.setShowsRootHandles(isSelected())); }}); - controlPanel.add(new JCheckBox("JTree.alternateRowColor") {{ - setSelected(Boolean.TRUE.equals(tree.getClientProperty("JTree.alternateRowColor"))); - addActionListener(e -> tree.putClientProperty("JTree.alternateRowColor", isSelected())); + controlPanel.add(new JCheckBox(DarkTreeUI.KEY_ALTERNATE_ROW_COLOR) {{ + setSelected(Boolean.TRUE.equals(tree.getClientProperty(DarkTreeUI.KEY_ALTERNATE_ROW_COLOR))); + addActionListener(e -> tree.putClientProperty(DarkTreeUI.KEY_ALTERNATE_ROW_COLOR, isSelected())); }}); - controlPanel.add(new JCheckBox("JTree.renderBooleanAsCheckBox") {{ - setSelected(Boolean.TRUE.equals(tree.getClientProperty("JTree.renderBooleanAsCheckBox"))); - addActionListener(e -> tree.putClientProperty("JTree.renderBooleanAsCheckBox", isSelected())); + controlPanel.add(new JCheckBox(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX) {{ + setSelected(Boolean.TRUE.equals(tree.getClientProperty(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX))); + addActionListener(e -> tree.putClientProperty(DarkTreeUI.KEY_RENDER_BOOLEAN_AS_CHECKBOX, isSelected())); }}, "span"); - controlPanel.add(new JLabel("JTree.booleanRenderType:", JLabel.RIGHT)); + controlPanel.add(new JLabel(DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE + ":", JLabel.RIGHT)); controlPanel.add(new JComboBox() {{ - addItem("checkBox"); - addItem("radioButton"); - setSelectedItem(tree.getClientProperty("JTree.booleanRenderType")); - addItemListener(e -> tree.putClientProperty("JTree.booleanRenderType", e.getItem())); + addItem(DarkTreeUI.RENDER_TYPE_CHECKBOX); + addItem(DarkTreeUI.RENDER_TYPE_RADIOBUTTON); + setSelectedItem(tree.getClientProperty(DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE)); + addItemListener(e -> tree.putClientProperty(DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE, e.getItem())); }}); controlPanel.add(new JLabel("JTree.lineStyle:", JLabel.RIGHT)); controlPanel.add(new JComboBox() {{ diff --git a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java index fb9261d8..898386b8 100644 --- a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java +++ b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java @@ -25,6 +25,7 @@ package com.github.weisj.darklaf.platform.macos.ui; import com.github.weisj.darklaf.decorations.CustomTitlePane; import com.github.weisj.darklaf.platform.macos.JNIDecorationsMacOS; +import com.github.weisj.darklaf.util.PropertyKey; import javax.swing.*; import java.awt.*; @@ -237,7 +238,7 @@ public class MacOSTitlePane extends CustomTitlePane { protected class PropertyChangeHandler implements PropertyChangeListener { public void propertyChange(final PropertyChangeEvent pce) { String name = pce.getPropertyName(); - if ("title".equals(name)) { + if (PropertyKey.TITLE.equals(name)) { titleLabel.setText(pce.getNewValue() == null ? "" : pce.getNewValue().toString()); repaint(); } diff --git a/property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java b/property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java index 3bc2578f..2576e481 100644 --- a/property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java @@ -27,6 +27,7 @@ import com.github.weisj.darklaf.icons.DarkUIAwareIcon; import com.github.weisj.darklaf.icons.EmptyIcon; import com.github.weisj.darklaf.icons.IconLoader; import com.github.weisj.darklaf.util.ColorUtil; +import com.github.weisj.darklaf.util.PropertyValue; import com.github.weisj.darklaf.util.StringUtil; import javax.swing.*; @@ -122,7 +123,7 @@ public final class PropertyLoader { private static Object parseValue(final String propertyKey, final String value, final boolean ignoreRequest, final Map defaults, final IconLoader iconLoader) { - if ("null".equals(value)) { + if (PropertyValue.NULL.equals(value)) { return null; } String key = propertyKey; @@ -148,22 +149,22 @@ public final class PropertyLoader { returnVal = parseIcon(value, iconLoader); } else if (key.endsWith("Size") || key.endsWith(".size")) { returnVal = parseSize(value); - } else if ("null".equalsIgnoreCase(value)) { + } else if (PropertyValue.NULL.equalsIgnoreCase(value)) { returnVal = null; } else if (value.startsWith("%")) { String val = value.substring(1); if (!defaults.containsKey(val)) { LOGGER.warning("Could not reference value '" + val + "'while loading '" + key + "'. " + - "May be a forward reference"); + "May be a forward reference"); } returnVal = defaults.get(val); } if (returnVal instanceof LoadError) { final Color color = ColorUtil.fromHex(value, null); final Integer invVal = getInteger(value); - final Boolean boolVal = "true".equalsIgnoreCase(value) + final Boolean boolVal = PropertyValue.TRUE.equalsIgnoreCase(value) ? Boolean.TRUE - : "false".equalsIgnoreCase(value) ? Boolean.FALSE : null; + : PropertyValue.FALSE.equalsIgnoreCase(value) ? Boolean.FALSE : null; if (color != null && (value.length() == 6 || value.length() == 8)) { return new ColorUIResource(color); } else if (invVal != null) { diff --git a/utils/src/main/java/com/github/weisj/darklaf/util/PropertyKey.java b/utils/src/main/java/com/github/weisj/darklaf/util/PropertyKey.java new file mode 100644 index 00000000..acb9de76 --- /dev/null +++ b/utils/src/main/java/com/github/weisj/darklaf/util/PropertyKey.java @@ -0,0 +1,46 @@ +/* + * 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; + +public class PropertyKey { + public static final String COMPONENT_ORIENTATION = "componentOrientation"; + public static final String LAYOUT_ORIENTATION = "layoutOrientation"; + public static final String ORIENTATION = "orientation"; + public static final String VALUE = "value"; + public static final String HTML = "html"; + public static final String COMPONENT = "component"; + public static final String OPAQUE = "opaque"; + public static final String ANCESTOR = "ancestor"; + public static final String EDITABLE = "editable"; + public static final String BACKGROUND = "background"; + public static final String FOREGROUND = "foreground"; + public static final String FONT = "font"; + public static final String DOCUMENT = "document"; + public static final String PAINTING_FOR_PRINT = "paintingForPrint"; + public static final String CARET = "caret"; + public static final String WINDOW_DECORATIONS_STYLE = "windowDecorationStyle"; + public static final String COMPONENT_POPUP_MENU = "componentPopupMenu"; + public static final String TITLE = "title"; + public static final String VISIBLE = "visible"; +} diff --git a/utils/src/main/java/com/github/weisj/darklaf/util/PropertyValue.java b/utils/src/main/java/com/github/weisj/darklaf/util/PropertyValue.java new file mode 100644 index 00000000..4fd2325c --- /dev/null +++ b/utils/src/main/java/com/github/weisj/darklaf/util/PropertyValue.java @@ -0,0 +1,30 @@ +/* + * 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; + +public class PropertyValue { + public static final String TRUE = "true"; + public static final String FALSE = "false"; + public static final String NULL = "null"; +} diff --git a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java index 198c0f9d..8b1e5bdc 100644 --- a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java +++ b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java @@ -29,6 +29,7 @@ import com.github.weisj.darklaf.icons.ScaledIcon; import com.github.weisj.darklaf.icons.ToggleIcon; import com.github.weisj.darklaf.platform.PointerUtil; import com.github.weisj.darklaf.platform.windows.JNIDecorationsWindows; +import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.Scale; import sun.awt.SunToolkit; @@ -46,6 +47,9 @@ import java.util.List; * @author Jannis Weis */ public class WindowsTitlePane extends CustomTitlePane { + public static final String KEY_RESIZABLE = "resizable"; + public static final String KEY_STATE = "state"; + public static final String KEY_ICON_IMAGE = "iconImage"; private static final int PAD = 5; private static final int BAR_HEIGHT = 28; private static final int BUTTON_WIDTH = 46; @@ -771,26 +775,26 @@ public class WindowsTitlePane extends CustomTitlePane { protected class PropertyChangeHandler implements PropertyChangeListener { public void propertyChange(final PropertyChangeEvent pce) { String name = pce.getPropertyName(); - if ("resizable".equals(name) || "state".equals(name)) { + if (KEY_RESIZABLE.equals(name) || KEY_STATE.equals(name)) { Frame frame = getFrame(); if (frame != null) { setState(frame.getExtendedState(), true); } - if ("resizable".equals(name)) { + if (KEY_RESIZABLE.equals(name)) { JNIDecorationsWindows.setResizable(windowHandle, Boolean.TRUE.equals(pce.getNewValue())); getRootPane().repaint(); } - } else if ("title".equals(name)) { + } else if (PropertyKey.TITLE.equals(name)) { titleLabel.setText(pce.getNewValue() == null ? "" : pce.getNewValue().toString()); repaint(); - } else if ("componentOrientation".equals(name)) { + } else if (PropertyKey.COMPONENT_ORIENTATION.equals(name)) { revalidate(); repaint(); - } else if ("iconImage".equals(name)) { + } else if (KEY_ICON_IMAGE.equals(name)) { updateSystemIcon(); revalidate(); repaint(); - } else if ("background".equals(name) && pce.getNewValue() instanceof Color) { + } else if (PropertyKey.BACKGROUND.equals(name) && pce.getNewValue() instanceof Color) { Color color = (Color) pce.getNewValue(); if (color == null) return; JNIDecorationsWindows.setBackground(windowHandle, color.getRed(), color.getGreen(), color.getBlue());