Browse Source

Theme: Specify predefined values for each OS

pull/336/head
Jannis Weis 2 years ago
parent
commit
d372be93d2
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 29
      core/src/main/java/com/github/weisj/darklaf/task/ThemeDefaultsInitTask.java
  2. 30
      core/src/main/resources/com/github/weisj/darklaf/nativelaf/predef_base.properties
  3. 14
      core/src/test/resources/com/github/weisj/darklaf/core/theme/my_custom_theme_defaults.properties
  4. 17
      property-loader/src/main/java/com/github/weisj/darklaf/properties/PropertyLoader.java
  5. 14
      theme/src/main/resources/com/github/weisj/darklaf/theme/darcula/darcula_defaults.properties
  6. 14
      theme/src/main/resources/com/github/weisj/darklaf/theme/high_contrast_dark/high_contrast_dark_defaults.properties
  7. 14
      theme/src/main/resources/com/github/weisj/darklaf/theme/high_contrast_light/high_contrast_light_defaults.properties
  8. 14
      theme/src/main/resources/com/github/weisj/darklaf/theme/intellij/intellij_defaults.properties
  9. 14
      theme/src/main/resources/com/github/weisj/darklaf/theme/one_dark/one_dark_defaults.properties
  10. 14
      theme/src/main/resources/com/github/weisj/darklaf/theme/solarized_dark/solarized_dark_defaults.properties
  11. 14
      theme/src/main/resources/com/github/weisj/darklaf/theme/solarized_light/solarized_light_defaults.properties

29
core/src/main/java/com/github/weisj/darklaf/task/ThemeDefaultsInitTask.java

