From 4d4bb3fd7f5c93a40ac7f45607ecf90b0fa4fbec Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Wed, 21 Jul 2021 11:51:19 +0200 Subject: [PATCH] Styling: added `StyleableUI.getStyleableInfos()` for tooling (e.g. GUI builder) --- .../flatlaf/icons/FlatCheckBoxIcon.java | 8 + .../icons/FlatCheckBoxMenuItemIcon.java | 8 + .../flatlaf/icons/FlatHelpButtonIcon.java | 8 + .../flatlaf/icons/FlatMenuArrowIcon.java | 8 + .../icons/FlatTabbedPaneCloseIcon.java | 8 + .../com/formdev/flatlaf/ui/FlatBorder.java | 9 + .../com/formdev/flatlaf/ui/FlatButtonUI.java | 13 + .../flatlaf/ui/FlatCheckBoxMenuItemUI.java | 10 + .../formdev/flatlaf/ui/FlatComboBoxUI.java | 15 + .../flatlaf/ui/FlatDropShadowBorder.java | 12 + .../formdev/flatlaf/ui/FlatEditorPaneUI.java | 10 + .../flatlaf/ui/FlatInternalFrameUI.java | 25 + .../com/formdev/flatlaf/ui/FlatLabelUI.java | 10 + .../com/formdev/flatlaf/ui/FlatListUI.java | 10 + .../formdev/flatlaf/ui/FlatMenuBarBorder.java | 6 + .../com/formdev/flatlaf/ui/FlatMenuBarUI.java | 10 + .../flatlaf/ui/FlatMenuItemRenderer.java | 14 + .../formdev/flatlaf/ui/FlatMenuItemUI.java | 24 + .../com/formdev/flatlaf/ui/FlatMenuUI.java | 10 + .../flatlaf/ui/FlatPasswordFieldUI.java | 15 + .../formdev/flatlaf/ui/FlatProgressBarUI.java | 10 + .../flatlaf/ui/FlatRadioButtonMenuItemUI.java | 10 + .../formdev/flatlaf/ui/FlatRadioButtonUI.java | 15 + .../formdev/flatlaf/ui/FlatScrollBarUI.java | 18 + .../formdev/flatlaf/ui/FlatScrollPaneUI.java | 10 + .../formdev/flatlaf/ui/FlatSeparatorUI.java | 10 + .../com/formdev/flatlaf/ui/FlatSliderUI.java | 10 + .../com/formdev/flatlaf/ui/FlatSpinnerUI.java | 10 + .../formdev/flatlaf/ui/FlatSplitPaneUI.java | 20 + .../formdev/flatlaf/ui/FlatStyleSupport.java | 89 +- .../formdev/flatlaf/ui/FlatTabbedPaneUI.java | 30 +- .../formdev/flatlaf/ui/FlatTableHeaderUI.java | 12 +- .../com/formdev/flatlaf/ui/FlatTableUI.java | 10 + .../formdev/flatlaf/ui/FlatTextAreaUI.java | 10 + .../formdev/flatlaf/ui/FlatTextFieldUI.java | 10 + .../formdev/flatlaf/ui/FlatTextPaneUI.java | 10 + .../flatlaf/ui/FlatToggleButtonUI.java | 28 + .../flatlaf/ui/FlatToolBarSeparatorUI.java | 10 + .../com/formdev/flatlaf/ui/FlatToolBarUI.java | 10 + .../com/formdev/flatlaf/ui/FlatTreeUI.java | 10 + .../flatlaf/ui/TestFlatStyleableInfo.java | 1105 +++++++++++++++++ .../formdev/flatlaf/ui/TestFlatStyling.java | 27 +- .../com/formdev/flatlaf/ui/TestUtils.java | 14 + 43 files changed, 1703 insertions(+), 18 deletions(-) create mode 100644 flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxIcon.java index 41106a9b..0d73b165 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxIcon.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxIcon.java @@ -23,6 +23,7 @@ import java.awt.Component; import java.awt.Graphics2D; import java.awt.geom.Path2D; import java.awt.geom.RoundRectangle2D; +import java.util.Map; import javax.swing.AbstractButton; import javax.swing.JComponent; import javax.swing.UIManager; @@ -138,6 +139,13 @@ public class FlatCheckBoxIcon return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + public Map> getStyleableInfos() { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override protected void paintIcon( Component c, Graphics2D g ) { boolean indeterminate = isIndeterminate( c ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxMenuItemIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxMenuItemIcon.java index 97c76300..99eab2b2 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxMenuItemIcon.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxMenuItemIcon.java @@ -21,6 +21,7 @@ import java.awt.Color; import java.awt.Component; import java.awt.Graphics2D; import java.awt.geom.Path2D; +import java.util.Map; import javax.swing.AbstractButton; import javax.swing.JMenuItem; import javax.swing.UIManager; @@ -55,6 +56,13 @@ public class FlatCheckBoxMenuItemIcon return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + public Map> getStyleableInfos() { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override protected void paintIcon( Component c, Graphics2D g2 ) { boolean selected = (c instanceof AbstractButton) && ((AbstractButton)c).isSelected(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatHelpButtonIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatHelpButtonIcon.java index 9faee940..756858b0 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatHelpButtonIcon.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatHelpButtonIcon.java @@ -22,6 +22,7 @@ import java.awt.Component; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; import java.awt.geom.Path2D; +import java.util.Map; import javax.swing.UIManager; import com.formdev.flatlaf.ui.FlatButtonUI; import com.formdev.flatlaf.ui.FlatStyleSupport; @@ -80,6 +81,13 @@ public class FlatHelpButtonIcon return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + public Map> getStyleableInfos() { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override protected void paintIcon( Component c, Graphics2D g2 ) { /* diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatMenuArrowIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatMenuArrowIcon.java index b71e5c53..13260c76 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatMenuArrowIcon.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatMenuArrowIcon.java @@ -21,6 +21,7 @@ import java.awt.Color; import java.awt.Component; import java.awt.Graphics2D; import java.awt.geom.Path2D; +import java.util.Map; import javax.swing.JMenu; import javax.swing.UIManager; import com.formdev.flatlaf.ui.FlatStyleSupport; @@ -57,6 +58,13 @@ public class FlatMenuArrowIcon return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + public Map> getStyleableInfos() { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override protected void paintIcon( Component c, Graphics2D g ) { if( !c.getComponentOrientation().isLeftToRight() ) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatTabbedPaneCloseIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatTabbedPaneCloseIcon.java index 006fd13f..b5cf5cd8 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatTabbedPaneCloseIcon.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatTabbedPaneCloseIcon.java @@ -23,6 +23,7 @@ import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.geom.Line2D; import java.awt.geom.Path2D; +import java.util.Map; import javax.swing.UIManager; import com.formdev.flatlaf.ui.FlatButtonUI; import com.formdev.flatlaf.ui.FlatStyleSupport; @@ -72,6 +73,13 @@ public class FlatTabbedPaneCloseIcon return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + public Map> getStyleableInfos() { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override protected void paintIcon( Component c, Graphics2D g ) { // paint background diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java index 36454720..ac12fe9d 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java @@ -23,6 +23,7 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; import java.awt.Paint; +import java.util.Map; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JScrollPane; @@ -86,6 +87,14 @@ public class FlatBorder return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos() { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { Graphics2D g2 = (Graphics2D) g.create(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java index 07839597..b4bad010 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java @@ -48,6 +48,7 @@ import javax.swing.plaf.basic.BasicButtonUI; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.icons.FlatHelpButtonIcon; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; import com.formdev.flatlaf.util.UIScale; @@ -98,6 +99,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatButtonUI extends BasicButtonUI + implements StyleableUI { @Styleable protected int minimumWidth; protected int iconTextGap; @@ -296,6 +298,17 @@ public class FlatButtonUI return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, b, borderShared ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + Map> infos = FlatStyleSupport.getAnnotatedStyleableInfos( this, c.getBorder() ); + if( helpButtonIcon instanceof FlatHelpButtonIcon ) + FlatStyleSupport.putAllPrefixKey( infos, "help.", ((FlatHelpButtonIcon)helpButtonIcon).getStyleableInfos() ); + return infos; + } + static boolean isContentAreaFilled( Component c ) { return !(c instanceof AbstractButton) || ((AbstractButton)c).isContentAreaFilled(); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java index 879c23b7..27f422a0 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java @@ -25,6 +25,7 @@ import javax.swing.JComponent; import javax.swing.LookAndFeel; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; /** @@ -57,6 +58,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; */ public class FlatCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI + implements StyleableUI { private FlatMenuItemRenderer renderer; private Map oldStyleValues; @@ -118,6 +120,14 @@ public class FlatCheckBoxMenuItemUI return FlatMenuItemUI.applyStyleProperty( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatMenuItemUI.getStyleableInfos( renderer ); + } + @Override protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { return renderer.getPreferredMenuItemSize(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java index 6fc47546..5e5e6a1c 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java @@ -40,6 +40,7 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.geom.Rectangle2D; import java.beans.PropertyChangeListener; +import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import javax.swing.AbstractAction; @@ -70,6 +71,7 @@ import javax.swing.plaf.basic.ComboPopup; import javax.swing.text.JTextComponent; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.SystemInfo; /** @@ -111,6 +113,7 @@ import com.formdev.flatlaf.util.SystemInfo; */ public class FlatComboBoxUI extends BasicComboBoxUI + implements StyleableUI { @Styleable protected int minimumWidth; @Styleable protected int editorColumns; @@ -476,6 +479,18 @@ public class FlatComboBoxUI return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, comboBox, borderShared ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + Map> infos = new LinkedHashMap<>(); + infos.put( "padding", Insets.class ); + FlatStyleSupport.collectAnnotatedStyleableInfos( this, infos ); + FlatStyleSupport.collectStyleableInfos( comboBox.getBorder(), infos ); + return infos; + } + @Override public void update( Graphics g, JComponent c ) { float focusWidth = FlatUIUtils.getBorderFocusWidth( c ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatDropShadowBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatDropShadowBorder.java index 977c97cb..ede1bc4f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatDropShadowBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatDropShadowBorder.java @@ -24,6 +24,7 @@ import java.awt.Image; import java.awt.Insets; import java.awt.RadialGradientPaint; import java.awt.image.BufferedImage; +import java.util.Map; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableBorder; import com.formdev.flatlaf.util.HiDPIUtils; @@ -89,6 +90,9 @@ public class FlatDropShadowBorder Math.max( shadowInsets.top, shadowInsets.bottom ) ); } + /** + * @since TODO + */ @Override public Object applyStyleProperty( String key, Object value ) { Object oldValue = FlatStyleSupport.applyToAnnotatedObject( this, key, value ); @@ -99,6 +103,14 @@ public class FlatDropShadowBorder return oldValue; } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos() { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { if( shadowSize <= 0 ) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatEditorPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatEditorPaneUI.java index 80d5cce3..01e24725 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatEditorPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatEditorPaneUI.java @@ -33,6 +33,7 @@ import javax.swing.plaf.basic.BasicEditorPaneUI; import javax.swing.text.JTextComponent; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.HiDPIUtils; /** @@ -63,6 +64,7 @@ import com.formdev.flatlaf.util.HiDPIUtils; */ public class FlatEditorPaneUI extends BasicEditorPaneUI + implements StyleableUI { @Styleable protected int minimumWidth; protected boolean isIntelliJTheme; @@ -184,6 +186,14 @@ public class FlatEditorPaneUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + private void updateBackground() { FlatTextFieldUI.updateBackground( getComponent(), background, disabledBackground, inactiveBackground, diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatInternalFrameUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatInternalFrameUI.java index 5a1d9020..3e3bf482 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatInternalFrameUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatInternalFrameUI.java @@ -23,6 +23,7 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; import java.beans.PropertyChangeListener; +import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import javax.swing.JComponent; @@ -33,6 +34,7 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicInternalFrameUI; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableBorder; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; /** * Provides the Flat LaF UI delegate for {@link javax.swing.JInternalFrame}. @@ -88,6 +90,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableBorder; */ public class FlatInternalFrameUI extends BasicInternalFrameUI + implements StyleableUI { protected FlatWindowResizer windowResizer; @@ -157,6 +160,14 @@ public class FlatInternalFrameUI return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, frame, borderShared ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this, frame.getBorder() ); + } + //---- class FlatInternalFrameBorder -------------------------------------- public static class FlatInternalFrameBorder @@ -197,6 +208,20 @@ public class FlatInternalFrameUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + @Override + public Map> getStyleableInfos() { + Map> infos = new LinkedHashMap<>(); + FlatStyleSupport.collectAnnotatedStyleableInfos( this, infos ); + infos.put( "borderMargins", Insets.class ); + infos.put( "activeDropShadowColor", Color.class ); + infos.put( "activeDropShadowInsets", Insets.class ); + infos.put( "activeDropShadowOpacity", float.class ); + infos.put( "inactiveDropShadowColor", Color.class ); + infos.put( "inactiveDropShadowInsets", Insets.class ); + infos.put( "inactiveDropShadowOpacity", float.class ); + return infos; + } + @Override public Insets getBorderInsets( Component c, Insets insets ) { if( c instanceof JInternalFrame && ((JInternalFrame)c).isMaximum() ) { diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLabelUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLabelUI.java index 5ed7fd49..f7f25afc 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLabelUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLabelUI.java @@ -37,6 +37,7 @@ import javax.swing.plaf.basic.BasicLabelUI; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.UIScale; @@ -57,6 +58,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatLabelUI extends BasicLabelUI + implements StyleableUI { @Styleable protected Color disabledForeground; @@ -149,6 +151,14 @@ public class FlatLabelUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + /** * Checks whether text contains HTML tags that use "absolute-size" keywords * (e.g. "x-large") for font-size in default style sheet diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java index 6bebe094..5dfce689 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java @@ -28,6 +28,7 @@ import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicListUI; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; /** * Provides the Flat LaF UI delegate for {@link javax.swing.JList}. @@ -67,6 +68,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; */ public class FlatListUI extends BasicListUI + implements StyleableUI { @Styleable protected Color selectionBackground; @Styleable protected Color selectionForeground; @@ -179,6 +181,14 @@ public class FlatListUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + /** * Toggle selection colors from focused to inactive and vice versa. * diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarBorder.java index 10d2026d..dadf531f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarBorder.java @@ -21,6 +21,7 @@ import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import java.awt.Insets; +import java.util.Map; import javax.swing.JMenuBar; import javax.swing.UIManager; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; @@ -47,6 +48,11 @@ public class FlatMenuBarBorder return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + @Override + public Map> getStyleableInfos() { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { float lineHeight = scale( (float) 1 ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarUI.java index 5077ce76..135dbd72 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarUI.java @@ -40,6 +40,7 @@ import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicMenuBarUI; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatLaf; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.SystemInfo; /** @@ -60,6 +61,7 @@ import com.formdev.flatlaf.util.SystemInfo; */ public class FlatMenuBarUI extends BasicMenuBarUI + implements StyleableUI { private PropertyChangeListener propertyChangeListener; private Map oldStyleValues; @@ -141,6 +143,14 @@ public class FlatMenuBarUI return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, menuBar, borderShared ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this, menuBar.getBorder() ); + } + @Override public void update( Graphics g, JComponent c ) { // paint background diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java index 79580de1..a3f2c5d9 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java @@ -30,6 +30,7 @@ import java.awt.Rectangle; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.text.AttributedCharacterIterator; +import java.util.Map; import javax.swing.Icon; import javax.swing.JMenu; import javax.swing.JMenuItem; @@ -149,6 +150,19 @@ public class FlatMenuItemRenderer return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + public Map> getStyleableInfos() { + Map> infos = FlatStyleSupport.getAnnotatedStyleableInfos( this ); + if( checkIcon instanceof FlatCheckBoxMenuItemIcon ) + FlatStyleSupport.putAllPrefixKey( infos, "icon.", ((FlatCheckBoxMenuItemIcon)checkIcon).getStyleableInfos() ); + if( arrowIcon instanceof FlatMenuArrowIcon ) + FlatStyleSupport.putAllPrefixKey( infos, "icon.", ((FlatMenuArrowIcon)arrowIcon).getStyleableInfos() ); + infos.remove( "icon.selectionForeground" ); + return infos; + } + protected Dimension getPreferredMenuItemSize() { int width = 0; int height = 0; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java index fb4abf96..946b91e4 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java @@ -16,15 +16,18 @@ package com.formdev.flatlaf.ui; +import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.beans.PropertyChangeListener; +import java.util.LinkedHashMap; import java.util.Map; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.LookAndFeel; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicMenuItemUI; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; /** @@ -57,6 +60,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; */ public class FlatMenuItemUI extends BasicMenuItemUI + implements StyleableUI { private FlatMenuItemRenderer renderer; private Map oldStyleValues; @@ -120,6 +124,7 @@ public class FlatMenuItemUI static Object applyStyleProperty( BasicMenuItemUI ui, String key, Object value ) { switch( key ) { + // BasicMenuItemUI case "selectionBackground": case "selectionForeground": case "disabledForeground": @@ -131,6 +136,25 @@ public class FlatMenuItemUI } } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return getStyleableInfos( renderer ); + } + + static Map> getStyleableInfos( FlatMenuItemRenderer renderer ) { + Map> infos = new LinkedHashMap<>(); + infos.put( "selectionBackground", Color.class ); + infos.put( "selectionForeground", Color.class ); + infos.put( "disabledForeground", Color.class ); + infos.put( "acceleratorForeground", Color.class ); + infos.put( "acceleratorSelectionForeground", Color.class ); + infos.putAll( renderer.getStyleableInfos() ); + return infos; + } + @Override protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { return renderer.getPreferredMenuItemSize(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java index acb08a35..1b976879 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java @@ -33,6 +33,7 @@ import javax.swing.UIManager; import javax.swing.event.MouseInputListener; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicMenuUI; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; /** @@ -75,6 +76,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; */ public class FlatMenuUI extends BasicMenuUI + implements StyleableUI { private Color hoverBackground; private FlatMenuItemRenderer renderer; @@ -166,6 +168,14 @@ public class FlatMenuUI return FlatMenuItemUI.applyStyleProperty( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatMenuItemUI.getStyleableInfos( renderer ); + } + @Override public Dimension getMinimumSize( JComponent c ) { // avoid that top-level menus (in menu bar) are made smaller if horizontal space is rare diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java index bd16095e..adfbd0d6 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java @@ -16,6 +16,7 @@ package com.formdev.flatlaf.ui; +import java.awt.Color; import java.awt.Graphics; import java.awt.Insets; import java.awt.Shape; @@ -23,6 +24,7 @@ import java.awt.Toolkit; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +import java.util.Map; import javax.swing.Action; import javax.swing.ActionMap; import javax.swing.Icon; @@ -159,6 +161,9 @@ public class FlatPasswordFieldUI } } + /** + * @since TODO + */ @Override protected Object applyStyleProperty( String key, Object value ) { if( key.equals( "capsLockIconColor" ) && capsLockIcon instanceof FlatCapsLockIcon ) { @@ -172,6 +177,16 @@ public class FlatPasswordFieldUI return super.applyStyleProperty( key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + Map> infos = super.getStyleableInfos( c ); + infos.put( "capsLockIconColor", Color.class ); + return infos; + } + @Override public View create( Element elem ) { return new PasswordView( elem ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java index e7e5080c..072abd36 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java @@ -33,6 +33,7 @@ import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicProgressBarUI; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.UIScale; @@ -60,6 +61,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatProgressBarUI extends BasicProgressBarUI + implements StyleableUI { @Styleable protected int arc; @Styleable protected Dimension horizontalSize; @@ -141,6 +143,14 @@ public class FlatProgressBarUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override public Dimension getPreferredSize( JComponent c ) { Dimension size = super.getPreferredSize( c ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java index 3860319e..cfa7dcb3 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java @@ -25,6 +25,7 @@ import javax.swing.JComponent; import javax.swing.LookAndFeel; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; /** @@ -57,6 +58,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; */ public class FlatRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI + implements StyleableUI { private FlatMenuItemRenderer renderer; private Map oldStyleValues; @@ -118,6 +120,14 @@ public class FlatRadioButtonMenuItemUI return FlatMenuItemUI.applyStyleProperty( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatMenuItemUI.getStyleableInfos( renderer ); + } + @Override protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { return renderer.getPreferredMenuItemSize(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java index bd135cad..d26de632 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java @@ -37,6 +37,7 @@ import javax.swing.plaf.basic.BasicRadioButtonUI; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.icons.FlatCheckBoxIcon; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; import com.formdev.flatlaf.util.UIScale; @@ -62,6 +63,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatRadioButtonUI extends BasicRadioButtonUI + implements StyleableUI { protected int iconTextGap; @Styleable protected Color disabledText; @@ -181,6 +183,19 @@ public class FlatRadioButtonUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + Map> infos = FlatStyleSupport.getAnnotatedStyleableInfos( this ); + if( icon instanceof FlatCheckBoxIcon ) { + for( Map.Entry> e : ((FlatCheckBoxIcon)icon).getStyleableInfos().entrySet() ) + infos.put( "icon.".concat( e.getKey() ), e.getValue() ); + } + return infos; + } + private static Insets tempInsets = new Insets( 0, 0, 0, 0 ); @Override diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java index 8b0dcbef..937ed1d1 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java @@ -24,6 +24,7 @@ import java.awt.Rectangle; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.beans.PropertyChangeListener; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; import javax.swing.InputMap; @@ -37,6 +38,7 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicScrollBarUI; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.UIScale; /** @@ -76,6 +78,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatScrollBarUI extends BasicScrollBarUI + implements StyleableUI { // overrides BasicScrollBarUI.supportsAbsolutePositioning (which is private) @Styleable protected boolean allowsAbsolutePositioning; @@ -246,6 +249,21 @@ public class FlatScrollBarUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + Map> infos = new LinkedHashMap<>(); + infos.put( "track", Color.class ); + infos.put( "thumb", Color.class ); + infos.put( "width", int.class ); + infos.put( "minimumThumbSize", Dimension.class ); + infos.put( "maximumThumbSize", Dimension.class ); + FlatStyleSupport.collectAnnotatedStyleableInfos( this, infos ); + return infos; + } + @Override public Dimension getPreferredSize( JComponent c ) { return UIScale.scale( super.getPreferredSize( c ) ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java index bd406d4a..6532d5aa 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java @@ -48,6 +48,7 @@ import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicScrollPaneUI; import com.formdev.flatlaf.FlatClientProperties; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; /** * Provides the Flat LaF UI delegate for {@link javax.swing.JScrollPane}. @@ -68,6 +69,7 @@ import com.formdev.flatlaf.FlatClientProperties; */ public class FlatScrollPaneUI extends BasicScrollPaneUI + implements StyleableUI { private Handler handler; @@ -320,6 +322,14 @@ public class FlatScrollPaneUI return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, scrollpane, borderShared ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this, scrollpane.getBorder() ); + } + @Override protected void updateViewport( PropertyChangeEvent e ) { super.updateViewport( e ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSeparatorUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSeparatorUI.java index 5d8fd01b..b6cb9aae 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSeparatorUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSeparatorUI.java @@ -30,6 +30,7 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicSeparatorUI; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; /** * Provides the Flat LaF UI delegate for {@link javax.swing.JSeparator}. @@ -49,6 +50,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; */ public class FlatSeparatorUI extends BasicSeparatorUI + implements StyleableUI { @Styleable protected int height; @Styleable protected int stripeWidth; @@ -148,6 +150,14 @@ public class FlatSeparatorUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override public void paint( Graphics g, JComponent c ) { Graphics2D g2 = (Graphics2D) g.create(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java index b382e94c..4db7abd3 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java @@ -37,6 +37,7 @@ import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicSliderUI; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.Graphics2DProxy; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.UIScale; @@ -77,6 +78,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatSliderUI extends BasicSliderUI + implements StyleableUI { @Styleable protected int trackWidth; @Styleable protected Dimension thumbSize; @@ -202,6 +204,14 @@ public class FlatSliderUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override public int getBaseline( JComponent c, int width, int height ) { if( c == null ) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java index 5cce41c7..a59d924b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java @@ -45,6 +45,7 @@ import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicSpinnerUI; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; /** * Provides the Flat LaF UI delegate for {@link javax.swing.JSpinner}. @@ -81,6 +82,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; */ public class FlatSpinnerUI extends BasicSpinnerUI + implements StyleableUI { private Handler handler; @@ -205,6 +207,14 @@ public class FlatSpinnerUI return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, spinner, borderShared ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this, spinner.getBorder() ); + } + @Override protected JComponent createEditor() { JComponent editor = super.createEditor(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSplitPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSplitPaneUI.java index 47dfad80..c238a01c 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSplitPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSplitPaneUI.java @@ -36,6 +36,7 @@ import javax.swing.plaf.basic.BasicSplitPaneDivider; import javax.swing.plaf.basic.BasicSplitPaneUI; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; import com.formdev.flatlaf.util.UIScale; @@ -71,6 +72,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatSplitPaneUI extends BasicSplitPaneUI + implements StyleableUI { @Styleable protected String arrowType; @Styleable protected Color oneTouchArrowColor; @@ -159,6 +161,17 @@ public class FlatSplitPaneUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + Map> infos = FlatStyleSupport.getAnnotatedStyleableInfos( this ); + if( divider instanceof FlatSplitPaneDivider ) + infos.putAll( ((FlatSplitPaneDivider)divider).getStyleableInfos() ); + return infos; + } + //---- class FlatSplitPaneDivider ----------------------------------------- protected class FlatSplitPaneDivider @@ -183,6 +196,13 @@ public class FlatSplitPaneUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + public Map> getStyleableInfos() { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + void updateStyle() { if( leftButton instanceof FlatOneTouchButton ) ((FlatOneTouchButton)leftButton).updateStyle(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatStyleSupport.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatStyleSupport.java index 317c76d8..882dd7e6 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatStyleSupport.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatStyleSupport.java @@ -56,10 +56,16 @@ public class FlatStyleSupport @Retention(RetentionPolicy.RUNTIME) public @interface Styleable { boolean dot() default false; + Class type() default Void.class; + } + + public interface StyleableUI { + Map> getStyleableInfos( JComponent c ); } public interface StyleableBorder { Object applyStyleProperty( String key, Object value ); + Map> getStyleableInfos(); } /** @@ -250,8 +256,8 @@ public class FlatStyleSupport try { Field f = cls.getDeclaredField( fieldName ); if( predicate == null || predicate.test( f ) ) { - if( Modifier.isFinal( f.getModifiers() ) ) - throw new IllegalArgumentException( "field '" + cls.getName() + "." + fieldName + "' is final" ); + if( !isValidField( f ) ) + throw new IllegalArgumentException( "field '" + cls.getName() + "." + fieldName + "' is final or static" ); try { // necessary to access protected fields in other packages @@ -281,6 +287,11 @@ public class FlatStyleSupport } } + private static boolean isValidField( Field f ) { + int modifiers = f.getModifiers(); + return (modifiers & (Modifier.FINAL|Modifier.STATIC)) == 0 && !f.isSynthetic(); + } + static Object applyToAnnotatedObjectOrBorder( Object obj, String key, Object value, JComponent c, AtomicBoolean borderShared ) { @@ -342,6 +353,80 @@ public class FlatStyleSupport } } + /** + * Returns a map of all fields annotated with {@link Styleable}. + * The key is the name of the field and the value the type of the field. + */ + public static Map> getAnnotatedStyleableInfos( Object obj ) { + return getAnnotatedStyleableInfos( obj, null ); + } + + public static Map> getAnnotatedStyleableInfos( Object obj, Border border ) { + Map> infos = new LinkedHashMap<>(); + collectAnnotatedStyleableInfos( obj, infos ); + collectStyleableInfos( border, infos ); + return infos; + } + + /** + * Search for all fields annotated with {@link Styleable} and add them to the given map. + * The key is the name of the field and the value the type of the field. + */ + public static void collectAnnotatedStyleableInfos( Object obj, Map> infos ) { + Class cls = obj.getClass(); + + for(;;) { + for( Field f : cls.getDeclaredFields() ) { + if( !isValidField( f ) ) + continue; + + Styleable styleable = f.getAnnotation( Styleable.class ); + if( styleable == null ) + continue; + + String name = f.getName(); + Class type = f.getType(); + + // handle "dot" keys (e.g. change field name "iconArrowType" to style key "icon.arrowType") + if( styleable.dot() ) { + int len = name.length(); + for( int i = 0; i < len; i++ ) { + if( Character.isUpperCase( name.charAt( i ) ) ) { + name = name.substring( 0, i ) + '.' + + Character.toLowerCase( name.charAt( i ) ) + + name.substring( i + 1 ); + break; + } + } + } + + // field has a different type + if( styleable.type() != Void.class ) + type = styleable.type(); + + infos.put( name, type ); + } + + cls = cls.getSuperclass(); + if( cls == null ) + return; + + String superclassName = cls.getName(); + if( superclassName.startsWith( "java." ) || superclassName.startsWith( "javax." ) ) + return; + } + } + + public static void collectStyleableInfos( Border border, Map> infos ) { + if( border instanceof StyleableBorder ) + infos.putAll( ((StyleableBorder)border).getStyleableInfos() ); + } + + public static void putAllPrefixKey( Map> infos, String keyPrefix, Map> infos2 ) { + for( Map.Entry> e : infos2.entrySet() ) + infos.put( keyPrefix.concat( e.getKey() ), e.getValue() ); + } + //---- class UnknownStyleException ---------------------------------------- public static class UnknownStyleException diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java index ee884a8b..9bf6f17f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java @@ -52,6 +52,7 @@ import java.awt.geom.Rectangle2D; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -87,6 +88,7 @@ import javax.swing.text.View; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.icons.FlatTabbedPaneCloseIcon; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; import com.formdev.flatlaf.util.Animator; import com.formdev.flatlaf.util.CubicBezierEasing; @@ -160,6 +162,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatTabbedPaneUI extends BasicTabbedPaneUI + implements StyleableUI { // tabs popup policy / scroll arrows policy protected static final int NEVER = 0; @@ -202,13 +205,13 @@ public class FlatTabbedPaneUI @Styleable protected boolean hasFullBorder; @Styleable protected boolean tabsOpaque = true; - @Styleable private int tabsPopupPolicy; - @Styleable private int scrollButtonsPolicy; - @Styleable private int scrollButtonsPlacement; + @Styleable(type=String.class) private int tabsPopupPolicy; + @Styleable(type=String.class) private int scrollButtonsPolicy; + @Styleable(type=String.class) private int scrollButtonsPlacement; - @Styleable private int tabAreaAlignment; - @Styleable private int tabAlignment; - @Styleable private int tabWidthMode; + @Styleable(type=String.class) private int tabAreaAlignment; + @Styleable(type=String.class) private int tabAlignment; + @Styleable(type=String.class) private int tabWidthMode; protected Icon closeIcon; @Styleable protected String arrowType; @@ -626,6 +629,21 @@ public class FlatTabbedPaneUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + Map> infos = new LinkedHashMap<>(); + infos.put( "tabInsets", Insets.class ); + infos.put( "tabAreaInsets", Insets.class ); + infos.put( "textIconGap", int.class ); + FlatStyleSupport.collectAnnotatedStyleableInfos( this, infos ); + if( closeIcon instanceof FlatTabbedPaneCloseIcon ) + infos.putAll( ((FlatTabbedPaneCloseIcon)closeIcon).getStyleableInfos() ); + return infos; + } + protected void setRolloverTab( int x, int y ) { setRolloverTab( tabForCoordinate( tabPane, x, y ) ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableHeaderUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableHeaderUI.java index 0d5f45ea..43bb1eae 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableHeaderUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableHeaderUI.java @@ -39,6 +39,7 @@ import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumnModel; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.UIScale; /** @@ -71,10 +72,11 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatTableHeaderUI extends BasicTableHeaderUI + implements StyleableUI { @Styleable protected Color bottomSeparatorColor; @Styleable protected int height; - @Styleable protected int sortIconPosition; + @Styleable(type=String.class) protected int sortIconPosition; // for FlatTableHeaderBorder @Styleable protected Insets cellMargins; @@ -150,6 +152,14 @@ public class FlatTableHeaderUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + private static int parseSortIconPosition( String str ) { if( str == null ) str = ""; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java index 17a82a1f..1ed05dcd 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java @@ -39,6 +39,7 @@ import javax.swing.plaf.basic.BasicTableUI; import javax.swing.table.JTableHeader; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.Graphics2DProxy; import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.UIScale; @@ -92,6 +93,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatTableUI extends BasicTableUI + implements StyleableUI { protected boolean showHorizontalLines; protected boolean showVerticalLines; @@ -255,6 +257,14 @@ public class FlatTableUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + /** * Toggle selection colors from focused to inactive and vice versa. * diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextAreaUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextAreaUI.java index b17f8d14..8600994e 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextAreaUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextAreaUI.java @@ -29,6 +29,7 @@ import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTextAreaUI; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.HiDPIUtils; /** @@ -59,6 +60,7 @@ import com.formdev.flatlaf.util.HiDPIUtils; */ public class FlatTextAreaUI extends BasicTextAreaUI + implements StyleableUI { @Styleable protected int minimumWidth; protected boolean isIntelliJTheme; @@ -158,6 +160,14 @@ public class FlatTextAreaUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + private void updateBackground() { FlatTextFieldUI.updateBackground( getComponent(), background, disabledBackground, inactiveBackground, diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java index fa4d211b..2c173f08 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java @@ -43,6 +43,7 @@ import javax.swing.text.Caret; import javax.swing.text.JTextComponent; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.JavaCompatibility; import com.formdev.flatlaf.util.UIScale; @@ -78,6 +79,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatTextFieldUI extends BasicTextFieldUI + implements StyleableUI { @Styleable protected int minimumWidth; protected boolean isIntelliJTheme; @@ -216,6 +218,14 @@ public class FlatTextFieldUI return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, getComponent(), borderShared ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this, getComponent().getBorder() ); + } + private void updateBackground() { updateBackground( getComponent(), background, disabledBackground, inactiveBackground, diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextPaneUI.java index 25cf45cf..395c07f1 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextPaneUI.java @@ -29,6 +29,7 @@ import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTextPaneUI; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.HiDPIUtils; /** @@ -59,6 +60,7 @@ import com.formdev.flatlaf.util.HiDPIUtils; */ public class FlatTextPaneUI extends BasicTextPaneUI + implements StyleableUI { @Styleable protected int minimumWidth; protected boolean isIntelliJTheme; @@ -166,6 +168,14 @@ public class FlatTextPaneUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + private void updateBackground() { FlatTextFieldUI.updateBackground( getComponent(), background, disabledBackground, inactiveBackground, diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java index cc14d423..cd49f1b5 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java @@ -21,12 +21,15 @@ import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import java.beans.PropertyChangeEvent; +import java.util.Iterator; +import java.util.Map; import javax.swing.AbstractButton; import javax.swing.JComponent; import javax.swing.JToggleButton; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; import com.formdev.flatlaf.util.UIScale; /** @@ -143,6 +146,31 @@ public class FlatToggleButtonUI } } + /** + * @since TODO + */ + @Override + protected Object applyStyleProperty( AbstractButton b, String key, Object value ) { + if( key.startsWith( "help." ) ) + throw new UnknownStyleException( key ); + + return super.applyStyleProperty( b, key, value ); + } + + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + Map> infos = super.getStyleableInfos( c ); + Iterator it = infos.keySet().iterator(); + while( it.hasNext() ) { + if( it.next().startsWith( "help." ) ) + it.remove(); + } + return infos; + } + static boolean isTabButton( Component c ) { return c instanceof JToggleButton && clientPropertyEquals( (JToggleButton) c, BUTTON_TYPE, BUTTON_TYPE_TAB ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarSeparatorUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarSeparatorUI.java index 578879ab..f08b9d99 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarSeparatorUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarSeparatorUI.java @@ -33,6 +33,7 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicToolBarSeparatorUI; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; /** * Provides the Flat LaF UI delegate for {@link javax.swing.JToolBar.Separator}. @@ -46,6 +47,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; */ public class FlatToolBarSeparatorUI extends BasicToolBarSeparatorUI + implements StyleableUI { private static final int LINE_WIDTH = 1; @@ -144,6 +146,14 @@ public class FlatToolBarSeparatorUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + @Override public Dimension getPreferredSize( JComponent c ) { Dimension size = ((JToolBar.Separator)c).getSeparatorSize(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java index ca27d66b..bc7fea16 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java @@ -30,6 +30,7 @@ import javax.swing.border.Border; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicToolBarUI; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; /** * Provides the Flat LaF UI delegate for {@link javax.swing.JToolBar}. @@ -59,6 +60,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; */ public class FlatToolBarUI extends BasicToolBarUI + implements StyleableUI { /** @since 1.4 */ @Styleable protected boolean focusableButtons; @@ -153,6 +155,14 @@ public class FlatToolBarUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + /** * @since 1.4 */ diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java index cfd8b724..0c626f6f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java @@ -41,6 +41,7 @@ import javax.swing.plaf.basic.BasicTreeUI; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreePath; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI; import com.formdev.flatlaf.util.UIScale; /** @@ -122,6 +123,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatTreeUI extends BasicTreeUI + implements StyleableUI { @Styleable protected Color selectionBackground; @Styleable protected Color selectionForeground; @@ -301,6 +303,14 @@ public class FlatTreeUI return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); } + /** + * @since TODO + */ + @Override + public Map> getStyleableInfos( JComponent c ) { + return FlatStyleSupport.getAnnotatedStyleableInfos( this ); + } + /** * Same as super.paintRow(), but supports wide selection and uses * inactive selection background/foreground if tree is not focused. diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java new file mode 100644 index 00000000..70caf329 --- /dev/null +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java @@ -0,0 +1,1105 @@ +/* + * Copyright 2021 FormDev Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.formdev.flatlaf.ui; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static com.formdev.flatlaf.ui.TestUtils.assertMapEquals; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Insets; +import java.util.LinkedHashMap; +import java.util.Map; +import javax.swing.*; +import javax.swing.table.JTableHeader; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import com.formdev.flatlaf.icons.*; + +/** + * @author Karl Tauber + */ +public class TestFlatStyleableInfo +{ + @BeforeAll + static void setup() { + TestUtils.setup( false ); + } + + @AfterAll + static void cleanup() { + TestUtils.cleanup(); + } + + private Map> expectedMap( Object... keyValuePairs ) { + Map> map = new LinkedHashMap<>(); + expectedMap( map, keyValuePairs ); + return map; + } + + private void expectedMap( Map> map, Object... keyValuePairs ) { + for( int i = 0; i < keyValuePairs.length; i += 2 ) + map.put( (String) keyValuePairs[i], (Class) keyValuePairs[i+1] ); + } + + //---- components --------------------------------------------------------- + + @Test + void button() { + JButton b = new JButton(); + FlatButtonUI ui = (FlatButtonUI) b.getUI(); + + Map> expected = new LinkedHashMap<>(); + button( expected ); + + //---- FlatHelpButtonIcon ---- + + expectedMap( expected, + "help.focusWidth", int.class, + "help.focusColor", Color.class, + "help.innerFocusWidth", float.class, + "help.borderWidth", int.class, + + "help.borderColor", Color.class, + "help.disabledBorderColor", Color.class, + "help.focusedBorderColor", Color.class, + "help.hoverBorderColor", Color.class, + "help.background", Color.class, + "help.disabledBackground", Color.class, + "help.focusedBackground", Color.class, + "help.hoverBackground", Color.class, + "help.pressedBackground", Color.class, + "help.questionMarkColor", Color.class, + "help.disabledQuestionMarkColor", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( b ) ); + } + + private void button( Map> expected ) { + expectedMap( expected, + "minimumWidth", int.class, + + "focusedBackground", Color.class, + "hoverBackground", Color.class, + "pressedBackground", Color.class, + "selectedBackground", Color.class, + "selectedForeground", Color.class, + "disabledBackground", Color.class, + "disabledText", Color.class, + "disabledSelectedBackground", Color.class, + + "default.background", Color.class, + "default.foreground", Color.class, + "default.focusedBackground", Color.class, + "default.hoverBackground", Color.class, + "default.pressedBackground", Color.class, + "default.boldText", boolean.class, + + "paintShadow", boolean.class, + "shadowWidth", int.class, + "shadowColor", Color.class, + "default.shadowColor", Color.class, + + "toolbar.spacingInsets", Insets.class, + "toolbar.hoverBackground", Color.class, + "toolbar.pressedBackground", Color.class, + "toolbar.selectedBackground", Color.class + ); + + // border + flatButtonBorder( expected ); + } + + @Test + void checkBox() { + JCheckBox c = new JCheckBox(); + FlatCheckBoxUI ui = (FlatCheckBoxUI) c.getUI(); + + assertTrue( ui.getDefaultIcon() instanceof FlatCheckBoxIcon ); + + // FlatCheckBoxUI extends FlatRadioButtonUI + Map> expected = new LinkedHashMap<>(); + radioButton( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void comboBox() { + JComboBox c = new JComboBox<>(); + FlatComboBoxUI ui = (FlatComboBoxUI) c.getUI(); + + Map> expected = expectedMap( + "padding", Insets.class, + + "minimumWidth", int.class, + "editorColumns", int.class, + "buttonStyle", String.class, + "arrowType", String.class, + "borderColor", Color.class, + "disabledBorderColor", Color.class, + + "editableBackground", Color.class, + "focusedBackground", Color.class, + "disabledBackground", Color.class, + "disabledForeground", Color.class, + + "buttonBackground", Color.class, + "buttonFocusedBackground", Color.class, + "buttonEditableBackground", Color.class, + "buttonArrowColor", Color.class, + "buttonDisabledArrowColor", Color.class, + "buttonHoverArrowColor", Color.class, + "buttonPressedArrowColor", Color.class, + + "popupBackground", Color.class + ); + + // border + flatRoundBorder( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void editorPane() { + JEditorPane c = new JEditorPane(); + FlatEditorPaneUI ui = (FlatEditorPaneUI) c.getUI(); + + Map> expected = expectedMap( + "minimumWidth", int.class, + "disabledBackground", Color.class, + "inactiveBackground", Color.class, + "focusedBackground", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void formattedTextField() { + JFormattedTextField c = new JFormattedTextField(); + FlatFormattedTextFieldUI ui = (FlatFormattedTextFieldUI) c.getUI(); + + // FlatFormattedTextFieldUI extends FlatTextFieldUI + Map> expected = new LinkedHashMap<>(); + textField( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void internalFrame() { + JInternalFrame c = new JInternalFrame(); + FlatInternalFrameUI ui = (FlatInternalFrameUI) c.getUI(); + + Map> expected = expectedMap( + "activeBorderColor", Color.class, + "inactiveBorderColor", Color.class, + "borderLineWidth", int.class, + "dropShadowPainted", boolean.class, + "borderMargins", Insets.class, + + "activeDropShadowColor", Color.class, + "activeDropShadowInsets", Insets.class, + "activeDropShadowOpacity", float.class, + "inactiveDropShadowColor", Color.class, + "inactiveDropShadowInsets", Insets.class, + "inactiveDropShadowOpacity", float.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void label() { + JLabel c = new JLabel(); + FlatLabelUI ui = (FlatLabelUI) c.getUI(); + + Map> expected = expectedMap( + "disabledForeground", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void list() { + JList c = new JList<>(); + FlatListUI ui = (FlatListUI) c.getUI(); + + Map> expected = expectedMap( + "selectionBackground", Color.class, + "selectionForeground", Color.class, + "selectionInactiveBackground", Color.class, + "selectionInactiveForeground", Color.class, + + // FlatListCellBorder + "cellMargins", Insets.class, + "cellFocusColor", Color.class, + "showCellFocusIndicator", boolean.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void menuBar() { + JMenuBar c = new JMenuBar(); + FlatMenuBarUI ui = (FlatMenuBarUI) c.getUI(); + + Map> expected = expectedMap( + // FlatMenuBarBorder + "borderColor", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void menu() { + JMenu c = new JMenu(); + FlatMenuUI ui = (FlatMenuUI) c.getUI(); + + Map> expected = new LinkedHashMap<>(); + menuItem( expected ); + menuItem_arrowIcon( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void menuItem() { + JMenuItem c = new JMenuItem(); + FlatMenuItemUI ui = (FlatMenuItemUI) c.getUI(); + + Map> expected = new LinkedHashMap<>(); + menuItem( expected ); + menuItem_arrowIcon( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void checkBoxMenuItem() { + JCheckBoxMenuItem c = new JCheckBoxMenuItem(); + FlatCheckBoxMenuItemUI ui = (FlatCheckBoxMenuItemUI) c.getUI(); + + Map> expected = new LinkedHashMap<>(); + menuItem( expected ); + menuItem_checkIcon( expected ); + menuItem_arrowIcon( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void radioButtonMenuItem() { + JRadioButtonMenuItem c = new JRadioButtonMenuItem(); + FlatRadioButtonMenuItemUI ui = (FlatRadioButtonMenuItemUI) c.getUI(); + + Map> expected = new LinkedHashMap<>(); + menuItem( expected ); + menuItem_checkIcon( expected ); + menuItem_arrowIcon( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + private void menuItem( Map> expected ) { + expectedMap( expected, + "selectionBackground", Color.class, + "selectionForeground", Color.class, + "disabledForeground", Color.class, + "acceleratorForeground", Color.class, + "acceleratorSelectionForeground", Color.class + ); + + menuItemRenderer( expected ); + } + + private void menuItemRenderer( Map> expected ) { + expectedMap( expected, + "minimumWidth", int.class, + "minimumIconSize", Dimension.class, + "textAcceleratorGap", int.class, + "textNoAcceleratorGap", int.class, + "acceleratorArrowGap", int.class, + + "checkBackground", Color.class, + "checkMargins", Insets.class, + + "underlineSelectionBackground", Color.class, + "underlineSelectionCheckBackground", Color.class, + "underlineSelectionColor", Color.class, + "underlineSelectionHeight", int.class + ); + } + + private void menuItem_checkIcon( Map> expected ) { + expectedMap( expected, + "icon.checkmarkColor", Color.class, + "icon.disabledCheckmarkColor", Color.class, + "selectionForeground", Color.class + ); + } + + private void menuItem_arrowIcon( Map> expected ) { + expectedMap( expected, + "icon.arrowType", String.class, + "icon.arrowColor", Color.class, + "icon.disabledArrowColor", Color.class, + "selectionForeground", Color.class + ); + } + + @Test + void passwordField() { + JPasswordField c = new JPasswordField(); + FlatPasswordFieldUI ui = (FlatPasswordFieldUI) c.getUI(); + + Map> expected = new LinkedHashMap<>(); + expectedMap( expected, + "showCapsLock", boolean.class + ); + + // FlatPasswordFieldUI extends FlatTextFieldUI + textField( expected ); + + expectedMap( expected, + // capsLockIcon + "capsLockIconColor", Color.class + ); + + // border + flatTextBorder( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void popupMenuSeparator() { + JPopupMenu.Separator c = new JPopupMenu.Separator(); + FlatPopupMenuSeparatorUI ui = (FlatPopupMenuSeparatorUI) c.getUI(); + + Map> expected = new LinkedHashMap<>(); + + // FlatPopupMenuSeparatorUI extends FlatSeparatorUI + separator( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void progressBar() { + JProgressBar c = new JProgressBar(); + FlatProgressBarUI ui = (FlatProgressBarUI) c.getUI(); + + Map> expected = expectedMap( + "arc", int.class, + "horizontalSize", Dimension.class, + "verticalSize", Dimension.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void radioButton() { + JRadioButton c = new JRadioButton(); + FlatRadioButtonUI ui = (FlatRadioButtonUI) c.getUI(); + + assertTrue( ui.getDefaultIcon() instanceof FlatRadioButtonIcon ); + + Map> expected = new LinkedHashMap<>(); + radioButton( expected ); + + expectedMap( expected, + "icon.centerDiameter", int.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + private void radioButton( Map> expected ) { + expectedMap( expected, + "disabledText", Color.class, + + //---- icon ---- + + "icon.focusWidth", int.class, + "icon.focusColor", Color.class, + "icon.arc", int.class, + + // enabled + "icon.borderColor", Color.class, + "icon.background", Color.class, + "icon.selectedBorderColor", Color.class, + "icon.selectedBackground", Color.class, + "icon.checkmarkColor", Color.class, + + // disabled + "icon.disabledBorderColor", Color.class, + "icon.disabledBackground", Color.class, + "icon.disabledCheckmarkColor", Color.class, + + // focused + "icon.focusedBorderColor", Color.class, + "icon.focusedBackground", Color.class, + "icon.selectedFocusedBorderColor", Color.class, + "icon.selectedFocusedBackground", Color.class, + "icon.selectedFocusedCheckmarkColor", Color.class, + + // hover + "icon.hoverBorderColor", Color.class, + "icon.hoverBackground", Color.class, + "icon.selectedHoverBackground", Color.class, + + // pressed + "icon.pressedBackground", Color.class, + "icon.selectedPressedBackground", Color.class + ); + } + + @Test + void scrollBar() { + JScrollBar c = new JScrollBar(); + FlatScrollBarUI ui = (FlatScrollBarUI) c.getUI(); + + Map> expected = expectedMap( + "track", Color.class, + "thumb", Color.class, + "width", int.class, + "minimumThumbSize", Dimension.class, + "maximumThumbSize", Dimension.class, + "allowsAbsolutePositioning", boolean.class, + + "trackInsets", Insets.class, + "thumbInsets", Insets.class, + "trackArc", int.class, + "thumbArc", int.class, + "hoverTrackColor", Color.class, + "hoverThumbColor", Color.class, + "hoverThumbWithTrack", boolean.class, + "pressedTrackColor", Color.class, + "pressedThumbColor", Color.class, + "pressedThumbWithTrack", boolean.class, + + "showButtons", boolean.class, + "arrowType", String.class, + "buttonArrowColor", Color.class, + "buttonDisabledArrowColor", Color.class, + "hoverButtonBackground", Color.class, + "pressedButtonBackground", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void scrollPane() { + JScrollPane c = new JScrollPane(); + FlatScrollPaneUI ui = (FlatScrollPaneUI) c.getUI(); + + Map> expected = new LinkedHashMap<>(); + + // border + flatBorder( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void separator() { + JSeparator c = new JSeparator(); + FlatSeparatorUI ui = (FlatSeparatorUI) c.getUI(); + + Map> expected = new LinkedHashMap<>(); + separator( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + private void separator( Map> expected ) { + expectedMap( expected, + "height", int.class, + "stripeWidth", int.class, + "stripeIndent", int.class + ); + } + + @Test + void slider() { + JSlider c = new JSlider(); + FlatSliderUI ui = (FlatSliderUI) c.getUI(); + + Map> expected = expectedMap( + "trackWidth", int.class, + "thumbSize", Dimension.class, + "focusWidth", int.class, + + "trackValueColor", Color.class, + "trackColor", Color.class, + "thumbColor", Color.class, + "thumbBorderColor", Color.class, + "focusedColor", Color.class, + "focusedThumbBorderColor", Color.class, + "hoverThumbColor", Color.class, + "pressedThumbColor", Color.class, + "disabledTrackColor", Color.class, + "disabledThumbColor", Color.class, + "disabledThumbBorderColor", Color.class, + "tickColor", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void spinner() { + JSpinner c = new JSpinner(); + FlatSpinnerUI ui = (FlatSpinnerUI) c.getUI(); + + Map> expected = expectedMap( + "minimumWidth", int.class, + "buttonStyle", String.class, + "arrowType", String.class, + "borderColor", Color.class, + "disabledBorderColor", Color.class, + "disabledBackground", Color.class, + "disabledForeground", Color.class, + "focusedBackground", Color.class, + "buttonBackground", Color.class, + "buttonArrowColor", Color.class, + "buttonDisabledArrowColor", Color.class, + "buttonHoverArrowColor", Color.class, + "buttonPressedArrowColor", Color.class, + "padding", Insets.class + ); + + // border + flatRoundBorder( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void splitPane() { + JSplitPane c = new JSplitPane(); + FlatSplitPaneUI ui = (FlatSplitPaneUI) c.getUI(); + + Map> expected = expectedMap( + "arrowType", String.class, + "oneTouchArrowColor", Color.class, + "oneTouchHoverArrowColor", Color.class, + "oneTouchPressedArrowColor", Color.class, + + "style", String.class, + "gripColor", Color.class, + "gripDotCount", int.class, + "gripDotSize", int.class, + "gripGap", int.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void tabbedPane() { + JTabbedPane c = new JTabbedPane(); + FlatTabbedPaneUI ui = (FlatTabbedPaneUI) c.getUI(); + + Map> expected = expectedMap( + "tabInsets", Insets.class, + "tabAreaInsets", Insets.class, + "textIconGap", int.class, + + "disabledForeground", Color.class, + + "selectedBackground", Color.class, + "selectedForeground", Color.class, + "underlineColor", Color.class, + "disabledUnderlineColor", Color.class, + "hoverColor", Color.class, + "focusColor", Color.class, + "tabSeparatorColor", Color.class, + "contentAreaColor", Color.class, + + "minimumTabWidth", int.class, + "maximumTabWidth", int.class, + "tabHeight", int.class, + "tabSelectionHeight", int.class, + "contentSeparatorHeight", int.class, + "showTabSeparators", boolean.class, + "tabSeparatorsFullHeight", boolean.class, + "hasFullBorder", boolean.class, + "tabsOpaque", boolean.class, + + "tabsPopupPolicy", String.class, + "scrollButtonsPolicy", String.class, + "scrollButtonsPlacement", String.class, + + "tabAreaAlignment", String.class, + "tabAlignment", String.class, + "tabWidthMode", String.class, + + "arrowType", String.class, + "buttonInsets", Insets.class, + "buttonArc", int.class, + "buttonHoverBackground", Color.class, + "buttonPressedBackground", Color.class, + + "moreTabsButtonToolTipText", String.class, + + // FlatTabbedPaneCloseIcon + "closeSize", Dimension.class, + "closeArc", int.class, + "closeCrossPlainSize", float.class, + "closeCrossFilledSize", float.class, + "closeCrossLineWidth", float.class, + "closeBackground", Color.class, + "closeForeground", Color.class, + "closeHoverBackground", Color.class, + "closeHoverForeground", Color.class, + "closePressedBackground", Color.class, + "closePressedForeground", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void table() { + JTable c = new JTable(); + FlatTableUI ui = (FlatTableUI) c.getUI(); + + Map> expected = expectedMap( + "selectionBackground", Color.class, + "selectionForeground", Color.class, + "selectionInactiveBackground", Color.class, + "selectionInactiveForeground", Color.class, + + // FlatTableCellBorder + "cellMargins", Insets.class, + "cellFocusColor", Color.class, + "showCellFocusIndicator", boolean.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void tableHeader() { + JTableHeader c = new JTableHeader(); + FlatTableHeaderUI ui = (FlatTableHeaderUI) c.getUI(); + + Map> expected = expectedMap( + "bottomSeparatorColor", Color.class, + "height", int.class, + "sortIconPosition", String.class, + + // FlatTableHeaderBorder + "cellMargins", Insets.class, + "separatorColor", Color.class, + + // FlatAscendingSortIcon and FlatDescendingSortIcon + "arrowType", String.class, + "sortIconColor", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void textArea() { + JTextArea c = new JTextArea(); + FlatTextAreaUI ui = (FlatTextAreaUI) c.getUI(); + + Map> expected = expectedMap( + "minimumWidth", int.class, + "disabledBackground", Color.class, + "inactiveBackground", Color.class, + "focusedBackground", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void textField() { + JTextField c = new JTextField(); + FlatTextFieldUI ui = (FlatTextFieldUI) c.getUI(); + + Map> expected = new LinkedHashMap<>(); + textField( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + private void textField( Map> expected ) { + expectedMap( expected, + "minimumWidth", int.class, + "disabledBackground", Color.class, + "inactiveBackground", Color.class, + "placeholderForeground", Color.class, + "focusedBackground", Color.class + ); + + // border + flatTextBorder( expected ); + } + + @Test + void textPane() { + JTextPane c = new JTextPane(); + FlatTextPaneUI ui = (FlatTextPaneUI) c.getUI(); + + Map> expected = expectedMap( + "minimumWidth", int.class, + "disabledBackground", Color.class, + "inactiveBackground", Color.class, + "focusedBackground", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void toggleButton() { + JToggleButton b = new JToggleButton(); + FlatToggleButtonUI ui = (FlatToggleButtonUI) b.getUI(); + + Map> expected = expectedMap( + "tab.underlineHeight", int.class, + "tab.underlineColor", Color.class, + "tab.disabledUnderlineColor", Color.class, + "tab.selectedBackground", Color.class, + "tab.hoverBackground", Color.class, + "tab.focusBackground", Color.class + ); + + // FlatToggleButtonUI extends FlatButtonUI + button( expected ); + + assertMapEquals( expected, ui.getStyleableInfos( b ) ); + } + + @Test + void toolBar() { + JToolBar c = new JToolBar(); + FlatToolBarUI ui = (FlatToolBarUI) c.getUI(); + + Map> expected = expectedMap( + "focusableButtons", boolean.class, + + "borderMargins", Insets.class, + "gripColor", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void toolBarSeparator() { + JToolBar.Separator c = new JToolBar.Separator(); + FlatToolBarSeparatorUI ui = (FlatToolBarSeparatorUI) c.getUI(); + + Map> expected = expectedMap( + "separatorWidth", int.class, + "separatorColor", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + @Test + void tree() { + JTree c = new JTree(); + FlatTreeUI ui = (FlatTreeUI) c.getUI(); + + Map> expected = expectedMap( + "selectionBackground", Color.class, + "selectionForeground", Color.class, + "selectionInactiveBackground", Color.class, + "selectionInactiveForeground", Color.class, + "selectionBorderColor", Color.class, + "wideSelection", boolean.class, + "showCellFocusIndicator", boolean.class, + + // icons + "icon.arrowType", String.class, + "icon.expandedColor", Color.class, + "icon.collapsedColor", Color.class, + "icon.leafColor", Color.class, + "icon.closedColor", Color.class, + "icon.openColor", Color.class + ); + + assertMapEquals( expected, ui.getStyleableInfos( c ) ); + } + + //---- component borders -------------------------------------------------- + + private void flatButtonBorder( Map> expected ) { + flatBorder( expected ); + + expectedMap( expected, + "borderColor", Color.class, + "disabledBorderColor", Color.class, + "focusedBorderColor", Color.class, + "hoverBorderColor", Color.class, + + "default.borderColor", Color.class, + "default.focusedBorderColor", Color.class, + "default.focusColor", Color.class, + "default.hoverBorderColor", Color.class, + "toolbar.focusColor", Color.class, + + "borderWidth", int.class, + "default.borderWidth", int.class, + "toolbar.margin", Insets.class, + "toolbar.spacingInsets", Insets.class, + "toolbar.focusWidth", float.class, + "arc", int.class + ); + } + + private void flatRoundBorder( Map> expected ) { + flatBorder( expected ); + + expectedMap( expected, + "arc", int.class + ); + } + + private void flatTextBorder( Map> expected ) { + flatBorder( expected ); + + expectedMap( expected, + "arc", int.class + ); + } + + private void flatBorder( Map> expected ) { + expectedMap( expected, + "focusWidth", int.class, + "innerFocusWidth", float.class, + "innerOutlineWidth", float.class, + "focusColor", Color.class, + "borderColor", Color.class, + "disabledBorderColor", Color.class, + "focusedBorderColor", Color.class, + + "error.borderColor", Color.class, + "error.focusedBorderColor", Color.class, + "warning.borderColor", Color.class, + "warning.focusedBorderColor", Color.class, + "custom.borderColor", Color.class + ); + } + + //---- borders ------------------------------------------------------------ + + @Test + void flatButtonBorder() { + FlatButtonBorder border = new FlatButtonBorder(); + + Map> expected = new LinkedHashMap<>(); + flatButtonBorder( expected ); + + assertMapEquals( expected, border.getStyleableInfos() ); + } + + @Test + void flatRoundBorder() { + FlatRoundBorder border = new FlatRoundBorder(); + + Map> expected = new LinkedHashMap<>(); + flatRoundBorder( expected ); + + assertMapEquals( expected, border.getStyleableInfos() ); + } + + @Test + void flatTextBorder() { + FlatTextBorder border = new FlatTextBorder(); + + Map> expected = new LinkedHashMap<>(); + flatTextBorder( expected ); + + assertMapEquals( expected, border.getStyleableInfos() ); + } + + @Test + void flatBorder() { + FlatBorder border = new FlatBorder(); + + Map> expected = new LinkedHashMap<>(); + flatBorder( expected ); + + assertMapEquals( expected, border.getStyleableInfos() ); + } + + //---- icons -------------------------------------------------------------- + + @Test + void flatCheckBoxIcon() { + FlatCheckBoxIcon icon = new FlatCheckBoxIcon(); + + Map> expected = new LinkedHashMap<>(); + flatCheckBoxIcon( expected ); + + assertMapEquals( expected, icon.getStyleableInfos() ); + } + + @Test + void flatRadioButtonIcon() { + FlatRadioButtonIcon icon = new FlatRadioButtonIcon(); + + // FlatRadioButtonIcon extends FlatCheckBoxIcon + Map> expected = new LinkedHashMap<>(); + flatCheckBoxIcon( expected ); + + expectedMap( expected, + "centerDiameter", int.class + ); + + assertMapEquals( expected, icon.getStyleableInfos() ); + } + + private void flatCheckBoxIcon( Map> expected ) { + expectedMap( expected, + "focusWidth", int.class, + "focusColor", Color.class, + "arc", int.class, + + // enabled + "borderColor", Color.class, + "background", Color.class, + "selectedBorderColor", Color.class, + "selectedBackground", Color.class, + "checkmarkColor", Color.class, + + // disabled + "disabledBorderColor", Color.class, + "disabledBackground", Color.class, + "disabledCheckmarkColor", Color.class, + + // focused + "focusedBorderColor", Color.class, + "focusedBackground", Color.class, + "selectedFocusedBorderColor", Color.class, + "selectedFocusedBackground", Color.class, + "selectedFocusedCheckmarkColor", Color.class, + + // hover + "hoverBorderColor", Color.class, + "hoverBackground", Color.class, + "selectedHoverBackground", Color.class, + + // pressed + "pressedBackground", Color.class, + "selectedPressedBackground", Color.class + ); + } + + @Test + void flatCheckBoxMenuItemIcon() { + FlatCheckBoxMenuItemIcon icon = new FlatCheckBoxMenuItemIcon(); + + Map> expected = new LinkedHashMap<>(); + flatCheckBoxMenuItemIcon( expected ); + + assertMapEquals( expected, icon.getStyleableInfos() ); + } + + @Test + void flatRadioButtonMenuItemIcon() { + FlatRadioButtonMenuItemIcon icon = new FlatRadioButtonMenuItemIcon(); + + // FlatRadioButtonMenuItemIcon extends FlatCheckBoxMenuItemIcon + Map> expected = new LinkedHashMap<>(); + flatCheckBoxMenuItemIcon( expected ); + + assertMapEquals( expected, icon.getStyleableInfos() ); + } + + private void flatCheckBoxMenuItemIcon( Map> expected ) { + expectedMap( expected, + "checkmarkColor", Color.class, + "disabledCheckmarkColor", Color.class, + "selectionForeground", Color.class + ); + } + + @Test + void flatMenuArrowIcon() { + FlatMenuArrowIcon icon = new FlatMenuArrowIcon(); + + Map> expected = new LinkedHashMap<>(); + flatMenuArrowIcon( expected ); + + assertMapEquals( expected, icon.getStyleableInfos() ); + } + + @Test + void flatMenuItemArrowIcon() { + FlatMenuItemArrowIcon icon = new FlatMenuItemArrowIcon(); + + // FlatMenuItemArrowIcon extends FlatMenuArrowIcon + Map> expected = new LinkedHashMap<>(); + flatMenuArrowIcon( expected ); + + assertMapEquals( expected, icon.getStyleableInfos() ); + } + + private void flatMenuArrowIcon( Map> expected ) { + expectedMap( expected, + "arrowType", String.class, + "arrowColor", Color.class, + "disabledArrowColor", Color.class, + "selectionForeground", Color.class + ); + } + + @Test + void flatHelpButtonIcon() { + FlatHelpButtonIcon icon = new FlatHelpButtonIcon(); + + Map> expected = expectedMap( + "focusWidth", int.class, + "focusColor", Color.class, + "innerFocusWidth", float.class, + "borderWidth", int.class, + + "borderColor", Color.class, + "disabledBorderColor", Color.class, + "focusedBorderColor", Color.class, + "hoverBorderColor", Color.class, + "background", Color.class, + "disabledBackground", Color.class, + "focusedBackground", Color.class, + "hoverBackground", Color.class, + "pressedBackground", Color.class, + "questionMarkColor", Color.class, + "disabledQuestionMarkColor", Color.class + ); + + assertMapEquals( expected, icon.getStyleableInfos() ); + } +} diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java index 47747e1a..75d82e41 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java @@ -276,8 +276,8 @@ public class TestFlatStyling Consumer applyStyle = style -> ui.applyStyle( style ); menuItem( applyStyle ); - menuItem_arrowIcon( applyStyle ); menuItem_checkIcon( applyStyle ); + menuItem_arrowIcon( applyStyle ); } @Test @@ -287,8 +287,8 @@ public class TestFlatStyling Consumer applyStyle = style -> ui.applyStyle( style ); menuItem( applyStyle ); - menuItem_arrowIcon( applyStyle ); menuItem_checkIcon( applyStyle ); + menuItem_arrowIcon( applyStyle ); } private void menuItem( Consumer applyStyle ) { @@ -320,7 +320,7 @@ public class TestFlatStyling private void menuItem_checkIcon( Consumer applyStyle ) { applyStyle.accept( "icon.checkmarkColor: #fff" ); applyStyle.accept( "icon.disabledCheckmarkColor: #fff" ); - applyStyle.accept( "icon.selectionForeground: #fff" ); + applyStyle.accept( "selectionForeground: #fff" ); } private void menuItem_arrowIcon( Consumer applyStyle ) { @@ -335,11 +335,9 @@ public class TestFlatStyling JPasswordField c = new JPasswordField(); FlatPasswordFieldUI ui = (FlatPasswordFieldUI) c.getUI(); - ui.applyStyle( "minimumWidth: 100" ); - ui.applyStyle( "disabledBackground: #fff" ); - ui.applyStyle( "inactiveBackground: #fff" ); - ui.applyStyle( "placeholderForeground: #fff" ); - ui.applyStyle( "focusedBackground: #fff" ); + // FlatPasswordFieldUI extends FlatTextFieldUI + textField( ui ); + ui.applyStyle( "showCapsLock: true" ); // capsLockIcon @@ -543,6 +541,7 @@ public class TestFlatStyling ui.applyStyle( "tabInsets: 1,2,3,4" ); ui.applyStyle( "tabAreaInsets: 1,2,3,4" ); + ui.applyStyle( "textIconGap: 4" ); ui.applyStyle( "disabledForeground: #fff" ); @@ -555,7 +554,6 @@ public class TestFlatStyling ui.applyStyle( "tabSeparatorColor: #fff" ); ui.applyStyle( "contentAreaColor: #fff" ); - ui.applyStyle( "textIconGap: 4" ); ui.applyStyle( "minimumTabWidth: 50" ); ui.applyStyle( "maximumTabWidth: 100" ); ui.applyStyle( "tabHeight: 30" ); @@ -809,6 +807,16 @@ public class TestFlatStyling border.applyStyleProperty( "arc", 6 ); } + @Test + void flatRoundBorder() { + FlatRoundBorder border = new FlatRoundBorder(); + + // FlatRoundBorder extends FlatBorder + flatBorder( border ); + + border.applyStyleProperty( "arc", 6 ); + } + @Test void flatTextBorder() { FlatTextBorder border = new FlatTextBorder(); @@ -937,6 +945,7 @@ public class TestFlatStyling icon.applyStyleProperty( "disabledArrowColor", Color.WHITE ); icon.applyStyleProperty( "selectionForeground", Color.WHITE ); } + @Test void flatHelpButtonIcon() { FlatHelpButtonIcon icon = new FlatHelpButtonIcon(); diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestUtils.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestUtils.java index e4bead06..d9399383 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestUtils.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestUtils.java @@ -17,7 +17,10 @@ package com.formdev.flatlaf.ui; import java.awt.Font; +import java.util.Map; +import java.util.Objects; import javax.swing.UIManager; +import org.opentest4j.AssertionFailedError; import com.formdev.flatlaf.FlatIntelliJLaf; import com.formdev.flatlaf.FlatLightLaf; import com.formdev.flatlaf.FlatSystemProperties; @@ -50,4 +53,15 @@ public class TestUtils public static void resetFont() { UIManager.put( "defaultFont", null ); } + + public static void assertMapEquals( Map expected, Map actual ) { + if( !Objects.equals( expected, actual ) ) { + String expectedStr = String.valueOf( expected ).replace( ", ", ",\n" ); + String actualStr = String.valueOf( actual ).replace( ", ", ",\n" ); + String msg = String.format( "expected: <%s> but was: <%s>", expectedStr, actualStr ); + + // pass expected/actual strings to exception for nice diff in IDE + throw new AssertionFailedError( msg, expectedStr, actualStr ); + } + } }