From c7bfa231334dddda434e64ab86f82a733b215c00 Mon Sep 17 00:00:00 2001 From: weisj Date: Tue, 18 Feb 2020 21:12:32 +0100 Subject: [PATCH] Fixed aware icons not updating on theme change. Signed-off-by: weisj --- .../github/weisj/darklaf/icons/DarkUIAwareIcon.java | 6 +++--- .../com/github/weisj/darklaf/icons/IconLoader.java | 13 +++++++++---- .../github/weisj/darklaf/icons/ThemedSVGIcon.java | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java index bd115393..3824694d 100644 --- a/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java @@ -60,7 +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); + IconLoader.registerAwareIcon(this); this.darkKey = darkKey; this.lightKey = lightKey; this.w = w; @@ -71,7 +71,7 @@ public class DarkUIAwareIcon implements UIAwareIcon, UIResource, Serializable { private DarkUIAwareIcon(final DarkUIAwareIcon dual) { - IconLoader.registerAwareIcon(this, null); + IconLoader.registerAwareIcon(this); this.darkKey = dual.lightKey; this.lightKey = dual.darkKey; this.dual = dual; @@ -98,7 +98,7 @@ public class DarkUIAwareIcon implements UIAwareIcon, UIResource, Serializable { private boolean isLoaded() { - return loaded && (currentStyle != IconLoader.getAwareStyle(this)); + return loaded && (currentStyle == IconLoader.getAwareStyle(this)); } private void loadIcon() { diff --git a/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java index 649f2701..5984e999 100644 --- a/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java @@ -39,8 +39,11 @@ 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 Object currentThemeKey; + private static AwareIconStyle currentAwareStyle; private static final int DEFAULT_W = 16; private static final int DEFAULT_H = 16; @@ -69,10 +72,12 @@ public final class IconLoader { } public static void updateAwareStyle(final AwareIconStyle style) { + currentAwareStyle = style; uiAwareIconStatus.entrySet().forEach(e -> e.setValue(style)); } public static void updateThemeStatus(final Object theme) { + currentThemeKey = theme; themedIconStatus.entrySet().forEach(e -> e.setValue(theme)); } @@ -84,12 +89,12 @@ public final class IconLoader { return themedIconStatus.get(icon); } - public static void registerAwareIcon(final UIAwareIcon icon, final AwareIconStyle style) { - uiAwareIconStatus.put(icon, style); + public static void registerAwareIcon(final UIAwareIcon icon) { + uiAwareIconStatus.put(icon, currentAwareStyle); } - public static void registerThemedIcon(final ThemedSVGIcon icon, final Object status) { - themedIconStatus.put(icon, status); + public static void registerThemedIcon(final ThemedSVGIcon icon) { + themedIconStatus.put(icon, currentThemeKey); } public DarkUIAwareIcon getUIAwareIcon(final String path) { 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 15795856..4ea62125 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, new Object()); + IconLoader.registerThemedIcon(this); } @Override