diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java index 4770aeec..b64b578c 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java @@ -45,6 +45,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.function.Function; import javax.swing.Icon; @@ -431,7 +432,7 @@ class UIDefaultsLoader enum ValueType { UNKNOWN, STRING, BOOLEAN, CHARACTER, INTEGER, INTEGERORFLOAT, FLOAT, BORDER, ICON, INSETS, DIMENSION, COLOR, FONT, SCALEDINTEGER, SCALEDFLOAT, SCALEDINSETS, SCALEDDIMENSION, INSTANCE, CLASS, GRAYFILTER, NULL, LAZY } - private static final ValueType[] tempResultValueType = new ValueType[1]; + private static final AtomicReference tempResultValueType = new AtomicReference<>(); private static Map, ValueType> javaValueTypes; private static Map knownValueTypes; @@ -441,7 +442,7 @@ class UIDefaultsLoader return parseValue( key, value, valueType, null, v -> v, Collections.emptyList() ); } - static Object parseValue( String key, String value, Class javaValueType, ValueType[] resultValueType, + static Object parseValue( String key, String value, Class javaValueType, AtomicReference resultValueType, Function resolver, List addonClassLoaders ) throws IllegalArgumentException { @@ -450,7 +451,7 @@ class UIDefaultsLoader // do not parse styles here if( key.startsWith( "[style]" ) ) { - resultValueType[0] = ValueType.STRING; + resultValueType.set( ValueType.STRING ); return value; } @@ -458,7 +459,7 @@ class UIDefaultsLoader // null if( value.equals( "null" ) || value.isEmpty() ) { - resultValueType[0] = ValueType.NULL; + resultValueType.set( ValueType.NULL ); return null; } @@ -514,14 +515,14 @@ class UIDefaultsLoader } else { // false, true switch( value ) { - case "false": resultValueType[0] = ValueType.BOOLEAN; return false; - case "true": resultValueType[0] = ValueType.BOOLEAN; return true; + case "false": resultValueType.set( ValueType.BOOLEAN ); return false; + case "true": resultValueType.set( ValueType.BOOLEAN ); return true; } // check for function "lazy" // Syntax: lazy(uiKey) if( value.startsWith( "lazy(" ) && value.endsWith( ")" ) ) { - resultValueType[0] = ValueType.LAZY; + resultValueType.set( ValueType.LAZY ); String uiKey = StringUtils.substringTrimmed( value, 5, value.length() - 1 ); return (LazyValue) t -> { return lazyUIManagerGet( uiKey ); @@ -602,7 +603,7 @@ class UIDefaultsLoader } } - resultValueType[0] = valueType; + resultValueType.set( valueType ); // parse value switch( valueType ) { @@ -629,14 +630,14 @@ class UIDefaultsLoader default: // string if( value.startsWith( "\"" ) && value.endsWith( "\"" ) ) { - resultValueType[0] = ValueType.STRING; + resultValueType.set( ValueType.STRING ); return value.substring( 1, value.length() - 1 ); } // colors if( value.startsWith( "#" ) || value.endsWith( ")" ) ) { Object color = parseColorOrFunction( value, resolver ); - resultValueType[0] = (color != null) ? ValueType.COLOR : ValueType.NULL; + resultValueType.set( (color != null) ? ValueType.COLOR : ValueType.NULL ); return color; } @@ -648,7 +649,7 @@ class UIDefaultsLoader // integer try { Integer integer = parseInteger( value ); - resultValueType[0] = ValueType.INTEGER; + resultValueType.set( ValueType.INTEGER ); return integer; } catch( NumberFormatException ex ) { // ignore @@ -657,7 +658,7 @@ class UIDefaultsLoader // float try { Float f = parseFloat( value ); - resultValueType[0] = ValueType.FLOAT; + resultValueType.set( ValueType.FLOAT ); return f; } catch( NumberFormatException ex ) { // ignore @@ -665,7 +666,7 @@ class UIDefaultsLoader } // string - resultValueType[0] = ValueType.STRING; + resultValueType.set( ValueType.STRING ); return value; } } diff --git a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatUIDefaultsInspector.java b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatUIDefaultsInspector.java index 4a7b0081..3204caaf 100644 --- a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatUIDefaultsInspector.java +++ b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatUIDefaultsInspector.java @@ -30,6 +30,7 @@ import java.util.HashSet; import java.util.Locale; import java.util.Properties; import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicReference; import java.util.Set; import java.util.function.Predicate; import java.util.prefs.Preferences; @@ -310,7 +311,7 @@ public class FlatUIDefaultsInspector Set> defaultsSet = defaults.entrySet(); ArrayList items = new ArrayList<>( defaultsSet.size() ); HashSet keys = new HashSet<>( defaultsSet.size() ); - Color[] pBaseColor = new Color[1]; + AtomicReference pBaseColor = new AtomicReference<>(); for( Entry e : defaultsSet ) { Object key = e.getKey(); @@ -336,7 +337,7 @@ public class FlatUIDefaultsInspector if( value instanceof DerivedColor ) { Color resolvedColor = resolveDerivedColor( defaults, (String) key, (DerivedColor) value, pBaseColor ); if( resolvedColor != value ) - info = new Color[] { resolvedColor, pBaseColor[0] }; + info = new Color[] { resolvedColor, pBaseColor.get() }; } // check whether key was overridden using UIManager.put(key,value) @@ -351,9 +352,9 @@ public class FlatUIDefaultsInspector return items.toArray( new Item[items.size()] ); } - private Color resolveDerivedColor( UIDefaults defaults, String key, Color color, Color[] pBaseColor ) { + private Color resolveDerivedColor( UIDefaults defaults, String key, Color color, AtomicReference pBaseColor ) { if( pBaseColor != null ) - pBaseColor[0] = null; + pBaseColor.set( null ); if( !(color instanceof DerivedColor) ) return color; @@ -377,7 +378,7 @@ public class FlatUIDefaultsInspector baseColor = resolveDerivedColor( defaults, (String) baseKey, baseColor, null ); if( pBaseColor != null ) - pBaseColor[0] = baseColor; + pBaseColor.set( baseColor ); Color newColor = FlatUIUtils.deriveColor( color, baseColor ); diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowMaximizeTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowMaximizeTest.java index 74402902..bd57bae5 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowMaximizeTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowMaximizeTest.java @@ -23,6 +23,7 @@ import java.awt.event.ComponentListener; import java.awt.event.KeyEvent; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import javax.swing.JButton; import javax.swing.JComponent; @@ -143,7 +144,7 @@ public class FlatWindowMaximizeTest } private static void testMaximize( String msg, int expectedState, boolean showLater, Consumer testFunc ) { - JFrame[] pFrame = new JFrame[1]; + AtomicReference pFrame = new AtomicReference<>(); EventQueue.invokeLater( () -> { JFrame frame = new JFrame( "test" ); frame.setName( msg ); @@ -164,7 +165,7 @@ public class FlatWindowMaximizeTest testFunc.accept( frame ); if( !showLater ) frame.setVisible( true ); - pFrame[0] = frame; + pFrame.set( frame ); } ); try { @@ -172,14 +173,14 @@ public class FlatWindowMaximizeTest Thread.sleep( 500 ); EventQueue.invokeLater( () -> { - pFrame[0].setVisible( true ); + pFrame.get().setVisible( true ); } ); } Thread.sleep( 500 ); EventQueue.invokeAndWait( () -> { - int state = pFrame[0].getExtendedState(); + int state = pFrame.get().getExtendedState(); System.out.printf( " %-15s: %d %s\n", msg, state, (state != expectedState ? " FAILED" : "") ); } ); } catch( Exception ex ) { diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/uidefaults/UIDefaultsDump.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/uidefaults/UIDefaultsDump.java index 71bbd22d..3a376db5 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/uidefaults/UIDefaultsDump.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/uidefaults/UIDefaultsDump.java @@ -645,14 +645,14 @@ public class UIDefaultsDump } private void dumpColor( PrintWriter out, String key, Color color ) { - Color[] retBaseColor = new Color[1]; + AtomicReference retBaseColor = new AtomicReference<>(); Color resolvedColor = resolveDerivedColor( key, color, retBaseColor ); if( resolvedColor != color && resolvedColor.getRGB() != color.getRGB() ) { if( !isIntelliJTheme ) { System.err.println( "Key '" + key + "': derived colors not equal" ); System.err.println( " Default color: " + dumpColorHexAndHSL( color ) ); System.err.println( " Resolved color: " + dumpColorHexAndHSL( resolvedColor ) ); - System.err.println( " Base color: " + dumpColorHexAndHSL( retBaseColor[0] ) ); + System.err.println( " Base color: " + dumpColorHexAndHSL( retBaseColor.get() ) ); } out.printf( "%s / ", @@ -891,7 +891,7 @@ public class UIDefaultsDump return properties; } - private Color resolveDerivedColor( String key, Color color, Color[] retBaseColor ) { + private Color resolveDerivedColor( String key, Color color, AtomicReference retBaseColor ) { if( !(color instanceof DerivedColor) ) return color; @@ -914,7 +914,7 @@ public class UIDefaultsDump if( baseColor instanceof DerivedColor ) baseColor = resolveDerivedColor( (String) baseKey, baseColor, retBaseColor ); - retBaseColor[0] = baseColor; + retBaseColor.set( baseColor ); Color newColor = FlatUIUtils.deriveColor( color, baseColor ); diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/UIDefaultsLoaderAccessor.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/UIDefaultsLoaderAccessor.java index 209b99c5..7f6351a7 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/UIDefaultsLoaderAccessor.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/UIDefaultsLoaderAccessor.java @@ -18,6 +18,7 @@ package com.formdev.flatlaf; import java.util.Collections; import java.util.Properties; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import com.formdev.flatlaf.UIDefaultsLoader.ValueType; @@ -57,14 +58,14 @@ public class UIDefaultsLoaderAccessor return UIDefaultsLoader.resolveValue( value, propertiesGetter ); } - public static Object parseValue( String key, String value, Object[] resultValueType, + public static Object parseValue( String key, String value, AtomicReference resultValueType, Function resolver ) throws IllegalArgumentException { - ValueType[] resultValueType2 = new ValueType[1]; + AtomicReference resultValueType2 = new AtomicReference<>(); Object result = UIDefaultsLoader.parseValue( key, value, null, resultValueType2, resolver, Collections.emptyList() ); - resultValueType[0] = resultValueType2[0]; + resultValueType.set( resultValueType2.get() ); return result; } diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesSupport.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesSupport.java index 0ce5345b..4a56736d 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesSupport.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePropertiesSupport.java @@ -26,6 +26,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import javax.swing.UIDefaults; import javax.swing.event.DocumentEvent; @@ -96,7 +97,7 @@ class FlatThemePropertiesSupport return null; try { - Object[] resultValueType = new Object[1]; + AtomicReference resultValueType = new AtomicReference<>(); String value = resolveValue( keyValue.value ); parsedValue = UIDefaultsLoaderAccessor.parseValue( keyValue.key, value, resultValueType, resolver ); parsedValueCache.put( lineKey, parsedValue ); @@ -156,7 +157,7 @@ class FlatThemePropertiesSupport return null; try { - Object[] resultValueType = new Object[1]; + AtomicReference resultValueType = new AtomicReference<>(); String value = resolveValue( str ); parsedValue = UIDefaultsLoaderAccessor.parseValue( key, value, resultValueType, resolver ); parsedValueCache2.put( key, parsedValue );