diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCapsLockIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCapsLockIcon.java index 639b640a..a4e4e978 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCapsLockIcon.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCapsLockIcon.java @@ -28,6 +28,7 @@ import java.awt.geom.RoundRectangle2D; import java.util.Collections; import java.util.Map; import javax.swing.UIManager; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException; import com.formdev.flatlaf.ui.FlatUIUtils; @@ -40,6 +41,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils; */ public class FlatCapsLockIcon extends FlatAbstractIcon + implements StyleableObject { private Path2D path; @@ -48,6 +50,7 @@ public class FlatCapsLockIcon } /** @since 2 */ + @Override public Object applyStyleProperty( String key, Object value ) { Object oldValue; switch( key ) { @@ -57,11 +60,13 @@ public class FlatCapsLockIcon } /** @since 3.7 */ + @Override public Map> getStyleableInfos() throws IllegalArgumentException { return Collections.singletonMap( "capsLockIconColor", Color.class ); } /** @since 2.5 */ + @Override public Object getStyleableValue( String key ) { switch( key ) { case "capsLockIconColor": return color; 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 f2fa0254..5127c006 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 @@ -24,13 +24,12 @@ 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; import com.formdev.flatlaf.ui.FlatButtonUI; -import com.formdev.flatlaf.ui.FlatStylingSupport; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatUIUtils; /** @@ -103,6 +102,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils; */ public class FlatCheckBoxIcon extends FlatAbstractIcon + implements StyleableObject { protected final String style = UIManager.getString( getPropertyPrefix() + "icon.style" ); @Styleable protected float focusWidth = getUIFloat( "CheckBox.icon.focusWidth", UIManager.getInt( "Component.focusWidth" ), style ); @@ -197,21 +197,6 @@ public class FlatCheckBoxIcon super( ICON_SIZE, ICON_SIZE, null ); } - /** @since 2 */ - public Object applyStyleProperty( String key, Object value ) { - return FlatStylingSupport.applyToAnnotatedObject( this, key, value ); - } - - /** @since 2 */ - public Map> getStyleableInfos() { - return FlatStylingSupport.getAnnotatedStyleableInfos( this ); - } - - /** @since 2.5 */ - public Object getStyleableValue( String key ) { - return FlatStylingSupport.getAnnotatedStyleableValue( this, key ); - } - @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 30c85d79..535e0977 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,12 +21,11 @@ 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; -import com.formdev.flatlaf.ui.FlatStylingSupport; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; /** * Icon for {@link javax.swing.JCheckBoxMenuItem}. @@ -40,6 +39,7 @@ import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; */ public class FlatCheckBoxMenuItemIcon extends FlatAbstractIcon + implements StyleableObject { @Styleable protected Color checkmarkColor = UIManager.getColor( "CheckBoxMenuItem.icon.checkmarkColor" ); @Styleable protected Color disabledCheckmarkColor = UIManager.getColor( "CheckBoxMenuItem.icon.disabledCheckmarkColor" ); @@ -49,21 +49,6 @@ public class FlatCheckBoxMenuItemIcon super( 15, 15, null ); } - /** @since 2 */ - public Object applyStyleProperty( String key, Object value ) { - return FlatStylingSupport.applyToAnnotatedObject( this, key, value ); - } - - /** @since 2 */ - public Map> getStyleableInfos() { - return FlatStylingSupport.getAnnotatedStyleableInfos( this ); - } - - /** @since 2.5 */ - public Object getStyleableValue( String key ) { - return FlatStylingSupport.getAnnotatedStyleableValue( this, key ); - } - @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/FlatClearIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatClearIcon.java index 58393f8f..de3cd135 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatClearIcon.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatClearIcon.java @@ -21,12 +21,11 @@ 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.AbstractButton; import javax.swing.ButtonModel; import javax.swing.UIManager; -import com.formdev.flatlaf.ui.FlatStylingSupport; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatUIUtils; /** @@ -41,6 +40,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils; */ public class FlatClearIcon extends FlatAbstractIcon + implements StyleableObject { @Styleable protected Color clearIconColor = UIManager.getColor( "SearchField.clearIconColor" ); @Styleable protected Color clearIconHoverColor = UIManager.getColor( "SearchField.clearIconHoverColor" ); @@ -58,21 +58,6 @@ public class FlatClearIcon this.ignoreButtonState = ignoreButtonState; } - /** @since 2 */ - public Object applyStyleProperty( String key, Object value ) { - return FlatStylingSupport.applyToAnnotatedObject( this, key, value ); - } - - /** @since 2 */ - public Map> getStyleableInfos() { - return FlatStylingSupport.getAnnotatedStyleableInfos( this ); - } - - /** @since 2.5 */ - public Object getStyleableValue( String key ) { - return FlatStylingSupport.getAnnotatedStyleableValue( this, key ); - } - @Override protected void paintIcon( Component c, Graphics2D g ) { if( !ignoreButtonState && c instanceof AbstractButton ) { 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 2ef479e6..4e531681 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 @@ -24,11 +24,10 @@ import java.awt.Graphics2D; import java.awt.RenderingHints; 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.FlatStylingSupport; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatUIUtils; /** @@ -54,6 +53,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils; */ public class FlatHelpButtonIcon extends FlatAbstractIcon + implements StyleableObject { @Styleable protected int focusWidth = UIManager.getInt( "Component.focusWidth" ); @Styleable protected Color focusColor = UIManager.getColor( "Component.focusColor" ); @@ -76,21 +76,6 @@ public class FlatHelpButtonIcon super( 0, 0, null ); } - /** @since 2 */ - public Object applyStyleProperty( String key, Object value ) { - return FlatStylingSupport.applyToAnnotatedObject( this, key, value ); - } - - /** @since 2 */ - public Map> getStyleableInfos() { - return FlatStylingSupport.getAnnotatedStyleableInfos( this ); - } - - /** @since 2.5 */ - public Object getStyleableValue( String key ) { - return FlatStylingSupport.getAnnotatedStyleableValue( this, key ); - } - @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 a0553a8f..3bd1b071 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,12 +21,11 @@ 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.FlatStylingSupport; import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; /** * "arrow" icon for {@link javax.swing.JMenu}. @@ -41,6 +40,7 @@ import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; */ public class FlatMenuArrowIcon extends FlatAbstractIcon + implements StyleableObject { @Styleable protected String arrowType = UIManager.getString( "Component.arrowType" ); @Styleable protected Color arrowColor = UIManager.getColor( "Menu.icon.arrowColor" ); @@ -51,21 +51,6 @@ public class FlatMenuArrowIcon super( 6, 10, null ); } - /** @since 2 */ - public Object applyStyleProperty( String key, Object value ) { - return FlatStylingSupport.applyToAnnotatedObject( this, key, value ); - } - - /** @since 2 */ - public Map> getStyleableInfos() { - return FlatStylingSupport.getAnnotatedStyleableInfos( this ); - } - - /** @since 2.5 */ - public Object getStyleableValue( String key ) { - return FlatStylingSupport.getAnnotatedStyleableValue( this, key ); - } - @Override protected void paintIcon( Component c, Graphics2D g ) { if( c != null && !c.getComponentOrientation().isLeftToRight() ) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatSearchIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatSearchIcon.java index bcaf2bc1..ecba9e26 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatSearchIcon.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatSearchIcon.java @@ -21,11 +21,10 @@ import java.awt.Component; import java.awt.Graphics2D; import java.awt.geom.Area; import java.awt.geom.Ellipse2D; -import java.util.Map; import javax.swing.UIManager; import com.formdev.flatlaf.ui.FlatButtonUI; -import com.formdev.flatlaf.ui.FlatStylingSupport; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatUIUtils; /** @@ -40,6 +39,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils; */ public class FlatSearchIcon extends FlatAbstractIcon + implements StyleableObject { @Styleable protected Color searchIconColor = UIManager.getColor( "SearchField.searchIconColor" ); @Styleable protected Color searchIconHoverColor = UIManager.getColor( "SearchField.searchIconHoverColor" ); @@ -58,21 +58,6 @@ public class FlatSearchIcon this.ignoreButtonState = ignoreButtonState; } - /** @since 2 */ - public Object applyStyleProperty( String key, Object value ) { - return FlatStylingSupport.applyToAnnotatedObject( this, key, value ); - } - - /** @since 2 */ - public Map> getStyleableInfos() { - return FlatStylingSupport.getAnnotatedStyleableInfos( this ); - } - - /** @since 2.5 */ - public Object getStyleableValue( String key ) { - return FlatStylingSupport.getAnnotatedStyleableValue( this, key ); - } - @Override protected void paintIcon( Component c, Graphics2D g ) { /* 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 a57b4fbe..efd69ac4 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 @@ -22,11 +22,10 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.geom.Path2D; -import java.util.Map; import javax.swing.UIManager; import com.formdev.flatlaf.ui.FlatButtonUI; -import com.formdev.flatlaf.ui.FlatStylingSupport; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatUIUtils; /** @@ -48,6 +47,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils; */ public class FlatTabbedPaneCloseIcon extends FlatAbstractIcon + implements StyleableObject { @Styleable protected Dimension closeSize = UIManager.getDimension( "TabbedPane.closeSize" ); @Styleable protected int closeArc = UIManager.getInt( "TabbedPane.closeArc" ); @@ -65,21 +65,6 @@ public class FlatTabbedPaneCloseIcon super( 16, 16, null ); } - /** @since 2 */ - public Object applyStyleProperty( String key, Object value ) { - return FlatStylingSupport.applyToAnnotatedObject( this, key, value ); - } - - /** @since 2 */ - public Map> getStyleableInfos() { - return FlatStylingSupport.getAnnotatedStyleableInfos( this ); - } - - /** @since 2.5 */ - public Object getStyleableValue( String key ) { - return FlatStylingSupport.getAnnotatedStyleableValue( this, key ); - } - @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 4a4b0111..dd4ff501 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,7 +23,6 @@ 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; @@ -32,7 +31,7 @@ import javax.swing.UIManager; import javax.swing.plaf.basic.BasicBorders; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; -import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableBorder; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.util.DerivedColor; /** @@ -67,7 +66,7 @@ import com.formdev.flatlaf.util.DerivedColor; */ public class FlatBorder extends BasicBorders.MarginBorder - implements StyleableBorder + implements StyleableObject { @Styleable protected int focusWidth = UIManager.getInt( "Component.focusWidth" ); @Styleable protected float innerFocusWidth = FlatUIUtils.getUIFloat( "Component.innerFocusWidth", 0 ); @@ -92,24 +91,6 @@ public class FlatBorder /** @since 2 */ @Styleable protected Color outlineColor; /** @since 2 */ @Styleable protected Color outlineFocusedColor; - /** @since 2 */ - @Override - public Object applyStyleProperty( String key, Object value ) { - return FlatStylingSupport.applyToAnnotatedObject( this, key, value ); - } - - /** @since 2 */ - @Override - public Map> getStyleableInfos() { - return FlatStylingSupport.getAnnotatedStyleableInfos( this ); - } - - /** @since 2.5 */ - @Override - public Object getStyleableValue( String key ) { - return FlatStylingSupport.getAnnotatedStyleableValue( this, key ); - } - @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 f99f4ccd..4a51579d 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 @@ -58,8 +58,8 @@ import javax.swing.plaf.basic.BasicHTML; import javax.swing.text.View; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatLaf; -import com.formdev.flatlaf.icons.FlatHelpButtonIcon; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException; import com.formdev.flatlaf.util.HiDPIUtils; @@ -369,7 +369,7 @@ public class FlatButtonUI /** @since 2 */ protected Object applyStyleProperty( AbstractButton b, String key, Object value ) { if( key.startsWith( "help." ) ) { - if( !(helpButtonIcon instanceof FlatHelpButtonIcon) ) + if( !(helpButtonIcon instanceof StyleableObject) ) throw new UnknownStyleException( key ); if( helpButtonIconShared ) { @@ -378,7 +378,7 @@ public class FlatButtonUI } key = key.substring( "help.".length() ); - return ((FlatHelpButtonIcon)helpButtonIcon).applyStyleProperty( key, value ); + return ((StyleableObject)helpButtonIcon).applyStyleProperty( key, value ); } // update internal values; otherwise isCustomBackground() and isCustomForeground() would return wrong results @@ -399,8 +399,8 @@ public class FlatButtonUI @Override public Map> getStyleableInfos( JComponent c ) { Map> infos = FlatStylingSupport.getAnnotatedStyleableInfos( this, c.getBorder() ); - if( helpButtonIcon instanceof FlatHelpButtonIcon ) - FlatStylingSupport.putAllPrefixKey( infos, "help.", ((FlatHelpButtonIcon)helpButtonIcon).getStyleableInfos() ); + if( helpButtonIcon instanceof StyleableObject ) + FlatStylingSupport.putAllPrefixKey( infos, "help.", ((StyleableObject)helpButtonIcon).getStyleableInfos() ); return infos; } @@ -408,8 +408,8 @@ public class FlatButtonUI @Override public Object getStyleableValue( JComponent c, String key ) { if( key.startsWith( "help." ) ) { - return (helpButtonIcon instanceof FlatHelpButtonIcon) - ? ((FlatHelpButtonIcon)helpButtonIcon).getStyleableValue( key.substring( "help.".length() ) ) + return (helpButtonIcon instanceof StyleableObject) + ? ((StyleableObject)helpButtonIcon).getStyleableValue( key.substring( "help.".length() ) ) : null; } 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 25f09c6d..38d3f0eb 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,9 +24,8 @@ 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.FlatStylingSupport.Styleable; -import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableBorder; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.UIScale; @@ -43,7 +42,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatDropShadowBorder extends FlatEmptyBorder - implements StyleableBorder + implements StyleableObject { @Styleable protected Color shadowColor; @Styleable protected Insets shadowInsets; @@ -93,7 +92,7 @@ public class FlatDropShadowBorder /** @since 2 */ @Override public Object applyStyleProperty( String key, Object value ) { - Object oldValue = FlatStylingSupport.applyToAnnotatedObject( this, key, value ); + Object oldValue = StyleableObject.super.applyStyleProperty( key, value ); if( key.equals( "shadowInsets" ) ) { applyStyleProperty( nonNegativeInsets( shadowInsets ) ); shadowSize = maxInset( shadowInsets ); @@ -101,18 +100,6 @@ public class FlatDropShadowBorder return oldValue; } - /** @since 2 */ - @Override - public Map> getStyleableInfos() { - return FlatStylingSupport.getAnnotatedStyleableInfos( this ); - } - - /** @since 2.5 */ - @Override - public Object getStyleableValue( String key ) { - return FlatStylingSupport.getAnnotatedStyleableValue( this, key ); - } - @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/FlatInternalFrameUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatInternalFrameUI.java index bc5c41e9..7b6f3179 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 @@ -35,7 +35,7 @@ import javax.swing.event.MouseInputAdapter; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicInternalFrameUI; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; -import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableBorder; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI; import com.formdev.flatlaf.util.LoggingFacade; @@ -209,7 +209,7 @@ public class FlatInternalFrameUI public static class FlatInternalFrameBorder extends FlatEmptyBorder - implements StyleableBorder + implements StyleableObject { @Styleable protected Color activeBorderColor = UIManager.getColor( "InternalFrame.activeBorderColor" ); @Styleable protected Color inactiveBorderColor = UIManager.getColor( "InternalFrame.inactiveBorderColor" ); 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 e454c25f..001f6791 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 @@ -25,7 +25,7 @@ import java.util.Map; import javax.swing.JMenuBar; import javax.swing.UIManager; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; -import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableBorder; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; /** * Border for {@link javax.swing.JMenuBar}. @@ -36,7 +36,7 @@ import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableBorder; */ public class FlatMenuBarBorder extends FlatMarginBorder - implements StyleableBorder + implements StyleableObject { @Styleable protected Color borderColor = UIManager.getColor( "MenuBar.borderColor" ); 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 bb7c9cfa..c24a0bb1 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 @@ -40,8 +40,8 @@ import javax.swing.text.JTextComponent; import javax.swing.text.PasswordView; import javax.swing.text.View; import com.formdev.flatlaf.FlatClientProperties; -import com.formdev.flatlaf.icons.FlatCapsLockIcon; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.UIScale; @@ -214,12 +214,12 @@ public class FlatPasswordFieldUI /** @since 2 */ @Override protected Object applyStyleProperty( String key, Object value ) { - if( key.equals( "capsLockIconColor" ) && capsLockIcon instanceof FlatCapsLockIcon ) { + if( key.equals( "capsLockIconColor" ) && capsLockIcon instanceof StyleableObject ) { if( capsLockIconShared ) { capsLockIcon = FlatStylingSupport.cloneIcon( capsLockIcon ); capsLockIconShared = false; } - return ((FlatCapsLockIcon)capsLockIcon).applyStyleProperty( key, value ); + return ((StyleableObject)capsLockIcon).applyStyleProperty( key, value ); } return super.applyStyleProperty( key, value ); @@ -229,15 +229,15 @@ public class FlatPasswordFieldUI @Override public Map> getStyleableInfos( JComponent c ) { Map> infos = super.getStyleableInfos( c ); - if( capsLockIcon instanceof FlatCapsLockIcon ) - infos.putAll( ((FlatCapsLockIcon)capsLockIcon).getStyleableInfos() ); + if( capsLockIcon instanceof StyleableObject ) + infos.putAll( ((StyleableObject)capsLockIcon).getStyleableInfos() ); return infos; } @Override public Object getStyleableValue( JComponent c, String key ) { - if( key.equals( "capsLockIconColor" ) && capsLockIcon instanceof FlatCapsLockIcon ) - return ((FlatCapsLockIcon)capsLockIcon).getStyleableValue( key ); + if( key.equals( "capsLockIconColor" ) && capsLockIcon instanceof StyleableObject ) + return ((StyleableObject)capsLockIcon).getStyleableValue( key ); return super.getStyleableValue( c, key ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupMenuBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupMenuBorder.java index fb00b60f..002c2dd3 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupMenuBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupMenuBorder.java @@ -23,7 +23,7 @@ import java.awt.Insets; import java.util.Map; import javax.swing.JScrollPane; import javax.swing.UIManager; -import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableBorder; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException; import com.formdev.flatlaf.util.UIScale; @@ -37,7 +37,7 @@ import com.formdev.flatlaf.util.UIScale; */ public class FlatPopupMenuBorder extends FlatLineBorder - implements StyleableBorder + implements StyleableObject { private Color borderColor; 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 5255fc8a..d470cd61 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 @@ -45,6 +45,7 @@ import javax.swing.plaf.basic.BasicRadioButtonUI; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.icons.FlatCheckBoxIcon; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException; import com.formdev.flatlaf.util.HiDPIUtils; @@ -204,7 +205,7 @@ public class FlatRadioButtonUI // style icon if( key.startsWith( "icon." ) ) { Icon icon = getRealIcon( b ); - if( !(icon instanceof FlatCheckBoxIcon) ) + if( !(icon instanceof StyleableObject) ) throw new UnknownStyleException( key ); if( icon == this.icon && iconShared ) { @@ -213,7 +214,7 @@ public class FlatRadioButtonUI } key = key.substring( "icon.".length() ); - return ((FlatCheckBoxIcon)icon).applyStyleProperty( key, value ); + return ((StyleableObject)icon).applyStyleProperty( key, value ); } if( "iconTextGap".equals( key ) && value instanceof Integer ) @@ -227,8 +228,8 @@ public class FlatRadioButtonUI public Map> getStyleableInfos( JComponent c ) { Map> infos = FlatStylingSupport.getAnnotatedStyleableInfos( this ); Icon icon = getRealIcon( c ); - if( icon instanceof FlatCheckBoxIcon ) { - for( Map.Entry> e : ((FlatCheckBoxIcon)icon).getStyleableInfos().entrySet() ) + if( icon instanceof StyleableObject ) { + for( Map.Entry> e : ((StyleableObject)icon).getStyleableInfos().entrySet() ) infos.put( "icon.".concat( e.getKey() ), e.getValue() ); } return infos; @@ -240,8 +241,8 @@ public class FlatRadioButtonUI // style icon if( key.startsWith( "icon." ) ) { Icon icon = getRealIcon( c ); - return (icon instanceof FlatCheckBoxIcon) - ? ((FlatCheckBoxIcon)icon).getStyleableValue( key.substring( "icon.".length() ) ) + return (icon instanceof StyleableObject) + ? ((StyleableObject)icon).getStyleableValue( key.substring( "icon.".length() ) ) : null; } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatStylingSupport.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatStylingSupport.java index ebb35271..9f803cca 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatStylingSupport.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatStylingSupport.java @@ -51,6 +51,9 @@ import com.formdev.flatlaf.util.StringUtils; */ public class FlatStylingSupport { + + //---- annotations -------------------------------------------------------- + /** * Indicates that a field is intended to be used by FlatLaf styling support. *

@@ -98,17 +101,56 @@ public class FlatStylingSupport } + //---- interfaces --------------------------------------------------------- + /** @since 2 */ public interface StyleableUI { Map> getStyleableInfos( JComponent c ) throws IllegalArgumentException; /** @since 2.5 */ Object getStyleableValue( JComponent c, String key ) throws IllegalArgumentException; } - /** @since 2 */ - public interface StyleableBorder { - Object applyStyleProperty( String key, Object value ); - Map> getStyleableInfos() throws IllegalArgumentException; - /** @since 2.5 */ Object getStyleableValue( String key ) throws IllegalArgumentException; + /** + * An object that implements this interface is intended to support FlatLaf styling. + * + * @since 3.7 + */ + public interface StyleableObject { + /** + * Applies the given value to this object. + *

+ * The default implementation invokes {@link FlatStylingSupport#applyToAnnotatedObject(Object, String, Object)}. + * + * @param key the name of the property + * @param value the new value + * @return the old value of the property + */ + default Object applyStyleProperty( String key, Object value ) + throws UnknownStyleException, IllegalArgumentException + { + return applyToAnnotatedObject( this, key, value ); + } + + /** + * Returns a map of all styleable properties. + * The key is the name of the property and the value the type of the property. + *

+ * The default implementation invokes {@link FlatStylingSupport#getAnnotatedStyleableInfos(Object)}. + */ + default Map> getStyleableInfos() throws IllegalArgumentException { + return getAnnotatedStyleableInfos( this ); + } + + /** + * Returns the current value for the given property key. + *

+ * The default implementation invokes {@link FlatStylingSupport#getAnnotatedStyleableValue(Object, String)}. + * + * @param key the name of the property + * @return the current value of the property + */ + default Object getStyleableValue( String key ) throws IllegalArgumentException { + return getAnnotatedStyleableValue( this, key ); + } } /** @since 2.5 */ @@ -117,6 +159,8 @@ public class FlatStylingSupport } + //---- methods ------------------------------------------------------------ + /** * Returns the style specified in client property {@link FlatClientProperties#STYLE}. */ @@ -675,7 +719,7 @@ public class FlatStylingSupport } catch( UnknownStyleException ex ) { // apply to border Border border = c.getBorder(); - if( border instanceof StyleableBorder ) { + if( border instanceof StyleableObject ) { if( borderShared.get() ) { border = cloneBorder( border ); c.setBorder( border ); @@ -683,7 +727,7 @@ public class FlatStylingSupport } try { - return ((StyleableBorder)border).applyStyleProperty( key, value ); + return ((StyleableObject)border).applyStyleProperty( key, value ); } catch( UnknownStyleException ex2 ) { // ignore } @@ -833,8 +877,8 @@ public class FlatStylingSupport } public static void collectStyleableInfos( Border border, Map> infos ) { - if( border instanceof StyleableBorder ) - infos.putAll( ((StyleableBorder)border).getStyleableInfos() ); + if( border instanceof StyleableObject ) + infos.putAll( ((StyleableObject)border).getStyleableInfos() ); } public static void putAllPrefixKey( Map> infos, String keyPrefix, Map> infos2 ) { @@ -882,8 +926,8 @@ public class FlatStylingSupport } public static Object getAnnotatedStyleableValue( Object obj, Border border, String key ) { - if( border instanceof StyleableBorder ) { - Object value = ((StyleableBorder)border).getStyleableValue( key ); + if( border instanceof StyleableObject ) { + Object value = ((StyleableObject)border).getStyleableValue( key ); if( value != null ) return value; } 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 0ceccbfd..83a0abef 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 @@ -92,8 +92,8 @@ import javax.swing.text.JTextComponent; import javax.swing.text.View; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatLaf; -import com.formdev.flatlaf.icons.FlatTabbedPaneCloseIcon; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException; import com.formdev.flatlaf.util.Animator; @@ -670,7 +670,7 @@ public class FlatTabbedPaneUI protected Object applyStyleProperty( String key, Object value ) { // close icon if( key.startsWith( "close" ) ) { - if( !(closeIcon instanceof FlatTabbedPaneCloseIcon) ) + if( !(closeIcon instanceof StyleableObject) ) throw new UnknownStyleException( key ); if( closeIconShared ) { @@ -678,7 +678,7 @@ public class FlatTabbedPaneUI closeIconShared = false; } - return ((FlatTabbedPaneCloseIcon)closeIcon).applyStyleProperty( key, value ); + return ((StyleableObject)closeIcon).applyStyleProperty( key, value ); } if( value instanceof String ) { @@ -720,8 +720,8 @@ public class FlatTabbedPaneUI infos.put( "tabAreaInsets", Insets.class ); infos.put( "textIconGap", int.class ); FlatStylingSupport.collectAnnotatedStyleableInfos( this, infos ); - if( closeIcon instanceof FlatTabbedPaneCloseIcon ) - infos.putAll( ((FlatTabbedPaneCloseIcon)closeIcon).getStyleableInfos() ); + if( closeIcon instanceof StyleableObject ) + infos.putAll( ((StyleableObject)closeIcon).getStyleableInfos() ); return infos; } @@ -730,8 +730,8 @@ public class FlatTabbedPaneUI public Object getStyleableValue( JComponent c, String key ) { // close icon if( key.startsWith( "close" ) ) { - return (closeIcon instanceof FlatTabbedPaneCloseIcon) - ? ((FlatTabbedPaneCloseIcon)closeIcon).getStyleableValue( key ) + return (closeIcon instanceof StyleableObject) + ? ((StyleableObject)closeIcon).getStyleableValue( key ) : null; } diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableValue.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableValue.java index 36a3b1c4..0aaf32b6 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableValue.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableValue.java @@ -17,6 +17,7 @@ package com.formdev.flatlaf.ui; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; import java.awt.Color; import java.awt.Component; @@ -77,6 +78,7 @@ import com.formdev.flatlaf.icons.FlatRadioButtonIcon; import com.formdev.flatlaf.icons.FlatRadioButtonMenuItemIcon; import com.formdev.flatlaf.icons.FlatSearchIcon; import com.formdev.flatlaf.icons.FlatSearchWithHistoryIcon; +import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI; import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException; import com.formdev.flatlaf.ui.TestFlatStyling.CustomCheckBoxIcon; @@ -181,17 +183,13 @@ public class TestFlatStyleableValue } private void testValue( Object obj, String key, Object value ) { - try { - Method m = obj.getClass().getMethod( "applyStyleProperty", String.class, Object.class ); - m.invoke( obj, key, value ); + assertInstanceOf( StyleableObject.class, obj ); - m = obj.getClass().getMethod( "getStyleableValue", String.class ); - Object actualValue = m.invoke( obj, key ); + StyleableObject sobj = (StyleableObject) obj; + sobj.applyStyleProperty( key, value ); + Object actualValue = sobj.getStyleableValue( key ); - assertEquals( value, actualValue ); - } catch( Exception ex ) { - Assertions.fail( ex ); - } + assertEquals( value, actualValue ); } //---- components ---------------------------------------------------------