diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorOverlay.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorOverlay.java index 9e0d6749..e769a37c 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorOverlay.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorOverlay.java @@ -24,9 +24,11 @@ import java.awt.Point; import java.awt.Rectangle; import javax.swing.JComponent; import javax.swing.JLayer; +import javax.swing.UIDefaults.LazyValue; import javax.swing.plaf.LayerUI; import javax.swing.text.BadLocationException; import org.fife.ui.rsyntaxtextarea.Token; +import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.UIDefaultsLoaderAccessor; import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.util.HSLColor; @@ -157,6 +159,20 @@ class FlatThemeEditorOverlay private Color getColorInLine( FlatSyntaxTextArea textArea, int line ) { Object value = textArea.propertiesSupport.getParsedValueAtLine( line ); + + // resolve lazy value + if( value instanceof LazyValue ) { + Object[] pValue = new Object[] { value }; + FlatLaf.runWithUIDefaultsGetter( key -> { + return (key instanceof String) + ? textArea.propertiesSupport.getParsedProperty( (String) key ) + : null; + }, () -> { + pValue[0] = ((LazyValue)pValue[0]).createValue( null ); + } ); + value = pValue[0]; + } + if( value instanceof Color ) return (Color) value; diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesBaseManager.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesBaseManager.java index 72d7a839..d3152cdd 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesBaseManager.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesBaseManager.java @@ -29,6 +29,7 @@ import java.util.Properties; import java.util.Set; import com.formdev.flatlaf.FlatDarculaLaf; import com.formdev.flatlaf.FlatDarkLaf; +import com.formdev.flatlaf.FlatIconColors; import com.formdev.flatlaf.FlatIntelliJLaf; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLightLaf; @@ -111,10 +112,6 @@ class FlatThemePropertiesBaseManager // core themes switch( name ) { - case "FlatLaf": - result.add( "FlatLightLaf" ); - break; - case "FlatLightLaf": case "FlatDarkLaf": result.add( "FlatLaf" ); @@ -160,6 +157,10 @@ class FlatThemePropertiesBaseManager result.add( "FlatLaf" ); break; } + + // exclude base properties if editing base properties + if( name.equals( "FlatLaf" ) ) + result.remove( "FlatLaf" ); } return result; @@ -173,6 +174,7 @@ class FlatThemePropertiesBaseManager private final String name; private final FlatThemePropertiesSupport propertiesSupport; private final boolean isCoreTheme; + private final String coreBaseTheme; private List baseFiles; private String lastBaseTheme; @@ -181,10 +183,22 @@ class FlatThemePropertiesBaseManager this.name = name; this.propertiesSupport = propertiesSupport; this.isCoreTheme = isCoreTheme; + + switch( name ) { + case "FlatLightLaf": coreBaseTheme = "light"; break; + case "FlatDarkLaf": coreBaseTheme = "dark"; break; + case "FlatIntelliJLaf": coreBaseTheme = "intellij"; break; + case "FlatDarculaLaf": coreBaseTheme = "darcula"; break; + default: coreBaseTheme = null; break; + } } @Override public String getProperty( String key, String baseTheme ) { + // override base theme for core themes + if( coreBaseTheme != null ) + baseTheme = coreBaseTheme; + updateBaseFiles( baseTheme ); // search in opened editors @@ -209,6 +223,15 @@ class FlatThemePropertiesBaseManager } } + // search in icon colors + if( key.startsWith( "Actions." ) || key.startsWith( "Objects." ) ) { + boolean dark = FlatThemePropertiesSupport.isDark( baseTheme ); + for( FlatIconColors c : FlatIconColors.values() ) { + if( c.key.equals( key ) && (c.light == !dark || c.dark == dark) ) + return String.format( "#%06x", c.rgb ); + } + } + return null; } @@ -236,6 +259,10 @@ class FlatThemePropertiesBaseManager @Override public void addAllKeys( Set allKeys, String baseTheme ) { + // override base theme for core themes + if( coreBaseTheme != null ) + baseTheme = coreBaseTheme; + updateBaseFiles( baseTheme ); // search in opened editors @@ -257,6 +284,10 @@ class FlatThemePropertiesBaseManager for( String baseFile : baseFiles ) copyKeys( coreThemes.get( baseFile ), allKeys ); } + + // icon colors + for( FlatIconColors c : FlatIconColors.values() ) + allKeys.add( c.key ); } private void copyKeys( Properties properties, Set allKeys ) { diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesSupport.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesSupport.java index 61cff44c..ba669e66 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesSupport.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesSupport.java @@ -207,6 +207,10 @@ class FlatThemePropertiesSupport return allKeysCache; } + static boolean isDark( String baseTheme ) { + return "dark".equals( baseTheme ) || "darcula".equals( baseTheme ); + } + private String getBaseTheme() { if( baseTheme == null ) baseTheme = getProperties().getProperty( "@baseTheme", "light" );