UIDefaultsLoader: reduced need for {float} in properties files and in CSS styles

This commit is contained in:
Karl Tauber
2021-10-29 13:33:55 +02:00
parent 5e03eb9b51
commit fb4fe175d9
10 changed files with 35 additions and 20 deletions

View File

@@ -335,7 +335,7 @@ class UIDefaultsLoader
throw new IllegalArgumentException( "property value type '" + newValue.getClass().getName() + "' not supported in references" );
}
enum ValueType { UNKNOWN, STRING, BOOLEAN, CHARACTER, INTEGER, FLOAT, BORDER, ICON, INSETS, DIMENSION, COLOR, FONT,
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 ValueType[] tempResultValueType = new ValueType[1];
@@ -468,7 +468,7 @@ class UIDefaultsLoader
else if( key.endsWith( "Size" ) )
valueType = ValueType.DIMENSION;
else if( key.endsWith( "Width" ) || key.endsWith( "Height" ) )
valueType = ValueType.INTEGER;
valueType = ValueType.INTEGERORFLOAT;
else if( key.endsWith( "Char" ) )
valueType = ValueType.CHARACTER;
else if( key.endsWith( "grayFilter" ) )
@@ -484,6 +484,7 @@ class UIDefaultsLoader
case BOOLEAN: return parseBoolean( value );
case CHARACTER: return parseCharacter( value );
case INTEGER: return parseInteger( value, true );
case INTEGERORFLOAT:return parseIntegerOrFloat( value, true );
case FLOAT: return parseFloat( value, true );
case BORDER: return parseBorder( value, resolver, addonClassLoaders );
case ICON: return parseInstance( value, addonClassLoaders );
@@ -1160,6 +1161,20 @@ class UIDefaultsLoader
return null;
}
private static Number parseIntegerOrFloat( String value, boolean reportError ) {
try {
return Integer.parseInt( value );
} catch( NumberFormatException ex ) {
try {
return Float.parseFloat( value );
} catch( NumberFormatException ex2 ) {
if( reportError )
throw new NumberFormatException( "invalid integer or float '" + value + "'" );
}
}
return null;
}
private static Float parseFloat( String value, boolean reportError ) {
try {
return Float.parseFloat( value );

View File

@@ -226,8 +226,8 @@ ComboBox.buttonPressedArrowColor = @buttonPressedArrowColor
#---- Component ----
Component.focusWidth = 0
Component.innerFocusWidth = {float}0.5
Component.innerOutlineWidth = {float}1
Component.innerFocusWidth = 0.5
Component.innerOutlineWidth = 1
Component.arc = 5
Component.minimumWidth = 64
# allowed values: chevron or triangle
@@ -626,7 +626,7 @@ TabbedPane.closeSize = 16,16
TabbedPane.closeArc = 4
TabbedPane.closeCrossPlainSize = {float}7.5
TabbedPane.closeCrossFilledSize = $TabbedPane.closeCrossPlainSize
TabbedPane.closeCrossLineWidth = {float}1
TabbedPane.closeCrossLineWidth = 1
#---- Table ----

View File

@@ -56,7 +56,7 @@ public class TestUIDefaultsLoader
assertEquals( 123, UIDefaultsLoader.parseValue( "dummy", "123", null ) );
assertEquals( 123, UIDefaultsLoader.parseValue( "dummyWidth", "123", null ) );
assertEquals( 1.23f, UIDefaultsLoader.parseValue( "dummy", "1.23", null ) );
assertEquals( 1.23f, UIDefaultsLoader.parseValue( "dummyWidth", "{float}1.23", null ) );
assertEquals( 1.23f, UIDefaultsLoader.parseValue( "dummyWidth", "1.23", null ) );
assertEquals( new Insets( 2,2,2,2 ), UIDefaultsLoader.parseValue( "dummyInsets", "2,2,2,2", null ) );
assertEquals( new Dimension( 2,2 ), UIDefaultsLoader.parseValue( "dummySize", "2,2", null ) );

View File

@@ -201,7 +201,7 @@ public class TestFlatStyling
ui.applyStyle( b, "help.focusWidth: 2" );
ui.applyStyle( b, "help.focusColor: #fff" );
ui.applyStyle( b, "help.innerFocusWidth: {float}0.5" );
ui.applyStyle( b, "help.innerFocusWidth: 0.5" );
ui.applyStyle( b, "help.borderWidth: 1" );
ui.applyStyle( b, "help.borderColor: #fff" );
@@ -869,7 +869,7 @@ public class TestFlatStyling
ui.applyStyle( "closeArc: 4" );
ui.applyStyle( "closeCrossPlainSize: {float}7.5" );
ui.applyStyle( "closeCrossFilledSize: {float}7.5" );
ui.applyStyle( "closeCrossLineWidth: {float}1" );
ui.applyStyle( "closeCrossLineWidth: 1" );
ui.applyStyle( "closeBackground: #fff" );
ui.applyStyle( "closeForeground: #fff" );
ui.applyStyle( "closeHoverBackground: #fff" );
@@ -1124,7 +1124,7 @@ public class TestFlatStyling
applyStyle.accept( "default.borderWidth: 2" );
applyStyle.accept( "toolbar.margin: 1,2,3,4" );
applyStyle.accept( "toolbar.spacingInsets: 1,2,3,4" );
applyStyle.accept( "toolbar.focusWidth: {float}1.5" );
applyStyle.accept( "toolbar.focusWidth: 1.5" );
applyStyle.accept( "arc: 6" );
}
@@ -1146,8 +1146,8 @@ public class TestFlatStyling
private void flatBorder( Consumer<String> applyStyle ) {
applyStyle.accept( "focusWidth: 2" );
applyStyle.accept( "innerFocusWidth: {float}0.5" );
applyStyle.accept( "innerOutlineWidth: {float}1.5" );
applyStyle.accept( "innerFocusWidth: 0.5" );
applyStyle.accept( "innerOutlineWidth: 1.5" );
applyStyle.accept( "focusColor: #fff" );
applyStyle.accept( "borderColor: #fff" );
applyStyle.accept( "disabledBorderColor: #fff" );

View File

@@ -38,7 +38,7 @@
- Component.innerFocusWidth 0.5
+ Component.innerFocusWidth 0
- Component.innerOutlineWidth 1.0
- Component.innerOutlineWidth 1
+ Component.innerOutlineWidth 0

View File

@@ -234,7 +234,7 @@ Component.focusedBorderColor #446e9e HSL 212 40 44 javax.swing.plaf.Colo
Component.grayFilter [lazy] [unknown type] com.formdev.flatlaf.util.GrayFilter
Component.hideMnemonics true
Component.innerFocusWidth 0.5
Component.innerOutlineWidth 1.0
Component.innerOutlineWidth 1
Component.linkColor #579bf6 HSL 214 90 65 javax.swing.plaf.ColorUIResource [UI]
Component.minimumWidth 64
Component.warning.borderColor #725627 HSL 38 49 30 javax.swing.plaf.ColorUIResource [UI]
@@ -1000,7 +1000,7 @@ TabbedPane.buttonInsets 2,1,2,1 javax.swing.plaf.InsetsUIResource [UI]
TabbedPane.buttonPressedBackground #282a2c HSL 210 5 16 com.formdev.flatlaf.util.DerivedColor [UI] darken(8%)
TabbedPane.closeArc 4
TabbedPane.closeCrossFilledSize 7.5
TabbedPane.closeCrossLineWidth 1.0
TabbedPane.closeCrossLineWidth 1
TabbedPane.closeCrossPlainSize 7.5
TabbedPane.closeForeground #8c8c8c HSL 0 0 55 javax.swing.plaf.ColorUIResource [UI]
TabbedPane.closeHoverBackground #484c4e HSL 200 4 29 com.formdev.flatlaf.util.DerivedColor [UI] lighten(5% autoInverse)

View File

@@ -69,7 +69,7 @@
- Component.innerFocusWidth 0.5
+ Component.innerFocusWidth 0
- Component.innerOutlineWidth 1.0
- Component.innerOutlineWidth 1
+ Component.innerOutlineWidth 0

View File

@@ -238,7 +238,7 @@ Component.focusedBorderColor #89b0d4 HSL 209 47 68 javax.swing.plaf.Colo
Component.grayFilter [lazy] [unknown type] com.formdev.flatlaf.util.GrayFilter
Component.hideMnemonics true
Component.innerFocusWidth 0.5
Component.innerOutlineWidth 1.0
Component.innerOutlineWidth 1
Component.linkColor #236db2 HSL 209 67 42 javax.swing.plaf.ColorUIResource [UI]
Component.minimumWidth 64
Component.warning.borderColor #fed284 HSL 38 98 76 javax.swing.plaf.ColorUIResource [UI]
@@ -1005,7 +1005,7 @@ TabbedPane.buttonInsets 2,1,2,1 javax.swing.plaf.InsetsUIResource [UI]
TabbedPane.buttonPressedBackground #d9d9d9 HSL 0 0 85 com.formdev.flatlaf.util.DerivedColor [UI] darken(10% autoInverse)
TabbedPane.closeArc 4
TabbedPane.closeCrossFilledSize 7.5
TabbedPane.closeCrossLineWidth 1.0
TabbedPane.closeCrossLineWidth 1
TabbedPane.closeCrossPlainSize 7.5
TabbedPane.closeForeground #8c8c8c HSL 0 0 55 javax.swing.plaf.ColorUIResource [UI]
TabbedPane.closeHoverBackground #bfbfbf HSL 0 0 75 com.formdev.flatlaf.util.DerivedColor [UI] darken(20% autoInverse)

View File

@@ -234,7 +234,7 @@ Component.focusedBorderColor #466d94 HSL 210 36 43 javax.swing.plaf.Colo
Component.grayFilter [lazy] [unknown type] com.formdev.flatlaf.util.GrayFilter
Component.hideMnemonics true
Component.innerFocusWidth 0.5
Component.innerOutlineWidth 1.0
Component.innerOutlineWidth 1
Component.minimumWidth 64
@@ -1006,7 +1006,7 @@ TabbedPane.buttonInsets 2,1,2,1 javax.swing.plaf.InsetsUIResource [UI]
TabbedPane.buttonPressedBackground #ffc800 HSL 47 100 50 javax.swing.plaf.ColorUIResource [UI]
TabbedPane.closeArc 999
TabbedPane.closeCrossFilledSize 6.5
TabbedPane.closeCrossLineWidth 2.0
TabbedPane.closeCrossLineWidth 2
TabbedPane.closeCrossPlainSize 12.0
TabbedPane.closeForeground #ff0000 HSL 0 100 50 javax.swing.plaf.ColorUIResource [UI]
TabbedPane.closeHoverBackground #aa0000 HSL 0 100 33 javax.swing.plaf.ColorUIResource [UI]

View File

@@ -344,7 +344,7 @@ TabbedPane.closeSize = 16,16
TabbedPane.closeArc = 999
TabbedPane.closeCrossPlainSize = {float}12
TabbedPane.closeCrossFilledSize = {float}6.5
TabbedPane.closeCrossLineWidth = {float}2
TabbedPane.closeCrossLineWidth = 2
#TabbedPane.closeBackground = #faa
TabbedPane.closeForeground = #f00
TabbedPane.closeHoverBackground = #a00