@ -66,8 +66,9 @@ public class ThemeDefaultsInitTask implements DefaultsInitTask {
private void loadThemeDefaults(final Theme currentTheme, final UIDefaults defaults) { private void loadThemeDefaults(final Theme currentTheme, final UIDefaults defaults) {
Properties uiProps = new Properties(); Properties uiProps = new Properties();
currentTheme.loadDefaults(uiProps, defaults, DarkUIUtil.iconResolver()); initPlatformPredefinitions(uiProps, defaults);
currentTheme.loadDefaults(uiProps, defaults, DarkUIUtil.iconResolver());
backupAccentColors(uiProps); backupAccentColors(uiProps);
/* /*
@ -96,6 +97,17 @@ public class ThemeDefaultsInitTask implements DefaultsInitTask {
defaults.putAll(uiProps); defaults.putAll(uiProps);
} }
private void initPlatformPredefinitions(final Properties uiProps, final UIDefaults defaults) {
IconResolver iconResolver = DarkUIUtil.iconResolver();
Consumer<String> osPlatformLoader = osName -> PropertyLoader.putProperties(
PropertyLoader.loadProperties(
DarkLaf.class, osName, "nativelaf/",
PropertyLoader.LoadMode.AllowMissing),
uiProps, defaults, iconResolver);
osPlatformLoader.accept("predef_base");
setupOSSpecific("predef_", osPlatformLoader);
}
private void backupAccentColors(final Properties uiProps) { private void backupAccentColors(final Properties uiProps) {
uiProps.put(ACCENT_COLOR_BACKUP_KEY, Objects.requireNonNull( uiProps.put(ACCENT_COLOR_BACKUP_KEY, Objects.requireNonNull(
uiProps.get(ACCENT_COLOR_SOURCE_KEY), ACCENT_COLOR_SOURCE_KEY)); uiProps.get(ACCENT_COLOR_SOURCE_KEY), ACCENT_COLOR_SOURCE_KEY));
@ -162,13 +174,9 @@ public class ThemeDefaultsInitTask implements DefaultsInitTask {
private void initPlatformProperties(final Theme currentTheme, final UIDefaults defaults, final Properties uiProps) { private void initPlatformProperties(final Theme currentTheme, final UIDefaults defaults, final Properties uiProps) {
IconResolver iconResolver = DarkUIUtil.iconResolver(); IconResolver iconResolver = DarkUIUtil.iconResolver();
Consumer<String> osPlatformLoader = osName -> PropertyLoader.putProperties( setupOSSpecific("", osName -> PropertyLoader.putProperties(
PropertyLoader.loadProperties(DarkLaf.class, osName, "nativelaf/"), PropertyLoader.loadProperties(DarkLaf.class, osName, "nativelaf/"),
uiProps, defaults, iconResolver); uiProps, defaults, iconResolver));
osPlatformLoader.accept(getOsName());
if (SystemInfo.isWindows11()) {
osPlatformLoader.accept("windows11");
}
currentTheme.customizePlatformProperties(uiProps, defaults, iconResolver); currentTheme.customizePlatformProperties(uiProps, defaults, iconResolver);
} }
@ -177,6 +185,13 @@ public class ThemeDefaultsInitTask implements DefaultsInitTask {
return osName != null ? osName : SystemInfo.getOsName(); return osName != null ? osName : SystemInfo.getOsName();
} }
private void setupOSSpecific(final String prefix, final Consumer<String> setupFunction) {
setupFunction.accept(prefix + getOsName());
if (SystemInfo.isWindows11()) {
setupFunction.accept(prefix + "windows11");
}
}
private void adjustPlatformSpecifics(final Properties uiProps) { private void adjustPlatformSpecifics(final Properties uiProps) {
PropertyUtil.installSystemProperty(MAC_OS_MENU_BAR_KEY, "true"); PropertyUtil.installSystemProperty(MAC_OS_MENU_BAR_KEY, "true");
boolean useScreenMenuBar = Boolean.getBoolean(MAC_OS_MENU_BAR_KEY); boolean useScreenMenuBar = Boolean.getBoolean(MAC_OS_MENU_BAR_KEY);

30
core/src/main/resources/com/github/weisj/darklaf/nativelaf/predef_base.properties

@ -0,0 +1,30 @@
# MIT License
#
# Copyright (c) 2019-2023 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.
#
# suppress inspection "UnusedProperty" for whole file
%os_arc = 5
%os_arcFocus = 5
%os_arcSecondary = 3
%os_arcSecondaryFocus = 3
%os_borderThickness = 2
%os_shadowHeight = 2

14
core/src/test/resources/com/github/weisj/darklaf/core/theme/my_custom_theme_defaults.properties

@ -1,6 +1,6 @@
# MIT License # MIT License
# #
# Copyright (c) 2019-2021 Jannis Weis # Copyright (c) 2019-2023 Jannis Weis
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -131,10 +131,10 @@
%glowWarningLine = #F6CA7C %glowWarningLine = #F6CA7C
#Arc #Arc
%arc = 5 %arc = %os_arc
%arcFocus = 5 %arcFocus = %os_arcFocus
%arcSecondary = 3 %arcSecondary = %os_arcSecondary
%arcSecondaryFocus = 3 %arcSecondaryFocus = %os_arcSecondaryFocus
%borderThickness = 2 %borderThickness = %os_borderThickness
%shadowHeight = 2 %shadowHeight = %os_shadowHeight

17
property-loader/src/main/java/com/github/weisj/darklaf/properties/PropertyLoader.java

@ -1,7 +1,7 @@
/* /*
* MIT License * MIT License
* *
* Copyright (c) 2019-2021 Jannis Weis * Copyright (c) 2019-2023 Jannis Weis
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * 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, * associated documentation files (the "Software"), to deal in the Software without restriction,
@ -42,17 +42,30 @@ import com.github.weisj.darklaf.util.*;
* @author Jannis Weis * @author Jannis Weis
*/ */
public final class PropertyLoader { public final class PropertyLoader {
public enum LoadMode {
Strict,
AllowMissing
}
private static final Logger LOGGER = LogUtil.getLogger(PropertyLoader.class); private static final Logger LOGGER = LogUtil.getLogger(PropertyLoader.class);
private static final char REFERENCE_PREFIX = '%'; private static final char REFERENCE_PREFIX = '%';
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) {
return loadProperties(clazz, name, path, LoadMode.Strict);
}
public static Properties loadProperties(final Class<?> clazz, final String name, final String path,
final LoadMode mode) {
final Properties properties = new Properties(); final Properties properties = new Properties();
String p = path + name + ".properties"; String p = path + name + ".properties";
try (InputStream stream = clazz.getResourceAsStream(p)) { try (InputStream stream = clazz.getResourceAsStream(p)) {
properties.load(stream); properties.load(stream);
} catch (IOException | NullPointerException e) { } catch (IOException | NullPointerException e) {
LOGGER.log(Level.SEVERE, "Could not load " + p + " " + e.getMessage(), e); if (mode == LoadMode.Strict) {
LOGGER.log(Level.SEVERE, "Could not load " + p + " " + e.getMessage(), e);
}
} }
return properties; return properties;
} }

14
theme/src/main/resources/com/github/weisj/darklaf/theme/darcula/darcula_defaults.properties

@ -1,6 +1,6 @@
# MIT License # MIT License
# #
# Copyright (c) 2019-2021 Jannis Weis # Copyright (c) 2019-2023 Jannis Weis
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -155,10 +155,10 @@ Theme.highContrast = false
%glowWarningLine = #6e5324 %glowWarningLine = #6e5324
#Arc #Arc
%arc = 5 %arc = %os_arc
%arcFocus = 5 %arcFocus = %os_arcFocus
%arcSecondary = 3 %arcSecondary = %os_arcSecondary
%arcSecondaryFocus = 3 %arcSecondaryFocus = %os_arcSecondaryFocus
%borderThickness = 2 %borderThickness = %os_borderThickness
%shadowHeight = 2 %shadowHeight = %os_shadowHeight

14
theme/src/main/resources/com/github/weisj/darklaf/theme/high_contrast_dark/high_contrast_dark_defaults.properties

@ -1,6 +1,6 @@
# MIT License # MIT License
# #
# Copyright (c) 2020-2021 Jannis Weis # Copyright (c) 2020-2023 Jannis Weis
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -155,10 +155,10 @@ Theme.highContrast = true
%glowWarningLine = #F58231 %glowWarningLine = #F58231
#Arc #Arc
%arc = 5 %arc = %os_arc
%arcFocus = 5 %arcFocus = %os_arcFocus
%arcSecondary = 3 %arcSecondary = %os_arcSecondary
%arcSecondaryFocus = 3 %arcSecondaryFocus = %os_arcSecondaryFocus
%borderThickness = 2 %borderThickness = %os_borderThickness
%shadowHeight = 2 %shadowHeight = %os_shadowHeight

14
theme/src/main/resources/com/github/weisj/darklaf/theme/high_contrast_light/high_contrast_light_defaults.properties

@ -1,6 +1,6 @@
# MIT License # MIT License
# #
# Copyright (c) 2020-2021 Jannis Weis # Copyright (c) 2020-2023 Jannis Weis
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -155,10 +155,10 @@ Theme.highContrast = true
%glowWarningLine = #CE5B0A %glowWarningLine = #CE5B0A
#Arc #Arc
%arc = 5 %arc = %os_arc
%arcFocus = 5 %arcFocus = %os_arcFocus
%arcSecondary = 3 %arcSecondary = %os_arcSecondary
%arcSecondaryFocus = 3 %arcSecondaryFocus = %os_arcSecondaryFocus
%borderThickness = 2 %borderThickness = %os_borderThickness
%shadowHeight = 2 %shadowHeight = %os_shadowHeight

14
theme/src/main/resources/com/github/weisj/darklaf/theme/intellij/intellij_defaults.properties

@ -1,6 +1,6 @@
# MIT License # MIT License
# #
# Copyright (c) 2019-2021 Jannis Weis # Copyright (c) 2019-2023 Jannis Weis
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -157,10 +157,10 @@ Theme.highContrast = false
%glowWarningLine = #ffd385 %glowWarningLine = #ffd385
#Arc #Arc
%arc = 5 %arc = %os_arc
%arcFocus = 5 %arcFocus = %os_arcFocus
%arcSecondary = 3 %arcSecondary = %os_arcSecondary
%arcSecondaryFocus = 3 %arcSecondaryFocus = %os_arcSecondaryFocus
%borderThickness = 2 %borderThickness = %os_borderThickness
%shadowHeight = 2 %shadowHeight = %os_shadowHeight

14
theme/src/main/resources/com/github/weisj/darklaf/theme/one_dark/one_dark_defaults.properties

@ -1,6 +1,6 @@
# MIT License # MIT License
# #
# Copyright (c) 2020-2021 Jannis Weis # Copyright (c) 2020-2023 Jannis Weis
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -155,10 +155,10 @@ Theme.highContrast = false
%glowWarningLine = #5f4422 %glowWarningLine = #5f4422
#Arc #Arc
%arc = 5 %arc = %os_arc
%arcFocus = 5 %arcFocus = %os_arcFocus
%arcSecondary = 3 %arcSecondary = %os_arcSecondary
%arcSecondaryFocus = 3 %arcSecondaryFocus = %os_arcSecondaryFocus
%borderThickness = 2 %borderThickness = %os_borderThickness
%shadowHeight = 2 %shadowHeight = %os_shadowHeight

14
theme/src/main/resources/com/github/weisj/darklaf/theme/solarized_dark/solarized_dark_defaults.properties

@ -1,6 +1,6 @@
# MIT License # MIT License
# #
# Copyright (c) 2019-2021 Jannis Weis # Copyright (c) 2019-2023 Jannis Weis
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -156,10 +156,10 @@ Theme.highContrast = false
%glowWarningLine = #93A16A %glowWarningLine = #93A16A
#Arc #Arc
%arc = 5 %arc = %os_arc
%arcFocus = 5 %arcFocus = %os_arcFocus
%arcSecondary = 3 %arcSecondary = %os_arcSecondary
%arcSecondaryFocus = 3 %arcSecondaryFocus = %os_arcSecondaryFocus
%borderThickness = 2 %borderThickness = %os_borderThickness
%shadowHeight = 2 %shadowHeight = %os_shadowHeight

14
theme/src/main/resources/com/github/weisj/darklaf/theme/solarized_light/solarized_light_defaults.properties

@ -1,6 +1,6 @@
# MIT License # MIT License
# #
# Copyright (c) 2019-2021 Jannis Weis # Copyright (c) 2019-2023 Jannis Weis
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -155,10 +155,10 @@ Theme.highContrast = false
%glowWarningLine = #F6CA7C %glowWarningLine = #F6CA7C
#Arc #Arc
%arc = 5 %arc = %os_arc
%arcFocus = 5 %arcFocus = %os_arcFocus
%arcSecondary = 3 %arcSecondary = %os_arcSecondary
%arcSecondaryFocus = 3 %arcSecondaryFocus = %os_arcSecondaryFocus
%borderThickness = 2 %borderThickness = %os_borderThickness
%shadowHeight = 2 %shadowHeight = %os_shadowHeight

Loading…
Cancel
Save