Theme Editor: fixed preview of focused button in FlatDarkLaf (and probably other null value related issues)

This commit is contained in:
Karl Tauber
2021-08-27 18:03:39 +02:00
parent ebd5905947
commit cd20f4086b
3 changed files with 76 additions and 4 deletions

View File

@@ -161,6 +161,17 @@ class FlatThemePreview
value = ((ActiveValue)value).createValue( null );
// System.out.println( key + " = " + value );
// If value is null and is a property that is defined in a core theme,
// then force the value to null.
// This is necessary for cases where the current application Laf defines a property
// but the edited theme does not (or has set the value explicitly to null).
// E.g. FlatLightLaf defines Button.focusedBackground, but in FlatDarkLaf
// it is not defined. Without this code, the preview for FlatDarkLaf would use
// Button.focusedBackground from FlatLightLaf if FlatLightLaf is the current application Laf.
if( value == null && FlatThemePropertiesBaseManager.getDefindedCoreKeys().contains( key ) )
return FlatLaf.NULL_VALUE;
return value;
}

View File

@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -47,7 +48,8 @@ class FlatThemePropertiesBaseManager
};
private final Map<String, MyBasePropertyProvider> providers = new HashMap<>();
private Map<String, Properties> coreThemes;
private static Map<String, Properties> coreThemes;
private static Set<String> definedCoreKeys;
FlatThemePropertiesSupport.BasePropertyProvider create( File file, FlatThemePropertiesSupport propertiesSupport ) {
String name = StringUtils.removeTrailing( file.getName(), ".properties" );
@@ -61,7 +63,31 @@ class FlatThemePropertiesBaseManager
providers.clear();
}
private void loadCoreThemes() {
static Set<String> getDefindedCoreKeys() {
if( definedCoreKeys != null )
return definedCoreKeys;
loadCoreThemes();
definedCoreKeys = new HashSet<>();
for( Properties properties : coreThemes.values() ) {
for( Object k : properties.keySet() ) {
String key = (String) k;
if( key.startsWith( "*." ) || key.startsWith( "@" ) )
continue;
if( key.startsWith( "[" ) ) {
int closeIndex = key.indexOf( ']' );
if( closeIndex < 0 )
continue;
key = key.substring( closeIndex + 1 );
}
definedCoreKeys.add( key );
}
}
return definedCoreKeys;
}
private static void loadCoreThemes() {
if( coreThemes != null )
return;