Browse Source

SWING-DSL: Provide spacing hints for the swing-dsl library and set a ComponentFactory to provide darklaf specific components.

pull/235/head
weisj 4 years ago
parent
commit
db9283d51a
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 3
      build.gradle.kts
  2. 1
      core/build.gradle.kts
  3. 2
      core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java
  4. 25
      core/src/main/java/com/github/weisj/darklaf/swingdsl/DarklafComponentFactory.java
  5. 4
      core/src/main/java/com/github/weisj/darklaf/swingdsl/VisualPaddingListener.java
  6. 33
      core/src/main/java/com/github/weisj/darklaf/swingdsl/VisualPaddingUtil.java
  7. 5
      core/src/main/java/com/github/weisj/darklaf/task/UtilityDefaultsInitTask.java
  8. 2
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java
  9. 2
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java
  10. 2
      core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxBorder.java
  11. 2
      core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java
  12. 4
      core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java
  13. 2
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java
  14. 2
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java
  15. 2
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java
  16. 2
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java
  17. 2
      core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/checkbox/DarkCheckBoxBorder.java
  18. 2
      core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/radiobutton/DarkRadioButtonBorder.java
  19. 2
      core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/radiobutton/DarkRadioButtonUI.java
  20. 1
      dependencies-bom/build.gradle.kts
  21. 1
      gradle.properties

3
build.gradle.kts

@ -94,6 +94,9 @@ allprojects {
if (enableMavenLocal) {
mavenLocal()
}
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
mavenCentral()
}

1
core/build.gradle.kts

