|
|
@ -75,10 +75,11 @@ public final class IconColorMapper { |
|
|
|
for (Object child : children) { |
|
|
|
for (Object child : children) { |
|
|
|
if (child instanceof LinearGradient) { |
|
|
|
if (child instanceof LinearGradient) { |
|
|
|
String id = ((LinearGradient) child).getId(); |
|
|
|
String id = ((LinearGradient) child).getId(); |
|
|
|
String[] fallbacks = getFallbacks((LinearGradient) child); |
|
|
|
StyleAttribute fallbacks = getFallbacks((LinearGradient) child); |
|
|
|
float opacity = getOpacity((LinearGradient) child); |
|
|
|
String opacityKey = getOpacityKey((LinearGradient) child); |
|
|
|
Color c = resolveColor(id, fallbacks, FALLBACK_COLOR, defaults); |
|
|
|
float opacity = getOpacity(opacityKey); |
|
|
|
Pair<LinearGradient, Runnable> result = createColor(c, id, opacity); |
|
|
|
Color c = resolveColor(id, getFallbacks(fallbacks), FALLBACK_COLOR, defaults); |
|
|
|
|
|
|
|
Pair<LinearGradient, Runnable> result = createColor(c, id, opacityKey, fallbacks, opacity); |
|
|
|
LinearGradient gradient = result.getFirst(); |
|
|
|
LinearGradient gradient = result.getFirst(); |
|
|
|
Runnable finalizer = result.getSecond(); |
|
|
|
Runnable finalizer = result.getSecond(); |
|
|
|
themedDefs.loaderAddChild(null, gradient); |
|
|
|
themedDefs.loaderAddChild(null, gradient); |
|
|
@ -101,39 +102,59 @@ public final class IconColorMapper { |
|
|
|
return color; |
|
|
|
return color; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static String[] getFallbacks(final LinearGradient child) { |
|
|
|
private static StyleAttribute getFallbacks(final LinearGradient child) { |
|
|
|
StyleAttribute attribute = new StyleAttribute(); |
|
|
|
StyleAttribute attribute = new StyleAttribute(); |
|
|
|
attribute.setName("fallback"); |
|
|
|
attribute.setName("fallback"); |
|
|
|
try { |
|
|
|
try { |
|
|
|
child.getStyle(attribute); |
|
|
|
child.getStyle(attribute); |
|
|
|
} catch (SVGException e) { |
|
|
|
} catch (SVGException e) { |
|
|
|
return new String[0]; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
return attribute.getStringList(); |
|
|
|
return attribute; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static float getOpacity(final LinearGradient child) { |
|
|
|
private static String[] getFallbacks(final StyleAttribute fallbacks) { |
|
|
|
StyleAttribute attribute = new StyleAttribute(); |
|
|
|
if (fallbacks == null) return new String[0]; |
|
|
|
attribute.setName("opacity"); |
|
|
|
return fallbacks.getStringList(); |
|
|
|
try { |
|
|
|
} |
|
|
|
child.getStyle(attribute); |
|
|
|
|
|
|
|
} catch (SVGException e) { |
|
|
|
private static float getOpacity(final String key) { |
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// UIManager defaults to 0, if the values isn't an integer (or null).
|
|
|
|
// UIManager defaults to 0, if the values isn't an integer (or null).
|
|
|
|
Object obj = UIManager.get(attribute.getStringValue()); |
|
|
|
Object obj = UIManager.get(key); |
|
|
|
if (obj instanceof Integer) { |
|
|
|
if (obj instanceof Integer) { |
|
|
|
return ((Integer) obj) / 100.0f; |
|
|
|
return ((Integer) obj) / 100.0f; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (key != null && !key.isEmpty()) { |
|
|
|
|
|
|
|
LOGGER.warning(obj + " is an invalid opacity value. Key = '" + key + "'"); |
|
|
|
|
|
|
|
} |
|
|
|
// In this case we default to 1.
|
|
|
|
// In this case we default to 1.
|
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String getOpacityKey(final LinearGradient child) { |
|
|
|
|
|
|
|
StyleAttribute attribute = new StyleAttribute(); |
|
|
|
|
|
|
|
attribute.setName("opacity"); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
child.getStyle(attribute); |
|
|
|
|
|
|
|
} catch (SVGException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return attribute.getStringValue(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Pair<LinearGradient, Runnable> createColor(final Color c, |
|
|
|
private static Pair<LinearGradient, Runnable> createColor(final Color c, |
|
|
|
final String name, |
|
|
|
final String name, final String opacityKey, |
|
|
|
|
|
|
|
final StyleAttribute fallbacks, |
|
|
|
final float opacity) throws SVGElementException { |
|
|
|
final float opacity) throws SVGElementException { |
|
|
|
LinearGradient grad = new LinearGradient(); |
|
|
|
LinearGradient grad = new LinearGradient(); |
|
|
|
grad.addAttribute("id", AnimationElement.AT_XML, name); |
|
|
|
grad.addAttribute("id", AnimationElement.AT_XML, name); |
|
|
|
|
|
|
|
if (opacityKey != null) { |
|
|
|
|
|
|
|
grad.addAttribute("opacity", AnimationElement.AT_XML, opacityKey); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (fallbacks != null) { |
|
|
|
|
|
|
|
grad.addAttribute(fallbacks.getName(), AnimationElement.AT_XML, fallbacks.getStringValue()); |
|
|
|
|
|
|
|
} |
|
|
|
return new Pair<>(grad, () -> { |
|
|
|
return new Pair<>(grad, () -> { |
|
|
|
Stop stop1 = new Stop(); |
|
|
|
Stop stop1 = new Stop(); |
|
|
|
Stop stop2 = new Stop(); |
|
|
|
Stop stop2 = new Stop(); |
|
|
|