Browse Source

Fixed aware icons not updating on theme change.

Signed-off-by: weisj <weisj@arcor.de>
pull/52/head
weisj 5 years ago
parent
commit
c7bfa23133
  1. 6
      property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java
  2. 13
      property-loader/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java
  3. 2
      property-loader/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java

6
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() {

13
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<Class<?>, IconLoader> iconLoaderMap = new HashMap<>();
private static final IconLoader instance = new IconLoader(IconLoader.class);
private static final Map<UIAwareIcon, AwareIconStyle> uiAwareIconStatus = new WeakHashMap<>();
private static final Map<ThemedSVGIcon, Object> 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) {

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, new Object());
IconLoader.registerThemedIcon(this);
}
@Override

Loading…
Cancel
Save