From 3b5d390d3dd2977acf4f40bff3c481d326c45de2 Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Mon, 5 Apr 2021 22:34:23 +0200 Subject: [PATCH] Swing-DSL: Update implementation to match latest changes. --- build.gradle.kts | 4 ++ .../swingdsl/DarklafComponentFactory.java | 64 +++++++++++++++++-- .../darklaf/task/UtilityDefaultsInitTask.java | 5 +- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c9e5b836..723327a4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -100,6 +100,10 @@ allprojects { mavenCentral() } + configurations.all { + resolutionStrategy.cacheChangingModulesFor(0, "seconds") + } + val githubAccessToken by props("") plugins.withType { diff --git a/core/src/main/java/com/github/weisj/darklaf/swingdsl/DarklafComponentFactory.java b/core/src/main/java/com/github/weisj/darklaf/swingdsl/DarklafComponentFactory.java index 4498ecba..d9c849e8 100644 --- a/core/src/main/java/com/github/weisj/darklaf/swingdsl/DarklafComponentFactory.java +++ b/core/src/main/java/com/github/weisj/darklaf/swingdsl/DarklafComponentFactory.java @@ -21,18 +21,60 @@ */ package com.github.weisj.darklaf.swingdsl; -import javax.swing.BorderFactory; +import java.awt.Color; + +import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JScrollPane; -import javax.swing.border.Border; +import javax.swing.UIManager; import com.github.weisj.darklaf.components.OverlayScrollPane; -import com.github.weisj.darklaf.components.border.DarkBorders; +import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.swingdsl.laf.CollapsibleComponent; +import com.github.weisj.swingdsl.laf.ComponentFactoryDelegate; import com.github.weisj.swingdsl.laf.DefaultComponentFactory; +import com.github.weisj.swingdsl.laf.DefaultSupplier; import com.github.weisj.swingdsl.laf.DefaultWrappedComponent; +import com.github.weisj.swingdsl.laf.SeparatorSpec; +import com.github.weisj.swingdsl.laf.TextProperty; import com.github.weisj.swingdsl.laf.WrappedComponent; -public class DarklafComponentFactory extends DefaultComponentFactory { +public class DarklafComponentFactory extends ComponentFactoryDelegate { + + private final DefaultSupplier lineColorSupplier = enabled -> { + if (enabled) { + Color c = UIManager.getColor("borderSecondary"); + if (c != null) return c; + c = UIManager.getColor("Label.foreground"); + if (c != null) return c; + return Color.BLACK; + } else { + Color c = UIManager.getColor("widgetBorderInactive"); + if (c != null) return c; + c = UIManager.getColor("Label.disabledForeground"); + if (c != null) return c; + return Color.GRAY; + } + }; + private final DefaultSupplier expandedIconSupplier = enabled -> { + if (enabled) { + return DarkUIUtil.ICON_LOADER.getIcon("navigation/arrow/thick/arrowDown.svg"); + } else { + return DarkUIUtil.ICON_LOADER.getIcon("navigation/arrow/thick/arrowDownDisabled.svg"); + } + }; + private final DefaultSupplier collapsedIconSupplier = enabled -> { + if (enabled) { + return DarkUIUtil.ICON_LOADER.getIcon("navigation/arrow/thick/arrowRight.svg"); + } else { + return DarkUIUtil.ICON_LOADER.getIcon("navigation/arrow/thick/arrowRightDisabled.svg"); + } + }; + + public DarklafComponentFactory() { + super(DefaultComponentFactory.create()); + } + @Override public WrappedComponent createScrollPane(final JComponent content) { OverlayScrollPane sp = new OverlayScrollPane(content); @@ -40,7 +82,17 @@ public class DarklafComponentFactory extends DefaultComponentFactory { } @Override - public Border createDividerBorder(final String title) { - return BorderFactory.createTitledBorder(DarkBorders.createTopBorder(), title); + public SeparatorSpec createSeparatorComponent(final TextProperty label) { + return new SeparatorSpec<>(null, new SeparatorSpec.Default(lineColorSupplier)); + } + + @Override + public SeparatorSpec createCollapsibleSeparatorComponent( + final TextProperty label) { + return new SeparatorSpec<>(null, + new SeparatorSpec.DefaultCollapsible( + lineColorSupplier, + collapsedIconSupplier, + expandedIconSupplier)); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/task/UtilityDefaultsInitTask.java b/core/src/main/java/com/github/weisj/darklaf/task/UtilityDefaultsInitTask.java index bd028dda..0874c273 100644 --- a/core/src/main/java/com/github/weisj/darklaf/task/UtilityDefaultsInitTask.java +++ b/core/src/main/java/com/github/weisj/darklaf/task/UtilityDefaultsInitTask.java @@ -21,6 +21,8 @@ */ package com.github.weisj.darklaf.task; +import java.util.function.Supplier; + import javax.swing.*; import com.github.weisj.darklaf.graphics.PaintUtil; @@ -59,7 +61,8 @@ public class UtilityDefaultsInitTask implements DefaultsInitTask { IconLoader.reloadFrameIcons(); // Support for external libraries. - defaults.put(ComponentFactory.COMPONENT_FACTORY_KEY, new DarklafComponentFactory()); + defaults.put(ComponentFactory.COMPONENT_FACTORY_PROVIDER_KEY, + (Supplier) DarklafComponentFactory::new); } private float getOpacity(final UIDefaults defaults, final String key) {