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