mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 23:37:13 -06:00
Theme Editor: Preview: support usage of variables in styles
This commit is contained in:
@@ -80,7 +80,7 @@ class UIDefaultsLoader
|
|||||||
private static final String OPTIONAL_PREFIX = "?";
|
private static final String OPTIONAL_PREFIX = "?";
|
||||||
private static final String WILDCARD_PREFIX = "*.";
|
private static final String WILDCARD_PREFIX = "*.";
|
||||||
|
|
||||||
private static final String KEY_VARIABLES = "FlatLaf.internal.variables";
|
static final String KEY_VARIABLES = "FlatLaf.internal.variables";
|
||||||
|
|
||||||
private static int parseColorDepth;
|
private static int parseColorDepth;
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import com.formdev.flatlaf.UIDefaultsLoader.ValueType;
|
|||||||
*/
|
*/
|
||||||
public class UIDefaultsLoaderAccessor
|
public class UIDefaultsLoaderAccessor
|
||||||
{
|
{
|
||||||
|
public static final String KEY_VARIABLES = UIDefaultsLoader.KEY_VARIABLES;
|
||||||
|
|
||||||
public static Object UNKNOWN = ValueType.UNKNOWN;
|
public static Object UNKNOWN = ValueType.UNKNOWN;
|
||||||
public static Object STRING = ValueType.STRING;
|
public static Object STRING = ValueType.STRING;
|
||||||
public static Object BOOLEAN = ValueType.BOOLEAN;
|
public static Object BOOLEAN = ValueType.BOOLEAN;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.formdev.flatlaf.themeeditor;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.HierarchyEvent;
|
import java.awt.event.HierarchyEvent;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
@@ -28,6 +29,7 @@ import javax.swing.UIDefaults.LazyValue;
|
|||||||
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
import com.formdev.flatlaf.FlatLaf;
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
|
import com.formdev.flatlaf.UIDefaultsLoaderAccessor;
|
||||||
import com.formdev.flatlaf.extras.components.*;
|
import com.formdev.flatlaf.extras.components.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,6 +53,7 @@ class FlatThemePreview
|
|||||||
private final Map<LazyValue, Object> lazyValueCache = new WeakHashMap<>();
|
private final Map<LazyValue, Object> lazyValueCache = new WeakHashMap<>();
|
||||||
private int runWithUIDefaultsGetterLevel;
|
private int runWithUIDefaultsGetterLevel;
|
||||||
private boolean inGetDefaultFont;
|
private boolean inGetDefaultFont;
|
||||||
|
private boolean inGetVariables;
|
||||||
|
|
||||||
FlatThemePreview( FlatSyntaxTextArea textArea ) {
|
FlatThemePreview( FlatSyntaxTextArea textArea ) {
|
||||||
this.textArea = textArea;
|
this.textArea = textArea;
|
||||||
@@ -162,6 +165,7 @@ class FlatThemePreview
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( "unchecked" )
|
||||||
Object getUIDefaultProperty( Object key ) {
|
Object getUIDefaultProperty( Object key ) {
|
||||||
// avoid StackOverflowError because "defaultFont" value is an active value
|
// avoid StackOverflowError because "defaultFont" value is an active value
|
||||||
// that itself uses UIManager.getFont( "defaultFont" ) to get base font
|
// that itself uses UIManager.getFont( "defaultFont" ) to get base font
|
||||||
@@ -176,6 +180,19 @@ class FlatThemePreview
|
|||||||
if( ((String)key).endsWith( "UI" ) )
|
if( ((String)key).endsWith( "UI" ) )
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
// handle access to variables map, which is used in styles
|
||||||
|
if( UIDefaultsLoaderAccessor.KEY_VARIABLES.equals( key ) ) {
|
||||||
|
if( inGetVariables )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
inGetVariables = true;
|
||||||
|
try {
|
||||||
|
return new VariablesDelegateMap( (Map<String, String>) UIManager.get( UIDefaultsLoaderAccessor.KEY_VARIABLES ) );
|
||||||
|
} finally {
|
||||||
|
inGetVariables = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Object value = textArea.propertiesSupport.getParsedProperty( (String) key );
|
Object value = textArea.propertiesSupport.getParsedProperty( (String) key );
|
||||||
|
|
||||||
boolean isDefaultFont = "defaultFont".equals( key );
|
boolean isDefaultFont = "defaultFont".equals( key );
|
||||||
@@ -341,4 +358,31 @@ class FlatThemePreview
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---- class VariablesDelegateMap -----------------------------------------
|
||||||
|
|
||||||
|
private class VariablesDelegateMap
|
||||||
|
extends HashMap<String, String>
|
||||||
|
{
|
||||||
|
private final Map<String, String> variables;
|
||||||
|
|
||||||
|
public VariablesDelegateMap( Map<String, String> variables ) {
|
||||||
|
this.variables = variables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get( Object key ) {
|
||||||
|
String value = textArea.propertiesSupport.getProperty( (String) key );
|
||||||
|
if( value != null )
|
||||||
|
return value;
|
||||||
|
|
||||||
|
if( variables != null ) {
|
||||||
|
value = variables.get( key );
|
||||||
|
if( value != null )
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.get( key );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ class FlatThemePropertiesSupport
|
|||||||
return getProperty( wildcardKey );
|
return getProperty( wildcardKey );
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getProperty( String key ) {
|
String getProperty( String key ) {
|
||||||
// look in current text area
|
// look in current text area
|
||||||
String value = getProperties().getProperty( key );
|
String value = getProperties().getProperty( key );
|
||||||
if( value != null )
|
if( value != null )
|
||||||
|
|||||||
@@ -117,3 +117,8 @@ Prop.6.selectionForeground = contrast($Prop.6.selectionBackground,#000,#fff)
|
|||||||
|
|
||||||
Prop.7.selectionBackground = #FF9500
|
Prop.7.selectionBackground = #FF9500
|
||||||
Prop.7.selectionForeground = contrast($Prop.7.selectionBackground,#000,#fff)
|
Prop.7.selectionForeground = contrast($Prop.7.selectionBackground,#000,#fff)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@varStyle1 = #f0f
|
||||||
|
[style].style1 = background: @varStyle1
|
||||||
|
|||||||
Reference in New Issue
Block a user