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. 23
      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.loadUIProperties(uiProps, defaults);
currentTheme.loadIconProperties(uiProps, defaults); currentTheme.loadIconProperties(uiProps, defaults);
currentTheme.loadPlatformProperties(uiProps, defaults); currentTheme.loadPlatformProperties(uiProps, defaults);
currentTheme.loadDecorationProperties(uiProps, defaults); JNIDecorations.loadDecorationProperties(uiProps, defaults);
adjustPlatformSpecifics(uiProps); adjustPlatformSpecifics(uiProps);
defaults.putAll(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() { public static void install() {
try { try {
getTheme();
UIManager.setLookAndFeel(DarkLaf.class.getCanonicalName()); UIManager.setLookAndFeel(DarkLaf.class.getCanonicalName());
updateLaf(); updateLaf();
} catch (final ClassNotFoundException } 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.CustomTitlePane;
import com.github.weisj.darklaf.decorations.JNIDecorationsProvider; 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 javax.swing.*;
import java.util.Properties;
public final class JNIDecorations { public final class JNIDecorations {
@ -54,4 +55,8 @@ public final class JNIDecorations {
public static boolean updateLibrary() { public static boolean updateLibrary() {
return decorationsProvider.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); 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() { private String getOsName() {
return SystemInfo.isMac ? "mac" : SystemInfo.isWindows ? "windows" : "linux"; 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) { public static Properties loadProperties(final Class<?> clazz, final String name, final String path) {
final Properties properties = new Properties(); 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); properties.load(stream);
} catch (IOException e) { } catch (IOException | NullPointerException e) {
LOGGER.log(Level.SEVERE, "Could not load" + name + ".properties", e.getMessage()); LOGGER.log(Level.SEVERE, "Could not load " + p + " " + e.getMessage(), e.getStackTrace());
} }
return properties; return properties;
} }
public static void putProperties(final Properties properties, final Properties accumulator, public static void putProperties(final Properties properties, final Properties accumulator,
final UIDefaults currentDefaults) { 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()) { for (final String key : properties.stringPropertyNames()) {
final String value = properties.getProperty(key); final String value = properties.getProperty(key);
Object parsed = parseValue(key, value, accumulator); Object parsed = parseValue(key, value, accumulator, iconLoader);
if (parsed instanceof ObjectRequest) { if (parsed instanceof ObjectRequest) {
objectsToLoad.add((ObjectRequest) parsed); objectsToLoad.add((ObjectRequest) parsed);
} else if (parsed != null) { } else if (parsed != null) {
@ -100,8 +106,8 @@ public final class PropertyLoader {
} }
private static Object parseValue(final String key, final String value, private static Object parseValue(final String key, final String value,
final Map<Object, Object> defaults) { final Map<Object, Object> defaults, final IconLoader iconLoader) {
return parseValue(key, value, false, defaults); return parseValue(key, value, false, defaults, iconLoader);
} }
private static String parseKey(final String key) { 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, 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)) { if ("null".equals(value)) {
return null; return null;
} }
@ -134,7 +141,7 @@ public final class PropertyLoader {
} else if (key.endsWith(".font")) { } else if (key.endsWith(".font")) {
returnVal = parseFont(value); returnVal = parseFont(value);
} else if (key.endsWith(".icon") || key.endsWith("Icon")) { } else if (key.endsWith(".icon") || key.endsWith("Icon")) {
returnVal = parseIcon(value); returnVal = parseIcon(value, iconLoader);
} else if (key.endsWith("Size") || key.endsWith(".size")) { } else if (key.endsWith("Size") || key.endsWith(".size")) {
returnVal = parseSize(value); returnVal = parseSize(value);
} else if ("null".equalsIgnoreCase(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; String path = value;
Dimension dim = new Dimension(16, 16); Dimension dim = new Dimension(16, 16);
if (value.charAt(value.length() - 1) == ')') { if (value.charAt(value.length() - 1) == ')') {
@ -210,9 +217,9 @@ public final class PropertyLoader {
} }
String iconPath = path.substring(0, path.length() - tag.length()); String iconPath = path.substring(0, path.length() - tag.length());
if (tag.equals(THEMED_KEY)) { 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 { } 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)) { if (tag.equals(DUAL_KEY)) {
return icon.getDual(); return icon.getDual();
} else { } else {
@ -223,7 +230,7 @@ public final class PropertyLoader {
if (path.equals("empty")) { if (path.equals("empty")) {
return EmptyIcon.create(dim.width, dim.height); 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 { } else {
Object obj = parseObject(value); Object obj = parseObject(value);
if (obj == null) { if (obj == null) {
obj = parseValue(key, value, true, defaults); obj = parseValue(key, value, true, defaults, ICON_LOADER);
if (obj instanceof ObjectRequest) { if (obj instanceof ObjectRequest) {
LOGGER.severe("Failed to resolve object. " + this); LOGGER.severe("Failed to resolve object. " + this);
return; 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) { public ThemedSVGIcon(final URI uri, final int displayWidth, final int displayHeight) {
super(uri, displayWidth, displayHeight); super(uri, displayWidth, displayHeight);
IconLoader.registerThemedIcon(this, null); IconLoader.registerThemedIcon(this, new Object());
} }
@Override @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 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * 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.PropertyLoader;
import com.github.weisj.darklaf.decorations.CustomTitlePane; import com.github.weisj.darklaf.decorations.CustomTitlePane;
import com.github.weisj.darklaf.decorations.JNIDecorationsProvider; 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 javax.swing.*;
import java.util.Properties; import java.util.Properties;
@ -50,11 +51,12 @@ public class WindowsDecorationsProvider implements JNIDecorationsProvider {
@Override @Override
public void loadDecorationProperties(final Properties properties, final UIDefaults currentDefaults) { public void loadDecorationProperties(final Properties properties, final UIDefaults currentDefaults) {
PropertyLoader.putProperties(PropertyLoader.loadProperties(getClass(), "windows_decorations", IconLoader iconLoader = IconLoader.get(WindowsDecorationsProvider.class);
"properties/platform/"), PropertyLoader.putProperties(PropertyLoader.loadProperties(WindowsDecorationsProvider.class,
properties, currentDefaults); "windows_decorations", ""),
PropertyLoader.putProperties(PropertyLoader.loadProperties(getClass(), "windows_icons", properties, currentDefaults, iconLoader);
"properties/platform/"), PropertyLoader.putProperties(PropertyLoader.loadProperties(WindowsDecorationsProvider.class,
properties, currentDefaults); "windows_icons", ""),
properties, currentDefaults, iconLoader);
} }
} }

23
windows/src/main/resources/com/github/weisj/darklaf/platform/windows/windows_decorations.properties

@ -1,3 +1,4 @@
#
# MIT License # MIT License
# #
# Copyright (c) 2020 Jannis Weis # Copyright (c) 2020 Jannis Weis
@ -20,22 +21,20 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
# #
# suppress inspection "UnusedProperty" for whole file TitlePane.minimize.icon = icons/windows/minimize.svg[themed]
#TitlePane TitlePane.minimizeInactive.icon = icons/windows/minimizeInactive.svg[themed]
TitlePane.minimize.icon = windows/minimize.svg[themed] TitlePane.maximize.icon = icons/windows/maximize.svg[themed]
TitlePane.minimizeInactive.icon = windows/minimizeInactive.svg[themed] TitlePane.maximizeInactive.icon = icons/windows/maximizeInactive.svg[themed]
TitlePane.maximize.icon = windows/maximize.svg[themed] TitlePane.restore.icon = icons/windows/restore.svg[themed]
TitlePane.maximizeInactive.icon = windows/maximizeInactive.svg[themed] TitlePane.restoreInactive.icon = icons/windows/restoreInactive.svg[themed]
TitlePane.restore.icon = windows/restore.svg[themed] TitlePane.close.icon = icons/windows/closeActive.svg[themed]
TitlePane.restoreInactive.icon = windows/restoreInactive.svg[themed] TitlePane.closeInactive.icon = icons/windows/closeInactive.svg[themed]
TitlePane.close.icon = windows/closeActive.svg[themed] TitlePane.closeHover.icon = icons/windows/closeHover.svg[themed]
TitlePane.closeInactive.icon = windows/closeInactive.svg[themed]
TitlePane.closeHover.icon = windows/closeHover.svg[themed]
TitlePane.close.clickColor = F1707A TitlePane.close.clickColor = F1707A
TitlePane.close.rollOverColor = E81123 TitlePane.close.rollOverColor = E81123
TitlePane.icon = duke.svg TitlePane.icon = icons/duke.svg
TitlePane.borderColor = %borderSecondary TitlePane.borderColor = %borderSecondary
TitlePane.background = %background TitlePane.background = %background

Loading…
Cancel
Save