@ -16,6 +16,7 @@ dependencies {
implementation(project(":darklaf-macos"))
implementation("org.swinglabs:jxlayer")
implementation("com.formdev:svgSalamander")
implementation("com.github.weisj:swing-dsl-laf-support")
compileOnly("org.swinglabs:swingx")
testImplementation("com.formdev:svgSalamander")

2
core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java

@ -48,12 +48,12 @@ import com.github.weisj.darklaf.theme.info.AccentColorRule;
import com.github.weisj.darklaf.theme.info.FontSizePreset;
import com.github.weisj.darklaf.theme.info.FontSizeRule;
import com.github.weisj.darklaf.theme.info.PreferredThemeStyle;
import com.github.weisj.darklaf.ui.VisualPaddingProvider;
import com.github.weisj.darklaf.ui.combobox.ComboBoxConstants;
import com.github.weisj.darklaf.ui.slider.DarkSliderUI;
import com.github.weisj.darklaf.ui.tooltip.ToolTipConstants;
import com.github.weisj.darklaf.util.Alignment;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.swingdsl.laf.VisualPaddingProvider;
public class ThemeSettingsPanel extends JPanel {

25
core/src/main/java/com/github/weisj/darklaf/swingdsl/DarklafComponentFactory.java

@ -0,0 +1,25 @@
package com.github.weisj.darklaf.swingdsl;
import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.components.border.DarkBorders;
import com.github.weisj.swingdsl.laf.DefaultComponentFactory;
import com.github.weisj.swingdsl.laf.DefaultWrappedComponent;
import com.github.weisj.swingdsl.laf.WrappedComponent;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.border.Border;
public class DarklafComponentFactory extends DefaultComponentFactory {
@Override
public WrappedComponent<JScrollPane> createScrollPane(final JComponent content) {
OverlayScrollPane sp = new OverlayScrollPane(content);
return new DefaultWrappedComponent<>(sp.getScrollPane(), sp);
}
@Override
public Border createDividerBorder(final String title) {
return BorderFactory.createTitledBorder(DarkBorders.createTopBorder(), title);
}
}

4
core/src/main/java/com/github/weisj/darklaf/ui/VisualPaddingListener.java → core/src/main/java/com/github/weisj/darklaf/swingdsl/VisualPaddingListener.java

@ -19,7 +19,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package com.github.weisj.darklaf.ui;
package com.github.weisj.darklaf.swingdsl;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@ -34,7 +34,7 @@ public class VisualPaddingListener implements PropertyChangeListener {
@Override
public void propertyChange(final PropertyChangeEvent evt) {
if (PropertyKey.BORDER.equals(evt.getPropertyName())) {
VisualPaddingProvider.updateProperty(Types.safeCast(evt.getSource(), JComponent.class));
VisualPaddingUtil.updateProperty(Types.safeCast(evt.getSource(), JComponent.class));
}
}
}

33
core/src/main/java/com/github/weisj/darklaf/ui/VisualPaddingProvider.java → core/src/main/java/com/github/weisj/darklaf/swingdsl/VisualPaddingUtil.java

@ -19,24 +19,28 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package com.github.weisj.darklaf.ui;
package com.github.weisj.darklaf.swingdsl;
import java.awt.*;
import java.awt.Insets;
import javax.swing.*;
import javax.swing.JComponent;
import javax.swing.border.Border;
import javax.swing.plaf.InsetsUIResource;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
import com.github.weisj.swingdsl.laf.VisualPaddingProvider;
public interface VisualPaddingProvider {
public final class VisualPaddingUtil {
String VISUAL_PADDING_PROP = "visualPadding";
Insets getVisualPaddings(Component component);
static void updateProperty(final JComponent c) {
/**
* Update the {@link VisualPaddingProvider#VISUAL_PADDING_PROP} property of the component based on
* the components border.
*
* @param c the component.
*/
public static void updateProperty(final JComponent c) {
Border b = DarkUIUtil.getUnwrappedBorder(c);
if (b instanceof VisualPaddingProvider) {
updateProperty(c, ((VisualPaddingProvider) b).getVisualPaddings(c));
@ -45,12 +49,19 @@ public interface VisualPaddingProvider {
}
}
static void updateProperty(final JComponent c, final Insets ins) {
/**
* Update the {@link VisualPaddingProvider#VISUAL_PADDING_PROP} property of the component based on
* the given insets.
*
* @param c the component.
* @param ins the padding insets. Null insets mean the property will be uninstalled.
*/
public static void updateProperty(final JComponent c, final Insets ins) {
if (ins != null) {
PropertyUtil.installProperty(c, VISUAL_PADDING_PROP,
PropertyUtil.installProperty(c, VisualPaddingProvider.VISUAL_PADDING_PROP,
new InsetsUIResource(ins.top, ins.left, ins.bottom, ins.right));
} else {
PropertyUtil.uninstallProperty(c, VISUAL_PADDING_PROP);
PropertyUtil.uninstallProperty(c, VisualPaddingProvider.VISUAL_PADDING_PROP);
}
}
}

5
core/src/main/java/com/github/weisj/darklaf/task/UtilityDefaultsInitTask.java

@ -26,8 +26,10 @@ import javax.swing.*;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.icons.AwareIconStyle;
import com.github.weisj.darklaf.icons.IconLoader;
import com.github.weisj.darklaf.swingdsl.DarklafComponentFactory;
import com.github.weisj.darklaf.theme.Theme;
import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.swingdsl.laf.ComponentFactory;
public class UtilityDefaultsInitTask implements DefaultsInitTask {
@Override
@ -55,6 +57,9 @@ public class UtilityDefaultsInitTask implements DefaultsInitTask {
IconLoader.updateAwareStyle(Theme.isDark(currentTheme) ? AwareIconStyle.DARK : AwareIconStyle.LIGHT);
IconLoader.updateThemeStatus(new Object());
IconLoader.reloadFrameIcons();
// Support for external libraries.
defaults.put(ComponentFactory.COMPONENT_FACTORY_KEY, new DarklafComponentFactory());
}
private float getOpacity(final UIDefaults defaults, final String key) {

2
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java

@ -29,11 +29,11 @@ import javax.swing.plaf.InsetsUIResource;
import javax.swing.plaf.UIResource;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.ui.VisualPaddingProvider;
import com.github.weisj.darklaf.util.AlignmentExt;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
import com.github.weisj.darklaf.util.graphics.GraphicsContext;
import com.github.weisj.swingdsl.laf.VisualPaddingProvider;
/** @author Jannis Weis */
public class DarkButtonBorder implements Border, UIResource, VisualPaddingProvider {

2
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

@ -37,7 +37,7 @@ import com.github.weisj.darklaf.components.tooltip.ToolTipStyle;
import com.github.weisj.darklaf.delegate.AbstractButtonLayoutDelegate;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.graphics.StringPainter;
import com.github.weisj.darklaf.ui.VisualPaddingListener;
import com.github.weisj.darklaf.swingdsl.VisualPaddingListener;
import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonFocusNavigationActions;
import com.github.weisj.darklaf.ui.tooltip.ToolTipConstants;
import com.github.weisj.darklaf.util.AlignmentExt;

2
core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxBorder.java

@ -30,8 +30,8 @@ import javax.swing.plaf.UIResource;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.ui.DividedWidgetPainter;
import com.github.weisj.darklaf.ui.VisualPaddingProvider;
import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.swingdsl.laf.VisualPaddingProvider;
public class DarkComboBoxBorder implements Border, UIResource, VisualPaddingProvider {

2
core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java

@ -36,8 +36,8 @@ import javax.swing.plaf.basic.ComboPopup;
import javax.swing.text.JTextComponent;
import com.github.weisj.darklaf.components.ArrowButton;
import com.github.weisj.darklaf.swingdsl.VisualPaddingListener;
import com.github.weisj.darklaf.ui.DividedWidgetPainter;
import com.github.weisj.darklaf.ui.VisualPaddingListener;
import com.github.weisj.darklaf.ui.list.DarkDefaultListCellRenderer;
import com.github.weisj.darklaf.ui.popupmenu.DarkPopupMenuUI;
import com.github.weisj.darklaf.ui.text.DarkTextUI;

4
core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java

@ -33,7 +33,7 @@ import javax.swing.plaf.basic.BasicSliderUI;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.icons.RotatableIcon;
import com.github.weisj.darklaf.ui.VisualPaddingProvider;
import com.github.weisj.darklaf.swingdsl.VisualPaddingUtil;
import com.github.weisj.darklaf.util.Alignment;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey;
@ -145,7 +145,7 @@ public class DarkSliderUI extends BasicSliderUI {
calculateGeometry();
Rectangle r = new Rectangle(contentRect);
Insets ins = new Insets(r.y, r.x, slider.getHeight() - (r.y + r.height), slider.getWidth() - (r.x + r.width));
VisualPaddingProvider.updateProperty(slider, ins);
VisualPaddingUtil.updateProperty(slider, ins);
}
@Override

2
core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java

@ -29,9 +29,9 @@ import javax.swing.plaf.InsetsUIResource;
import javax.swing.plaf.UIResource;
import com.github.weisj.darklaf.ui.DividedWidgetPainter;
import com.github.weisj.darklaf.ui.VisualPaddingProvider;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.graphics.GraphicsContext;
import com.github.weisj.swingdsl.laf.VisualPaddingProvider;
/**
* @author Konstantin Bulenkov

2
core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java

@ -33,8 +33,8 @@ import javax.swing.plaf.basic.BasicSpinnerUI;
import javax.swing.text.JTextComponent;
import com.github.weisj.darklaf.components.ArrowButton;
import com.github.weisj.darklaf.swingdsl.VisualPaddingListener;
import com.github.weisj.darklaf.ui.DividedWidgetPainter;
import com.github.weisj.darklaf.ui.VisualPaddingListener;
import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;

2
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java

@ -31,11 +31,11 @@ import javax.swing.text.JTextComponent;
import com.github.weisj.darklaf.graphics.Outline;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.ui.VisualPaddingProvider;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
import com.github.weisj.darklaf.util.graphics.GraphicsContext;
import com.github.weisj.darklaf.util.graphics.GraphicsUtil;
import com.github.weisj.swingdsl.laf.VisualPaddingProvider;
/** @author Jannis Weis */
public class DarkTextBorder implements Border, UIResource, VisualPaddingProvider {

2
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java

@ -35,8 +35,8 @@ import com.github.weisj.darklaf.components.border.MarginBorderWrapper;
import com.github.weisj.darklaf.components.tooltip.ToolTipStyle;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.graphics.StringPainter;
import com.github.weisj.darklaf.swingdsl.VisualPaddingListener;
import com.github.weisj.darklaf.ui.OpacityBufferedUI;
import com.github.weisj.darklaf.ui.VisualPaddingListener;
import com.github.weisj.darklaf.ui.cell.DarkCellBorder;
import com.github.weisj.darklaf.ui.list.DarkListUI;
import com.github.weisj.darklaf.ui.table.DarkTableUI;

2
core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/checkbox/DarkCheckBoxBorder.java

@ -27,9 +27,9 @@ import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.UIResource;
import com.github.weisj.darklaf.ui.VisualPaddingProvider;
import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonConstants;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.swingdsl.laf.VisualPaddingProvider;
/** @author Jannis Weis */
public class DarkCheckBoxBorder extends EmptyBorder implements UIResource, ToggleButtonConstants,

2
core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/radiobutton/DarkRadioButtonBorder.java

@ -27,9 +27,9 @@ import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.UIResource;
import com.github.weisj.darklaf.ui.VisualPaddingProvider;
import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonConstants;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.swingdsl.laf.VisualPaddingProvider;
/** @author Jannis Weis */
public class DarkRadioButtonBorder extends EmptyBorder implements UIResource, ToggleButtonConstants,

2
core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/radiobutton/DarkRadioButtonUI.java

@ -35,7 +35,7 @@ import javax.swing.plaf.metal.MetalRadioButtonUI;
import sun.swing.SwingUtilities2;
import com.github.weisj.darklaf.graphics.StringPainter;
import com.github.weisj.darklaf.ui.VisualPaddingListener;
import com.github.weisj.darklaf.swingdsl.VisualPaddingListener;
import com.github.weisj.darklaf.ui.togglebutton.DarkToggleButtonUI;
import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonConstants;
import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonFocusNavigationActions;

1
dependencies-bom/build.gradle.kts

@ -41,5 +41,6 @@ dependencies {
apiv("com.google.auto.service:auto-service-annotations", "auto-service")
apiv("com.google.auto.service:auto-service", "auto-service")
apiv("com.github.lgooddatepicker:LGoodDatePicker")
apiv("com.github.weisj:swing-dsl-laf-support", "swing-dsl")
}
}

1
gradle.properties

@ -24,3 +24,4 @@ junit.version = 5.6.2
rsyntaxtextarea.version = 3.1.1
auto-service.version = 1.0-rc7
LGoodDatePicker.version = 11.0.2
swing-dsl.version = latest.integration

Loading…
Cancel
Save