mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 06:20:53 +03:00
Theme Editor: preview improvements:
- fixed table header borders (runWithUIDefaultsGetter() in paint()) - cache lazy values - use runWithUIDefaultsGetter() in layout(), validateTree() and paint()
This commit is contained in:
@@ -20,6 +20,8 @@ package com.formdev.flatlaf.themeeditor;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.HierarchyEvent;
|
import java.awt.event.HierarchyEvent;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.UIDefaults.ActiveValue;
|
import javax.swing.UIDefaults.ActiveValue;
|
||||||
@@ -44,6 +46,9 @@ class FlatThemePreview
|
|||||||
private final FlatSyntaxTextArea textArea;
|
private final FlatSyntaxTextArea textArea;
|
||||||
private final Timer timer;
|
private final Timer timer;
|
||||||
|
|
||||||
|
private final Map<LazyValue, Object> lazyValueCache = new WeakHashMap<>();
|
||||||
|
private int runWithUIDefaultsGetterLevel;
|
||||||
|
|
||||||
FlatThemePreview( FlatSyntaxTextArea textArea ) {
|
FlatThemePreview( FlatSyntaxTextArea textArea ) {
|
||||||
this.textArea = textArea;
|
this.textArea = textArea;
|
||||||
|
|
||||||
@@ -100,7 +105,7 @@ class FlatThemePreview
|
|||||||
if( !isShowing() )
|
if( !isShowing() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FlatLaf.runWithUIDefaultsGetter( this::getUIDefaultProperty, this::updateComponentTreeUI );
|
runWithUIDefaultsGetter( this::updateComponentTreeUI );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateComponentTreeUI() {
|
private void updateComponentTreeUI() {
|
||||||
@@ -111,6 +116,18 @@ class FlatThemePreview
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void runWithUIDefaultsGetter( Runnable runnable ) {
|
||||||
|
try {
|
||||||
|
runWithUIDefaultsGetterLevel++;
|
||||||
|
if( runWithUIDefaultsGetterLevel == 1 )
|
||||||
|
FlatLaf.runWithUIDefaultsGetter( this::getUIDefaultProperty, runnable );
|
||||||
|
else
|
||||||
|
runnable.run();
|
||||||
|
} finally {
|
||||||
|
runWithUIDefaultsGetterLevel--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Object getUIDefaultProperty( Object key ) {
|
private Object getUIDefaultProperty( Object key ) {
|
||||||
if( !(key instanceof String) )
|
if( !(key instanceof String) )
|
||||||
return null;
|
return null;
|
||||||
@@ -121,9 +138,11 @@ class FlatThemePreview
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
Object value = textArea.propertiesSupport.getParsedProperty( (String) key );
|
Object value = textArea.propertiesSupport.getParsedProperty( (String) key );
|
||||||
if( value instanceof LazyValue )
|
if( value instanceof LazyValue ) {
|
||||||
value = ((LazyValue)value).createValue( null );
|
value = lazyValueCache.computeIfAbsent( (LazyValue) value, k -> {
|
||||||
else if( value instanceof ActiveValue )
|
return k.createValue( null );
|
||||||
|
} );
|
||||||
|
} else if( value instanceof ActiveValue )
|
||||||
value = ((ActiveValue)value).createValue( null );
|
value = ((ActiveValue)value).createValue( null );
|
||||||
|
|
||||||
// System.out.println( key + " = " + value );
|
// System.out.println( key + " = " + value );
|
||||||
@@ -134,7 +153,9 @@ class FlatThemePreview
|
|||||||
@Override
|
@Override
|
||||||
public void layout() {
|
public void layout() {
|
||||||
try {
|
try {
|
||||||
super.layout();
|
runWithUIDefaultsGetter( () -> {
|
||||||
|
super.layout();
|
||||||
|
} );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -143,7 +164,9 @@ class FlatThemePreview
|
|||||||
@Override
|
@Override
|
||||||
protected void validateTree() {
|
protected void validateTree() {
|
||||||
try {
|
try {
|
||||||
super.validateTree();
|
runWithUIDefaultsGetter( () -> {
|
||||||
|
super.validateTree();
|
||||||
|
} );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -182,7 +205,9 @@ class FlatThemePreview
|
|||||||
@Override
|
@Override
|
||||||
public void paint( Graphics g ) {
|
public void paint( Graphics g ) {
|
||||||
try {
|
try {
|
||||||
super.paint( g );
|
runWithUIDefaultsGetter( () -> {
|
||||||
|
super.paint( g );
|
||||||
|
} );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -191,7 +216,9 @@ class FlatThemePreview
|
|||||||
@Override
|
@Override
|
||||||
protected void paintComponent( Graphics g ) {
|
protected void paintComponent( Graphics g ) {
|
||||||
try {
|
try {
|
||||||
super.paintComponent( g );
|
runWithUIDefaultsGetter( () -> {
|
||||||
|
super.paintComponent( g );
|
||||||
|
} );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -200,14 +227,16 @@ class FlatThemePreview
|
|||||||
@Override
|
@Override
|
||||||
protected void paintChildren( Graphics g ) {
|
protected void paintChildren( Graphics g ) {
|
||||||
try {
|
try {
|
||||||
super.paintChildren( g );
|
runWithUIDefaultsGetter( () -> {
|
||||||
|
super.paintChildren( g );
|
||||||
|
} );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enabledChanged() {
|
private void enabledChanged() {
|
||||||
FlatLaf.runWithUIDefaultsGetter( this::getUIDefaultProperty, () -> {
|
runWithUIDefaultsGetter( () -> {
|
||||||
enableDisable( this, enabledCheckBox.isSelected() );
|
enableDisable( this, enabledCheckBox.isSelected() );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user