mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
Styling: support styling any component property that has public getter and setter methods
This commit is contained in:
@@ -55,6 +55,7 @@ import javax.swing.RootPaneContainer;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIDefaults;
|
||||
import javax.swing.UIDefaults.ActiveValue;
|
||||
import javax.swing.UIDefaults.LazyValue;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
@@ -794,7 +795,16 @@ public abstract class FlatLaf
|
||||
public static Object parseDefaultsValue( String key, String value, Class<?> valueType )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
return UIDefaultsLoader.parseValue( key, value, valueType );
|
||||
// parse value
|
||||
Object val = UIDefaultsLoader.parseValue( key, value, valueType );
|
||||
|
||||
// create actual value if lazy or active
|
||||
if( val instanceof LazyValue )
|
||||
val = ((LazyValue)val).createValue( null );
|
||||
else if( val instanceof ActiveValue )
|
||||
val = ((ActiveValue)val).createValue( null );
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
private static void reSetLookAndFeel() {
|
||||
|
||||
@@ -391,9 +391,9 @@ class UIDefaultsLoader
|
||||
(key.endsWith( ".background" ) || key.endsWith( "Background" ) || key.equals( "background" ) ||
|
||||
key.endsWith( ".foreground" ) || key.endsWith( "Foreground" ) || key.equals( "foreground" ))) )
|
||||
valueType = ValueType.COLOR;
|
||||
else if( key.endsWith( ".border" ) || key.endsWith( "Border" ) )
|
||||
else if( key.endsWith( ".border" ) || key.endsWith( "Border" ) || key.equals( "border" ) )
|
||||
valueType = ValueType.BORDER;
|
||||
else if( key.endsWith( ".icon" ) || key.endsWith( "Icon" ) )
|
||||
else if( key.endsWith( ".icon" ) || key.endsWith( "Icon" ) || key.equals( "icon" ) )
|
||||
valueType = ValueType.ICON;
|
||||
else if( key.endsWith( ".margin" ) || key.equals( "margin" ) ||
|
||||
key.endsWith( ".padding" ) || key.equals( "padding" ) ||
|
||||
|
||||
@@ -117,7 +117,7 @@ public class FlatCheckBoxMenuItemUI
|
||||
// ignore
|
||||
}
|
||||
|
||||
return FlatMenuItemUI.applyStyleProperty( this, key, value );
|
||||
return FlatMenuItemUI.applyStyleProperty( this, menuItem, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -188,7 +188,7 @@ public class FlatEditorPaneUI
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, getComponent(), key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -83,7 +83,7 @@ public class FlatLabelUI
|
||||
public void installUI( JComponent c ) {
|
||||
super.installUI( c );
|
||||
|
||||
applyStyle( FlatStylingSupport.getStyle( c ) );
|
||||
applyStyle( (JLabel) c, FlatStylingSupport.getStyle( c ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -132,7 +132,7 @@ public class FlatLabelUI
|
||||
ui = (FlatLabelUI) c.getUI();
|
||||
}
|
||||
|
||||
ui.applyStyle( style );
|
||||
ui.applyStyle( c, style );
|
||||
c.revalidate();
|
||||
c.repaint();
|
||||
}
|
||||
@@ -140,15 +140,16 @@ public class FlatLabelUI
|
||||
/**
|
||||
* @since TODO
|
||||
*/
|
||||
protected void applyStyle( Object style ) {
|
||||
oldStyleValues = FlatStylingSupport.parseAndApply( oldStyleValues, style, this::applyStyleProperty );
|
||||
protected void applyStyle( JLabel c, Object style ) {
|
||||
oldStyleValues = FlatStylingSupport.parseAndApply( oldStyleValues, style,
|
||||
(key, value) -> applyStyleProperty( c, key, value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
protected Object applyStyleProperty( JLabel c, String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, c, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -178,7 +178,7 @@ public class FlatListUI
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, list, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicMenuItemUI;
|
||||
@@ -119,10 +120,10 @@ public class FlatMenuItemUI
|
||||
// ignore
|
||||
}
|
||||
|
||||
return applyStyleProperty( this, key, value );
|
||||
return applyStyleProperty( this, menuItem, key, value );
|
||||
}
|
||||
|
||||
static Object applyStyleProperty( BasicMenuItemUI ui, String key, Object value ) {
|
||||
static Object applyStyleProperty( BasicMenuItemUI ui, JMenuItem menuItem, String key, Object value ) {
|
||||
switch( key ) {
|
||||
// BasicMenuItemUI
|
||||
case "selectionBackground":
|
||||
@@ -132,7 +133,8 @@ public class FlatMenuItemUI
|
||||
case "acceleratorSelectionForeground":
|
||||
return FlatStylingSupport.applyToField( ui, key, key, value );
|
||||
|
||||
default: throw new UnknownStyleException( key );
|
||||
default:
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( ui, menuItem, key, value );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ public class FlatMenuUI
|
||||
// ignore
|
||||
}
|
||||
|
||||
return FlatMenuItemUI.applyStyleProperty( this, key, value );
|
||||
return FlatMenuItemUI.applyStyleProperty( this, menuItem, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -140,7 +140,7 @@ public class FlatProgressBarUI
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, progressBar, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -117,7 +117,7 @@ public class FlatRadioButtonMenuItemUI
|
||||
// ignore
|
||||
}
|
||||
|
||||
return FlatMenuItemUI.applyStyleProperty( this, key, value );
|
||||
return FlatMenuItemUI.applyStyleProperty( this, menuItem, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,7 +92,7 @@ public class FlatRadioButtonUI
|
||||
public void installUI( JComponent c ) {
|
||||
super.installUI( c );
|
||||
|
||||
applyStyle( FlatStylingSupport.getStyle( c ) );
|
||||
applyStyle( (AbstractButton) c, FlatStylingSupport.getStyle( c ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,7 +150,7 @@ public class FlatRadioButtonUI
|
||||
ui = (FlatRadioButtonUI) b.getUI();
|
||||
}
|
||||
|
||||
ui.applyStyle( style );
|
||||
ui.applyStyle( b, style );
|
||||
b.revalidate();
|
||||
b.repaint();
|
||||
}
|
||||
@@ -158,14 +158,15 @@ public class FlatRadioButtonUI
|
||||
/**
|
||||
* @since TODO
|
||||
*/
|
||||
protected void applyStyle( Object style ) {
|
||||
oldStyleValues = FlatStylingSupport.parseAndApply( oldStyleValues, style, this::applyStyleProperty );
|
||||
protected void applyStyle( AbstractButton b, Object style ) {
|
||||
oldStyleValues = FlatStylingSupport.parseAndApply( oldStyleValues, style,
|
||||
(key, value) -> applyStyleProperty( b, key, value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
protected Object applyStyleProperty( AbstractButton b, String key, Object value ) {
|
||||
// style icon
|
||||
if( key.startsWith( "icon." ) ) {
|
||||
if( !(icon instanceof FlatCheckBoxIcon) )
|
||||
@@ -180,7 +181,7 @@ public class FlatRadioButtonUI
|
||||
return ((FlatCheckBoxIcon)icon).applyStyleProperty( key, value );
|
||||
}
|
||||
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, b, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -246,7 +246,7 @@ public class FlatScrollBarUI
|
||||
case "maximumThumbSize": oldValue = maximumThumbSize; maximumThumbSize = (Dimension) value; return oldValue;
|
||||
}
|
||||
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, scrollbar, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -82,7 +82,7 @@ public class FlatSeparatorUI
|
||||
public void installUI( JComponent c ) {
|
||||
super.installUI( c );
|
||||
|
||||
applyStyle( FlatStylingSupport.getStyle( c ) );
|
||||
applyStyle( (JSeparator) c, FlatStylingSupport.getStyle( c ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,7 +131,7 @@ public class FlatSeparatorUI
|
||||
ui = (FlatSeparatorUI) s.getUI();
|
||||
}
|
||||
|
||||
ui.applyStyle( style );
|
||||
ui.applyStyle( s, style );
|
||||
s.revalidate();
|
||||
s.repaint();
|
||||
}
|
||||
@@ -139,15 +139,16 @@ public class FlatSeparatorUI
|
||||
/**
|
||||
* @since TODO
|
||||
*/
|
||||
protected void applyStyle( Object style ) {
|
||||
oldStyleValues = FlatStylingSupport.parseAndApply( oldStyleValues, style, this::applyStyleProperty );
|
||||
protected void applyStyle( JSeparator s, Object style ) {
|
||||
oldStyleValues = FlatStylingSupport.parseAndApply( oldStyleValues, style,
|
||||
(key, value) -> applyStyleProperty( s, key, value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
protected Object applyStyleProperty( JSeparator s, String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, s, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -201,7 +201,7 @@ public class FlatSliderUI
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, slider, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -158,7 +158,7 @@ public class FlatSplitPaneUI
|
||||
} catch( UnknownStyleException ex ) {
|
||||
// ignore
|
||||
}
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, splitPane, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -81,7 +82,7 @@ public class FlatStylingSupport
|
||||
* @return map of old values modified by the given style, or {@code null}
|
||||
* @throws UnknownStyleException on unknown style keys
|
||||
* @throws IllegalArgumentException on syntax errors
|
||||
* @throws ClassCastException if value type does not fit to expected type
|
||||
* @throws ClassCastException if value type does not fit to expected type
|
||||
*/
|
||||
public static Map<String, Object> parseAndApply( Map<String, Object> oldStyleValues,
|
||||
Object style, BiFunction<String, Object, Object> applyProperty )
|
||||
@@ -210,7 +211,7 @@ public class FlatStylingSupport
|
||||
* @param value the new value
|
||||
* @return the old value of the field
|
||||
* @throws UnknownStyleException if object does not have a annotated field with given name
|
||||
* @throws IllegalArgumentException if value type does not fit to expected type
|
||||
* @throws IllegalArgumentException if value type does not fit to expected type
|
||||
*/
|
||||
public static Object applyToAnnotatedObject( Object obj, String key, Object value )
|
||||
throws UnknownStyleException, IllegalArgumentException
|
||||
@@ -239,7 +240,7 @@ public class FlatStylingSupport
|
||||
* @param value the new value
|
||||
* @return the old value of the field
|
||||
* @throws UnknownStyleException if object does not have a field with given name
|
||||
* @throws IllegalArgumentException if value type does not fit to expected type
|
||||
* @throws IllegalArgumentException if value type does not fit to expected type
|
||||
*/
|
||||
static Object applyToField( Object obj, String fieldName, String key, Object value )
|
||||
throws UnknownStyleException, IllegalArgumentException
|
||||
@@ -292,12 +293,90 @@ public class FlatStylingSupport
|
||||
return (modifiers & (Modifier.FINAL|Modifier.STATIC)) == 0 && !f.isSynthetic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the given value to a property of the given object.
|
||||
* Works only for properties that have public getter and setter methods.
|
||||
* First the property getter is invoked to get the old value,
|
||||
* then the property setter is invoked to set the new value.
|
||||
*
|
||||
* @param obj the object
|
||||
* @param name the name of the property
|
||||
* @param value the new value
|
||||
* @return the old value of the property
|
||||
* @throws UnknownStyleException if object does not have a property with given name
|
||||
* @throws IllegalArgumentException if value type does not fit to expected type
|
||||
*/
|
||||
private static Object applyToProperty( Object obj, String name, Object value )
|
||||
throws UnknownStyleException, IllegalArgumentException
|
||||
{
|
||||
Class<?> cls = obj.getClass();
|
||||
String getterName = buildMethodName( "get", name );
|
||||
String setterName = buildMethodName( "set", name );
|
||||
|
||||
try {
|
||||
Method getter;
|
||||
try {
|
||||
getter = cls.getMethod( getterName );
|
||||
} catch( NoSuchMethodException ex ) {
|
||||
getter = cls.getMethod( buildMethodName( "is", name ) );
|
||||
}
|
||||
Method setter = cls.getMethod( setterName, getter.getReturnType() );
|
||||
Object oldValue = getter.invoke( obj );
|
||||
setter.invoke( obj, value );
|
||||
return oldValue;
|
||||
} catch( NoSuchMethodException ex ) {
|
||||
throw new UnknownStyleException( name );
|
||||
} catch( Exception ex ) {
|
||||
throw new IllegalArgumentException( "failed to invoke property methods '" + cls.getName() + "."
|
||||
+ getterName + "()' or '" + setterName + "(...)'", ex );
|
||||
}
|
||||
}
|
||||
|
||||
private static String buildMethodName( String prefix, String name ) {
|
||||
int prefixLength = prefix.length();
|
||||
int nameLength = name.length();
|
||||
char[] chars = new char[prefixLength + nameLength];
|
||||
prefix.getChars( 0, prefixLength, chars, 0 );
|
||||
name.getChars( 0, nameLength, chars, prefixLength );
|
||||
chars[prefixLength] = Character.toUpperCase( chars[prefixLength] );
|
||||
return new String( chars );
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the given value to an annotated field of the given object
|
||||
* or to a property of the given component.
|
||||
* The field must be annotated with {@link Styleable}.
|
||||
* The component property must have public getter and setter methods.
|
||||
*
|
||||
* @param obj the object
|
||||
* @param comp the component, or {@code null}
|
||||
* @param key the name of the field
|
||||
* @param value the new value
|
||||
* @return the old value of the field
|
||||
* @throws UnknownStyleException if object does not have a annotated field with given name
|
||||
* @throws IllegalArgumentException if value type does not fit to expected type
|
||||
*/
|
||||
public static Object applyToAnnotatedObjectOrComponent( Object obj, Object comp, String key, Object value ) {
|
||||
try {
|
||||
return applyToAnnotatedObject( obj, key, value );
|
||||
} catch( UnknownStyleException ex ) {
|
||||
try {
|
||||
if( comp != null )
|
||||
return applyToProperty( comp, key, value );
|
||||
} catch( UnknownStyleException ex2 ) {
|
||||
// ignore
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
static Object applyToAnnotatedObjectOrBorder( Object obj, String key, Object value,
|
||||
JComponent c, AtomicBoolean borderShared )
|
||||
{
|
||||
try {
|
||||
return applyToAnnotatedObject( obj, key, value );
|
||||
} catch( UnknownStyleException ex ) {
|
||||
// apply to border
|
||||
Border border = c.getBorder();
|
||||
if( border instanceof StyleableBorder ) {
|
||||
if( borderShared.get() ) {
|
||||
@@ -312,6 +391,13 @@ public class FlatStylingSupport
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// apply to component property
|
||||
try {
|
||||
return applyToProperty( c, key, value );
|
||||
} catch( UnknownStyleException ex2 ) {
|
||||
// ignore
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,7 +626,7 @@ public class FlatTabbedPaneUI
|
||||
}
|
||||
}
|
||||
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, tabPane, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -149,7 +149,7 @@ public class FlatTableHeaderUI
|
||||
if( key.equals( "sortIconPosition" ) && value instanceof String )
|
||||
value = parseSortIconPosition( (String) value );
|
||||
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, header, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -254,7 +254,7 @@ public class FlatTableUI
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, table, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -162,7 +162,7 @@ public class FlatTextAreaUI
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, getComponent(), key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -170,7 +170,7 @@ public class FlatTextPaneUI
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, getComponent(), key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -152,7 +152,7 @@ public class FlatToolBarUI
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, toolBar, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -320,7 +320,7 @@ public class FlatTreeUI
|
||||
* @since TODO
|
||||
*/
|
||||
protected Object applyStyleProperty( String key, Object value ) {
|
||||
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
|
||||
return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, tree, key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -131,6 +131,14 @@ public class TestFlatStyling
|
||||
|
||||
// border
|
||||
flatButtonBorder( style -> ui.applyStyle( b, style ) );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( b, "background: #fff" );
|
||||
ui.applyStyle( b, "foreground: #fff" );
|
||||
ui.applyStyle( b, "border: 2,2,2,2,#f00" );
|
||||
|
||||
// AbstractButton properties
|
||||
ui.applyStyle( b, "margin: 2,2,2,2" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,7 +149,7 @@ public class TestFlatStyling
|
||||
assertTrue( ui.getDefaultIcon() instanceof FlatCheckBoxIcon );
|
||||
|
||||
// FlatCheckBoxUI extends FlatRadioButtonUI
|
||||
radioButton( ui );
|
||||
radioButton( ui, c );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,6 +183,11 @@ public class TestFlatStyling
|
||||
|
||||
// border
|
||||
flatRoundBorder( style -> ui.applyStyle( style ) );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,6 +199,17 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "disabledBackground: #fff" );
|
||||
ui.applyStyle( "inactiveBackground: #fff" );
|
||||
ui.applyStyle( "focusedBackground: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
|
||||
// JTextComponent properties
|
||||
ui.applyStyle( "caretColor: #fff" );
|
||||
ui.applyStyle( "selectionColor: #fff" );
|
||||
ui.applyStyle( "selectedTextColor: #fff" );
|
||||
ui.applyStyle( "disabledTextColor: #fff" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,6 +238,11 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "inactiveDropShadowColor: #fff" );
|
||||
ui.applyStyle( "inactiveDropShadowInsets: 1,2,3,4" );
|
||||
ui.applyStyle( "inactiveDropShadowOpacity: 0.5" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -221,7 +250,15 @@ public class TestFlatStyling
|
||||
JLabel c = new JLabel();
|
||||
FlatLabelUI ui = (FlatLabelUI) c.getUI();
|
||||
|
||||
ui.applyStyle( "disabledForeground: #fff" );
|
||||
ui.applyStyle( c, "disabledForeground: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( c, "background: #fff" );
|
||||
ui.applyStyle( c, "foreground: #fff" );
|
||||
ui.applyStyle( c, "border: 2,2,2,2,#f00" );
|
||||
|
||||
// JLabel properties
|
||||
ui.applyStyle( c, "icon: com.formdev.flatlaf.icons.FlatTreeExpandedIcon" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -238,6 +275,14 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "cellMargins: 1,2,3,4" );
|
||||
ui.applyStyle( "cellFocusColor: #fff" );
|
||||
ui.applyStyle( "showCellFocusIndicator: true" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
|
||||
// JList properties
|
||||
ui.applyStyle( "visibleRowCount: 20" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -247,6 +292,11 @@ public class TestFlatStyling
|
||||
|
||||
// FlatMenuBarBorder
|
||||
ui.applyStyle( "borderColor: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -299,6 +349,14 @@ public class TestFlatStyling
|
||||
applyStyle.accept( "acceleratorSelectionForeground: #fff" );
|
||||
|
||||
menuItemRenderer( applyStyle );
|
||||
|
||||
// JComponent properties
|
||||
applyStyle.accept( "background: #fff" );
|
||||
applyStyle.accept( "foreground: #fff" );
|
||||
applyStyle.accept( "border: 2,2,2,2,#f00" );
|
||||
|
||||
// AbstractButton properties
|
||||
applyStyle.accept( "margin: 2,2,2,2" );
|
||||
}
|
||||
|
||||
private void menuItemRenderer( Consumer<String> applyStyle ) {
|
||||
@@ -354,6 +412,11 @@ public class TestFlatStyling
|
||||
|
||||
ui.applyStyle( "borderInsets: 1,2,3,4" );
|
||||
ui.applyStyle( "borderColor: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -362,7 +425,7 @@ public class TestFlatStyling
|
||||
FlatPopupMenuSeparatorUI ui = (FlatPopupMenuSeparatorUI) c.getUI();
|
||||
|
||||
// FlatPopupMenuSeparatorUI extends FlatSeparatorUI
|
||||
separator( ui );
|
||||
separator( ui, c );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -373,6 +436,11 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "arc: 5" );
|
||||
ui.applyStyle( "horizontalSize: 100,12" );
|
||||
ui.applyStyle( "verticalSize: 12,100" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -382,47 +450,55 @@ public class TestFlatStyling
|
||||
|
||||
assertTrue( ui.getDefaultIcon() instanceof FlatRadioButtonIcon );
|
||||
|
||||
radioButton( ui );
|
||||
radioButton( ui, c );
|
||||
|
||||
ui.applyStyle( "icon.centerDiameter: 8" );
|
||||
ui.applyStyle( c, "icon.centerDiameter: 8" );
|
||||
}
|
||||
|
||||
private void radioButton( FlatRadioButtonUI ui ) {
|
||||
ui.applyStyle( "disabledText: #fff" );
|
||||
private void radioButton( FlatRadioButtonUI ui, AbstractButton b ) {
|
||||
ui.applyStyle( b, "disabledText: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( b, "background: #fff" );
|
||||
ui.applyStyle( b, "foreground: #fff" );
|
||||
ui.applyStyle( b, "border: 2,2,2,2,#f00" );
|
||||
|
||||
// AbstractButton properties
|
||||
ui.applyStyle( b, "margin: 2,2,2,2" );
|
||||
|
||||
//---- icon ----
|
||||
|
||||
ui.applyStyle( "icon.focusWidth: 2" );
|
||||
ui.applyStyle( "icon.focusColor: #fff" );
|
||||
ui.applyStyle( "icon.arc: 5" );
|
||||
ui.applyStyle( b, "icon.focusWidth: 2" );
|
||||
ui.applyStyle( b, "icon.focusColor: #fff" );
|
||||
ui.applyStyle( b, "icon.arc: 5" );
|
||||
|
||||
// enabled
|
||||
ui.applyStyle( "icon.borderColor: #fff" );
|
||||
ui.applyStyle( "icon.background: #fff" );
|
||||
ui.applyStyle( "icon.selectedBorderColor: #fff" );
|
||||
ui.applyStyle( "icon.selectedBackground: #fff" );
|
||||
ui.applyStyle( "icon.checkmarkColor: #fff" );
|
||||
ui.applyStyle( b, "icon.borderColor: #fff" );
|
||||
ui.applyStyle( b, "icon.background: #fff" );
|
||||
ui.applyStyle( b, "icon.selectedBorderColor: #fff" );
|
||||
ui.applyStyle( b, "icon.selectedBackground: #fff" );
|
||||
ui.applyStyle( b, "icon.checkmarkColor: #fff" );
|
||||
|
||||
// disabled
|
||||
ui.applyStyle( "icon.disabledBorderColor: #fff" );
|
||||
ui.applyStyle( "icon.disabledBackground: #fff" );
|
||||
ui.applyStyle( "icon.disabledCheckmarkColor: #fff" );
|
||||
ui.applyStyle( b, "icon.disabledBorderColor: #fff" );
|
||||
ui.applyStyle( b, "icon.disabledBackground: #fff" );
|
||||
ui.applyStyle( b, "icon.disabledCheckmarkColor: #fff" );
|
||||
|
||||
// focused
|
||||
ui.applyStyle( "icon.focusedBorderColor: #fff" );
|
||||
ui.applyStyle( "icon.focusedBackground: #fff" );
|
||||
ui.applyStyle( "icon.selectedFocusedBorderColor: #fff" );
|
||||
ui.applyStyle( "icon.selectedFocusedBackground: #fff" );
|
||||
ui.applyStyle( "icon.selectedFocusedCheckmarkColor: #fff" );
|
||||
ui.applyStyle( b, "icon.focusedBorderColor: #fff" );
|
||||
ui.applyStyle( b, "icon.focusedBackground: #fff" );
|
||||
ui.applyStyle( b, "icon.selectedFocusedBorderColor: #fff" );
|
||||
ui.applyStyle( b, "icon.selectedFocusedBackground: #fff" );
|
||||
ui.applyStyle( b, "icon.selectedFocusedCheckmarkColor: #fff" );
|
||||
|
||||
// hover
|
||||
ui.applyStyle( "icon.hoverBorderColor: #fff" );
|
||||
ui.applyStyle( "icon.hoverBackground: #fff" );
|
||||
ui.applyStyle( "icon.selectedHoverBackground: #fff" );
|
||||
ui.applyStyle( b, "icon.hoverBorderColor: #fff" );
|
||||
ui.applyStyle( b, "icon.hoverBackground: #fff" );
|
||||
ui.applyStyle( b, "icon.selectedHoverBackground: #fff" );
|
||||
|
||||
// pressed
|
||||
ui.applyStyle( "icon.pressedBackground: #fff" );
|
||||
ui.applyStyle( "icon.selectedPressedBackground: #fff" );
|
||||
ui.applyStyle( b, "icon.pressedBackground: #fff" );
|
||||
ui.applyStyle( b, "icon.selectedPressedBackground: #fff" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -454,6 +530,11 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "buttonDisabledArrowColor: #fff" );
|
||||
ui.applyStyle( "hoverButtonBackground: #fff" );
|
||||
ui.applyStyle( "pressedButtonBackground: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -463,6 +544,11 @@ public class TestFlatStyling
|
||||
|
||||
// border
|
||||
flatBorder( style -> ui.applyStyle( style ) );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -470,13 +556,18 @@ public class TestFlatStyling
|
||||
JSeparator c = new JSeparator();
|
||||
FlatSeparatorUI ui = (FlatSeparatorUI) c.getUI();
|
||||
|
||||
separator( ui );
|
||||
separator( ui, c );
|
||||
}
|
||||
|
||||
private void separator( FlatSeparatorUI ui ) {
|
||||
ui.applyStyle( "height: 6" );
|
||||
ui.applyStyle( "stripeWidth: 2" );
|
||||
ui.applyStyle( "stripeIndent: 10" );
|
||||
private void separator( FlatSeparatorUI ui, JSeparator c ) {
|
||||
ui.applyStyle( c, "height: 6" );
|
||||
ui.applyStyle( c, "stripeWidth: 2" );
|
||||
ui.applyStyle( c, "stripeIndent: 10" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( c, "background: #fff" );
|
||||
ui.applyStyle( c, "foreground: #fff" );
|
||||
ui.applyStyle( c, "border: 2,2,2,2,#f00" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -500,6 +591,17 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "disabledThumbColor: #fff" );
|
||||
ui.applyStyle( "disabledThumbBorderColor: #fff" );
|
||||
ui.applyStyle( "tickColor: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
|
||||
// JSlider properties
|
||||
ui.applyStyle( "paintLabels: true" );
|
||||
ui.applyStyle( "paintTicks: true" );
|
||||
ui.applyStyle( "paintTrack: true" );
|
||||
ui.applyStyle( "snapToTicks: true" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -524,6 +626,11 @@ public class TestFlatStyling
|
||||
|
||||
// border
|
||||
flatRoundBorder( style -> ui.applyStyle( style ) );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -541,6 +648,14 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "gripDotCount: 3" );
|
||||
ui.applyStyle( "gripDotSize: {integer}3" );
|
||||
ui.applyStyle( "gripGap: 2" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
|
||||
// JSplitPane properties
|
||||
ui.applyStyle( "dividerSize: {integer}20" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -601,6 +716,11 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "closeHoverForeground: #fff" );
|
||||
ui.applyStyle( "closePressedBackground: #fff" );
|
||||
ui.applyStyle( "closePressedForeground: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -617,6 +737,18 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "cellMargins: 1,2,3,4" );
|
||||
ui.applyStyle( "cellFocusColor: #fff" );
|
||||
ui.applyStyle( "showCellFocusIndicator: true" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
|
||||
// JTable properties
|
||||
ui.applyStyle( "fillsViewportHeight: true" );
|
||||
ui.applyStyle( "rowHeight: 30" );
|
||||
ui.applyStyle( "showHorizontalLines: true" );
|
||||
ui.applyStyle( "showVerticalLines: true" );
|
||||
ui.applyStyle( "intercellSpacing: {dimension}1,1" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -635,6 +767,11 @@ public class TestFlatStyling
|
||||
// FlatAscendingSortIcon and FlatDescendingSortIcon
|
||||
ui.applyStyle( "arrowType: chevron" );
|
||||
ui.applyStyle( "sortIconColor: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -646,6 +783,17 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "disabledBackground: #fff" );
|
||||
ui.applyStyle( "inactiveBackground: #fff" );
|
||||
ui.applyStyle( "focusedBackground: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
|
||||
// JTextComponent properties
|
||||
ui.applyStyle( "caretColor: #fff" );
|
||||
ui.applyStyle( "selectionColor: #fff" );
|
||||
ui.applyStyle( "selectedTextColor: #fff" );
|
||||
ui.applyStyle( "disabledTextColor: #fff" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -665,6 +813,17 @@ public class TestFlatStyling
|
||||
|
||||
// border
|
||||
flatTextBorder( style -> ui.applyStyle( style ) );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
|
||||
// JTextComponent properties
|
||||
ui.applyStyle( "caretColor: #fff" );
|
||||
ui.applyStyle( "selectionColor: #fff" );
|
||||
ui.applyStyle( "selectedTextColor: #fff" );
|
||||
ui.applyStyle( "disabledTextColor: #fff" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -676,6 +835,17 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "disabledBackground: #fff" );
|
||||
ui.applyStyle( "inactiveBackground: #fff" );
|
||||
ui.applyStyle( "focusedBackground: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
|
||||
// JTextComponent properties
|
||||
ui.applyStyle( "caretColor: #fff" );
|
||||
ui.applyStyle( "selectionColor: #fff" );
|
||||
ui.applyStyle( "selectedTextColor: #fff" );
|
||||
ui.applyStyle( "disabledTextColor: #fff" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -703,6 +873,17 @@ public class TestFlatStyling
|
||||
|
||||
ui.applyStyle( "borderMargins: 1,2,3,4" );
|
||||
ui.applyStyle( "gripColor: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
|
||||
// JToolBar properties
|
||||
ui.applyStyle( "borderPainted: true" );
|
||||
ui.applyStyle( "floatable: true" );
|
||||
ui.applyStyle( "margin: 2,2,2,2" );
|
||||
ui.applyStyle( "rollover: true" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -734,6 +915,18 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "icon.leafColor: #fff" );
|
||||
ui.applyStyle( "icon.closedColor: #fff" );
|
||||
ui.applyStyle( "icon.openColor: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
ui.applyStyle( "border: 2,2,2,2,#f00" );
|
||||
|
||||
// JTree properties
|
||||
ui.applyStyle( "rootVisible: true" );
|
||||
ui.applyStyle( "rowHeight: 30" );
|
||||
ui.applyStyle( "scrollsOnExpand: true" );
|
||||
ui.applyStyle( "showsRootHandles: true" );
|
||||
ui.applyStyle( "visibleRowCount: 20" );
|
||||
}
|
||||
|
||||
//---- component borders --------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user