diff --git a/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java index fcf8494c..084f8d17 100644 --- a/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java @@ -131,7 +131,27 @@ public class DarkSVGIcon implements DerivableIcon, RotateIcon, Seri public Image createImage(final Dimension size) { ensureLoaded(false); icon.setPreferredSize(size); - return icon.getImage(); + try { + return icon.getImage(); + } catch (RuntimeException e) { + if (!(this instanceof ThemedSVGIcon)) { + IconColorMapper.patchColors(icon); + Image img = icon.getImage(); + /* + * If we get to here the issue was that the icon hasn't been patched because it isn't loaded as a themed + * svg icon. + */ + LOGGER.severe("Icon '" + getName() + "' that defines custom colors isn't loaded as themed icon."); + return img; + } + throw e; + } + } + + private String getName() { + String name = uri.toASCIIString(); + name = name.substring(Math.min(name.length() - 1, name.lastIndexOf('/') + 1)); + return name; } protected void ensureImageLoaded(final Component c, final double rotation) { diff --git a/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java index 26510aa0..ce9a66d7 100644 --- a/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java @@ -158,15 +158,15 @@ public final class IconColorMapper { final float opacity) throws SVGElementException { LinearGradient grad = new LinearGradient(); grad.addAttribute("id", AnimationElement.AT_XML, name); - if (opacityKey != null) { + if (opacityKey != null && !opacityKey.isEmpty()) { grad.addAttribute("opacity", AnimationElement.AT_XML, opacityKey); } - if (fallbacks != null) { + if (fallbacks != null && !fallbacks.getStringValue().isEmpty()) { grad.addAttribute(fallbacks.getName(), AnimationElement.AT_XML, fallbacks.getStringValue()); } return new Pair<>(grad, () -> { - Stop stop1 = new Stop(); - Stop stop2 = new Stop(); + SolidStop stop1 = new SolidStop(); + SolidStop stop2 = new SolidStop(); String color = toHexString(c); try { stop1.addAttribute("stop-color", AnimationElement.AT_XML, color); @@ -177,9 +177,11 @@ public final class IconColorMapper { stop1.addAttribute("stop-opacity", AnimationElement.AT_XML, String.valueOf(opacity)); stop2.addAttribute("stop-opacity", AnimationElement.AT_XML, String.valueOf(opacity)); } - grad.loaderAddChild(null, stop1); - grad.loaderAddChild(null, stop2); - } catch (SVGElementException e) { + stop1.build(); + stop2.build(); + grad.appendStop(stop1); + grad.appendStop(stop2); + } catch (SVGException e) { e.printStackTrace(); } }); @@ -188,4 +190,12 @@ public final class IconColorMapper { private static String toHexString(final Color color) { return "#" + ColorUtil.toHex(color); } + + private static class SolidStop extends Stop { + + @Override + public void build() throws SVGException { + super.build(); + } + } } 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 139ed829..c629f0f5 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 @@ -24,7 +24,6 @@ */ package com.github.weisj.darklaf.icons; -import java.awt.*; import java.net.URI; /**