PasswordField: get echoChar from .properties files and no longer hard code it on macOS

This commit is contained in:
Karl Tauber
2020-02-13 11:17:29 +01:00
parent b319cb278b
commit 87dd5a9ebb
5 changed files with 13 additions and 8 deletions

View File

@@ -221,7 +221,7 @@ class UIDefaultsLoader
return resolveValue( properties, newValue );
}
private enum ValueType { UNKNOWN, STRING, INTEGER, FLOAT, BORDER, ICON, INSETS, DIMENSION, COLOR,
private enum ValueType { UNKNOWN, STRING, CHARACTER, INTEGER, FLOAT, BORDER, ICON, INSETS, DIMENSION, COLOR,
SCALEDINTEGER, SCALEDFLOAT, SCALEDINSETS, SCALEDDIMENSION, INSTANCE, CLASS }
static Object parseValue( String key, String value ) {
@@ -285,6 +285,8 @@ class UIDefaultsLoader
valueType = ValueType.DIMENSION;
else if( key.endsWith( "Width" ) || key.endsWith( "Height" ) )
valueType = ValueType.INTEGER;
else if( key.endsWith( "Char" ) )
valueType = ValueType.CHARACTER;
else if( key.endsWith( "UI" ) )
valueType = ValueType.STRING;
}
@@ -292,6 +294,7 @@ class UIDefaultsLoader
// parse value
switch( valueType ) {
case STRING: return value;
case CHARACTER: return parseCharacter( value );
case INTEGER: return parseInteger( value, true );
case FLOAT: return parseFloat( value, true );
case BORDER: return parseBorder( value, resolver, addonClassLoaders );
@@ -599,6 +602,12 @@ class UIDefaultsLoader
return val;
}
private static Character parseCharacter( String value ) {
if( value.length() != 1 )
throw new IllegalArgumentException( "invalid character '" + value + "'" );
return value.charAt( 0 );
}
private static Integer parseInteger( String value, int min, int max ) {
Integer integer = parseInteger( value, true );
if( integer.intValue() < min || integer.intValue() > max )

View File

@@ -29,7 +29,6 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPasswordFieldUI;
import javax.swing.text.Caret;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.SystemInfo;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JPasswordField}.
@@ -78,10 +77,6 @@ public class FlatPasswordFieldUI
protected void installDefaults() {
super.installDefaults();
// use other echoChar on Mac because the default is too large in SF font
if( SystemInfo.IS_MAC )
LookAndFeel.installProperty( getComponent(), "echoChar", '\u2022' );
String prefix = getPropertyPrefix();
focusWidth = UIManager.getInt( "Component.focusWidth" );
minimumWidth = UIManager.getInt( "Component.minimumWidth" );

View File

@@ -297,6 +297,7 @@ PasswordField.border=com.formdev.flatlaf.ui.FlatBorder
PasswordField.margin=@textComponentMargin
PasswordField.background=@textComponentBackground
PasswordField.placeholderForeground=@disabledText
PasswordField.echoChar=\u2022
#---- PopupMenu ----

View File

@@ -1034,7 +1034,7 @@ PasswordField.capsLockIconColor #64000000 javax.swing.plaf.ColorUIResource [U
PasswordField.caretBlinkRate 500
PasswordField.caretForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI]
PasswordField.disabledBackground #3c3f41 javax.swing.plaf.ColorUIResource [UI]
PasswordField.echoChar '\u25cf'
PasswordField.echoChar '\u2022'
PasswordField.focusInputMap [lazy] 66 javax.swing.plaf.InputMapUIResource [UI]
alt pressed BACK_SPACE delete-previous-word
alt pressed DELETE delete-next-word

View File

@@ -1036,7 +1036,7 @@ PasswordField.capsLockIconColor #64000000 javax.swing.plaf.ColorUIResource [U
PasswordField.caretBlinkRate 500
PasswordField.caretForeground #000000 javax.swing.plaf.ColorUIResource [UI]
PasswordField.disabledBackground #f2f2f2 javax.swing.plaf.ColorUIResource [UI]
PasswordField.echoChar '\u25cf'
PasswordField.echoChar '\u2022'
PasswordField.focusInputMap [lazy] 66 javax.swing.plaf.InputMapUIResource [UI]
alt pressed BACK_SPACE delete-previous-word
alt pressed DELETE delete-next-word