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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -23,6 +23,7 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.beans.PropertyChangeListener;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.JComponent;
@@ -33,6 +34,7 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableBorder;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JInternalFrame}.
@@ -88,6 +90,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableBorder;
*/
public class FlatInternalFrameUI
extends BasicInternalFrameUI
implements StyleableUI
{
protected FlatWindowResizer windowResizer;
@@ -157,6 +160,14 @@ public class FlatInternalFrameUI
return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, frame, borderShared );
}
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this, frame.getBorder() );
}
//---- class FlatInternalFrameBorder --------------------------------------
public static class FlatInternalFrameBorder
@@ -197,6 +208,20 @@ public class FlatInternalFrameUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
}
@Override
public Map<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
public Insets getBorderInsets( Component c, Insets insets ) {
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.FlatLaf;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.UIScale;
@@ -57,6 +58,7 @@ import com.formdev.flatlaf.util.UIScale;
*/
public class FlatLabelUI
extends BasicLabelUI
implements StyleableUI
{
@Styleable protected Color disabledForeground;
@@ -149,6 +151,14 @@ public class FlatLabelUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
}
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
/**
* Checks whether text contains HTML tags that use "absolute-size" keywords
* (e.g. "x-large") for font-size in default style sheet

View File

@@ -28,6 +28,7 @@ import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicListUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JList}.
@@ -67,6 +68,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
*/
public class FlatListUI
extends BasicListUI
implements StyleableUI
{
@Styleable protected Color selectionBackground;
@Styleable protected Color selectionForeground;
@@ -179,6 +181,14 @@ public class FlatListUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
}
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
/**
* 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.Graphics;
import java.awt.Insets;
import java.util.Map;
import javax.swing.JMenuBar;
import javax.swing.UIManager;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
@@ -47,6 +48,11 @@ public class FlatMenuBarBorder
return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
}
@Override
public Map<String, Class<?>> getStyleableInfos() {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
float lineHeight = scale( (float) 1 );

View File

@@ -40,6 +40,7 @@ import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicMenuBarUI;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.util.SystemInfo;
/**
@@ -60,6 +61,7 @@ import com.formdev.flatlaf.util.SystemInfo;
*/
public class FlatMenuBarUI
extends BasicMenuBarUI
implements StyleableUI
{
private PropertyChangeListener propertyChangeListener;
private Map<String, Object> oldStyleValues;
@@ -141,6 +143,14 @@ public class FlatMenuBarUI
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
public void update( Graphics g, JComponent c ) {
// paint background

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -37,6 +37,7 @@ import javax.swing.plaf.basic.BasicRadioButtonUI;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.icons.FlatCheckBoxIcon;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
import com.formdev.flatlaf.util.UIScale;
@@ -62,6 +63,7 @@ import com.formdev.flatlaf.util.UIScale;
*/
public class FlatRadioButtonUI
extends BasicRadioButtonUI
implements StyleableUI
{
protected int iconTextGap;
@Styleable protected Color disabledText;
@@ -181,6 +183,19 @@ public class FlatRadioButtonUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
}
/**
* @since TODO
*/
@Override
public Map<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 );
@Override

View File

@@ -24,6 +24,7 @@ import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeListener;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import javax.swing.InputMap;
@@ -37,6 +38,7 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicScrollBarUI;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
import com.formdev.flatlaf.util.UIScale;
/**
@@ -76,6 +78,7 @@ import com.formdev.flatlaf.util.UIScale;
*/
public class FlatScrollBarUI
extends BasicScrollBarUI
implements StyleableUI
{
// overrides BasicScrollBarUI.supportsAbsolutePositioning (which is private)
@Styleable protected boolean allowsAbsolutePositioning;
@@ -246,6 +249,21 @@ public class FlatScrollBarUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
}
/**
* @since TODO
*/
@Override
public Map<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
public Dimension getPreferredSize( JComponent 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.basic.BasicScrollPaneUI;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JScrollPane}.
@@ -68,6 +69,7 @@ import com.formdev.flatlaf.FlatClientProperties;
*/
public class FlatScrollPaneUI
extends BasicScrollPaneUI
implements StyleableUI
{
private Handler handler;
@@ -320,6 +322,14 @@ public class FlatScrollPaneUI
return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, scrollpane, borderShared );
}
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this, scrollpane.getBorder() );
}
@Override
protected void updateViewport( PropertyChangeEvent e ) {
super.updateViewport( e );

View File

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

View File

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

View File

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

View File

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

View File

@@ -56,10 +56,16 @@ public class FlatStyleSupport
@Retention(RetentionPolicy.RUNTIME)
public @interface Styleable {
boolean dot() default false;
Class<?> type() default Void.class;
}
public interface StyleableUI {
Map<String, Class<?>> getStyleableInfos( JComponent c );
}
public interface StyleableBorder {
Object applyStyleProperty( String key, Object value );
Map<String, Class<?>> getStyleableInfos();
}
/**
@@ -250,8 +256,8 @@ public class FlatStyleSupport
try {
Field f = cls.getDeclaredField( fieldName );
if( predicate == null || predicate.test( f ) ) {
if( Modifier.isFinal( f.getModifiers() ) )
throw new IllegalArgumentException( "field '" + cls.getName() + "." + fieldName + "' is final" );
if( !isValidField( f ) )
throw new IllegalArgumentException( "field '" + cls.getName() + "." + fieldName + "' is final or static" );
try {
// necessary to access protected fields in other packages
@@ -281,6 +287,11 @@ public class FlatStyleSupport
}
}
private static boolean isValidField( Field f ) {
int modifiers = f.getModifiers();
return (modifiers & (Modifier.FINAL|Modifier.STATIC)) == 0 && !f.isSynthetic();
}
static Object applyToAnnotatedObjectOrBorder( Object obj, String key, Object value,
JComponent c, AtomicBoolean borderShared )
{
@@ -342,6 +353,80 @@ public class FlatStyleSupport
}
}
/**
* Returns a map of all fields annotated with {@link Styleable}.
* The key is the name of the field and the value the type of the field.
*/
public static Map<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 ----------------------------------------
public static class UnknownStyleException

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -21,12 +21,15 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.beans.PropertyChangeEvent;
import java.util.Iterator;
import java.util.Map;
import javax.swing.AbstractButton;
import javax.swing.JComponent;
import javax.swing.JToggleButton;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
import com.formdev.flatlaf.util.UIScale;
/**
@@ -143,6 +146,31 @@ public class FlatToggleButtonUI
}
}
/**
* @since TODO
*/
@Override
protected Object applyStyleProperty( AbstractButton b, String key, Object value ) {
if( key.startsWith( "help." ) )
throw new UnknownStyleException( key );
return super.applyStyleProperty( b, key, value );
}
/**
* @since TODO
*/
@Override
public Map<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 ) {
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 com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JToolBar.Separator}.
@@ -46,6 +47,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
*/
public class FlatToolBarSeparatorUI
extends BasicToolBarSeparatorUI
implements StyleableUI
{
private static final int LINE_WIDTH = 1;
@@ -144,6 +146,14 @@ public class FlatToolBarSeparatorUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
}
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
@Override
public Dimension getPreferredSize( JComponent c ) {
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.basic.BasicToolBarUI;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.StyleableUI;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JToolBar}.
@@ -59,6 +60,7 @@ import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
*/
public class FlatToolBarUI
extends BasicToolBarUI
implements StyleableUI
{
/** @since 1.4 */
@Styleable protected boolean focusableButtons;
@@ -153,6 +155,14 @@ public class FlatToolBarUI
return FlatStyleSupport.applyToAnnotatedObject( this, key, value );
}
/**
* @since TODO
*/
@Override
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStyleSupport.getAnnotatedStyleableInfos( this );
}
/**
* @since 1.4
*/

View File

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

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

View File

@@ -17,7 +17,10 @@
package com.formdev.flatlaf.ui;
import java.awt.Font;
import java.util.Map;
import java.util.Objects;
import javax.swing.UIManager;
import org.opentest4j.AssertionFailedError;
import com.formdev.flatlaf.FlatIntelliJLaf;
import com.formdev.flatlaf.FlatLightLaf;
import com.formdev.flatlaf.FlatSystemProperties;
@@ -50,4 +53,15 @@ public class TestUtils
public static void resetFont() {
UIManager.put( "defaultFont", null );
}
public static void assertMapEquals( Map<?, ?> expected, Map<?, ?> actual ) {
if( !Objects.equals( expected, actual ) ) {
String expectedStr = String.valueOf( expected ).replace( ", ", ",\n" );
String actualStr = String.valueOf( actual ).replace( ", ", ",\n" );
String msg = String.format( "expected: <%s> but was: <%s>", expectedStr, actualStr );
// pass expected/actual strings to exception for nice diff in IDE
throw new AssertionFailedError( msg, expectedStr, actualStr );
}
}
}