From ce1274869103a1e308f72ca7a59f6eccdeb101af Mon Sep 17 00:00:00 2001 From: weisj Date: Tue, 18 Feb 2020 15:22:58 +0100 Subject: [PATCH 1/2] Moved property loading to own module to make darklaf-windows self contained. Moved shared utility classes to own module. Signed-off-by: weisj --- core/build.gradle.kts | 5 +- .../com/github/weisj/darklaf/DarkLaf.java | 1 - .../com/github/weisj/darklaf/LafManager.java | 7 +- .../components/border/BubbleBorder.java | 2 +- .../components/tabframe/JTabFrame.java | 2 +- .../components/tabframe/PanelPopup.java | 2 +- .../components/tabframe/TabFrameContent.java | 2 +- .../tabframe/TabFrameContentPane.java | 2 +- .../components/tabframe/TabFramePopup.java | 2 +- .../components/tabframe/TabFrameTab.java | 2 +- .../tabframe/TabFrameTabContainer.java | 2 +- .../components/tabframe/TabFrameTabLabel.java | 2 +- .../components/tabframe/TabFrameUI.java | 2 +- .../components/tooltip/DarkToolTip.java | 2 +- .../components/tooltip/ToolTipContext.java | 2 +- .../tooltip/TooltipAwareButton.java | 2 +- .../tooltip/TooltipAwareToggleButton.java | 2 +- .../platform/DefaultDecorationsProvider.java | 5 ++ .../weisj/darklaf/theme/IntelliJTheme.java | 2 +- .../com/github/weisj/darklaf/theme/Theme.java | 2 +- .../ui/colorchooser/SlideComponent.java | 4 +- .../darklaf/ui/colorchooser/SwatchPanel.java | 8 +- .../darklaf/ui/tabframe/DarkPanelPopupUI.java | 2 +- .../DarkTabFrameComponentPopupMenu.java | 2 +- .../tabframe/DarkTabFrameTabContainerUI.java | 2 +- .../ui/tabframe/DarkTabFrameTabLabelUI.java | 2 +- .../darklaf/ui/tabframe/DarkTabFrameUI.java | 8 +- .../darklaf/ui/tabframe/TabFrameLayout.java | 2 +- .../ui/tabframe/TabFrameTransferHandler.java | 16 +--- .../darklaf/ui/tooltip/DarkTooltipBorder.java | 2 +- .../darklaf/ui/tooltip/DarkTooltipUI.java | 8 +- core/src/test/java/icon/AllIcons.java | 3 +- .../test/java/ui/tabFrame/TabFrameDemo.java | 2 +- .../src/test/java/ui/toolTip/ToolTipDemo.java | 2 +- .../decorations/JNIDecorationsProvider.java | 10 +++ .../weisj/darklaf/platform/SystemInfo.java | 12 --- property-loader/build.gradle.kts | 9 +++ .../github/weisj/darklaf}/PropertyLoader.java | 5 +- .../weisj/darklaf/icons/AwareIconStyle.java | 29 +++++++ .../weisj/darklaf/icons/DarkSVGIcon.java | 0 .../weisj/darklaf/icons/DarkUIAwareIcon.java | 14 ++-- .../github/weisj/darklaf/icons/EmptyIcon.java | 0 .../weisj/darklaf/icons/IconColorMapper.java | 9 +-- .../weisj/darklaf/icons/IconLoader.java | 29 ++++++- .../github/weisj/darklaf/icons/LazyIcon.java | 0 .../weisj/darklaf/icons/LazyImageIcon.java | 0 .../weisj/darklaf/icons/RotatableIcon.java | 2 +- .../weisj/darklaf/icons}/ScaledIcon.java | 12 ++- .../weisj/darklaf/icons/ThemedSVGIcon.java | 8 +- .../weisj/darklaf/icons/UIAwareIcon.java | 2 + settings.gradle.kts | 4 +- utils/build.gradle.kts | 3 + .../github/weisj/darklaf/util}/Alignment.java | 4 +- .../weisj/darklaf/util}/AlignmentHelper.java | 2 +- .../github/weisj/darklaf/util/ColorUtil.java | 1 - .../com/github/weisj/darklaf/util/Pair.java | 0 .../com/github/weisj/darklaf/util/Scale.java | 5 +- .../github/weisj/darklaf/util/StringUtil.java | 0 windows/build.gradle.kts | 2 + .../platform/windows/ui/CloseButtonUI.java | 79 ------------------- .../windows/ui/DarkTitlePaneWindows.java | 17 ++-- .../ui/WindowsDecorationsProvider.java | 12 +++ .../{ => platform/windows}/icons/duke.svg | 0 .../windows}/icons/windows/closeActive.svg | 0 .../windows}/icons/windows/closeHover.svg | 0 .../windows}/icons/windows/closeInactive.svg | 0 .../windows}/icons/windows/maximize.svg | 0 .../icons/windows/maximizeInactive.svg | 0 .../windows}/icons/windows/minimize.svg | 0 .../icons/windows/minimizeInactive.svg | 0 .../windows}/icons/windows/restore.svg | 0 .../icons/windows/restoreInactive.svg | 0 .../windows}/windows_decorations.properties | 0 .../windows}/windows_icons.properties | 0 74 files changed, 181 insertions(+), 202 deletions(-) create mode 100644 property-loader/build.gradle.kts rename {core/src/main/java/com/github/weisj/darklaf/util => property-loader/src/main/java/com/github/weisj/darklaf}/PropertyLoader.java (98%) create mode 100644 property-loader/src/main/java/com/github/weisj/darklaf/icons/AwareIconStyle.java rename {core => property-loader}/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java (100%) rename {core => property-loader}/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java (92%) rename {core => property-loader}/src/main/java/com/github/weisj/darklaf/icons/EmptyIcon.java (100%) rename {core => property-loader}/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java (94%) rename {core => property-loader}/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java (87%) rename {core => property-loader}/src/main/java/com/github/weisj/darklaf/icons/LazyIcon.java (100%) rename {core => property-loader}/src/main/java/com/github/weisj/darklaf/icons/LazyImageIcon.java (100%) rename {core => property-loader}/src/main/java/com/github/weisj/darklaf/icons/RotatableIcon.java (98%) rename {windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui => property-loader/src/main/java/com/github/weisj/darklaf/icons}/ScaledIcon.java (84%) rename {core => property-loader}/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java (91%) rename {core => property-loader}/src/main/java/com/github/weisj/darklaf/icons/UIAwareIcon.java (99%) create mode 100644 utils/build.gradle.kts rename {core/src/main/java/com/github/weisj/darklaf/components/alignment => utils/src/main/java/com/github/weisj/darklaf/util}/Alignment.java (98%) rename {core/src/main/java/com/github/weisj/darklaf/components/alignment => utils/src/main/java/com/github/weisj/darklaf/util}/AlignmentHelper.java (98%) rename {core => utils}/src/main/java/com/github/weisj/darklaf/util/ColorUtil.java (99%) rename {core => utils}/src/main/java/com/github/weisj/darklaf/util/Pair.java (100%) rename {core => utils}/src/main/java/com/github/weisj/darklaf/util/Scale.java (91%) rename {core => utils}/src/main/java/com/github/weisj/darklaf/util/StringUtil.java (100%) delete mode 100644 windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/CloseButtonUI.java rename windows/src/main/resources/com/github/weisj/darklaf/{ => platform/windows}/icons/duke.svg (100%) rename windows/src/main/resources/com/github/weisj/darklaf/{ => platform/windows}/icons/windows/closeActive.svg (100%) rename windows/src/main/resources/com/github/weisj/darklaf/{ => platform/windows}/icons/windows/closeHover.svg (100%) rename windows/src/main/resources/com/github/weisj/darklaf/{ => platform/windows}/icons/windows/closeInactive.svg (100%) rename windows/src/main/resources/com/github/weisj/darklaf/{ => platform/windows}/icons/windows/maximize.svg (100%) rename windows/src/main/resources/com/github/weisj/darklaf/{ => platform/windows}/icons/windows/maximizeInactive.svg (100%) rename windows/src/main/resources/com/github/weisj/darklaf/{ => platform/windows}/icons/windows/minimize.svg (100%) rename windows/src/main/resources/com/github/weisj/darklaf/{ => platform/windows}/icons/windows/minimizeInactive.svg (100%) rename windows/src/main/resources/com/github/weisj/darklaf/{ => platform/windows}/icons/windows/restore.svg (100%) rename windows/src/main/resources/com/github/weisj/darklaf/{ => platform/windows}/icons/windows/restoreInactive.svg (100%) rename windows/src/main/resources/com/github/weisj/darklaf/{properties/platform => platform/windows}/windows_decorations.properties (100%) rename windows/src/main/resources/com/github/weisj/darklaf/{properties/platform => platform/windows}/windows_icons.properties (100%) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index ed0ef6ca..36229a53 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -9,11 +9,12 @@ plugins { dependencies { implementation(project(":darklaf-native-utils")) + implementation(project(":darklaf-utils")) implementation(project(":darklaf-windows")) - implementation("com.formdev:svgSalamander") - implementation("net.java.dev.jna:jna") + implementation(project(":darklaf-property-loader")) implementation("org.swinglabs:jxlayer") compileOnly("org.swinglabs:swingx") + testImplementation("com.formdev:svgSalamander") testImplementation("org.swinglabs:swingx") } 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 185734ab..d08d538f 100644 --- a/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java +++ b/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java @@ -28,7 +28,6 @@ import com.github.weisj.darklaf.platform.JNIDecorations; import com.github.weisj.darklaf.platform.SystemInfo; import com.github.weisj.darklaf.theme.Theme; import com.github.weisj.darklaf.ui.popupmenu.DarkPopupMenuUI; -import com.github.weisj.darklaf.util.PropertyLoader; import sun.awt.AppContext; import javax.swing.*; diff --git a/core/src/main/java/com/github/weisj/darklaf/LafManager.java b/core/src/main/java/com/github/weisj/darklaf/LafManager.java index 785551a1..141e7e76 100644 --- a/core/src/main/java/com/github/weisj/darklaf/LafManager.java +++ b/core/src/main/java/com/github/weisj/darklaf/LafManager.java @@ -23,6 +23,8 @@ */ package com.github.weisj.darklaf; +import com.github.weisj.darklaf.icons.AwareIconStyle; +import com.github.weisj.darklaf.icons.IconLoader; import com.github.weisj.darklaf.theme.DarculaTheme; import com.github.weisj.darklaf.theme.IntelliJTheme; import com.github.weisj.darklaf.theme.Theme; @@ -110,7 +112,7 @@ public final class LafManager { */ public static Theme getTheme() { if (theme == null) { - theme = new IntelliJTheme(); + setTheme(new IntelliJTheme()); } return theme; } @@ -122,6 +124,9 @@ public final class LafManager { */ public static void setTheme(final Theme theme) { LafManager.theme = theme; + IconLoader.updateAwareStyle(theme.useDarkIcons() ? AwareIconStyle.DARK + : AwareIconStyle.LIGHT); + IconLoader.updateThemeStatus(theme); } diff --git a/core/src/main/java/com/github/weisj/darklaf/components/border/BubbleBorder.java b/core/src/main/java/com/github/weisj/darklaf/components/border/BubbleBorder.java index 78510a87..4a2f9390 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/border/BubbleBorder.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/border/BubbleBorder.java @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.components.border; -import com.github.weisj.darklaf.components.alignment.Alignment; +import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; 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 7f6b3951..0f0e6b4d 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 @@ -23,8 +23,8 @@ */ package com.github.weisj.darklaf.components.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.ui.tabframe.TabFrameTransferHandler; +import com.github.weisj.darklaf.util.Alignment; import javax.swing.*; import javax.swing.plaf.ComponentUI; 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 7feef01c..9ef71f1c 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 @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.components.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; +import com.github.weisj.darklaf.util.Alignment; import javax.swing.*; import java.awt.*; diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContent.java b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContent.java index f0aa1557..c4aa1239 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContent.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContent.java @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.components.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; +import com.github.weisj.darklaf.util.Alignment; import java.awt.*; diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContentPane.java b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContentPane.java index ace286e1..ac304573 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContentPane.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContentPane.java @@ -23,8 +23,8 @@ */ package com.github.weisj.darklaf.components.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.decorators.AncestorAdapter; +import com.github.weisj.darklaf.util.Alignment; import javax.swing.*; import javax.swing.event.AncestorEvent; 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 6bc865b4..83744f9b 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 @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.components.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; +import com.github.weisj.darklaf.util.Alignment; import javax.swing.*; import java.awt.*; 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 76d09d11..42a0ee7f 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 @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.components.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; +import com.github.weisj.darklaf.util.Alignment; import java.awt.*; 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 e68bb737..963dfc79 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 @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.components.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; +import com.github.weisj.darklaf.util.Alignment; import javax.swing.*; import java.awt.*; 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 f3d91dc8..bdb73810 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 @@ -23,9 +23,9 @@ */ package com.github.weisj.darklaf.components.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.icons.EmptyIcon; import com.github.weisj.darklaf.ui.tabframe.DarkTabFrameTabLabelUI; +import com.github.weisj.darklaf.util.Alignment; import javax.swing.*; import java.awt.*; diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameUI.java b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameUI.java index febe9891..be1b828b 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameUI.java @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.components.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; +import com.github.weisj.darklaf.util.Alignment; import javax.swing.plaf.ComponentUI; import java.awt.*; 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 3199ddf1..dc1de80e 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 @@ -23,9 +23,9 @@ */ package com.github.weisj.darklaf.components.tooltip; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.decorators.AncestorAdapter; import com.github.weisj.darklaf.ui.tooltip.DarkTooltipBorder; +import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.Animator; import com.github.weisj.darklaf.util.GraphicsContext; diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java b/core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java index 6e40a637..55ad6e46 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java @@ -23,9 +23,9 @@ */ package com.github.weisj.darklaf.components.tooltip; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.alignment.AlignmentStrategy; import com.github.weisj.darklaf.ui.tooltip.DarkTooltipBorder; +import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.DarkUIUtil; import javax.swing.*; diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tooltip/TooltipAwareButton.java b/core/src/main/java/com/github/weisj/darklaf/components/tooltip/TooltipAwareButton.java index 7dc6fbe5..c96e41bf 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tooltip/TooltipAwareButton.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tooltip/TooltipAwareButton.java @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.components.tooltip; -import com.github.weisj.darklaf.components.alignment.Alignment; +import com.github.weisj.darklaf.util.Alignment; import javax.swing.*; import java.awt.*; diff --git a/core/src/main/java/com/github/weisj/darklaf/components/tooltip/TooltipAwareToggleButton.java b/core/src/main/java/com/github/weisj/darklaf/components/tooltip/TooltipAwareToggleButton.java index d389870e..fbe2201b 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/tooltip/TooltipAwareToggleButton.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/tooltip/TooltipAwareToggleButton.java @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.components.tooltip; -import com.github.weisj.darklaf.components.alignment.Alignment; +import com.github.weisj.darklaf.util.Alignment; import javax.swing.*; import java.awt.*; diff --git a/core/src/main/java/com/github/weisj/darklaf/platform/DefaultDecorationsProvider.java b/core/src/main/java/com/github/weisj/darklaf/platform/DefaultDecorationsProvider.java index fdb6233c..47cef96f 100644 --- a/core/src/main/java/com/github/weisj/darklaf/platform/DefaultDecorationsProvider.java +++ b/core/src/main/java/com/github/weisj/darklaf/platform/DefaultDecorationsProvider.java @@ -27,6 +27,7 @@ import com.github.weisj.darklaf.decorations.CustomTitlePane; import com.github.weisj.darklaf.decorations.JNIDecorationsProvider; import javax.swing.*; +import java.util.Properties; public class DefaultDecorationsProvider implements JNIDecorationsProvider { @Override @@ -47,4 +48,8 @@ public class DefaultDecorationsProvider implements JNIDecorationsProvider { public boolean updateLibrary() { return false; } + + @Override + public void loadDecorationProperties(final Properties properties, final UIDefaults currentDefaults) { + } } diff --git a/core/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java b/core/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java index 12be13ab..93111892 100644 --- a/core/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java +++ b/core/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.theme; -import com.github.weisj.darklaf.util.PropertyLoader; +import com.github.weisj.darklaf.PropertyLoader; import com.github.weisj.darklaf.platform.SystemInfo; import javax.swing.*; diff --git a/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java b/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java index 26f7eb66..e703522c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java +++ b/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java @@ -25,8 +25,8 @@ package com.github.weisj.darklaf.theme; import com.github.weisj.darklaf.DarkLaf; import com.github.weisj.darklaf.DarkMetalTheme; +import com.github.weisj.darklaf.PropertyLoader; import com.github.weisj.darklaf.platform.SystemInfo; -import com.github.weisj.darklaf.util.PropertyLoader; import javax.swing.*; import javax.swing.plaf.metal.MetalLookAndFeel; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SlideComponent.java b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SlideComponent.java index 0c19fd58..36c8de0d 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SlideComponent.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SlideComponent.java @@ -24,8 +24,8 @@ package com.github.weisj.darklaf.ui.colorchooser; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tooltip.ToolTipContext; +import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.ColorUtil; import com.github.weisj.darklaf.util.DarkUIUtil; @@ -311,4 +311,4 @@ class SlideComponent extends JComponent implements ColorListener { return LEVEL.equals(unit) ? LEVEL_MAX_VALUE : PERCENT_MAX_VALUE; } } -} \ No newline at end of file +} diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SwatchPanel.java b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SwatchPanel.java index 1059ccaa..71dd0944 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SwatchPanel.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SwatchPanel.java @@ -23,18 +23,14 @@ */ package com.github.weisj.darklaf.ui.colorchooser; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tooltip.ToolTipContext; +import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsUtil; import javax.swing.*; import java.awt.*; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; +import java.awt.event.*; /** * @author Jannis Weis 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 ae7c5c50..bdb6ef65 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 @@ -23,13 +23,13 @@ */ package com.github.weisj.darklaf.ui.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; 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.tooltip.ToolTipContext; import com.github.weisj.darklaf.components.uiresource.JLabelUIResource; import com.github.weisj.darklaf.ui.panel.DarkPanelUI; +import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.DarkUIUtil; import javax.swing.FocusManager; 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 07f2d8fb..df8ccec2 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 @@ -24,9 +24,9 @@ package com.github.weisj.darklaf.ui.tabframe; import com.github.weisj.darklaf.components.JXPopupMenu; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tabframe.TabFrameTab; import com.github.weisj.darklaf.icons.EmptyIcon; +import com.github.weisj.darklaf.util.Alignment; import javax.swing.*; import javax.swing.plaf.UIResource; 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 9b46acb9..631cc971 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 @@ -23,11 +23,11 @@ */ package com.github.weisj.darklaf.ui.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tabframe.JTabFrame; 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 javax.swing.*; 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 b46686bb..8ef4f013 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 @@ -23,12 +23,12 @@ */ package com.github.weisj.darklaf.ui.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tabframe.JTabFrame; 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 sun.swing.SwingUtilities2; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameUI.java index 8456210f..c8676b3c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameUI.java @@ -23,14 +23,10 @@ */ package com.github.weisj.darklaf.ui.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.border.MutableLineBorder; -import com.github.weisj.darklaf.components.tabframe.JTabFrame; -import com.github.weisj.darklaf.components.tabframe.PopupContainer; -import com.github.weisj.darklaf.components.tabframe.TabFramePopup; -import com.github.weisj.darklaf.components.tabframe.TabFrameTab; -import com.github.weisj.darklaf.components.tabframe.TabFrameUI; +import com.github.weisj.darklaf.components.tabframe.*; import com.github.weisj.darklaf.components.uiresource.JPanelUIResource; +import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.Pair; import org.jdesktop.jxlayer.JXLayer; import org.pbjar.jxlayer.plaf.ext.transform.DefaultTransformModel; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameLayout.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameLayout.java index 410590ce..a9ecdb90 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameLayout.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameLayout.java @@ -23,9 +23,9 @@ */ package com.github.weisj.darklaf.ui.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tabframe.JTabFrame; import com.github.weisj.darklaf.components.tabframe.TabFrameTab; +import com.github.weisj.darklaf.util.Alignment; import java.awt.*; import java.util.Arrays; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameTransferHandler.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameTransferHandler.java index 1c21bf48..b530bb7a 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameTransferHandler.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameTransferHandler.java @@ -23,11 +23,11 @@ */ package com.github.weisj.darklaf.ui.tabframe; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tabframe.JTabFrame; import com.github.weisj.darklaf.components.tabframe.TabFramePopup; import com.github.weisj.darklaf.components.tabframe.TabFrameTab; import com.github.weisj.darklaf.components.tabframe.TabFrameUI; +import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.ImageUtil; import javax.swing.*; @@ -35,19 +35,7 @@ import java.awt.*; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; -import java.awt.dnd.DragGestureEvent; -import java.awt.dnd.DragGestureListener; -import java.awt.dnd.DragGestureRecognizer; -import java.awt.dnd.DragSource; -import java.awt.dnd.DragSourceContext; -import java.awt.dnd.DragSourceDragEvent; -import java.awt.dnd.DragSourceDropEvent; -import java.awt.dnd.DragSourceEvent; -import java.awt.dnd.DragSourceListener; -import java.awt.dnd.DropTargetDragEvent; -import java.awt.dnd.DropTargetDropEvent; -import java.awt.dnd.DropTargetEvent; -import java.awt.dnd.DropTargetListener; +import java.awt.dnd.*; import java.awt.event.InputEvent; import java.awt.event.MouseEvent; 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 1d2a3bcf..c20c09a9 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 @@ -23,10 +23,10 @@ */ package com.github.weisj.darklaf.ui.tooltip; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.border.BubbleBorder; import com.github.weisj.darklaf.components.border.DropShadowBorder; import com.github.weisj.darklaf.components.tooltip.ToolTipStyle; +import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.DarkUIUtil; import javax.swing.*; 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 1108ce01..f1051ce4 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 @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.ui.tooltip; -import com.github.weisj.darklaf.components.alignment.Alignment; +import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.DarkUIUtil; import javax.swing.*; @@ -32,11 +32,7 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicToolTipUI; import javax.swing.text.View; import java.awt.*; -import java.awt.event.HierarchyEvent; -import java.awt.event.HierarchyListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; +import java.awt.event.*; import java.awt.geom.Area; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; diff --git a/core/src/test/java/icon/AllIcons.java b/core/src/test/java/icon/AllIcons.java index d9539484..18d5514c 100644 --- a/core/src/test/java/icon/AllIcons.java +++ b/core/src/test/java/icon/AllIcons.java @@ -93,7 +93,8 @@ public class AllIcons { for (File f : files) { if (f.getName().endsWith(".svg")) { int SIZE = 30; - ThemedSVGIcon icon = (ThemedSVGIcon) IconLoader.get().loadSVGIcon(folder + "/" + f.getName(), SIZE, SIZE, true); + ThemedSVGIcon icon = (ThemedSVGIcon) IconLoader.get().loadSVGIcon(folder + "/" + f.getName(), + SIZE, SIZE, true); SVGIcon svgIcon = icon.getSVGIcon(); int autosize = svgIcon.getAutosize(); svgIcon.setAutosize(SVGIcon.AUTOSIZE_NONE); diff --git a/core/src/test/java/ui/tabFrame/TabFrameDemo.java b/core/src/test/java/ui/tabFrame/TabFrameDemo.java index e89b3821..b1cc69c7 100644 --- a/core/src/test/java/ui/tabFrame/TabFrameDemo.java +++ b/core/src/test/java/ui/tabFrame/TabFrameDemo.java @@ -23,13 +23,13 @@ */ package ui.tabFrame; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tabframe.JTabFrame; import com.github.weisj.darklaf.components.tabframe.TabbedPopup; import com.github.weisj.darklaf.components.text.NonWrappingTextPane; import com.github.weisj.darklaf.components.text.NumberedTextComponent; import com.github.weisj.darklaf.components.text.NumberingPane; import com.github.weisj.darklaf.icons.IconLoader; +import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.StringUtil; import ui.ComponentDemo; import ui.DemoResources; diff --git a/core/src/test/java/ui/toolTip/ToolTipDemo.java b/core/src/test/java/ui/toolTip/ToolTipDemo.java index 3714ea7e..5137379b 100644 --- a/core/src/test/java/ui/toolTip/ToolTipDemo.java +++ b/core/src/test/java/ui/toolTip/ToolTipDemo.java @@ -23,11 +23,11 @@ */ package ui.toolTip; -import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.alignment.AlignmentStrategy; import com.github.weisj.darklaf.components.tooltip.ToolTipContext; import com.github.weisj.darklaf.components.tooltip.ToolTipStyle; import com.github.weisj.darklaf.components.tooltip.TooltipAwareButton; +import com.github.weisj.darklaf.util.Alignment; import ui.ComponentDemo; import ui.DemoPanel; diff --git a/native-utils/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorationsProvider.java b/native-utils/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorationsProvider.java index 16f0f000..44288d88 100644 --- a/native-utils/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorationsProvider.java +++ b/native-utils/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorationsProvider.java @@ -24,6 +24,7 @@ package com.github.weisj.darklaf.decorations; import javax.swing.*; +import java.util.Properties; public interface JNIDecorationsProvider { @@ -48,4 +49,13 @@ public interface JNIDecorationsProvider { * @return true if successful and library wasn't already loaded. */ boolean updateLibrary(); + + /** + * Load the necessary properties into the defaults. + * + * @param properties the properties to load the values into. + * @param currentDefaults the current ui defaults. + */ + void loadDecorationProperties(Properties properties, UIDefaults currentDefaults); + } diff --git a/native-utils/src/main/java/com/github/weisj/darklaf/platform/SystemInfo.java b/native-utils/src/main/java/com/github/weisj/darklaf/platform/SystemInfo.java index f981e8d7..99351775 100644 --- a/native-utils/src/main/java/com/github/weisj/darklaf/platform/SystemInfo.java +++ b/native-utils/src/main/java/com/github/weisj/darklaf/platform/SystemInfo.java @@ -23,15 +23,12 @@ */ package com.github.weisj.darklaf.platform; -import java.awt.*; -import java.util.logging.Logger; import java.util.regex.Pattern; /** * @author Konstantin Bulenkov */ public class SystemInfo { - public static final double SCALE; public static final String X86 = "32"; public static final String X64 = "64"; public static final String OS_NAME = System.getProperty("os.name"); @@ -52,9 +49,6 @@ public class SystemInfo { public static final boolean isX64; public static final boolean isUndefined; protected static final String _OS_NAME; - public static final double SCALE_X; - public static final double SCALE_Y; - private static final Logger LOGGER = Logger.getLogger(SystemInfo.class.getName()); static { _OS_NAME = OS_NAME.toLowerCase(); @@ -70,12 +64,6 @@ public class SystemInfo { isX64 = X64.equals(jreArchitecture); isX86 = X86.equals(jreArchitecture); isUndefined = !isX86 & !isX64; - DisplayMode mode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode(); - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - SCALE_X = mode.getWidth() / (double) screenSize.width; - SCALE_Y = mode.getHeight() / (double) screenSize.height; - SCALE = SCALE_X; - LOGGER.fine("Using screen scaling SCALE_X=" + SCALE_X + ", SCALE_Y=" + SCALE_Y); } public static boolean isOsVersionAtLeast(final String version) { diff --git a/property-loader/build.gradle.kts b/property-loader/build.gradle.kts new file mode 100644 index 00000000..a38b94f0 --- /dev/null +++ b/property-loader/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + `java-library` +} + +dependencies { + implementation(project(":darklaf-utils")) + implementation("com.formdev:svgSalamander") +} + diff --git a/core/src/main/java/com/github/weisj/darklaf/util/PropertyLoader.java b/property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java similarity index 98% rename from core/src/main/java/com/github/weisj/darklaf/util/PropertyLoader.java rename to property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java index 68571868..b721bca3 100644 --- a/core/src/main/java/com/github/weisj/darklaf/util/PropertyLoader.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java @@ -21,11 +21,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.github.weisj.darklaf.util; +package com.github.weisj.darklaf; 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.StringUtil; import javax.swing.*; import javax.swing.plaf.ColorUIResource; @@ -174,7 +176,6 @@ public final class PropertyLoader { Integer.parseInt(numbers.get(3))); } - private static Object parseFont(final String value) { try { final String[] decode = value.split("-"); diff --git a/property-loader/src/main/java/com/github/weisj/darklaf/icons/AwareIconStyle.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/AwareIconStyle.java new file mode 100644 index 00000000..60c83e54 --- /dev/null +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/AwareIconStyle.java @@ -0,0 +1,29 @@ +/* + * 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.icons; + +public enum AwareIconStyle { + DARK, + LIGHT +} diff --git a/core/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java similarity index 100% rename from core/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java rename to property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java diff --git a/core/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java similarity index 92% rename from core/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java rename to property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java index 35a98b3f..bd115393 100644 --- a/core/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.icons; -import com.github.weisj.darklaf.LafManager; -import com.github.weisj.darklaf.theme.Theme; - import javax.swing.*; import javax.swing.plaf.UIResource; import java.awt.*; @@ -46,9 +43,10 @@ public class DarkUIAwareIcon implements UIAwareIcon, UIResource, Serializable { private final int w; private final int h; private final Class parentClass; - private Theme currentTheme; private transient boolean loaded; private transient Icon icon; + private AwareIconStyle currentStyle; + /** * Create new ui aware icon. @@ -62,6 +60,7 @@ public class DarkUIAwareIcon implements UIAwareIcon, UIResource, Serializable { public DarkUIAwareIcon(final String darkKey, final String lightKey, final int w, final int h, final Class parentClass) { + IconLoader.registerAwareIcon(this, null); this.darkKey = darkKey; this.lightKey = lightKey; this.w = w; @@ -72,6 +71,7 @@ public class DarkUIAwareIcon implements UIAwareIcon, UIResource, Serializable { private DarkUIAwareIcon(final DarkUIAwareIcon dual) { + IconLoader.registerAwareIcon(this, null); this.darkKey = dual.lightKey; this.lightKey = dual.darkKey; this.dual = dual; @@ -98,12 +98,12 @@ public class DarkUIAwareIcon implements UIAwareIcon, UIResource, Serializable { private boolean isLoaded() { - return loaded && LafManager.getTheme().equals(currentTheme); + return loaded && (currentStyle != IconLoader.getAwareStyle(this)); } private void loadIcon() { - currentTheme = LafManager.getTheme(); - if (currentTheme.useDarkIcons()) { + currentStyle = IconLoader.getAwareStyle(this); + if (currentStyle == AwareIconStyle.DARK) { icon = IconLoader.get(parentClass).getIcon(darkKey, w, h); } else { icon = IconLoader.get(parentClass).getIcon(lightKey, w, h); diff --git a/core/src/main/java/com/github/weisj/darklaf/icons/EmptyIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/EmptyIcon.java similarity index 100% rename from core/src/main/java/com/github/weisj/darklaf/icons/EmptyIcon.java rename to property-loader/src/main/java/com/github/weisj/darklaf/icons/EmptyIcon.java diff --git a/core/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java similarity index 94% rename from core/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java rename to property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java index 968d8c37..fc107def 100644 --- a/core/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java @@ -24,14 +24,7 @@ package com.github.weisj.darklaf.icons; import com.github.weisj.darklaf.util.Pair; -import com.kitfox.svg.Defs; -import com.kitfox.svg.LinearGradient; -import com.kitfox.svg.SVGDiagram; -import com.kitfox.svg.SVGElement; -import com.kitfox.svg.SVGElementException; -import com.kitfox.svg.SVGRoot; -import com.kitfox.svg.SVGUniverse; -import com.kitfox.svg.Stop; +import com.kitfox.svg.*; import com.kitfox.svg.animation.AnimationElement; import com.kitfox.svg.app.beans.SVGIcon; diff --git a/core/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java similarity index 87% rename from core/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java rename to property-loader/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java index 589c297b..649f2701 100644 --- a/core/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java @@ -28,6 +28,7 @@ import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.WeakHashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -38,13 +39,15 @@ public final class IconLoader { private static final Logger LOGGER = Logger.getLogger(IconLoader.class.getName()); private static final Map, IconLoader> iconLoaderMap = new HashMap<>(); private static final IconLoader instance = new IconLoader(IconLoader.class); + private static final Map uiAwareIconStatus = new WeakHashMap<>(); + private static final Map themedIconStatus = new WeakHashMap<>(); + private static final int DEFAULT_W = 16; private static final int DEFAULT_H = 16; private final Class parentClass; private final Map awareIconMap = new HashMap<>(); private final Map iconMap = new HashMap<>(); - private IconLoader(final Class parentClass) { this.parentClass = parentClass; iconLoaderMap.put(parentClass, this); @@ -65,6 +68,30 @@ public final class IconLoader { } } + public static void updateAwareStyle(final AwareIconStyle style) { + uiAwareIconStatus.entrySet().forEach(e -> e.setValue(style)); + } + + public static void updateThemeStatus(final Object theme) { + themedIconStatus.entrySet().forEach(e -> e.setValue(theme)); + } + + public static AwareIconStyle getAwareStyle(final UIAwareIcon icon) { + return uiAwareIconStatus.get(icon); + } + + public static Object getThemeStatus(final ThemedSVGIcon icon) { + return themedIconStatus.get(icon); + } + + public static void registerAwareIcon(final UIAwareIcon icon, final AwareIconStyle style) { + uiAwareIconStatus.put(icon, style); + } + + public static void registerThemedIcon(final ThemedSVGIcon icon, final Object status) { + themedIconStatus.put(icon, status); + } + public DarkUIAwareIcon getUIAwareIcon(final String path) { return getUIAwareIcon(path, DEFAULT_W, DEFAULT_H); } diff --git a/core/src/main/java/com/github/weisj/darklaf/icons/LazyIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/LazyIcon.java similarity index 100% rename from core/src/main/java/com/github/weisj/darklaf/icons/LazyIcon.java rename to property-loader/src/main/java/com/github/weisj/darklaf/icons/LazyIcon.java diff --git a/core/src/main/java/com/github/weisj/darklaf/icons/LazyImageIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/LazyImageIcon.java similarity index 100% rename from core/src/main/java/com/github/weisj/darklaf/icons/LazyImageIcon.java rename to property-loader/src/main/java/com/github/weisj/darklaf/icons/LazyImageIcon.java diff --git a/core/src/main/java/com/github/weisj/darklaf/icons/RotatableIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/RotatableIcon.java similarity index 98% rename from core/src/main/java/com/github/weisj/darklaf/icons/RotatableIcon.java rename to property-loader/src/main/java/com/github/weisj/darklaf/icons/RotatableIcon.java index 1cf774fc..6f2b1041 100644 --- a/core/src/main/java/com/github/weisj/darklaf/icons/RotatableIcon.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/RotatableIcon.java @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.icons; -import com.github.weisj.darklaf.components.alignment.Alignment; +import com.github.weisj.darklaf.util.Alignment; import javax.swing.*; import java.awt.*; diff --git a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/ScaledIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/ScaledIcon.java similarity index 84% rename from windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/ScaledIcon.java rename to property-loader/src/main/java/com/github/weisj/darklaf/icons/ScaledIcon.java index e20912a0..e7804a09 100644 --- a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/ScaledIcon.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/ScaledIcon.java @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.github.weisj.darklaf.platform.windows.ui; +package com.github.weisj.darklaf.icons; -import com.github.weisj.darklaf.platform.SystemInfo; +import com.github.weisj.darklaf.util.Scale; import javax.swing.*; import java.awt.*; @@ -31,8 +31,6 @@ import java.awt.*; public class ScaledIcon implements Icon { private Image img; - - public ScaledIcon(final Image img) { this.img = img; } @@ -41,17 +39,17 @@ public class ScaledIcon implements Icon { public void paintIcon(final Component c, final Graphics g2, final int x, final int y) { Graphics2D g = (Graphics2D) g2; g.translate(x, y); - g.scale(1.0 / SystemInfo.SCALE_X, 1.0 / SystemInfo.SCALE_Y); + g.scale(1.0 / Scale.SCALE_X, 1.0 / Scale.SCALE_Y); g.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null); } @Override public int getIconWidth() { - return (int) (img.getWidth(null) / SystemInfo.SCALE_X); + return (int) (img.getWidth(null) / Scale.SCALE_X); } @Override public int getIconHeight() { - return (int) (img.getHeight(null) / SystemInfo.SCALE_Y); + return (int) (img.getHeight(null) / Scale.SCALE_Y); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java similarity index 91% rename from core/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java rename to property-loader/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java index c283a102..227f68de 100644 --- a/core/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.icons; -import com.github.weisj.darklaf.LafManager; -import com.github.weisj.darklaf.theme.Theme; - import java.awt.*; import java.net.URI; @@ -34,10 +31,11 @@ import java.net.URI; */ public class ThemedSVGIcon extends DarkSVGIcon { - private Theme currentTheme; + private Object currentTheme; public ThemedSVGIcon(final URI uri, final int displayWidth, final int displayHeight) { super(uri, displayWidth, displayHeight); + IconLoader.registerThemedIcon(this, null); } @Override @@ -47,7 +45,7 @@ public class ThemedSVGIcon extends DarkSVGIcon { } private void ensureTheme() { - Theme theme = LafManager.getTheme(); + Object theme = IconLoader.getThemeStatus(this); if (currentTheme != theme) { IconColorMapper.patchColors(getSVGIcon()); currentTheme = theme; diff --git a/core/src/main/java/com/github/weisj/darklaf/icons/UIAwareIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/UIAwareIcon.java similarity index 99% rename from core/src/main/java/com/github/weisj/darklaf/icons/UIAwareIcon.java rename to property-loader/src/main/java/com/github/weisj/darklaf/icons/UIAwareIcon.java index 706a5110..3878f484 100644 --- a/core/src/main/java/com/github/weisj/darklaf/icons/UIAwareIcon.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/UIAwareIcon.java @@ -31,4 +31,6 @@ import javax.swing.*; public interface UIAwareIcon extends Icon { UIAwareIcon getDual(); + + } diff --git a/settings.gradle.kts b/settings.gradle.kts index 028f9d61..51217fd1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -18,7 +18,9 @@ include( "dependencies-bom", "native-utils", "core", - "windows" + "windows", + "property-loader", + "utils" ) for (p in rootProject.children) { diff --git a/utils/build.gradle.kts b/utils/build.gradle.kts new file mode 100644 index 00000000..f6727627 --- /dev/null +++ b/utils/build.gradle.kts @@ -0,0 +1,3 @@ +plugins { + `java-library` +} diff --git a/core/src/main/java/com/github/weisj/darklaf/components/alignment/Alignment.java b/utils/src/main/java/com/github/weisj/darklaf/util/Alignment.java similarity index 98% rename from core/src/main/java/com/github/weisj/darklaf/components/alignment/Alignment.java rename to utils/src/main/java/com/github/weisj/darklaf/util/Alignment.java index e18e6eb5..5e562b43 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/alignment/Alignment.java +++ b/utils/src/main/java/com/github/weisj/darklaf/util/Alignment.java @@ -21,12 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.github.weisj.darklaf.components.alignment; +package com.github.weisj.darklaf.util; import java.awt.*; import java.util.function.BiFunction; -import static com.github.weisj.darklaf.components.alignment.AlignmentHelper.*; +import static com.github.weisj.darklaf.util.AlignmentHelper.*; /** * @author Jannis Weis diff --git a/core/src/main/java/com/github/weisj/darklaf/components/alignment/AlignmentHelper.java b/utils/src/main/java/com/github/weisj/darklaf/util/AlignmentHelper.java similarity index 98% rename from core/src/main/java/com/github/weisj/darklaf/components/alignment/AlignmentHelper.java rename to utils/src/main/java/com/github/weisj/darklaf/util/AlignmentHelper.java index 38629a09..e63cd80e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/alignment/AlignmentHelper.java +++ b/utils/src/main/java/com/github/weisj/darklaf/util/AlignmentHelper.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.github.weisj.darklaf.components.alignment; +package com.github.weisj.darklaf.util; import java.awt.*; import java.util.function.BiFunction; diff --git a/core/src/main/java/com/github/weisj/darklaf/util/ColorUtil.java b/utils/src/main/java/com/github/weisj/darklaf/util/ColorUtil.java similarity index 99% rename from core/src/main/java/com/github/weisj/darklaf/util/ColorUtil.java rename to utils/src/main/java/com/github/weisj/darklaf/util/ColorUtil.java index ae8bb6cc..8cb0c298 100644 --- a/core/src/main/java/com/github/weisj/darklaf/util/ColorUtil.java +++ b/utils/src/main/java/com/github/weisj/darklaf/util/ColorUtil.java @@ -82,7 +82,6 @@ public final class ColorUtil { } } - public static Color removeAlpha(final Color color) { return toAlpha(color, 255); } diff --git a/core/src/main/java/com/github/weisj/darklaf/util/Pair.java b/utils/src/main/java/com/github/weisj/darklaf/util/Pair.java similarity index 100% rename from core/src/main/java/com/github/weisj/darklaf/util/Pair.java rename to utils/src/main/java/com/github/weisj/darklaf/util/Pair.java diff --git a/core/src/main/java/com/github/weisj/darklaf/util/Scale.java b/utils/src/main/java/com/github/weisj/darklaf/util/Scale.java similarity index 91% rename from core/src/main/java/com/github/weisj/darklaf/util/Scale.java rename to utils/src/main/java/com/github/weisj/darklaf/util/Scale.java index d3eb7a3c..526612bb 100644 --- a/core/src/main/java/com/github/weisj/darklaf/util/Scale.java +++ b/utils/src/main/java/com/github/weisj/darklaf/util/Scale.java @@ -24,13 +24,11 @@ package com.github.weisj.darklaf.util; import java.awt.*; -import java.util.logging.Logger; -public final class Scale { +public class Scale { public static final double SCALE; public static final double SCALE_X; public static final double SCALE_Y; - private static final Logger LOGGER = Logger.getLogger(Scale.class.getName()); static { DisplayMode mode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode(); @@ -38,7 +36,6 @@ public final class Scale { SCALE_X = mode.getWidth() / (double) screenSize.width; SCALE_Y = mode.getHeight() / (double) screenSize.height; SCALE = SCALE_X; - LOGGER.info("Using screen scaling SCALE_X=" + SCALE_X + ", SCALE_Y=" + SCALE_Y); } diff --git a/core/src/main/java/com/github/weisj/darklaf/util/StringUtil.java b/utils/src/main/java/com/github/weisj/darklaf/util/StringUtil.java similarity index 100% rename from core/src/main/java/com/github/weisj/darklaf/util/StringUtil.java rename to utils/src/main/java/com/github/weisj/darklaf/util/StringUtil.java diff --git a/windows/build.gradle.kts b/windows/build.gradle.kts index 5e009bfb..ed96c1c9 100644 --- a/windows/build.gradle.kts +++ b/windows/build.gradle.kts @@ -9,6 +9,8 @@ fun DependencyHandlerScope.javaImplementation(dep: Any) { dependencies { javaImplementation(project(":darklaf-native-utils")) + javaImplementation(project(":darklaf-utils")) + javaImplementation(project(":darklaf-property-loader")) javaImplementation("net.java.dev.jna:jna") } diff --git a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/CloseButtonUI.java b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/CloseButtonUI.java deleted file mode 100644 index af8f785a..00000000 --- a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/CloseButtonUI.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.platform.windows.ui; - -import javax.swing.*; -import javax.swing.plaf.basic.BasicButtonUI; -import java.awt.*; - -/** - * @author Jannis Weis - */ -public class CloseButtonUI extends BasicButtonUI { - - protected static final Rectangle viewRect = new Rectangle(); - protected static final Rectangle textRect = new Rectangle(); - protected static final Rectangle iconRect = new Rectangle(); - - protected Color closeHover; - protected Color closeClick; - - @Override - protected void installDefaults(final AbstractButton b) { - super.installDefaults(b); - closeHover = UIManager.getColor("TitlePane.close.rollOverColor"); - closeClick = UIManager.getColor("TitlePane.close.clickColor"); - } - - protected String layout(final AbstractButton b, final JComponent c, final FontMetrics fm, - final int width, final int height) { - Insets i = b.getInsets(); - viewRect.x = i.left; - viewRect.y = i.top; - viewRect.width = width - (i.right + viewRect.x); - viewRect.height = height - (i.bottom + viewRect.y); - - textRect.x = textRect.y = textRect.width = textRect.height = 0; - iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0; - - // layout the text and icon - return SwingUtilities.layoutCompoundLabel( - b, fm, b.getText(), b.getIcon(), - b.getVerticalAlignment(), b.getHorizontalAlignment(), - b.getVerticalTextPosition(), b.getHorizontalTextPosition(), - viewRect, iconRect, textRect, - b.getText() == null ? 0 : b.getIconTextGap()); - } - - @Override - public void paint(final Graphics g, final JComponent c) { - g.setColor(getBackground((AbstractButton) c)); - g.fillRect(0, 0, c.getWidth(), c.getHeight()); - paintIcon(g, c, iconRect); - } - - protected Color getBackground(final AbstractButton c) { - return c.getModel().isArmed() ? closeClick : closeHover; - } -} diff --git a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/DarkTitlePaneWindows.java b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/DarkTitlePaneWindows.java index c529650f..0318d111 100644 --- a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/DarkTitlePaneWindows.java +++ b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/DarkTitlePaneWindows.java @@ -25,8 +25,9 @@ package com.github.weisj.darklaf.platform.windows.ui; import com.github.weisj.darklaf.decorations.CustomTitlePane; -import com.github.weisj.darklaf.platform.SystemInfo; +import com.github.weisj.darklaf.icons.ScaledIcon; import com.github.weisj.darklaf.platform.windows.JNIDecorationsWindows; +import com.github.weisj.darklaf.util.Scale; import sun.awt.SunToolkit; import javax.accessibility.AccessibleContext; @@ -574,12 +575,12 @@ public class DarkTitlePaneWindows extends CustomTitlePane { if (icons.size() == 0) { systemIcon = UIManager.getIcon("TitlePane.icon"); } else if (icons.size() == 1) { - systemIcon = new ScaledIcon(icons.get(0).getScaledInstance((int) (SystemInfo.SCALE_X * ICON_SIZE), - (int) (SystemInfo.SCALE_Y * ICON_SIZE), + systemIcon = new ScaledIcon(icons.get(0).getScaledInstance(Scale.scaleWidth(ICON_SIZE), + Scale.scaleHeight(ICON_SIZE), Image.SCALE_AREA_AVERAGING)); } else { - systemIcon = new ScaledIcon(SunToolkit.getScaledIconImage(icons, (int) (SystemInfo.SCALE_X * ICON_SIZE), - (int) (SystemInfo.SCALE_Y * ICON_SIZE)) + systemIcon = new ScaledIcon(SunToolkit.getScaledIconImage(icons, Scale.scaleWidth(ICON_SIZE), + Scale.scaleHeight(ICON_SIZE)) ); } if (windowIconButton != null) { @@ -713,9 +714,9 @@ public class DarkTitlePaneWindows extends CustomTitlePane { } JNIDecorationsWindows.updateValues(windowHandle, - (int) (SystemInfo.SCALE_X * left), - (int) (SystemInfo.SCALE_X * right), - (int) (SystemInfo.SCALE_Y * height)); + Scale.scaleWidth(left), + Scale.scaleWidth(right), + Scale.scaleHeight(height)); } diff --git a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsDecorationsProvider.java b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsDecorationsProvider.java index efb51cc5..eb21300e 100644 --- a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsDecorationsProvider.java +++ b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsDecorationsProvider.java @@ -23,11 +23,13 @@ */ package com.github.weisj.darklaf.platform.windows.ui; +import com.github.weisj.darklaf.PropertyLoader; import com.github.weisj.darklaf.decorations.CustomTitlePane; import com.github.weisj.darklaf.decorations.JNIDecorationsProvider; import com.github.weisj.darklaf.platform.windows.JNIDecorationsWindows; import javax.swing.*; +import java.util.Properties; public class WindowsDecorationsProvider implements JNIDecorationsProvider { @@ -45,4 +47,14 @@ public class WindowsDecorationsProvider implements JNIDecorationsProvider { public boolean updateLibrary() { return JNIDecorationsWindows.updateLibrary(); } + + @Override + public void loadDecorationProperties(final Properties properties, final UIDefaults currentDefaults) { + PropertyLoader.putProperties(PropertyLoader.loadProperties(getClass(), "windows_decorations", + "properties/platform/"), + properties, currentDefaults); + PropertyLoader.putProperties(PropertyLoader.loadProperties(getClass(), "windows_icons", + "properties/platform/"), + properties, currentDefaults); + } } diff --git a/windows/src/main/resources/com/github/weisj/darklaf/icons/duke.svg b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/duke.svg similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/icons/duke.svg rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/duke.svg diff --git a/windows/src/main/resources/com/github/weisj/darklaf/icons/windows/closeActive.svg b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/closeActive.svg similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/icons/windows/closeActive.svg rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/closeActive.svg diff --git a/windows/src/main/resources/com/github/weisj/darklaf/icons/windows/closeHover.svg b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/closeHover.svg similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/icons/windows/closeHover.svg rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/closeHover.svg diff --git a/windows/src/main/resources/com/github/weisj/darklaf/icons/windows/closeInactive.svg b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/closeInactive.svg similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/icons/windows/closeInactive.svg rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/closeInactive.svg diff --git a/windows/src/main/resources/com/github/weisj/darklaf/icons/windows/maximize.svg b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/maximize.svg similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/icons/windows/maximize.svg rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/maximize.svg diff --git a/windows/src/main/resources/com/github/weisj/darklaf/icons/windows/maximizeInactive.svg b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/maximizeInactive.svg similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/icons/windows/maximizeInactive.svg rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/maximizeInactive.svg diff --git a/windows/src/main/resources/com/github/weisj/darklaf/icons/windows/minimize.svg b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/minimize.svg similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/icons/windows/minimize.svg rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/minimize.svg diff --git a/windows/src/main/resources/com/github/weisj/darklaf/icons/windows/minimizeInactive.svg b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/minimizeInactive.svg similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/icons/windows/minimizeInactive.svg rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/minimizeInactive.svg diff --git a/windows/src/main/resources/com/github/weisj/darklaf/icons/windows/restore.svg b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/restore.svg similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/icons/windows/restore.svg rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/restore.svg diff --git a/windows/src/main/resources/com/github/weisj/darklaf/icons/windows/restoreInactive.svg b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/restoreInactive.svg similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/icons/windows/restoreInactive.svg rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/icons/windows/restoreInactive.svg diff --git a/windows/src/main/resources/com/github/weisj/darklaf/properties/platform/windows_decorations.properties b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/windows_decorations.properties similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/properties/platform/windows_decorations.properties rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/windows_decorations.properties diff --git a/windows/src/main/resources/com/github/weisj/darklaf/properties/platform/windows_icons.properties b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/windows_icons.properties similarity index 100% rename from windows/src/main/resources/com/github/weisj/darklaf/properties/platform/windows_icons.properties rename to windows/src/main/resources/com/github/weisj/darklaf/platform/windows/windows_icons.properties From c65475afb867c2d29d8ed46442fcd30d242c69d4 Mon Sep 17 00:00:00 2001 From: weisj Date: Tue, 18 Feb 2020 16:30:36 +0100 Subject: [PATCH 2/2] Fixed property loading from different location. Signed-off-by: weisj --- .../com/github/weisj/darklaf/DarkLaf.java | 2 +- .../com/github/weisj/darklaf/LafManager.java | 1 + .../darklaf/platform/JNIDecorations.java | 7 ++- .../com/github/weisj/darklaf/theme/Theme.java | 15 ----- .../github/weisj/darklaf/PropertyLoader.java | 33 ++++++----- .../weisj/darklaf/icons/ThemedSVGIcon.java | 2 +- .../{ui => }/WindowsDecorationsProvider.java | 18 +++--- .../windows/windows_decorations.properties | 57 +++++++++---------- 8 files changed, 67 insertions(+), 68 deletions(-) rename windows/src/main/java/com/github/weisj/darklaf/platform/windows/{ui => }/WindowsDecorationsProvider.java (84%) 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 d08d538f..67832e7e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java +++ b/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java @@ -166,7 +166,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener currentTheme.loadUIProperties(uiProps, defaults); currentTheme.loadIconProperties(uiProps, defaults); currentTheme.loadPlatformProperties(uiProps, defaults); - currentTheme.loadDecorationProperties(uiProps, defaults); + JNIDecorations.loadDecorationProperties(uiProps, defaults); adjustPlatformSpecifics(uiProps); defaults.putAll(uiProps); diff --git a/core/src/main/java/com/github/weisj/darklaf/LafManager.java b/core/src/main/java/com/github/weisj/darklaf/LafManager.java index 141e7e76..d47cc27e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/LafManager.java +++ b/core/src/main/java/com/github/weisj/darklaf/LafManager.java @@ -168,6 +168,7 @@ public final class LafManager { */ public static void install() { try { + getTheme(); UIManager.setLookAndFeel(DarkLaf.class.getCanonicalName()); updateLaf(); } catch (final ClassNotFoundException diff --git a/core/src/main/java/com/github/weisj/darklaf/platform/JNIDecorations.java b/core/src/main/java/com/github/weisj/darklaf/platform/JNIDecorations.java index b974a743..68dad573 100644 --- a/core/src/main/java/com/github/weisj/darklaf/platform/JNIDecorations.java +++ b/core/src/main/java/com/github/weisj/darklaf/platform/JNIDecorations.java @@ -25,9 +25,10 @@ package com.github.weisj.darklaf.platform; import com.github.weisj.darklaf.decorations.CustomTitlePane; import com.github.weisj.darklaf.decorations.JNIDecorationsProvider; -import com.github.weisj.darklaf.platform.windows.ui.WindowsDecorationsProvider; +import com.github.weisj.darklaf.platform.windows.WindowsDecorationsProvider; import javax.swing.*; +import java.util.Properties; public final class JNIDecorations { @@ -54,4 +55,8 @@ public final class JNIDecorations { public static boolean updateLibrary() { return decorationsProvider.updateLibrary(); } + + public static void loadDecorationProperties(final Properties uiProps, final UIDefaults defaults) { + decorationsProvider.loadDecorationProperties(uiProps, defaults); + } } diff --git a/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java b/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java index e703522c..18e86c51 100644 --- a/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java +++ b/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java @@ -139,21 +139,6 @@ public abstract class Theme { properties, currentDefaults); } - /** - * Load the platform defaults. - * - * @param properties the properties to load the values into. - * @param currentDefaults the current ui defaults. - */ - public void loadDecorationProperties(final Properties properties, final UIDefaults currentDefaults) { - PropertyLoader.putProperties(PropertyLoader.loadProperties(DarkLaf.class, getOsName() + "_decorations", - "properties/platform/"), - properties, currentDefaults); - PropertyLoader.putProperties(PropertyLoader.loadProperties(DarkLaf.class, getOsName() + "_icons", - "properties/platform/"), - properties, currentDefaults); - } - private String getOsName() { return SystemInfo.isMac ? "mac" : SystemInfo.isWindows ? "windows" : "linux"; } 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 b721bca3..32eee022 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 @@ -76,19 +76,25 @@ public final class PropertyLoader { public static Properties loadProperties(final Class clazz, final String name, final String path) { final Properties properties = new Properties(); - try (InputStream stream = clazz.getResourceAsStream(path + name + ".properties")) { + String p = path + name + ".properties"; + try (InputStream stream = clazz.getResourceAsStream(p)) { properties.load(stream); - } catch (IOException e) { - LOGGER.log(Level.SEVERE, "Could not load" + name + ".properties", e.getMessage()); + } catch (IOException | NullPointerException e) { + LOGGER.log(Level.SEVERE, "Could not load " + p + " " + e.getMessage(), e.getStackTrace()); } return properties; } public static void putProperties(final Properties properties, final Properties accumulator, final UIDefaults currentDefaults) { + putProperties(properties, accumulator, currentDefaults, ICON_LOADER); + } + + public static void putProperties(final Properties properties, final Properties accumulator, + final UIDefaults currentDefaults, final IconLoader iconLoader) { for (final String key : properties.stringPropertyNames()) { final String value = properties.getProperty(key); - Object parsed = parseValue(key, value, accumulator); + Object parsed = parseValue(key, value, accumulator, iconLoader); if (parsed instanceof ObjectRequest) { objectsToLoad.add((ObjectRequest) parsed); } else if (parsed != null) { @@ -100,8 +106,8 @@ public final class PropertyLoader { } private static Object parseValue(final String key, final String value, - final Map defaults) { - return parseValue(key, value, false, defaults); + final Map defaults, final IconLoader iconLoader) { + return parseValue(key, value, false, defaults, iconLoader); } private static String parseKey(final String key) { @@ -110,7 +116,8 @@ public final class PropertyLoader { private static Object parseValue(final String propertyKey, final String value, - final boolean ignoreRequest, final Map defaults) { + final boolean ignoreRequest, final Map defaults, + final IconLoader iconLoader) { if ("null".equals(value)) { return null; } @@ -134,7 +141,7 @@ public final class PropertyLoader { } else if (key.endsWith(".font")) { returnVal = parseFont(value); } else if (key.endsWith(".icon") || key.endsWith("Icon")) { - returnVal = parseIcon(value); + returnVal = parseIcon(value, iconLoader); } else if (key.endsWith("Size") || key.endsWith(".size")) { returnVal = parseSize(value); } else if ("null".equalsIgnoreCase(value)) { @@ -185,7 +192,7 @@ public final class PropertyLoader { } } - private static Icon parseIcon(final String value) { + private static Icon parseIcon(final String value, final IconLoader iconLoader) { String path = value; Dimension dim = new Dimension(16, 16); if (value.charAt(value.length() - 1) == ')') { @@ -210,9 +217,9 @@ public final class PropertyLoader { } String iconPath = path.substring(0, path.length() - tag.length()); if (tag.equals(THEMED_KEY)) { - return ICON_LOADER.getIcon(iconPath, dim.width, dim.height, true); + return iconLoader.getIcon(iconPath, dim.width, dim.height, true); } else { - DarkUIAwareIcon icon = ICON_LOADER.getUIAwareIcon(iconPath, dim.width, dim.height); + DarkUIAwareIcon icon = iconLoader.getUIAwareIcon(iconPath, dim.width, dim.height); if (tag.equals(DUAL_KEY)) { return icon.getDual(); } else { @@ -223,7 +230,7 @@ public final class PropertyLoader { if (path.equals("empty")) { return EmptyIcon.create(dim.width, dim.height); } - return ICON_LOADER.getIcon(path, dim.width, dim.height); + return iconLoader.getIcon(path, dim.width, dim.height); } @@ -270,7 +277,7 @@ public final class PropertyLoader { } else { Object obj = parseObject(value); if (obj == null) { - obj = parseValue(key, value, true, defaults); + obj = parseValue(key, value, true, defaults, ICON_LOADER); if (obj instanceof ObjectRequest) { LOGGER.severe("Failed to resolve object. " + this); return; diff --git a/property-loader/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java index 227f68de..15795856 100644 --- a/property-loader/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java @@ -35,7 +35,7 @@ public class ThemedSVGIcon extends DarkSVGIcon { public ThemedSVGIcon(final URI uri, final int displayWidth, final int displayHeight) { super(uri, displayWidth, displayHeight); - IconLoader.registerThemedIcon(this, null); + IconLoader.registerThemedIcon(this, new Object()); } @Override diff --git a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsDecorationsProvider.java b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java similarity index 84% rename from windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsDecorationsProvider.java rename to windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java index eb21300e..49b7f6e3 100644 --- a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsDecorationsProvider.java +++ b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java @@ -21,12 +21,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.github.weisj.darklaf.platform.windows.ui; +package com.github.weisj.darklaf.platform.windows; import com.github.weisj.darklaf.PropertyLoader; import com.github.weisj.darklaf.decorations.CustomTitlePane; import com.github.weisj.darklaf.decorations.JNIDecorationsProvider; -import com.github.weisj.darklaf.platform.windows.JNIDecorationsWindows; +import com.github.weisj.darklaf.icons.IconLoader; +import com.github.weisj.darklaf.platform.windows.ui.DarkTitlePaneWindows; import javax.swing.*; import java.util.Properties; @@ -50,11 +51,12 @@ public class WindowsDecorationsProvider implements JNIDecorationsProvider { @Override public void loadDecorationProperties(final Properties properties, final UIDefaults currentDefaults) { - PropertyLoader.putProperties(PropertyLoader.loadProperties(getClass(), "windows_decorations", - "properties/platform/"), - properties, currentDefaults); - PropertyLoader.putProperties(PropertyLoader.loadProperties(getClass(), "windows_icons", - "properties/platform/"), - properties, currentDefaults); + IconLoader iconLoader = IconLoader.get(WindowsDecorationsProvider.class); + PropertyLoader.putProperties(PropertyLoader.loadProperties(WindowsDecorationsProvider.class, + "windows_decorations", ""), + properties, currentDefaults, iconLoader); + PropertyLoader.putProperties(PropertyLoader.loadProperties(WindowsDecorationsProvider.class, + "windows_icons", ""), + properties, currentDefaults, iconLoader); } } diff --git a/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/windows_decorations.properties b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/windows_decorations.properties index 99af58f1..e209e237 100644 --- a/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/windows_decorations.properties +++ b/windows/src/main/resources/com/github/weisj/darklaf/platform/windows/windows_decorations.properties @@ -1,41 +1,40 @@ -#MIT License # -#Copyright (c) 2020 Jannis Weis +# MIT License # -#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: +# Copyright (c) 2020 Jannis Weis # -#The above copyright notice and this permission notice shall be included in all -#copies or substantial portions of the Software. +# 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 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. +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. # -# suppress inspection "UnusedProperty" for whole file -#TitlePane -TitlePane.minimize.icon = windows/minimize.svg[themed] -TitlePane.minimizeInactive.icon = windows/minimizeInactive.svg[themed] -TitlePane.maximize.icon = windows/maximize.svg[themed] -TitlePane.maximizeInactive.icon = windows/maximizeInactive.svg[themed] -TitlePane.restore.icon = windows/restore.svg[themed] -TitlePane.restoreInactive.icon = windows/restoreInactive.svg[themed] -TitlePane.close.icon = windows/closeActive.svg[themed] -TitlePane.closeInactive.icon = windows/closeInactive.svg[themed] -TitlePane.closeHover.icon = windows/closeHover.svg[themed] +# 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. +# +TitlePane.minimize.icon = icons/windows/minimize.svg[themed] +TitlePane.minimizeInactive.icon = icons/windows/minimizeInactive.svg[themed] +TitlePane.maximize.icon = icons/windows/maximize.svg[themed] +TitlePane.maximizeInactive.icon = icons/windows/maximizeInactive.svg[themed] +TitlePane.restore.icon = icons/windows/restore.svg[themed] +TitlePane.restoreInactive.icon = icons/windows/restoreInactive.svg[themed] +TitlePane.close.icon = icons/windows/closeActive.svg[themed] +TitlePane.closeInactive.icon = icons/windows/closeInactive.svg[themed] +TitlePane.closeHover.icon = icons/windows/closeHover.svg[themed] TitlePane.close.clickColor = F1707A TitlePane.close.rollOverColor = E81123 -TitlePane.icon = duke.svg +TitlePane.icon = icons/duke.svg TitlePane.borderColor = %borderSecondary TitlePane.background = %background