Styling: added StyleableUI.getStyleableInfos() for tooling (e.g. GUI builder)

This commit is contained in:
Karl Tauber
2021-07-21 11:51:19 +02:00
parent 7fd64a1b73
commit 4d4bb3fd7f
43 changed files with 1703 additions and 18 deletions

View File

@@ -23,6 +23,7 @@ import java.awt.Component;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.geom.Path2D; import java.awt.geom.Path2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import java.util.Map;
import javax.swing.AbstractButton; import javax.swing.AbstractButton;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.UIManager; import javax.swing.UIManager;
@@ -138,6 +139,13 @@ public class FlatCheckBoxIcon
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
public Map<String, Class<?>> getStyleableInfos() {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
protected void paintIcon( Component c, Graphics2D g ) { protected void paintIcon( Component c, Graphics2D g ) {
boolean indeterminate = isIndeterminate( c ); boolean indeterminate = isIndeterminate( c );

View File

@@ -21,6 +21,7 @@ import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.geom.Path2D; import java.awt.geom.Path2D;
import java.util.Map;
import javax.swing.AbstractButton; import javax.swing.AbstractButton;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.UIManager; import javax.swing.UIManager;
@@ -55,6 +56,13 @@ public class FlatCheckBoxMenuItemIcon
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
public Map<String, Class<?>> getStyleableInfos() {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
protected void paintIcon( Component c, Graphics2D g2 ) { protected void paintIcon( Component c, Graphics2D g2 ) {
boolean selected = (c instanceof AbstractButton) && ((AbstractButton)c).isSelected(); boolean selected = (c instanceof AbstractButton) && ((AbstractButton)c).isSelected();

View File

@@ -22,6 +22,7 @@ import java.awt.Component;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
import java.awt.geom.Path2D; import java.awt.geom.Path2D;
import java.util.Map;
import javax.swing.UIManager; import javax.swing.UIManager;
import com.formdev.flatlaf.ui.FlatButtonUI; import com.formdev.flatlaf.ui.FlatButtonUI;
import com.formdev.flatlaf.ui.FlatStyleSupport; import com.formdev.flatlaf.ui.FlatStyleSupport;
@@ -80,6 +81,13 @@ public class FlatHelpButtonIcon
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
public Map<String, Class<?>> getStyleableInfos() {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
protected void paintIcon( Component c, Graphics2D g2 ) { protected void paintIcon( Component c, Graphics2D g2 ) {
/* /*

View File

@@ -21,6 +21,7 @@ import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.geom.Path2D; import java.awt.geom.Path2D;
import java.util.Map;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.UIManager; import javax.swing.UIManager;
import com.formdev.flatlaf.ui.FlatStyleSupport; import com.formdev.flatlaf.ui.FlatStyleSupport;
@@ -57,6 +58,13 @@ public class FlatMenuArrowIcon
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
public Map<String, Class<?>> getStyleableInfos() {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
protected void paintIcon( Component c, Graphics2D g ) { protected void paintIcon( Component c, Graphics2D g ) {
if( !c.getComponentOrientation().isLeftToRight() ) if( !c.getComponentOrientation().isLeftToRight() )

View File

@@ -23,6 +23,7 @@ import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.geom.Line2D; import java.awt.geom.Line2D;
import java.awt.geom.Path2D; import java.awt.geom.Path2D;
import java.util.Map;
import javax.swing.UIManager; import javax.swing.UIManager;
import com.formdev.flatlaf.ui.FlatButtonUI; import com.formdev.flatlaf.ui.FlatButtonUI;
import com.formdev.flatlaf.ui.FlatStyleSupport; import com.formdev.flatlaf.ui.FlatStyleSupport;
@@ -72,6 +73,13 @@ public class FlatTabbedPaneCloseIcon
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
public Map<String, Class<?>> getStyleableInfos() {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
protected void paintIcon( Component c, Graphics2D g ) { protected void paintIcon( Component c, Graphics2D g ) {
// paint background // paint background

View File

@@ -23,6 +23,7 @@ import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Insets; import java.awt.Insets;
import java.awt.Paint; import java.awt.Paint;
import java.util.Map;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
@@ -86,6 +87,14 @@ public class FlatBorder
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos() {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
Graphics2D g2 = (Graphics2D) g.create(); Graphics2D g2 = (Graphics2D) g.create();

View File

@@ -48,6 +48,7 @@ import javax.swing.plaf.basic.BasicButtonUI;
import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.icons.FlatHelpButtonIcon; import com.formdev.flatlaf.icons.FlatHelpButtonIcon;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.ui.FlatStyleSupport.UnknownStyleException;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -98,6 +99,7 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatButtonUI public class FlatButtonUI
extends BasicButtonUI extends BasicButtonUI
implements StyleableUI
{ {
@Styleable protected int minimumWidth; @Styleable protected int minimumWidth;
protected int iconTextGap; protected int iconTextGap;
@@ -296,6 +298,17 @@ public class FlatButtonUI
return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, b, borderShared ); return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, b, borderShared );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
Map<String, Class<?>> infos = FlatStyleSupport.getAnnotatedStyleableInfos( this, c.getBorder() );
if( helpButtonIcon instanceof FlatHelpButtonIcon )
FlatStyleSupport.putAllPrefixKey( infos, "help.", ((FlatHelpButtonIcon)helpButtonIcon).getStyleableInfos() );
return infos;
}
static boolean isContentAreaFilled( Component c ) { static boolean isContentAreaFilled( Component c ) {
return !(c instanceof AbstractButton) || ((AbstractButton)c).isContentAreaFilled(); return !(c instanceof AbstractButton) || ((AbstractButton)c).isContentAreaFilled();
} }

View File

@@ -25,6 +25,7 @@ import javax.swing.JComponent;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI; import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
/** /**
@@ -57,6 +58,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
*/ */
public class FlatCheckBoxMenuItemUI public class FlatCheckBoxMenuItemUI
extends BasicCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI
implements StyleableUI
{ {
private FlatMenuItemRenderer renderer; private FlatMenuItemRenderer renderer;
private Map<String, Object> oldStyleValues; private Map<String, Object> oldStyleValues;
@@ -118,6 +120,14 @@ public class FlatCheckBoxMenuItemUI
return FlatMenuItemUI.applyStyleProperty( this, key, value ); return FlatMenuItemUI.applyStyleProperty( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatMenuItemUI.getStyleableInfos( renderer );
}
@Override @Override
protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) {
return renderer.getPreferredMenuItemSize(); return renderer.getPreferredMenuItemSize();

View File

@@ -40,6 +40,7 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
@@ -70,6 +71,7 @@ import javax.swing.plaf.basic.ComboPopup;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
/** /**
@@ -111,6 +113,7 @@ import com.formdev.flatlaf.util.SystemInfo;
*/ */
public class FlatComboBoxUI public class FlatComboBoxUI
extends BasicComboBoxUI extends BasicComboBoxUI
implements StyleableUI
{ {
@Styleable protected int minimumWidth; @Styleable protected int minimumWidth;
@Styleable protected int editorColumns; @Styleable protected int editorColumns;
@@ -476,6 +479,18 @@ public class FlatComboBoxUI
return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, comboBox, borderShared ); return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, comboBox, borderShared );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
Map<String, Class<?>> infos = new LinkedHashMap<>();
infos.put( "padding", Insets.class );
FlatStyleSupport.collectAnnotatedStyleableInfos( this, infos );
FlatStyleSupport.collectStyleableInfos( comboBox.getBorder(), infos );
return infos;
}
@Override @Override
public void update( Graphics g, JComponent c ) { public void update( Graphics g, JComponent c ) {
float focusWidth = FlatUIUtils.getBorderFocusWidth( c ); float focusWidth = FlatUIUtils.getBorderFocusWidth( c );

View File

@@ -24,6 +24,7 @@ import java.awt.Image;
import java.awt.Insets; import java.awt.Insets;
import java.awt.RadialGradientPaint; import java.awt.RadialGradientPaint;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.Map;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableBorder; import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableBorder;
import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.HiDPIUtils;
@@ -89,6 +90,9 @@ public class FlatDropShadowBorder
Math.max( shadowInsets.top, shadowInsets.bottom ) ); Math.max( shadowInsets.top, shadowInsets.bottom ) );
} }
/**
* @since TODO
*/
@Override @Override
public Object applyStyleProperty( String key, Object value ) { public Object applyStyleProperty( String key, Object value ) {
Object oldValue = FlatStyleSupport.applyToAnnotatedObject( this, key, value ); Object oldValue = FlatStyleSupport.applyToAnnotatedObject( this, key, value );
@@ -99,6 +103,14 @@ public class FlatDropShadowBorder
return oldValue; return oldValue;
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos() {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
if( shadowSize <= 0 ) if( shadowSize <= 0 )

View File

@@ -33,6 +33,7 @@ import javax.swing.plaf.basic.BasicEditorPaneUI;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.HiDPIUtils;
/** /**
@@ -63,6 +64,7 @@ import com.formdev.flatlaf.util.HiDPIUtils;
*/ */
public class FlatEditorPaneUI public class FlatEditorPaneUI
extends BasicEditorPaneUI extends BasicEditorPaneUI
implements StyleableUI
{ {
@Styleable protected int minimumWidth; @Styleable protected int minimumWidth;
protected boolean isIntelliJTheme; protected boolean isIntelliJTheme;
@@ -184,6 +186,14 @@ public class FlatEditorPaneUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
private void updateBackground() { private void updateBackground() {
FlatTextFieldUI.updateBackground( getComponent(), background, FlatTextFieldUI.updateBackground( getComponent(), background,
disabledBackground, inactiveBackground, disabledBackground, inactiveBackground,

View File

@@ -23,6 +23,7 @@ import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Insets; import java.awt.Insets;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.JComponent; import javax.swing.JComponent;
@@ -33,6 +34,7 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicInternalFrameUI; import javax.swing.plaf.basic.BasicInternalFrameUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableBorder; 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}. * 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 public class FlatInternalFrameUI
extends BasicInternalFrameUI extends BasicInternalFrameUI
implements StyleableUI
{ {
protected FlatWindowResizer windowResizer; protected FlatWindowResizer windowResizer;
@@ -157,6 +160,14 @@ public class FlatInternalFrameUI
return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, frame, borderShared ); return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, frame, borderShared );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this, frame.getBorder() );
}
//---- class FlatInternalFrameBorder -------------------------------------- //---- class FlatInternalFrameBorder --------------------------------------
public static class FlatInternalFrameBorder public static class FlatInternalFrameBorder
@@ -197,6 +208,20 @@ public class FlatInternalFrameUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
@Override
public Map<String, Class<?>> getStyleableInfos() {
Map<String, Class<?>> 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 @Override
public Insets getBorderInsets( Component c, Insets insets ) { public Insets getBorderInsets( Component c, Insets insets ) {
if( c instanceof JInternalFrame && ((JInternalFrame)c).isMaximum() ) { if( c instanceof JInternalFrame && ((JInternalFrame)c).isMaximum() ) {

View File

@@ -37,6 +37,7 @@ import javax.swing.plaf.basic.BasicLabelUI;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.HiDPIUtils;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -57,6 +58,7 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatLabelUI public class FlatLabelUI
extends BasicLabelUI extends BasicLabelUI
implements StyleableUI
{ {
@Styleable protected Color disabledForeground; @Styleable protected Color disabledForeground;
@@ -149,6 +151,14 @@ public class FlatLabelUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
/** /**
* Checks whether text contains HTML tags that use "absolute-size" keywords * Checks whether text contains HTML tags that use "absolute-size" keywords
* (e.g. "x-large") for font-size in default style sheet * (e.g. "x-large") for font-size in default style sheet

View File

@@ -28,6 +28,7 @@ import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicListUI; import javax.swing.plaf.basic.BasicListUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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}. * 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 public class FlatListUI
extends BasicListUI extends BasicListUI
implements StyleableUI
{ {
@Styleable protected Color selectionBackground; @Styleable protected Color selectionBackground;
@Styleable protected Color selectionForeground; @Styleable protected Color selectionForeground;
@@ -179,6 +181,14 @@ public class FlatListUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
/** /**
* Toggle selection colors from focused to inactive and vice versa. * Toggle selection colors from focused to inactive and vice versa.
* *

View File

@@ -21,6 +21,7 @@ import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Insets; import java.awt.Insets;
import java.util.Map;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
import javax.swing.UIManager; import javax.swing.UIManager;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
@@ -47,6 +48,11 @@ public class FlatMenuBarBorder
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
@Override
public Map<String, Class<?>> getStyleableInfos() {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
float lineHeight = scale( (float) 1 ); float lineHeight = scale( (float) 1 );

View File

@@ -40,6 +40,7 @@ import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicMenuBarUI; import javax.swing.plaf.basic.BasicMenuBarUI;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
/** /**
@@ -60,6 +61,7 @@ import com.formdev.flatlaf.util.SystemInfo;
*/ */
public class FlatMenuBarUI public class FlatMenuBarUI
extends BasicMenuBarUI extends BasicMenuBarUI
implements StyleableUI
{ {
private PropertyChangeListener propertyChangeListener; private PropertyChangeListener propertyChangeListener;
private Map<String, Object> oldStyleValues; private Map<String, Object> oldStyleValues;
@@ -141,6 +143,14 @@ public class FlatMenuBarUI
return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, menuBar, borderShared ); return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, menuBar, borderShared );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this, menuBar.getBorder() );
}
@Override @Override
public void update( Graphics g, JComponent c ) { public void update( Graphics g, JComponent c ) {
// paint background // paint background

View File

@@ -30,6 +30,7 @@ import java.awt.Rectangle;
import java.awt.event.InputEvent; import java.awt.event.InputEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.text.AttributedCharacterIterator; import java.text.AttributedCharacterIterator;
import java.util.Map;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
@@ -149,6 +150,19 @@ public class FlatMenuItemRenderer
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
public Map<String, Class<?>> getStyleableInfos() {
Map<String, Class<?>> 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() { protected Dimension getPreferredMenuItemSize() {
int width = 0; int width = 0;
int height = 0; int height = 0;

View File

@@ -16,15 +16,18 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicMenuItemUI; import javax.swing.plaf.basic.BasicMenuItemUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
/** /**
@@ -57,6 +60,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
*/ */
public class FlatMenuItemUI public class FlatMenuItemUI
extends BasicMenuItemUI extends BasicMenuItemUI
implements StyleableUI
{ {
private FlatMenuItemRenderer renderer; private FlatMenuItemRenderer renderer;
private Map<String, Object> oldStyleValues; private Map<String, Object> oldStyleValues;
@@ -120,6 +124,7 @@ public class FlatMenuItemUI
static Object applyStyleProperty( BasicMenuItemUI ui, String key, Object value ) { static Object applyStyleProperty( BasicMenuItemUI ui, String key, Object value ) {
switch( key ) { switch( key ) {
// BasicMenuItemUI
case "selectionBackground": case "selectionBackground":
case "selectionForeground": case "selectionForeground":
case "disabledForeground": case "disabledForeground":
@@ -131,6 +136,25 @@ public class FlatMenuItemUI
} }
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return getStyleableInfos( renderer );
}
static Map<String, Class<?>> getStyleableInfos( FlatMenuItemRenderer renderer ) {
Map<String, Class<?>> 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 @Override
protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) {
return renderer.getPreferredMenuItemSize(); return renderer.getPreferredMenuItemSize();

View File

@@ -33,6 +33,7 @@ import javax.swing.UIManager;
import javax.swing.event.MouseInputListener; import javax.swing.event.MouseInputListener;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicMenuUI; import javax.swing.plaf.basic.BasicMenuUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
/** /**
@@ -75,6 +76,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
*/ */
public class FlatMenuUI public class FlatMenuUI
extends BasicMenuUI extends BasicMenuUI
implements StyleableUI
{ {
private Color hoverBackground; private Color hoverBackground;
private FlatMenuItemRenderer renderer; private FlatMenuItemRenderer renderer;
@@ -166,6 +168,14 @@ public class FlatMenuUI
return FlatMenuItemUI.applyStyleProperty( this, key, value ); return FlatMenuItemUI.applyStyleProperty( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatMenuItemUI.getStyleableInfos( renderer );
}
@Override @Override
public Dimension getMinimumSize( JComponent c ) { public Dimension getMinimumSize( JComponent c ) {
// avoid that top-level menus (in menu bar) are made smaller if horizontal space is rare // avoid that top-level menus (in menu bar) are made smaller if horizontal space is rare

View File

@@ -16,6 +16,7 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Insets; import java.awt.Insets;
import java.awt.Shape; import java.awt.Shape;
@@ -23,6 +24,7 @@ import java.awt.Toolkit;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.util.Map;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.ActionMap; import javax.swing.ActionMap;
import javax.swing.Icon; import javax.swing.Icon;
@@ -159,6 +161,9 @@ public class FlatPasswordFieldUI
} }
} }
/**
* @since TODO
*/
@Override @Override
protected Object applyStyleProperty( String key, Object value ) { protected Object applyStyleProperty( String key, Object value ) {
if( key.equals( "capsLockIconColor" ) && capsLockIcon instanceof FlatCapsLockIcon ) { if( key.equals( "capsLockIconColor" ) && capsLockIcon instanceof FlatCapsLockIcon ) {
@@ -172,6 +177,16 @@ public class FlatPasswordFieldUI
return super.applyStyleProperty( key, value ); return super.applyStyleProperty( key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
Map<String, Class<?>> infos = super.getStyleableInfos( c );
infos.put( "capsLockIconColor", Color.class );
return infos;
}
@Override @Override
public View create( Element elem ) { public View create( Element elem ) {
return new PasswordView( elem ); return new PasswordView( elem );

View File

@@ -33,6 +33,7 @@ import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicProgressBarUI; import javax.swing.plaf.basic.BasicProgressBarUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.HiDPIUtils;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -60,6 +61,7 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatProgressBarUI public class FlatProgressBarUI
extends BasicProgressBarUI extends BasicProgressBarUI
implements StyleableUI
{ {
@Styleable protected int arc; @Styleable protected int arc;
@Styleable protected Dimension horizontalSize; @Styleable protected Dimension horizontalSize;
@@ -141,6 +143,14 @@ public class FlatProgressBarUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
public Dimension getPreferredSize( JComponent c ) { public Dimension getPreferredSize( JComponent c ) {
Dimension size = super.getPreferredSize( c ); Dimension size = super.getPreferredSize( c );

View File

@@ -25,6 +25,7 @@ import javax.swing.JComponent;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI; import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
/** /**
@@ -57,6 +58,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
*/ */
public class FlatRadioButtonMenuItemUI public class FlatRadioButtonMenuItemUI
extends BasicRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI
implements StyleableUI
{ {
private FlatMenuItemRenderer renderer; private FlatMenuItemRenderer renderer;
private Map<String, Object> oldStyleValues; private Map<String, Object> oldStyleValues;
@@ -118,6 +120,14 @@ public class FlatRadioButtonMenuItemUI
return FlatMenuItemUI.applyStyleProperty( this, key, value ); return FlatMenuItemUI.applyStyleProperty( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatMenuItemUI.getStyleableInfos( renderer );
}
@Override @Override
protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) {
return renderer.getPreferredMenuItemSize(); return renderer.getPreferredMenuItemSize();

View File

@@ -37,6 +37,7 @@ import javax.swing.plaf.basic.BasicRadioButtonUI;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.icons.FlatCheckBoxIcon; import com.formdev.flatlaf.icons.FlatCheckBoxIcon;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.ui.FlatStyleSupport.UnknownStyleException;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -62,6 +63,7 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatRadioButtonUI public class FlatRadioButtonUI
extends BasicRadioButtonUI extends BasicRadioButtonUI
implements StyleableUI
{ {
protected int iconTextGap; protected int iconTextGap;
@Styleable protected Color disabledText; @Styleable protected Color disabledText;
@@ -181,6 +183,19 @@ public class FlatRadioButtonUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
Map<String, Class<?>> infos = FlatStyleSupport.getAnnotatedStyleableInfos( this );
if( icon instanceof FlatCheckBoxIcon ) {
for( Map.Entry<String, Class<?>> 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 ); private static Insets tempInsets = new Insets( 0, 0, 0, 0 );
@Override @Override

View File

@@ -24,6 +24,7 @@ import java.awt.Rectangle;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import javax.swing.InputMap; import javax.swing.InputMap;
@@ -37,6 +38,7 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicScrollBarUI; import javax.swing.plaf.basic.BasicScrollBarUI;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
/** /**
@@ -76,6 +78,7 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatScrollBarUI public class FlatScrollBarUI
extends BasicScrollBarUI extends BasicScrollBarUI
implements StyleableUI
{ {
// overrides BasicScrollBarUI.supportsAbsolutePositioning (which is private) // overrides BasicScrollBarUI.supportsAbsolutePositioning (which is private)
@Styleable protected boolean allowsAbsolutePositioning; @Styleable protected boolean allowsAbsolutePositioning;
@@ -246,6 +249,21 @@ public class FlatScrollBarUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
Map<String, Class<?>> 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 @Override
public Dimension getPreferredSize( JComponent c ) { public Dimension getPreferredSize( JComponent c ) {
return UIScale.scale( super.getPreferredSize( c ) ); return UIScale.scale( super.getPreferredSize( c ) );

View File

@@ -48,6 +48,7 @@ import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicScrollPaneUI; import javax.swing.plaf.basic.BasicScrollPaneUI;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
/** /**
* Provides the Flat LaF UI delegate for {@link javax.swing.JScrollPane}. * Provides the Flat LaF UI delegate for {@link javax.swing.JScrollPane}.
@@ -68,6 +69,7 @@ import com.formdev.flatlaf.FlatClientProperties;
*/ */
public class FlatScrollPaneUI public class FlatScrollPaneUI
extends BasicScrollPaneUI extends BasicScrollPaneUI
implements StyleableUI
{ {
private Handler handler; private Handler handler;
@@ -320,6 +322,14 @@ public class FlatScrollPaneUI
return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, scrollpane, borderShared ); return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, scrollpane, borderShared );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this, scrollpane.getBorder() );
}
@Override @Override
protected void updateViewport( PropertyChangeEvent e ) { protected void updateViewport( PropertyChangeEvent e ) {
super.updateViewport( e ); super.updateViewport( e );

View File

@@ -30,6 +30,7 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSeparatorUI; import javax.swing.plaf.basic.BasicSeparatorUI;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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}. * 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 public class FlatSeparatorUI
extends BasicSeparatorUI extends BasicSeparatorUI
implements StyleableUI
{ {
@Styleable protected int height; @Styleable protected int height;
@Styleable protected int stripeWidth; @Styleable protected int stripeWidth;
@@ -148,6 +150,14 @@ public class FlatSeparatorUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
public void paint( Graphics g, JComponent c ) { public void paint( Graphics g, JComponent c ) {
Graphics2D g2 = (Graphics2D) g.create(); Graphics2D g2 = (Graphics2D) g.create();

View File

@@ -37,6 +37,7 @@ import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSliderUI; import javax.swing.plaf.basic.BasicSliderUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.Graphics2DProxy;
import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -77,6 +78,7 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatSliderUI public class FlatSliderUI
extends BasicSliderUI extends BasicSliderUI
implements StyleableUI
{ {
@Styleable protected int trackWidth; @Styleable protected int trackWidth;
@Styleable protected Dimension thumbSize; @Styleable protected Dimension thumbSize;
@@ -202,6 +204,14 @@ public class FlatSliderUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
public int getBaseline( JComponent c, int width, int height ) { public int getBaseline( JComponent c, int width, int height ) {
if( c == null ) if( c == null )

View File

@@ -45,6 +45,7 @@ import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicSpinnerUI; import javax.swing.plaf.basic.BasicSpinnerUI;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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}. * 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 public class FlatSpinnerUI
extends BasicSpinnerUI extends BasicSpinnerUI
implements StyleableUI
{ {
private Handler handler; private Handler handler;
@@ -205,6 +207,14 @@ public class FlatSpinnerUI
return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, spinner, borderShared ); return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, spinner, borderShared );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this, spinner.getBorder() );
}
@Override @Override
protected JComponent createEditor() { protected JComponent createEditor() {
JComponent editor = super.createEditor(); JComponent editor = super.createEditor();

View File

@@ -36,6 +36,7 @@ import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI; import javax.swing.plaf.basic.BasicSplitPaneUI;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.ui.FlatStyleSupport.UnknownStyleException;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -71,6 +72,7 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatSplitPaneUI public class FlatSplitPaneUI
extends BasicSplitPaneUI extends BasicSplitPaneUI
implements StyleableUI
{ {
@Styleable protected String arrowType; @Styleable protected String arrowType;
@Styleable protected Color oneTouchArrowColor; @Styleable protected Color oneTouchArrowColor;
@@ -159,6 +161,17 @@ public class FlatSplitPaneUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
Map<String, Class<?>> infos = FlatStyleSupport.getAnnotatedStyleableInfos( this );
if( divider instanceof FlatSplitPaneDivider )
infos.putAll( ((FlatSplitPaneDivider)divider).getStyleableInfos() );
return infos;
}
//---- class FlatSplitPaneDivider ----------------------------------------- //---- class FlatSplitPaneDivider -----------------------------------------
protected class FlatSplitPaneDivider protected class FlatSplitPaneDivider
@@ -183,6 +196,13 @@ public class FlatSplitPaneUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
public Map<String, Class<?>> getStyleableInfos() {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
void updateStyle() { void updateStyle() {
if( leftButton instanceof FlatOneTouchButton ) if( leftButton instanceof FlatOneTouchButton )
((FlatOneTouchButton)leftButton).updateStyle(); ((FlatOneTouchButton)leftButton).updateStyle();

View File

@@ -56,10 +56,16 @@ public class FlatStyleSupport
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface Styleable { public @interface Styleable {
boolean dot() default false; boolean dot() default false;
Class<?> type() default Void.class;
}
public interface StyleableUI {
Map<String, Class<?>> getStyleableInfos( JComponent c );
} }
public interface StyleableBorder { public interface StyleableBorder {
Object applyStyleProperty( String key, Object value ); Object applyStyleProperty( String key, Object value );
Map<String, Class<?>> getStyleableInfos();
} }
/** /**
@@ -250,8 +256,8 @@ public class FlatStyleSupport
try { try {
Field f = cls.getDeclaredField( fieldName ); Field f = cls.getDeclaredField( fieldName );
if( predicate == null || predicate.test( f ) ) { if( predicate == null || predicate.test( f ) ) {
if( Modifier.isFinal( f.getModifiers() ) ) if( !isValidField( f ) )
throw new IllegalArgumentException( "field '" + cls.getName() + "." + fieldName + "' is final" ); throw new IllegalArgumentException( "field '" + cls.getName() + "." + fieldName + "' is final or static" );
try { try {
// necessary to access protected fields in other packages // 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, static Object applyToAnnotatedObjectOrBorder( Object obj, String key, Object value,
JComponent c, AtomicBoolean borderShared ) 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<String, Class<?>> getAnnotatedStyleableInfos( Object obj ) {
return getAnnotatedStyleableInfos( obj, null );
}
public static Map<String, Class<?>> getAnnotatedStyleableInfos( Object obj, Border border ) {
Map<String, Class<?>> 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<String, Class<?>> 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<String, Class<?>> infos ) {
if( border instanceof StyleableBorder )
infos.putAll( ((StyleableBorder)border).getStyleableInfos() );
}
public static void putAllPrefixKey( Map<String, Class<?>> infos, String keyPrefix, Map<String, Class<?>> infos2 ) {
for( Map.Entry<String, Class<?>> e : infos2.entrySet() )
infos.put( keyPrefix.concat( e.getKey() ), e.getValue() );
}
//---- class UnknownStyleException ---------------------------------------- //---- class UnknownStyleException ----------------------------------------
public static class UnknownStyleException public static class UnknownStyleException

View File

@@ -52,6 +52,7 @@ import java.awt.geom.Rectangle2D;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -87,6 +88,7 @@ import javax.swing.text.View;
import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.icons.FlatTabbedPaneCloseIcon; import com.formdev.flatlaf.icons.FlatTabbedPaneCloseIcon;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.ui.FlatStyleSupport.UnknownStyleException;
import com.formdev.flatlaf.util.Animator; import com.formdev.flatlaf.util.Animator;
import com.formdev.flatlaf.util.CubicBezierEasing; import com.formdev.flatlaf.util.CubicBezierEasing;
@@ -160,6 +162,7 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatTabbedPaneUI public class FlatTabbedPaneUI
extends BasicTabbedPaneUI extends BasicTabbedPaneUI
implements StyleableUI
{ {
// tabs popup policy / scroll arrows policy // tabs popup policy / scroll arrows policy
protected static final int NEVER = 0; protected static final int NEVER = 0;
@@ -202,13 +205,13 @@ public class FlatTabbedPaneUI
@Styleable protected boolean hasFullBorder; @Styleable protected boolean hasFullBorder;
@Styleable protected boolean tabsOpaque = true; @Styleable protected boolean tabsOpaque = true;
@Styleable private int tabsPopupPolicy; @Styleable(type=String.class) private int tabsPopupPolicy;
@Styleable private int scrollButtonsPolicy; @Styleable(type=String.class) private int scrollButtonsPolicy;
@Styleable private int scrollButtonsPlacement; @Styleable(type=String.class) private int scrollButtonsPlacement;
@Styleable private int tabAreaAlignment; @Styleable(type=String.class) private int tabAreaAlignment;
@Styleable private int tabAlignment; @Styleable(type=String.class) private int tabAlignment;
@Styleable private int tabWidthMode; @Styleable(type=String.class) private int tabWidthMode;
protected Icon closeIcon; protected Icon closeIcon;
@Styleable protected String arrowType; @Styleable protected String arrowType;
@@ -626,6 +629,21 @@ public class FlatTabbedPaneUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
Map<String, Class<?>> 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 ) { protected void setRolloverTab( int x, int y ) {
setRolloverTab( tabForCoordinate( tabPane, x, y ) ); setRolloverTab( tabForCoordinate( tabPane, x, y ) );
} }

View File

@@ -39,6 +39,7 @@ import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel; import javax.swing.table.TableColumnModel;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
/** /**
@@ -71,10 +72,11 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatTableHeaderUI public class FlatTableHeaderUI
extends BasicTableHeaderUI extends BasicTableHeaderUI
implements StyleableUI
{ {
@Styleable protected Color bottomSeparatorColor; @Styleable protected Color bottomSeparatorColor;
@Styleable protected int height; @Styleable protected int height;
@Styleable protected int sortIconPosition; @Styleable(type=String.class) protected int sortIconPosition;
// for FlatTableHeaderBorder // for FlatTableHeaderBorder
@Styleable protected Insets cellMargins; @Styleable protected Insets cellMargins;
@@ -150,6 +152,14 @@ public class FlatTableHeaderUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
private static int parseSortIconPosition( String str ) { private static int parseSortIconPosition( String str ) {
if( str == null ) if( str == null )
str = ""; str = "";

View File

@@ -39,6 +39,7 @@ import javax.swing.plaf.basic.BasicTableUI;
import javax.swing.table.JTableHeader; import javax.swing.table.JTableHeader;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.Graphics2DProxy;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -92,6 +93,7 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatTableUI public class FlatTableUI
extends BasicTableUI extends BasicTableUI
implements StyleableUI
{ {
protected boolean showHorizontalLines; protected boolean showHorizontalLines;
protected boolean showVerticalLines; protected boolean showVerticalLines;
@@ -255,6 +257,14 @@ public class FlatTableUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
/** /**
* Toggle selection colors from focused to inactive and vice versa. * Toggle selection colors from focused to inactive and vice versa.
* *

View File

@@ -29,6 +29,7 @@ import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTextAreaUI; import javax.swing.plaf.basic.BasicTextAreaUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.HiDPIUtils;
/** /**
@@ -59,6 +60,7 @@ import com.formdev.flatlaf.util.HiDPIUtils;
*/ */
public class FlatTextAreaUI public class FlatTextAreaUI
extends BasicTextAreaUI extends BasicTextAreaUI
implements StyleableUI
{ {
@Styleable protected int minimumWidth; @Styleable protected int minimumWidth;
protected boolean isIntelliJTheme; protected boolean isIntelliJTheme;
@@ -158,6 +160,14 @@ public class FlatTextAreaUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
private void updateBackground() { private void updateBackground() {
FlatTextFieldUI.updateBackground( getComponent(), background, FlatTextFieldUI.updateBackground( getComponent(), background,
disabledBackground, inactiveBackground, disabledBackground, inactiveBackground,

View File

@@ -43,6 +43,7 @@ import javax.swing.text.Caret;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.HiDPIUtils;
import com.formdev.flatlaf.util.JavaCompatibility; import com.formdev.flatlaf.util.JavaCompatibility;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -78,6 +79,7 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatTextFieldUI public class FlatTextFieldUI
extends BasicTextFieldUI extends BasicTextFieldUI
implements StyleableUI
{ {
@Styleable protected int minimumWidth; @Styleable protected int minimumWidth;
protected boolean isIntelliJTheme; protected boolean isIntelliJTheme;
@@ -216,6 +218,14 @@ public class FlatTextFieldUI
return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, getComponent(), borderShared ); return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, getComponent(), borderShared );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this, getComponent().getBorder() );
}
private void updateBackground() { private void updateBackground() {
updateBackground( getComponent(), background, updateBackground( getComponent(), background,
disabledBackground, inactiveBackground, disabledBackground, inactiveBackground,

View File

@@ -29,6 +29,7 @@ import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTextPaneUI; import javax.swing.plaf.basic.BasicTextPaneUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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.HiDPIUtils;
/** /**
@@ -59,6 +60,7 @@ import com.formdev.flatlaf.util.HiDPIUtils;
*/ */
public class FlatTextPaneUI public class FlatTextPaneUI
extends BasicTextPaneUI extends BasicTextPaneUI
implements StyleableUI
{ {
@Styleable protected int minimumWidth; @Styleable protected int minimumWidth;
protected boolean isIntelliJTheme; protected boolean isIntelliJTheme;
@@ -166,6 +168,14 @@ public class FlatTextPaneUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
private void updateBackground() { private void updateBackground() {
FlatTextFieldUI.updateBackground( getComponent(), background, FlatTextFieldUI.updateBackground( getComponent(), background,
disabledBackground, inactiveBackground, disabledBackground, inactiveBackground,

View File

@@ -21,12 +21,15 @@ import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Graphics; import java.awt.Graphics;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.util.Iterator;
import java.util.Map;
import javax.swing.AbstractButton; import javax.swing.AbstractButton;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JToggleButton; import javax.swing.JToggleButton;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
import com.formdev.flatlaf.util.UIScale; 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<String, Class<?>> getStyleableInfos( JComponent c ) {
Map<String, Class<?>> infos = super.getStyleableInfos( c );
Iterator<String> it = infos.keySet().iterator();
while( it.hasNext() ) {
if( it.next().startsWith( "help." ) )
it.remove();
}
return infos;
}
static boolean isTabButton( Component c ) { static boolean isTabButton( Component c ) {
return c instanceof JToggleButton && clientPropertyEquals( (JToggleButton) c, BUTTON_TYPE, BUTTON_TYPE_TAB ); return c instanceof JToggleButton && clientPropertyEquals( (JToggleButton) c, BUTTON_TYPE, BUTTON_TYPE_TAB );
} }

View File

@@ -33,6 +33,7 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicToolBarSeparatorUI; import javax.swing.plaf.basic.BasicToolBarSeparatorUI;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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}. * 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 public class FlatToolBarSeparatorUI
extends BasicToolBarSeparatorUI extends BasicToolBarSeparatorUI
implements StyleableUI
{ {
private static final int LINE_WIDTH = 1; private static final int LINE_WIDTH = 1;
@@ -144,6 +146,14 @@ public class FlatToolBarSeparatorUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override @Override
public Dimension getPreferredSize( JComponent c ) { public Dimension getPreferredSize( JComponent c ) {
Dimension size = ((JToolBar.Separator)c).getSeparatorSize(); Dimension size = ((JToolBar.Separator)c).getSeparatorSize();

View File

@@ -30,6 +30,7 @@ import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicToolBarUI; import javax.swing.plaf.basic.BasicToolBarUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; 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}. * 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 public class FlatToolBarUI
extends BasicToolBarUI extends BasicToolBarUI
implements StyleableUI
{ {
/** @since 1.4 */ /** @since 1.4 */
@Styleable protected boolean focusableButtons; @Styleable protected boolean focusableButtons;
@@ -153,6 +155,14 @@ public class FlatToolBarUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
/** /**
* @since 1.4 * @since 1.4
*/ */

View File

@@ -41,6 +41,7 @@ import javax.swing.plaf.basic.BasicTreeUI;
import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
/** /**
@@ -122,6 +123,7 @@ import com.formdev.flatlaf.util.UIScale;
*/ */
public class FlatTreeUI public class FlatTreeUI
extends BasicTreeUI extends BasicTreeUI
implements StyleableUI
{ {
@Styleable protected Color selectionBackground; @Styleable protected Color selectionBackground;
@Styleable protected Color selectionForeground; @Styleable protected Color selectionForeground;
@@ -301,6 +303,14 @@ public class FlatTreeUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
} }
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
/** /**
* Same as super.paintRow(), but supports wide selection and uses * Same as super.paintRow(), but supports wide selection and uses
* inactive selection background/foreground if tree is not focused. * inactive selection background/foreground if tree is not focused.

File diff suppressed because it is too large Load Diff

View File

@@ -276,8 +276,8 @@ public class TestFlatStyling
Consumer<String> applyStyle = style -> ui.applyStyle( style ); Consumer<String> applyStyle = style -> ui.applyStyle( style );
menuItem( applyStyle ); menuItem( applyStyle );
menuItem_arrowIcon( applyStyle );
menuItem_checkIcon( applyStyle ); menuItem_checkIcon( applyStyle );
menuItem_arrowIcon( applyStyle );
} }
@Test @Test
@@ -287,8 +287,8 @@ public class TestFlatStyling
Consumer<String> applyStyle = style -> ui.applyStyle( style ); Consumer<String> applyStyle = style -> ui.applyStyle( style );
menuItem( applyStyle ); menuItem( applyStyle );
menuItem_arrowIcon( applyStyle );
menuItem_checkIcon( applyStyle ); menuItem_checkIcon( applyStyle );
menuItem_arrowIcon( applyStyle );
} }
private void menuItem( Consumer<String> applyStyle ) { private void menuItem( Consumer<String> applyStyle ) {
@@ -320,7 +320,7 @@ public class TestFlatStyling
private void menuItem_checkIcon( Consumer<String> applyStyle ) { private void menuItem_checkIcon( Consumer<String> applyStyle ) {
applyStyle.accept( "icon.checkmarkColor: #fff" ); applyStyle.accept( "icon.checkmarkColor: #fff" );
applyStyle.accept( "icon.disabledCheckmarkColor: #fff" ); applyStyle.accept( "icon.disabledCheckmarkColor: #fff" );
applyStyle.accept( "icon.selectionForeground: #fff" ); applyStyle.accept( "selectionForeground: #fff" );
} }
private void menuItem_arrowIcon( Consumer<String> applyStyle ) { private void menuItem_arrowIcon( Consumer<String> applyStyle ) {
@@ -335,11 +335,9 @@ public class TestFlatStyling
JPasswordField c = new JPasswordField(); JPasswordField c = new JPasswordField();
FlatPasswordFieldUI ui = (FlatPasswordFieldUI) c.getUI(); FlatPasswordFieldUI ui = (FlatPasswordFieldUI) c.getUI();
ui.applyStyle( "minimumWidth: 100" ); // FlatPasswordFieldUI extends FlatTextFieldUI
ui.applyStyle( "disabledBackground: #fff" ); textField( ui );
ui.applyStyle( "inactiveBackground: #fff" );
ui.applyStyle( "placeholderForeground: #fff" );
ui.applyStyle( "focusedBackground: #fff" );
ui.applyStyle( "showCapsLock: true" ); ui.applyStyle( "showCapsLock: true" );
// capsLockIcon // capsLockIcon
@@ -543,6 +541,7 @@ public class TestFlatStyling
ui.applyStyle( "tabInsets: 1,2,3,4" ); ui.applyStyle( "tabInsets: 1,2,3,4" );
ui.applyStyle( "tabAreaInsets: 1,2,3,4" ); ui.applyStyle( "tabAreaInsets: 1,2,3,4" );
ui.applyStyle( "textIconGap: 4" );
ui.applyStyle( "disabledForeground: #fff" ); ui.applyStyle( "disabledForeground: #fff" );
@@ -555,7 +554,6 @@ public class TestFlatStyling
ui.applyStyle( "tabSeparatorColor: #fff" ); ui.applyStyle( "tabSeparatorColor: #fff" );
ui.applyStyle( "contentAreaColor: #fff" ); ui.applyStyle( "contentAreaColor: #fff" );
ui.applyStyle( "textIconGap: 4" );
ui.applyStyle( "minimumTabWidth: 50" ); ui.applyStyle( "minimumTabWidth: 50" );
ui.applyStyle( "maximumTabWidth: 100" ); ui.applyStyle( "maximumTabWidth: 100" );
ui.applyStyle( "tabHeight: 30" ); ui.applyStyle( "tabHeight: 30" );
@@ -809,6 +807,16 @@ public class TestFlatStyling
border.applyStyleProperty( "arc", 6 ); border.applyStyleProperty( "arc", 6 );
} }
@Test
void flatRoundBorder() {
FlatRoundBorder border = new FlatRoundBorder();
// FlatRoundBorder extends FlatBorder
flatBorder( border );
border.applyStyleProperty( "arc", 6 );
}
@Test @Test
void flatTextBorder() { void flatTextBorder() {
FlatTextBorder border = new FlatTextBorder(); FlatTextBorder border = new FlatTextBorder();
@@ -937,6 +945,7 @@ public class TestFlatStyling
icon.applyStyleProperty( "disabledArrowColor", Color.WHITE ); icon.applyStyleProperty( "disabledArrowColor", Color.WHITE );
icon.applyStyleProperty( "selectionForeground", Color.WHITE ); icon.applyStyleProperty( "selectionForeground", Color.WHITE );
} }
@Test @Test
void flatHelpButtonIcon() { void flatHelpButtonIcon() {
FlatHelpButtonIcon icon = new FlatHelpButtonIcon(); FlatHelpButtonIcon icon = new FlatHelpButtonIcon();

View File

@@ -17,7 +17,10 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import java.awt.Font; import java.awt.Font;
import java.util.Map;
import java.util.Objects;
import javax.swing.UIManager; import javax.swing.UIManager;
import org.opentest4j.AssertionFailedError;
import com.formdev.flatlaf.FlatIntelliJLaf; import com.formdev.flatlaf.FlatIntelliJLaf;
import com.formdev.flatlaf.FlatLightLaf; import com.formdev.flatlaf.FlatLightLaf;
import com.formdev.flatlaf.FlatSystemProperties; import com.formdev.flatlaf.FlatSystemProperties;
@@ -50,4 +53,15 @@ public class TestUtils
public static void resetFont() { public static void resetFont() {
UIManager.put( "defaultFont", null ); 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 );
}
}
} }