Skip to content

Commit db4173d

Browse files
committed
Styling: introduced interface StyleableObject
- has default implementations that use annotations - replaces `StyleableBorder` - used for styleable icons
1 parent 03b7a1c commit db4173d

19 files changed

+120
-209
lines changed

flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCapsLockIcon.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Collections;
2929
import java.util.Map;
3030
import javax.swing.UIManager;
31+
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject;
3132
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
3233
import com.formdev.flatlaf.ui.FlatUIUtils;
3334

@@ -40,6 +41,7 @@
4041
*/
4142
public class FlatCapsLockIcon
4243
extends FlatAbstractIcon
44+
implements StyleableObject
4345
{
4446
private Path2D path;
4547

@@ -48,6 +50,7 @@ public FlatCapsLockIcon() {
4850
}
4951

5052
/** @since 2 */
53+
@Override
5154
public Object applyStyleProperty( String key, Object value ) {
5255
Object oldValue;
5356
switch( key ) {
@@ -57,11 +60,13 @@ public Object applyStyleProperty( String key, Object value ) {
5760
}
5861

5962
/** @since 3.7 */
63+
@Override
6064
public Map<String, Class<?>> getStyleableInfos() throws IllegalArgumentException {
6165
return Collections.singletonMap( "capsLockIconColor", Color.class );
6266
}
6367

6468
/** @since 2.5 */
69+
@Override
6570
public Object getStyleableValue( String key ) {
6671
switch( key ) {
6772
case "capsLockIconColor": return color;

flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxIcon.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424
import java.awt.Graphics2D;
2525
import java.awt.geom.Path2D;
2626
import java.awt.geom.RoundRectangle2D;
27-
import java.util.Map;
2827
import javax.swing.AbstractButton;
2928
import javax.swing.JComponent;
3029
import javax.swing.UIManager;
3130
import com.formdev.flatlaf.ui.FlatButtonUI;
32-
import com.formdev.flatlaf.ui.FlatStylingSupport;
3331
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
32+
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject;
3433
import com.formdev.flatlaf.ui.FlatUIUtils;
3534

3635
/**
@@ -103,6 +102,7 @@
103102
*/
104103
public class FlatCheckBoxIcon
105104
extends FlatAbstractIcon
105+
implements StyleableObject
106106
{
107107
protected final String style = UIManager.getString( getPropertyPrefix() + "icon.style" );
108108
@Styleable protected float focusWidth = getUIFloat( "CheckBox.icon.focusWidth", UIManager.getInt( "Component.focusWidth" ), style );
@@ -197,21 +197,6 @@ public FlatCheckBoxIcon() {
197197
super( ICON_SIZE, ICON_SIZE, null );
198198
}
199199

200-
/** @since 2 */
201-
public Object applyStyleProperty( String key, Object value ) {
202-
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
203-
}
204-
205-
/** @since 2 */
206-
public Map<String, Class<?>> getStyleableInfos() {
207-
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
208-
}
209-
210-
/** @since 2.5 */
211-
public Object getStyleableValue( String key ) {
212-
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
213-
}
214-
215200
@Override
216201
protected void paintIcon( Component c, Graphics2D g ) {
217202
boolean indeterminate = isIndeterminate( c );

flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxMenuItemIcon.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
import java.awt.Component;
2222
import java.awt.Graphics2D;
2323
import java.awt.geom.Path2D;
24-
import java.util.Map;
2524
import javax.swing.AbstractButton;
2625
import javax.swing.JMenuItem;
2726
import javax.swing.UIManager;
28-
import com.formdev.flatlaf.ui.FlatStylingSupport;
2927
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
28+
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject;
3029

3130
/**
3231
* Icon for {@link javax.swing.JCheckBoxMenuItem}.
@@ -40,6 +39,7 @@
4039
*/
4140
public class FlatCheckBoxMenuItemIcon
4241
extends FlatAbstractIcon
42+
implements StyleableObject
4343
{
4444
@Styleable protected Color checkmarkColor = UIManager.getColor( "CheckBoxMenuItem.icon.checkmarkColor" );
4545
@Styleable protected Color disabledCheckmarkColor = UIManager.getColor( "CheckBoxMenuItem.icon.disabledCheckmarkColor" );
@@ -49,21 +49,6 @@ public FlatCheckBoxMenuItemIcon() {
4949
super( 15, 15, null );
5050
}
5151

52-
/** @since 2 */
53-
public Object applyStyleProperty( String key, Object value ) {
54-
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
55-
}
56-
57-
/** @since 2 */
58-
public Map<String, Class<?>> getStyleableInfos() {
59-
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
60-
}
61-
62-
/** @since 2.5 */
63-
public Object getStyleableValue( String key ) {
64-
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
65-
}
66-
6752
@Override
6853
protected void paintIcon( Component c, Graphics2D g2 ) {
6954
boolean selected = (c instanceof AbstractButton) && ((AbstractButton)c).isSelected();

flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatClearIcon.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
import java.awt.Graphics2D;
2222
import java.awt.geom.Ellipse2D;
2323
import java.awt.geom.Path2D;
24-
import java.util.Map;
2524
import javax.swing.AbstractButton;
2625
import javax.swing.ButtonModel;
2726
import javax.swing.UIManager;
28-
import com.formdev.flatlaf.ui.FlatStylingSupport;
2927
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
28+
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject;
3029
import com.formdev.flatlaf.ui.FlatUIUtils;
3130

3231
/**
@@ -41,6 +40,7 @@
4140
*/
4241
public class FlatClearIcon
4342
extends FlatAbstractIcon
43+
implements StyleableObject
4444
{
4545
@Styleable protected Color clearIconColor = UIManager.getColor( "SearchField.clearIconColor" );
4646
@Styleable protected Color clearIconHoverColor = UIManager.getColor( "SearchField.clearIconHoverColor" );
@@ -58,21 +58,6 @@ public FlatClearIcon( boolean ignoreButtonState ) {
5858
this.ignoreButtonState = ignoreButtonState;
5959
}
6060

61-
/** @since 2 */
62-
public Object applyStyleProperty( String key, Object value ) {
63-
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
64-
}
65-
66-
/** @since 2 */
67-
public Map<String, Class<?>> getStyleableInfos() {
68-
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
69-
}
70-
71-
/** @since 2.5 */
72-
public Object getStyleableValue( String key ) {
73-
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
74-
}
75-
7661
@Override
7762
protected void paintIcon( Component c, Graphics2D g ) {
7863
if( !ignoreButtonState && c instanceof AbstractButton ) {

flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatHelpButtonIcon.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
import java.awt.RenderingHints;
2525
import java.awt.geom.Ellipse2D;
2626
import java.awt.geom.Path2D;
27-
import java.util.Map;
2827
import javax.swing.UIManager;
2928
import com.formdev.flatlaf.ui.FlatButtonUI;
30-
import com.formdev.flatlaf.ui.FlatStylingSupport;
3129
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
30+
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject;
3231
import com.formdev.flatlaf.ui.FlatUIUtils;
3332

3433
/**
@@ -54,6 +53,7 @@
5453
*/
5554
public class FlatHelpButtonIcon
5655
extends FlatAbstractIcon
56+
implements StyleableObject
5757
{
5858
@Styleable protected int focusWidth = UIManager.getInt( "Component.focusWidth" );
5959
@Styleable protected Color focusColor = UIManager.getColor( "Component.focusColor" );
@@ -76,21 +76,6 @@ public FlatHelpButtonIcon() {
7676
super( 0, 0, null );
7777
}
7878

79-
/** @since 2 */
80-
public Object applyStyleProperty( String key, Object value ) {
81-
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
82-
}
83-
84-
/** @since 2 */
85-
public Map<String, Class<?>> getStyleableInfos() {
86-
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
87-
}
88-
89-
/** @since 2.5 */
90-
public Object getStyleableValue( String key ) {
91-
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
92-
}
93-
9479
@Override
9580
protected void paintIcon( Component c, Graphics2D g2 ) {
9681
/*

flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatMenuArrowIcon.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
import java.awt.Component;
2222
import java.awt.Graphics2D;
2323
import java.awt.geom.Path2D;
24-
import java.util.Map;
2524
import javax.swing.JMenu;
2625
import javax.swing.UIManager;
27-
import com.formdev.flatlaf.ui.FlatStylingSupport;
2826
import com.formdev.flatlaf.ui.FlatUIUtils;
2927
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
28+
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject;
3029

3130
/**
3231
* "arrow" icon for {@link javax.swing.JMenu}.
@@ -41,6 +40,7 @@
4140
*/
4241
public class FlatMenuArrowIcon
4342
extends FlatAbstractIcon
43+
implements StyleableObject
4444
{
4545
@Styleable protected String arrowType = UIManager.getString( "Component.arrowType" );
4646
@Styleable protected Color arrowColor = UIManager.getColor( "Menu.icon.arrowColor" );
@@ -51,21 +51,6 @@ public FlatMenuArrowIcon() {
5151
super( 6, 10, null );
5252
}
5353

54-
/** @since 2 */
55-
public Object applyStyleProperty( String key, Object value ) {
56-
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
57-
}
58-
59-
/** @since 2 */
60-
public Map<String, Class<?>> getStyleableInfos() {
61-
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
62-
}
63-
64-
/** @since 2.5 */
65-
public Object getStyleableValue( String key ) {
66-
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
67-
}
68-
6954
@Override
7055
protected void paintIcon( Component c, Graphics2D g ) {
7156
if( c != null && !c.getComponentOrientation().isLeftToRight() )

flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatSearchIcon.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
import java.awt.Graphics2D;
2222
import java.awt.geom.Area;
2323
import java.awt.geom.Ellipse2D;
24-
import java.util.Map;
2524
import javax.swing.UIManager;
2625
import com.formdev.flatlaf.ui.FlatButtonUI;
27-
import com.formdev.flatlaf.ui.FlatStylingSupport;
2826
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
27+
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject;
2928
import com.formdev.flatlaf.ui.FlatUIUtils;
3029

3130
/**
@@ -40,6 +39,7 @@
4039
*/
4140
public class FlatSearchIcon
4241
extends FlatAbstractIcon
42+
implements StyleableObject
4343
{
4444
@Styleable protected Color searchIconColor = UIManager.getColor( "SearchField.searchIconColor" );
4545
@Styleable protected Color searchIconHoverColor = UIManager.getColor( "SearchField.searchIconHoverColor" );
@@ -58,21 +58,6 @@ public FlatSearchIcon( boolean ignoreButtonState ) {
5858
this.ignoreButtonState = ignoreButtonState;
5959
}
6060

61-
/** @since 2 */
62-
public Object applyStyleProperty( String key, Object value ) {
63-
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
64-
}
65-
66-
/** @since 2 */
67-
public Map<String, Class<?>> getStyleableInfos() {
68-
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
69-
}
70-
71-
/** @since 2.5 */
72-
public Object getStyleableValue( String key ) {
73-
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
74-
}
75-
7661
@Override
7762
protected void paintIcon( Component c, Graphics2D g ) {
7863
/*

flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatTabbedPaneCloseIcon.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
import java.awt.Dimension;
2323
import java.awt.Graphics2D;
2424
import java.awt.geom.Path2D;
25-
import java.util.Map;
2625
import javax.swing.UIManager;
2726
import com.formdev.flatlaf.ui.FlatButtonUI;
28-
import com.formdev.flatlaf.ui.FlatStylingSupport;
2927
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
28+
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject;
3029
import com.formdev.flatlaf.ui.FlatUIUtils;
3130

3231
/**
@@ -48,6 +47,7 @@
4847
*/
4948
public class FlatTabbedPaneCloseIcon
5049
extends FlatAbstractIcon
50+
implements StyleableObject
5151
{
5252
@Styleable protected Dimension closeSize = UIManager.getDimension( "TabbedPane.closeSize" );
5353
@Styleable protected int closeArc = UIManager.getInt( "TabbedPane.closeArc" );
@@ -65,21 +65,6 @@ public FlatTabbedPaneCloseIcon() {
6565
super( 16, 16, null );
6666
}
6767

68-
/** @since 2 */
69-
public Object applyStyleProperty( String key, Object value ) {
70-
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
71-
}
72-
73-
/** @since 2 */
74-
public Map<String, Class<?>> getStyleableInfos() {
75-
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
76-
}
77-
78-
/** @since 2.5 */
79-
public Object getStyleableValue( String key ) {
80-
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
81-
}
82-
8368
@Override
8469
protected void paintIcon( Component c, Graphics2D g ) {
8570
// paint background

flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.awt.Graphics2D;
2424
import java.awt.Insets;
2525
import java.awt.Paint;
26-
import java.util.Map;
2726
import javax.swing.JComboBox;
2827
import javax.swing.JComponent;
2928
import javax.swing.JScrollPane;
@@ -32,7 +31,7 @@
3231
import javax.swing.plaf.basic.BasicBorders;
3332
import com.formdev.flatlaf.FlatClientProperties;
3433
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
35-
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableBorder;
34+
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject;
3635
import com.formdev.flatlaf.util.DerivedColor;
3736

3837
/**
@@ -67,7 +66,7 @@
6766
*/
6867
public class FlatBorder
6968
extends BasicBorders.MarginBorder
70-
implements StyleableBorder
69+
implements StyleableObject
7170
{
7271
@Styleable protected int focusWidth = UIManager.getInt( "Component.focusWidth" );
7372
@Styleable protected float innerFocusWidth = FlatUIUtils.getUIFloat( "Component.innerFocusWidth", 0 );
@@ -92,24 +91,6 @@ public class FlatBorder
9291
/** @since 2 */ @Styleable protected Color outlineColor;
9392
/** @since 2 */ @Styleable protected Color outlineFocusedColor;
9493

95-
/** @since 2 */
96-
@Override
97-
public Object applyStyleProperty( String key, Object value ) {
98-
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
99-
}
100-
101-
/** @since 2 */
102-
@Override
103-
public Map<String, Class<?>> getStyleableInfos() {
104-
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
105-
}
106-
107-
/** @since 2.5 */
108-
@Override
109-
public Object getStyleableValue( String key ) {
110-
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
111-
}
112-
11394
@Override
11495
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
11596
Graphics2D g2 = (Graphics2D) g.create();

0 commit comments

Comments
 (0)