mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
Theme Editor: support resolving properties that use wildcards
This commit is contained in:
@@ -19,14 +19,17 @@ package com.formdev.flatlaf.themeeditor;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import javax.swing.UIDefaults;
|
||||||
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
|
import javax.swing.plaf.basic.BasicLookAndFeel;
|
||||||
import javax.swing.text.BadLocationException;
|
import javax.swing.text.BadLocationException;
|
||||||
import com.formdev.flatlaf.UIDefaultsLoaderAccessor;
|
import com.formdev.flatlaf.UIDefaultsLoaderAccessor;
|
||||||
|
|
||||||
@@ -52,11 +55,13 @@ class FlatThemePropertiesSupport
|
|||||||
private static long globalCacheInvalidationCounter;
|
private static long globalCacheInvalidationCounter;
|
||||||
private long cacheInvalidationCounter;
|
private long cacheInvalidationCounter;
|
||||||
|
|
||||||
|
private static Set<String> wildcardKeys;
|
||||||
|
|
||||||
FlatThemePropertiesSupport( FlatSyntaxTextArea textArea ) {
|
FlatThemePropertiesSupport( FlatSyntaxTextArea textArea ) {
|
||||||
this.textArea = textArea;
|
this.textArea = textArea;
|
||||||
|
|
||||||
propertiesGetter = key -> {
|
propertiesGetter = key -> {
|
||||||
return getProperty( key );
|
return getPropertyOrWildcard( key );
|
||||||
};
|
};
|
||||||
resolver = v -> {
|
resolver = v -> {
|
||||||
return resolveValue( v );
|
return resolveValue( v );
|
||||||
@@ -118,6 +123,22 @@ class FlatThemePropertiesSupport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getPropertyOrWildcard( String key ) {
|
||||||
|
String value = getProperty( key );
|
||||||
|
if( value != null )
|
||||||
|
return value;
|
||||||
|
|
||||||
|
if( !isKeyAllowedForWildcard( key ) )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
int lastDotIndex = key.lastIndexOf( '.' );
|
||||||
|
if( lastDotIndex < 0 )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
String wildcardKey = "*.".concat( key.substring( lastDotIndex + 1 ) );
|
||||||
|
return getProperty( wildcardKey );
|
||||||
|
}
|
||||||
|
|
||||||
private String getProperty( String key ) {
|
private String getProperty( String key ) {
|
||||||
// look in current text area
|
// look in current text area
|
||||||
String value = getProperties().getProperty( key );
|
String value = getProperties().getProperty( key );
|
||||||
@@ -190,6 +211,58 @@ class FlatThemePropertiesSupport
|
|||||||
allKeysCache = null;
|
allKeysCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isKeyAllowedForWildcard( String key ) {
|
||||||
|
loadKeysAllowedForWildcard();
|
||||||
|
return wildcardKeys.contains( key );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadKeysAllowedForWildcard() {
|
||||||
|
if( wildcardKeys != null )
|
||||||
|
return;
|
||||||
|
wildcardKeys = new HashSet<>();
|
||||||
|
|
||||||
|
UIDefaults basicDefaults = new BasicLookAndFeel() {
|
||||||
|
@Override public String getName() { return "Basic"; }
|
||||||
|
@Override public String getID() { return "Basic"; }
|
||||||
|
@Override public String getDescription() { return "Basic"; }
|
||||||
|
@Override public boolean isNativeLookAndFeel() { return false; }
|
||||||
|
@Override public boolean isSupportedLookAndFeel() { return true; }
|
||||||
|
}.getDefaults();
|
||||||
|
|
||||||
|
for( Object key : basicDefaults.keySet() ) {
|
||||||
|
if( key instanceof String )
|
||||||
|
wildcardKeys.add( (String) key );
|
||||||
|
}
|
||||||
|
|
||||||
|
// same as added in FlatLaf.getDefaults()
|
||||||
|
wildcardKeys.addAll( Arrays.asList(
|
||||||
|
"Button.disabledBackground",
|
||||||
|
"EditorPane.disabledBackground",
|
||||||
|
"EditorPane.inactiveBackground",
|
||||||
|
"FormattedTextField.disabledBackground",
|
||||||
|
"PasswordField.disabledBackground",
|
||||||
|
"Spinner.disabledBackground",
|
||||||
|
"TextArea.disabledBackground",
|
||||||
|
"TextArea.inactiveBackground",
|
||||||
|
"TextField.disabledBackground",
|
||||||
|
"TextPane.disabledBackground",
|
||||||
|
"TextPane.inactiveBackground",
|
||||||
|
"ToggleButton.disabledBackground",
|
||||||
|
|
||||||
|
"Button.disabledText",
|
||||||
|
"CheckBox.disabledText",
|
||||||
|
"CheckBoxMenuItem.disabledForeground",
|
||||||
|
"Menu.disabledForeground",
|
||||||
|
"MenuItem.disabledForeground",
|
||||||
|
"RadioButton.disabledText",
|
||||||
|
"RadioButtonMenuItem.disabledForeground",
|
||||||
|
"Spinner.disabledForeground",
|
||||||
|
"ToggleButton.disabledText",
|
||||||
|
|
||||||
|
"DesktopIcon.foreground"
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
|
||||||
//---- interface DocumentListener ----
|
//---- interface DocumentListener ----
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user