mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 23:37:13 -06:00
Styling: support platform and light/dark theme specific styling with key prefixes [win], [mac], [linux], [light] and [dark]
e.g. `mySlider.putClientProperty( "FlatLaf.style", "[light]trackColor: #00f; [dark]trackColor: #f00" );`
This commit is contained in:
@@ -33,6 +33,7 @@ import javax.swing.border.Border;
|
|||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
import com.formdev.flatlaf.FlatLaf;
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
import com.formdev.flatlaf.util.StringUtils;
|
import com.formdev.flatlaf.util.StringUtils;
|
||||||
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Support for styling components in CSS syntax.
|
* Support for styling components in CSS syntax.
|
||||||
@@ -109,6 +110,19 @@ public class FlatStyleSupport
|
|||||||
String key = e.getKey();
|
String key = e.getKey();
|
||||||
Object newValue = e.getValue();
|
Object newValue = e.getValue();
|
||||||
|
|
||||||
|
if( key.startsWith( "[" ) ) {
|
||||||
|
if( (SystemInfo.isWindows && key.startsWith( "[win]" )) ||
|
||||||
|
(SystemInfo.isMacOS && key.startsWith( "[mac]" )) ||
|
||||||
|
(SystemInfo.isLinux && key.startsWith( "[linux]" )) ||
|
||||||
|
(key.startsWith( "[light]" ) && !FlatLaf.isLafDark()) ||
|
||||||
|
(key.startsWith( "[dark]" ) && FlatLaf.isLafDark()) )
|
||||||
|
{
|
||||||
|
// prefix is known and enabled --> remove prefix
|
||||||
|
key = key.substring( key.indexOf( ']' ) + 1 );
|
||||||
|
} else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Object oldValue = applyProperty.apply( key, newValue );
|
Object oldValue = applyProperty.apply( key, newValue );
|
||||||
oldValues.put( key, oldValue );
|
oldValues.put( key, oldValue );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user