mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 15:27:16 -06:00
use "variables" in .properties files
This commit is contained in:
@@ -40,6 +40,9 @@ import com.formdev.flatlaf.util.SystemInfo;
|
|||||||
public abstract class FlatLaf
|
public abstract class FlatLaf
|
||||||
extends BasicLookAndFeel
|
extends BasicLookAndFeel
|
||||||
{
|
{
|
||||||
|
private static final String VARIABLE_PREFIX = "@";
|
||||||
|
private static final String GLOBAL_PREFIX = "*.";
|
||||||
|
|
||||||
private BasicLookAndFeel base;
|
private BasicLookAndFeel base;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -143,14 +146,14 @@ public abstract class FlatLaf
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get globals, which override all other defaults that end with same suffix
|
// get globals, which override all other defaults that end with same suffix
|
||||||
String globalPrefix = "*.";
|
|
||||||
HashMap<String, Object> globals = new HashMap<>();
|
HashMap<String, Object> globals = new HashMap<>();
|
||||||
for( Object okey : properties.keySet() ) {
|
for( Map.Entry<Object, Object> e : properties.entrySet() ) {
|
||||||
String key = (String) okey;
|
String key = (String) e.getKey();
|
||||||
if( key.startsWith( globalPrefix ) ) {
|
if( !key.startsWith( GLOBAL_PREFIX ) )
|
||||||
Object value = parseValue( key, properties.getProperty( key ) );
|
continue;
|
||||||
globals.put( key.substring( globalPrefix.length() ), value );
|
|
||||||
}
|
String value = resolveVariable( properties, (String) e.getValue() );
|
||||||
|
globals.put( key.substring( GLOBAL_PREFIX.length() ), parseValue( key, value ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// override UI defaults with globals
|
// override UI defaults with globals
|
||||||
@@ -167,7 +170,10 @@ public abstract class FlatLaf
|
|||||||
// add non-global properties to UI defaults
|
// add non-global properties to UI defaults
|
||||||
for( Map.Entry<Object, Object> e : properties.entrySet() ) {
|
for( Map.Entry<Object, Object> e : properties.entrySet() ) {
|
||||||
String key = (String) e.getKey();
|
String key = (String) e.getKey();
|
||||||
String value = (String) e.getValue();
|
if( key.startsWith( VARIABLE_PREFIX ) || key.startsWith( GLOBAL_PREFIX ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String value = resolveVariable( properties, (String) e.getValue() );
|
||||||
defaults.put( key, parseValue( key, value ) );
|
defaults.put( key, parseValue( key, value ) );
|
||||||
}
|
}
|
||||||
} catch( IOException ex ) {
|
} catch( IOException ex ) {
|
||||||
@@ -175,6 +181,17 @@ public abstract class FlatLaf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String resolveVariable( Properties properties, String value ) {
|
||||||
|
if( !value.startsWith( VARIABLE_PREFIX ) )
|
||||||
|
return value;
|
||||||
|
|
||||||
|
String newValue = properties.getProperty( value );
|
||||||
|
if( newValue == null )
|
||||||
|
System.err.println( "variable '" + value + "' not found" );
|
||||||
|
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
|
||||||
private Object parseValue( String key, String value ) {
|
private Object parseValue( String key, String value ) {
|
||||||
value = value.trim();
|
value = value.trim();
|
||||||
|
|
||||||
|
|||||||
@@ -14,27 +14,32 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
#---- variables ----
|
||||||
|
|
||||||
|
@background=3c3f41
|
||||||
|
@foreground=bbbbbb
|
||||||
|
|
||||||
#---- globals ----
|
#---- globals ----
|
||||||
|
|
||||||
*.background=3c3f41
|
*.background=@background
|
||||||
*.foreground=bbbbbb
|
*.foreground=@foreground
|
||||||
*.textBackground=3c3f41
|
*.textBackground=@background
|
||||||
*.textForeground=bbbbbb
|
*.textForeground=@foreground
|
||||||
*.caretForeground=bbbbbb
|
*.caretForeground=@foreground
|
||||||
*.inactiveBackground=3C3F41
|
*.inactiveBackground=@background
|
||||||
*.inactiveForeground=bbbbbb
|
*.inactiveForeground=@foreground
|
||||||
*.selectionBackground=4B6EAF
|
*.selectionBackground=4B6EAF
|
||||||
*.selectionForeground=bbbbbb
|
*.selectionForeground=@foreground
|
||||||
|
|
||||||
|
|
||||||
#---- system ----
|
#---- system ----
|
||||||
|
|
||||||
control=3c3f41
|
control=@background
|
||||||
controlText=bbbbbb
|
controlText=@foreground
|
||||||
infoText=bbbbbb
|
infoText=@foreground
|
||||||
text=bbbbbb
|
text=@foreground
|
||||||
textText=bbbbbb
|
textText=@foreground
|
||||||
window=3c3f41
|
window=@background
|
||||||
|
|
||||||
|
|
||||||
#---- Label ----
|
#---- Label ----
|
||||||
|
|||||||
@@ -14,13 +14,18 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
#---- variables ----
|
||||||
|
|
||||||
|
@background=f2f2f2
|
||||||
|
@foreground=000000
|
||||||
|
|
||||||
#---- globals ----
|
#---- globals ----
|
||||||
|
|
||||||
*.background=f2f2f2
|
*.background=@background
|
||||||
*.foreground=000000
|
*.foreground=@foreground
|
||||||
*.textBackground=cccccc
|
*.textBackground=cccccc
|
||||||
*.textForeground=000000
|
*.textForeground=@foreground
|
||||||
*.caretForeground=000000
|
*.caretForeground=@foreground
|
||||||
*.inactiveBackground=ffffff
|
*.inactiveBackground=ffffff
|
||||||
*.inactiveForeground=777777
|
*.inactiveForeground=777777
|
||||||
*.selectionBackground=4A6EB7
|
*.selectionBackground=4A6EB7
|
||||||
@@ -30,11 +35,11 @@
|
|||||||
#---- system ----
|
#---- system ----
|
||||||
|
|
||||||
control=e0e0e0
|
control=e0e0e0
|
||||||
controlText=000000
|
controlText=@foreground
|
||||||
infoText=000000
|
infoText=@foreground
|
||||||
text=000000
|
text=@foreground
|
||||||
textText=000000
|
textText=@foreground
|
||||||
window=f2f2f2
|
window=@background
|
||||||
|
|
||||||
|
|
||||||
#---- Label ----
|
#---- Label ----
|
||||||
|
|||||||
Reference in New Issue
Block a user