Styling: fixed resolving of UI variables in styles that use other variables

This commit is contained in:
Karl Tauber
2023-01-18 23:26:34 +01:00
parent e34b5eafe1
commit 32dce16363
3 changed files with 20 additions and 3 deletions

View File

@@ -334,7 +334,7 @@ class UIDefaultsLoader
if( newValue == null )
throw new IllegalArgumentException( "variable '" + value + "' not found" );
return newValue;
return resolveValueFromUIManager( newValue );
}
if( !value.startsWith( PROPERTY_PREFIX ) )

View File

@@ -29,6 +29,7 @@ import javax.swing.table.JTableHeader;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.icons.*;
import com.formdev.flatlaf.util.ColorFunctions;
@@ -39,12 +40,20 @@ public class TestFlatStyling
{
@BeforeAll
static void setup() {
HashMap<String, String> globalExtraDefaults = new HashMap<>();
globalExtraDefaults.put( "@var1", "#f00" );
globalExtraDefaults.put( "@var2", "@var1" );
globalExtraDefaults.put( "var2Resolved", "@var2" );
FlatLaf.setGlobalExtraDefaults( globalExtraDefaults );
TestUtils.setup( false );
}
@AfterAll
static void cleanup() {
TestUtils.cleanup();
FlatLaf.setGlobalExtraDefaults( null );
}
@Test
@@ -171,6 +180,13 @@ public class TestFlatStyling
"saturate(darken(@background,20%),10%)" );
}
@Test
void parseRecursiveVariables() {
Color background = UIManager.getColor( "var2Resolved" );
testColorStyle( background.getRGB(), "@var2" );
}
private void testColorStyle( int expectedRGB, String style ) {
testStyle( "background", new Color( expectedRGB, (expectedRGB & 0xff000000) != 0 ), style );
}