diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4b2853ae..0c4ac545 100644 --- a/gradle/libs.versions.toml +++ b/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" } diff --git a/property-loader/build.gradle.kts b/property-loader/build.gradle.kts index c2b28ba0..e5fae30e 100644 --- a/property-loader/build.gradle.kts +++ b/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) } 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 5a62cd5e..98c56f28 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 @@ -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, RotateIcon, Serializable, ImageSource { +public class DarkSVGIcon + implements DerivableIcon, RotateIcon, Serializable, ImageSource, VisualPaddingProvider { private static final Logger LOGGER = LogUtil.getLogger(DarkSVGIcon.class); @@ -357,4 +364,21 @@ public class DarkSVGIcon implements DerivableIcon, 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); + } }