use 0.5 pixel "inner" focus border for "Flat Light" and "Flat Dark" themes

This commit is contained in:
Karl Tauber
2019-12-30 10:48:15 +01:00
parent 4b4837e3a1
commit d0029beb22
4 changed files with 30 additions and 6 deletions

View File

@@ -212,7 +212,7 @@ class UIDefaultsLoader
return resolveValue( properties, newValue ); return resolveValue( properties, newValue );
} }
private enum ValueType { UNKNOWN, STRING, INTEGER, BORDER, ICON, INSETS, DIMENSION, COLOR, SCALEDINTEGER, INSTANCE, CLASS } private enum ValueType { UNKNOWN, STRING, INTEGER, FLOAT, BORDER, ICON, INSETS, DIMENSION, COLOR, SCALEDINTEGER, INSTANCE, CLASS }
static Object parseValue( String key, String value ) { static Object parseValue( String key, String value ) {
return parseValue( key, value, v -> v, Collections.emptyList() ); return parseValue( key, value, v -> v, Collections.emptyList() );
@@ -242,7 +242,10 @@ class UIDefaultsLoader
// check whether value type is specified in the value // check whether value type is specified in the value
if( value.startsWith( "#" ) ) if( value.startsWith( "#" ) )
valueType = ValueType.COLOR; valueType = ValueType.COLOR;
else if( value.startsWith( TYPE_PREFIX ) ) { else if( value.startsWith( "\"" ) && value.endsWith( "\"" ) ) {
valueType = ValueType.STRING;
value = value.substring( 1, value.length() - 1 );
} else if( value.startsWith( TYPE_PREFIX ) ) {
int end = value.indexOf( TYPE_PREFIX_END ); int end = value.indexOf( TYPE_PREFIX_END );
if( end != -1 ) { if( end != -1 ) {
try { try {
@@ -280,6 +283,7 @@ class UIDefaultsLoader
switch( valueType ) { switch( valueType ) {
case STRING: return value; case STRING: return value;
case INTEGER: return parseInteger( value, true ); case INTEGER: return parseInteger( value, true );
case FLOAT: return parseFloat( value, true );
case BORDER: return parseBorder( value, resolver, addonClassLoaders ); case BORDER: return parseBorder( value, resolver, addonClassLoaders );
case ICON: return parseInstance( value, addonClassLoaders ); case ICON: return parseInstance( value, addonClassLoaders );
case INSETS: return parseInsets( value ); case INSETS: return parseInsets( value );
@@ -300,6 +304,11 @@ class UIDefaultsLoader
if( integer != null ) if( integer != null )
return integer; return integer;
// float
Float f = parseFloat( value, false );
if( f != null )
return f;
// string // string
return value; return value;
} }
@@ -594,6 +603,16 @@ class UIDefaultsLoader
return null; return null;
} }
private static Float parseFloat( String value, boolean reportError ) {
try {
return Float.parseFloat( value );
} catch( NumberFormatException ex ) {
if( reportError )
throw new NumberFormatException( "invalid float '" + value + "'" );
}
return null;
}
private static ActiveValue parseScaledInteger( String value ) { private static ActiveValue parseScaledInteger( String value ) {
int val = parseInteger( value, true ); int val = parseInteger( value, true );
return (ActiveValue) t -> { return (ActiveValue) t -> {

View File

@@ -48,7 +48,7 @@ import javax.swing.text.JTextComponent;
* {@link FlatUIUtils#paintParentBackground} to paint the empty space correctly. * {@link FlatUIUtils#paintParentBackground} to paint the empty space correctly.
* *
* @uiDefault Component.focusWidth int * @uiDefault Component.focusWidth int
* @uiDefault Component.innerFocusWidth int * @uiDefault Component.innerFocusWidth int or float
* @uiDefault Component.focusColor Color * @uiDefault Component.focusColor Color
* @uiDefault Component.borderColor Color * @uiDefault Component.borderColor Color
* @uiDefault Component.disabledBorderColor Color * @uiDefault Component.disabledBorderColor Color
@@ -60,7 +60,7 @@ public class FlatBorder
extends BasicBorders.MarginBorder extends BasicBorders.MarginBorder
{ {
protected final int focusWidth = UIManager.getInt( "Component.focusWidth" ); protected final int focusWidth = UIManager.getInt( "Component.focusWidth" );
protected final int innerFocusWidth = UIManager.getInt( "Component.innerFocusWidth" ); protected final float innerFocusWidth = FlatUIUtils.getUIFloat( "Component.innerFocusWidth", 0 );
protected final Color focusColor = UIManager.getColor( "Component.focusColor" ); protected final Color focusColor = UIManager.getColor( "Component.focusColor" );
protected final Color borderColor = UIManager.getColor( "Component.borderColor" ); protected final Color borderColor = UIManager.getColor( "Component.borderColor" );
protected final Color disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" ); protected final Color disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" );
@@ -80,7 +80,7 @@ public class FlatBorder
if( isFocused( c ) ) { if( isFocused( c ) ) {
g2.setColor( getFocusColor( c ) ); g2.setColor( getFocusColor( c ) );
FlatUIUtils.paintComponentOuterBorder( g2, x, y, width, height, focusWidth, FlatUIUtils.paintComponentOuterBorder( g2, x, y, width, height, focusWidth,
getLineWidth() + scale( (float) innerFocusWidth ), arc ); getLineWidth() + scale( innerFocusWidth ), arc );
} }
g2.setPaint( getBorderColor( c ) ); g2.setPaint( getBorderColor( c ) );

View File

@@ -102,6 +102,11 @@ public class FlatUIUtils
return (value instanceof Integer) ? (Integer) value : defaultValue; return (value instanceof Integer) ? (Integer) value : defaultValue;
} }
public static float getUIFloat( String key, float defaultValue ) {
Object value = UIManager.get( key );
return (value instanceof Number) ? ((Number)value).floatValue() : defaultValue;
}
public static Color nonUIResource( Color c ) { public static Color nonUIResource( Color c ) {
return (c instanceof ColorUIResource) ? new Color( c.getRGB(), true ) : c; return (c instanceof ColorUIResource) ? new Color( c.getRGB(), true ) : c;
} }

View File

@@ -137,7 +137,7 @@ ComboBox.padding=2,6,2,6
#---- Component ---- #---- Component ----
Component.focusWidth=0 Component.focusWidth=0
Component.innerFocusWidth=0 Component.innerFocusWidth={float}0.5
Component.arc=5 Component.arc=5
Component.minimumWidth=64 Component.minimumWidth=64
Component.arrowType=chevron Component.arrowType=chevron