From 16977351629337a5eb029e47561d2b7d4934b26a Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sat, 12 Sep 2020 18:13:34 +0200 Subject: [PATCH] UIDefaultsLoader: changed processing of "globals" so that they are first added to the `properties` table (instead of directly modifying `defaults` table), which is then parsed and copied to `defaults` table this has the advantage that they can be referenced in other values, which did not work before (because they only existed in `defaults` table) used for Tree.textForeground verified with UIDefaultsDump that there are no side effects --- .../com/formdev/flatlaf/UIDefaultsLoader.java | 40 +++++++++---------- .../formdev/flatlaf/FlatDarkLaf.properties | 2 - .../com/formdev/flatlaf/FlatLaf.properties | 1 + .../formdev/flatlaf/FlatLightLaf.properties | 2 - 4 files changed, 20 insertions(+), 25 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 8b47e1d0..503cf669 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java @@ -26,9 +26,11 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.function.Function; import java.util.logging.Level; @@ -203,37 +205,33 @@ class UIDefaultsLoader return resolveValue( value, propertiesGetter ); }; - // get globals, which override all other defaults that end with same suffix - HashMap globals = new HashMap<>(); - for( Map.Entry e : properties.entrySet() ) { + // get (and remove) globals, which override all other defaults that end with same suffix + HashMap globals = new HashMap<>(); + Iterator> it = properties.entrySet().iterator(); + while( it.hasNext() ) { + Entry e = it.next(); String key = (String) e.getKey(); - if( !key.startsWith( GLOBAL_PREFIX ) ) - continue; - - String value = resolveValue( (String) e.getValue(), propertiesGetter ); - try { - globals.put( key.substring( GLOBAL_PREFIX.length() ), - parseValue( key, value, null, resolver, addonClassLoaders ) ); - } catch( RuntimeException ex ) { - logParseError( Level.SEVERE, key, value, ex ); + if( key.startsWith( GLOBAL_PREFIX ) ) { + globals.put( key.substring( GLOBAL_PREFIX.length() ), (String) e.getValue() ); + it.remove(); } } // override UI defaults with globals - for( Object key : defaults.keySet() ) { - if( key instanceof String && ((String)key).contains( "." ) ) { - String skey = (String) key; - String globalKey = skey.substring( skey.lastIndexOf( '.' ) + 1 ); - Object globalValue = globals.get( globalKey ); - if( globalValue != null ) - defaults.put( key, globalValue ); + for( Object okey : defaults.keySet() ) { + if( okey instanceof String && ((String)okey).contains( "." ) ) { + String key = (String) okey; + String globalKey = key.substring( key.lastIndexOf( '.' ) + 1 ); + String globalValue = globals.get( globalKey ); + if( globalValue != null && !properties.containsKey( key ) ) + properties.put( key, globalValue ); } } - // add non-global properties to UI defaults + // parse and add properties to UI defaults for( Map.Entry e : properties.entrySet() ) { String key = (String) e.getKey(); - if( key.startsWith( VARIABLE_PREFIX ) || key.startsWith( GLOBAL_PREFIX ) ) + if( key.startsWith( VARIABLE_PREFIX ) ) continue; String value = resolveValue( (String) e.getValue(), propertiesGetter ); diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties index 53fdf717..b62d2437 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties @@ -46,8 +46,6 @@ *.background=@background *.foreground=@foreground -*.textBackground=@background -*.textForeground=@foreground *.caretForeground=@foreground *.inactiveBackground=@background *.inactiveForeground=@foreground 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 25525fbb..c3907dd4 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -671,6 +671,7 @@ Tree.editorBorder=1,1,1,1,@cellFocusColor Tree.selectionInactiveBackground=@selectionInactiveBackground Tree.selectionInactiveForeground=@selectionInactiveForeground Tree.textBackground=$Tree.background +Tree.textForeground=$Tree.foreground Tree.selectionBorderColor=@cellFocusColor Tree.dropCellBackground=@dropCellBackground Tree.dropCellForeground=@dropCellForeground diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties index 7b78a377..a5ff2639 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties @@ -46,8 +46,6 @@ *.background=@background *.foreground=@foreground -*.textBackground=#ccc -*.textForeground=@foreground *.caretForeground=@foreground *.inactiveBackground=@background *.inactiveForeground=@disabledText