From 4f8b6d6b2809a128f1e27e7a9eef736f9b484e21 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Wed, 23 Dec 2020 11:14:26 +0100 Subject: [PATCH] UIDefaultsLoader: - changed "globals" to "wildcard replacements" - strict checking for background/foreground keys --- .../com/formdev/flatlaf/UIDefaultsLoader.java | 29 ++++++++++--------- .../com/formdev/flatlaf/FlatLaf.properties | 2 +- .../flatlaf/testing/FlatTestLaf.properties | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java index 6a009b73..3bbf239a 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java @@ -70,7 +70,7 @@ class UIDefaultsLoader private static final String VARIABLE_PREFIX = "@"; private static final String PROPERTY_PREFIX = "$"; private static final String OPTIONAL_PREFIX = "?"; - private static final String GLOBAL_PREFIX = "*."; + private static final String WILDCARD_PREFIX = "*."; static void loadDefaultsFromProperties( Class lookAndFeelClass, List addons, Properties additionalDefaults, boolean dark, UIDefaults defaults ) @@ -198,19 +198,19 @@ class UIDefaultsLoader } } - // get (and remove) globals, which override all other defaults that end with same suffix - HashMap globals = new HashMap<>(); + // get (and remove) wildcard replacements, which override all other defaults that end with same suffix + HashMap wildcards = new HashMap<>(); Iterator> it = properties.entrySet().iterator(); while( it.hasNext() ) { Entry e = it.next(); String key = (String) e.getKey(); - if( key.startsWith( GLOBAL_PREFIX ) ) { - globals.put( key.substring( GLOBAL_PREFIX.length() ), (String) e.getValue() ); + if( key.startsWith( WILDCARD_PREFIX ) ) { + wildcards.put( key.substring( WILDCARD_PREFIX.length() ), (String) e.getValue() ); it.remove(); } } - // override UI defaults with globals + // override UI defaults with wildcard replacements for( Object key : defaults.keySet() ) { int dot; if( !(key instanceof String) || @@ -218,10 +218,10 @@ class UIDefaultsLoader (dot = ((String)key).lastIndexOf( '.' )) < 0 ) continue; - String globalKey = ((String)key).substring( dot + 1 ); - String globalValue = globals.get( globalKey ); - if( globalValue != null ) - properties.put( key, globalValue ); + String wildcardKey = ((String)key).substring( dot + 1 ); + String wildcardValue = wildcards.get( wildcardKey ); + if( wildcardValue != null ) + properties.put( key, wildcardValue ); } Function propertiesGetter = key -> { @@ -341,7 +341,12 @@ class UIDefaultsLoader // determine value type from key if( valueType == ValueType.UNKNOWN ) { - if( key.endsWith( "ground" ) || key.endsWith( "Color" ) ) + if( key.endsWith( "UI" ) ) + valueType = ValueType.STRING; + else if( key.endsWith( "Color" ) || + (key.endsWith( "ground" ) && + (key.endsWith( ".background" ) || key.endsWith( "Background" ) || + key.endsWith( ".foreground" ) || key.endsWith( "Foreground" ))) ) valueType = ValueType.COLOR; else if( key.endsWith( ".border" ) || key.endsWith( "Border" ) ) valueType = ValueType.BORDER; @@ -356,8 +361,6 @@ class UIDefaultsLoader valueType = ValueType.INTEGER; else if( key.endsWith( "Char" ) ) valueType = ValueType.CHARACTER; - else if( key.endsWith( "UI" ) ) - valueType = ValueType.STRING; else if( key.endsWith( "grayFilter" ) ) valueType = ValueType.GRAYFILTER; } diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties index e052def2..f0076a87 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -67,7 +67,7 @@ ViewportUI = com.formdev.flatlaf.ui.FlatViewportUI @menuItemMargin = 3,6,3,6 -#---- globals ---- +#---- wildcard replacements ---- *.background = @background *.foreground = @foreground diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/FlatTestLaf.properties b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/FlatTestLaf.properties index 497605fa..cf0c38a8 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/FlatTestLaf.properties +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/FlatTestLaf.properties @@ -38,7 +38,7 @@ @dropLineShortColor = #ff0 -#---- globals ---- +#---- wildcard replacements ---- *.caretForeground = #00f *.inactiveBackground = #f0f0f0