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:
Karl Tauber
2021-06-19 22:56:16 +02:00
parent 6affc70a66
commit 20027c2db7

View File

@@ -33,6 +33,7 @@ import javax.swing.border.Border;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.util.StringUtils;
import com.formdev.flatlaf.util.SystemInfo;
/**
* Support for styling components in CSS syntax.
@@ -109,6 +110,19 @@ public class FlatStyleSupport
String key = e.getKey();
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 );
oldValues.put( key, oldValue );
}