Browse Source

Provide mechanism to specify VisualPaddings for svg icons in the xml markup.

pull/245/head
weisj 4 years ago
parent
commit
fe19e2ebd2
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 1
      gradle/libs.versions.toml
  2. 2
      property-loader/build.gradle.kts
  3. 26
      property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java

1
gradle/libs.versions.toml

@ -18,6 +18,7 @@ jxlayer = { module = "org.swinglabs:jxlayer", version.ref = "jxlayer" }
swingx = { module = "org.swinglabs:swingx", version.ref = "swingx" }
svgSalamander = { module = "com.formdev:svgSalamander", version.ref = "svgSalamander" }
swingDslLafSupport = { module = "com.github.weisj:swing-extensions-laf-support", version.ref = "swingDsl" }
visualPaddings = { module = "com.github.weisj:swing-extensions-visual-padding", version.ref = "swingDsl" }
autoservice-annotations = { module = "com.google.auto.service:auto-service-annotations", version.ref = "autoservice" }
autoservice-processor = { module = "com.google.auto.service:auto-service", version.ref = "autoservice" }
nullabilityAnnotations = { module = "org.jetbrains:annotations", version.ref = "nullabilityAnnotations" }

2
property-loader/build.gradle.kts

@ -5,6 +5,8 @@ plugins {
dependencies {
api(projects.darklafUtils)
implementation(libs.svgSalamander)
implementation(libs.visualPaddings)
implementation(libs.nullabilityAnnotations)
testImplementation(libs.test.junit.api)
testRuntimeOnly(libs.test.junit.engine)
}

26
property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java

@ -32,9 +32,15 @@ import java.util.logging.Logger;
import javax.swing.UIManager;
import org.jetbrains.annotations.NotNull;
import com.github.weisj.darklaf.util.LogUtil;
import com.github.weisj.darklaf.util.Scale;
import com.github.weisj.swingdsl.visualpadding.VisualPaddingProvider;
import com.kitfox.svg.SVGException;
import com.kitfox.svg.SVGRoot;
import com.kitfox.svg.app.beans.SVGIcon;
import com.kitfox.svg.xml.StyleAttribute;
/**
* Icon from SVG image.
@ -42,7 +48,8 @@ import com.kitfox.svg.app.beans.SVGIcon;
* @author Jannis Weis
* @since 2019
*/
public class DarkSVGIcon implements DerivableIcon<DarkSVGIcon>, RotateIcon, Serializable, ImageSource {
public class DarkSVGIcon
implements DerivableIcon<DarkSVGIcon>, RotateIcon, Serializable, ImageSource, VisualPaddingProvider {
private static final Logger LOGGER = LogUtil.getLogger(DarkSVGIcon.class);
@ -357,4 +364,21 @@ public class DarkSVGIcon implements DerivableIcon<DarkSVGIcon>, RotateIcon, Seri
", image=" + image +
'}';
}
@Override
public @NotNull Insets getVisualPaddings(@NotNull Component component) {
SVGIcon icon = getSVGIcon();
SVGRoot root = icon.getSvgUniverse().getDiagram(icon.getSvgURI()).getRoot();
StyleAttribute attr = new StyleAttribute("visualPadding");
try {
if (root.getStyle(attr, false)) {
int[] paddings = attr.getIntList();
if (paddings.length == 4) {
return new Insets(paddings[0], paddings[1], paddings[2], paddings[3]);
}
}
} catch (SVGException ignore) {
}
return new Insets(0, 0, 0, 0);
}
}

Loading…
Cancel
Save