diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java index 485e53c5..e080fafa 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java @@ -19,8 +19,10 @@ package com.formdev.flatlaf.themeeditor; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; +import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.List; import javax.swing.JLayer; import javax.swing.JPanel; import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory; @@ -94,6 +96,10 @@ class FlatThemeEditorPane return font.deriveFont( (float) newFontSize ); } + void setBaseFiles( List baseFiles ) { + textArea.propertiesSupport.setBaseFiles( baseFiles ); + } + void load( FileLocation loc ) throws IOException { textArea.load( loc, StandardCharsets.ISO_8859_1 ); } diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java index 65609b82..fcb1a68d 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java @@ -16,10 +16,15 @@ package com.formdev.flatlaf.themeeditor; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Toolkit; import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import javax.swing.*; import org.fife.ui.rsyntaxtextarea.FileLocation; import com.formdev.flatlaf.FlatLightLaf; @@ -39,12 +44,17 @@ public class FlatThemeFileEditor ? args[0] : "theme-editor-test.properties" ); // TODO + List baseFiles = new ArrayList<>(); + for( int i = 1; i < args.length; i++ ) + baseFiles.add( new File( args[i] ) ); + SwingUtilities.invokeLater( () -> { FlatLightLaf.install(); FlatInspector.install( "ctrl alt shift X" ); FlatThemeFileEditor frame = new FlatThemeFileEditor(); + frame.themeEditorArea.setBaseFiles( baseFiles ); try { frame.themeEditorArea.load( FileLocation.create( file ) ); } catch( IOException ex ) { 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 0f215773..cb1d8db1 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 @@ -17,9 +17,12 @@ package com.formdev.flatlaf.themeeditor; import java.awt.Color; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.StringReader; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.function.Function; @@ -42,11 +45,15 @@ class FlatThemePropertiesSupport private Properties propertiesCache; private final Map parsedValueCache = new HashMap<>(); + private File[] baseFiles; + private long[] baseFilesLastModified; + private Properties[] basePropertiesCache; + FlatThemePropertiesSupport( FlatSyntaxTextArea textArea ) { this.textArea = textArea; propertiesGetter = key -> { - return getProperties().getProperty( key ); + return getProperty( key ); }; resolver = v -> { return resolveValue( v ); @@ -55,6 +62,14 @@ class FlatThemePropertiesSupport textArea.getDocument().addDocumentListener( this ); } + void setBaseFiles( List baseFiles ) { + int size = baseFiles.size(); + this.baseFiles = baseFiles.toArray( new File[size] ); + + baseFilesLastModified = new long[size]; + basePropertiesCache = new Properties[size]; + } + private String resolveValue( String value ) { return UIDefaultsLoaderAccessor.resolveValue( value, propertiesGetter ); } @@ -102,6 +117,37 @@ class FlatThemePropertiesSupport } } + private String getProperty( String key ) { + // look in current text area + String value = getProperties().getProperty( key ); + if( value != null ) + return value; + + if( baseFiles == null ) + return null; + + // look in base properties files + for( int i = 0; i < baseFiles.length; i++ ) { + long lastModified = baseFiles[i].lastModified(); + if( baseFilesLastModified[i] != lastModified ) { + // (re)load base properties file + baseFilesLastModified[i] = lastModified; + basePropertiesCache[i] = new Properties(); + try { + basePropertiesCache[i].load( new FileInputStream( baseFiles[i] ) ); + } catch( IOException ex ) { + ex.printStackTrace(); //TODO + } + } + + value = basePropertiesCache[i].getProperty( key ); + if( value != null ) + return value; + } + + return null; + } + private Properties getProperties() { if( propertiesCache != null ) return propertiesCache;