Browse Source

Fixed property loading from different location.

Signed-off-by: weisj <weisj@arcor.de>
pull/48/head
weisj 5 years ago
parent
commit
c65475afb8
  1. 2
      core/src/main/java/com/github/weisj/darklaf/DarkLaf.java
  2. 1
      core/src/main/java/com/github/weisj/darklaf/LafManager.java
  3. 7
      core/src/main/java/com/github/weisj/darklaf/platform/JNIDecorations.java
  4. 15
      core/src/main/java/com/github/weisj/darklaf/theme/Theme.java
  5. 33
      property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java
  6. 2
      property-loader/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java
  7. 18
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java
  8. 57
      windows/src/main/resources/com/github/weisj/darklaf/platform/windows/windows_decorations.properties

2
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);

1
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

7
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);
}
}

15
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";
}

33
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<Object, Object> defaults) {
return parseValue(key, value, false, defaults);
final Map<Object, Object> 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<Object, Object> defaults) {
final boolean ignoreRequest, final Map<Object, Object> 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;

2
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

18
windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsDecorationsProvider.java → 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);
}
}

57
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

Loading…
Cancel
Save