mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 14:30:56 +03:00
UIDefaultsLoader and FlatStylingSupport: explicitly specify throws IllegalArgumentException and improved catching
This commit is contained in:
@@ -271,8 +271,9 @@ class UIDefaultsLoader
|
||||
continue;
|
||||
}
|
||||
|
||||
String value = resolveValue( (String) e.getValue(), propertiesGetter );
|
||||
String value = (String) e.getValue();
|
||||
try {
|
||||
value = resolveValue( value, propertiesGetter );
|
||||
defaults.put( key, parseValue( key, value, null, null, resolver, addonClassLoaders ) );
|
||||
} catch( RuntimeException ex ) {
|
||||
logParseError( key, value, ex, true );
|
||||
@@ -297,7 +298,9 @@ class UIDefaultsLoader
|
||||
LoggingFacade.INSTANCE.logConfig( message, ex );
|
||||
}
|
||||
|
||||
static String resolveValue( String value, Function<String, String> propertiesGetter ) {
|
||||
static String resolveValue( String value, Function<String, String> propertiesGetter )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
value = value.trim();
|
||||
String value0 = value;
|
||||
|
||||
@@ -326,7 +329,9 @@ class UIDefaultsLoader
|
||||
return resolveValue( newValue, propertiesGetter );
|
||||
}
|
||||
|
||||
static String resolveValueFromUIManager( String value ) {
|
||||
static String resolveValueFromUIManager( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if( value.startsWith( VARIABLE_PREFIX ) ) {
|
||||
@SuppressWarnings( "unchecked" )
|
||||
Map<String, String> variables = (Map<String, String>) UIManager.get( KEY_VARIABLES );
|
||||
@@ -365,12 +370,15 @@ class UIDefaultsLoader
|
||||
private static Map<Class<?>, ValueType> javaValueTypes;
|
||||
private static Map<String, ValueType> knownValueTypes;
|
||||
|
||||
static Object parseValue( String key, String value, Class<?> valueType ) {
|
||||
static Object parseValue( String key, String value, Class<?> valueType )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
return parseValue( key, value, valueType, null, v -> v, Collections.emptyList() );
|
||||
}
|
||||
|
||||
static Object parseValue( String key, String value, Class<?> javaValueType, ValueType[] resultValueType,
|
||||
Function<String, String> resolver, List<ClassLoader> addonClassLoaders )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if( resultValueType == null )
|
||||
resultValueType = tempResultValueType;
|
||||
@@ -400,7 +408,7 @@ class UIDefaultsLoader
|
||||
if( value.startsWith( "if(" ) && value.endsWith( ")" ) ) {
|
||||
List<String> params = splitFunctionParams( value.substring( 3, value.length() - 1 ), ',' );
|
||||
if( params.size() != 3 )
|
||||
throwMissingParametersException( value );
|
||||
throw newMissingParametersException( value );
|
||||
|
||||
boolean ifCondition = parseCondition( params.get( 0 ), resolver, addonClassLoaders );
|
||||
String ifValue = params.get( ifCondition ? 1 : 2 );
|
||||
@@ -611,7 +619,9 @@ class UIDefaultsLoader
|
||||
}
|
||||
}
|
||||
|
||||
private static Object parseBorder( String value, Function<String, String> resolver, List<ClassLoader> addonClassLoaders ) {
|
||||
private static Object parseBorder( String value, Function<String, String> resolver, List<ClassLoader> addonClassLoaders )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if( value.indexOf( ',' ) >= 0 ) {
|
||||
// top,left,bottom,right[,lineColor[,lineThickness[,arc]]]
|
||||
List<String> parts = splitFunctionParams( value, ',' );
|
||||
@@ -671,7 +681,9 @@ class UIDefaultsLoader
|
||||
}
|
||||
}
|
||||
|
||||
private static Insets parseInsets( String value ) {
|
||||
private static Insets parseInsets( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
List<String> numbers = StringUtils.split( value, ',', true, false );
|
||||
try {
|
||||
return new InsetsUIResource(
|
||||
@@ -684,7 +696,9 @@ class UIDefaultsLoader
|
||||
}
|
||||
}
|
||||
|
||||
private static Dimension parseDimension( String value ) {
|
||||
private static Dimension parseDimension( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
List<String> numbers = StringUtils.split( value, ',', true, false );
|
||||
try {
|
||||
return new DimensionUIResource(
|
||||
@@ -695,7 +709,9 @@ class UIDefaultsLoader
|
||||
}
|
||||
}
|
||||
|
||||
private static Object parseColorOrFunction( String value, Function<String, String> resolver ) {
|
||||
private static Object parseColorOrFunction( String value, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if( value.endsWith( ")" ) )
|
||||
return parseColorFunctions( value, resolver );
|
||||
|
||||
@@ -706,7 +722,9 @@ class UIDefaultsLoader
|
||||
* Parses a hex color in {@code #RGB}, {@code #RGBA}, {@code #RRGGBB} or {@code #RRGGBBAA}
|
||||
* format and returns it as color object.
|
||||
*/
|
||||
static ColorUIResource parseColor( String value ) {
|
||||
static ColorUIResource parseColor( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
int rgba = parseColorRGBA( value );
|
||||
return ((rgba & 0xff000000) == 0xff000000)
|
||||
? new ColorUIResource( rgba )
|
||||
@@ -718,7 +736,9 @@ class UIDefaultsLoader
|
||||
* format and returns it as {@code rgba} integer suitable for {@link java.awt.Color},
|
||||
* which includes alpha component in bits 24-31.
|
||||
*/
|
||||
static int parseColorRGBA( String value ) {
|
||||
static int parseColorRGBA( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
int len = value.length();
|
||||
if( (len != 4 && len != 5 && len != 7 && len != 9) || value.charAt( 0 ) != '#' )
|
||||
throw newInvalidColorException( value );
|
||||
@@ -759,7 +779,9 @@ class UIDefaultsLoader
|
||||
return new IllegalArgumentException( "invalid color '" + value + "'" );
|
||||
}
|
||||
|
||||
private static Object parseColorFunctions( String value, Function<String, String> resolver ) {
|
||||
private static Object parseColorFunctions( String value, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
int paramsStart = value.indexOf( '(' );
|
||||
if( paramsStart < 0 )
|
||||
throw new IllegalArgumentException( "missing opening parenthesis in function '" + value + "'" );
|
||||
@@ -767,7 +789,7 @@ class UIDefaultsLoader
|
||||
String function = StringUtils.substringTrimmed( value, 0, paramsStart );
|
||||
List<String> params = splitFunctionParams( value.substring( paramsStart + 1, value.length() - 1 ), ',' );
|
||||
if( params.isEmpty() )
|
||||
throwMissingParametersException( value );
|
||||
throw newMissingParametersException( value );
|
||||
|
||||
if( parseColorDepth > 100 )
|
||||
throw new IllegalArgumentException( "endless recursion in color function '" + value + "'" );
|
||||
@@ -812,9 +834,11 @@ class UIDefaultsLoader
|
||||
* This "if" function is only used if the "if" is passed as parameter to another
|
||||
* color function. Otherwise, the general "if" function is used.
|
||||
*/
|
||||
private static Object parseColorIf( String value, List<String> params, Function<String, String> resolver ) {
|
||||
private static Object parseColorIf( String value, List<String> params, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if( params.size() != 3 )
|
||||
throwMissingParametersException( value );
|
||||
throw newMissingParametersException( value );
|
||||
|
||||
boolean ifCondition = parseCondition( params.get( 0 ), resolver, Collections.emptyList() );
|
||||
String ifValue = params.get( ifCondition ? 1 : 2 );
|
||||
@@ -826,9 +850,11 @@ class UIDefaultsLoader
|
||||
* - name: system color name
|
||||
* - defaultValue: default color value used if system color is not available
|
||||
*/
|
||||
private static Object parseColorSystemColor( String value, List<String> params, Function<String, String> resolver ) {
|
||||
private static Object parseColorSystemColor( String value, List<String> params, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if( params.size() < 1 )
|
||||
throwMissingParametersException( value );
|
||||
throw newMissingParametersException( value );
|
||||
|
||||
ColorUIResource systemColor = getSystemColor( params.get( 0 ) );
|
||||
if( systemColor != null )
|
||||
@@ -868,6 +894,7 @@ class UIDefaultsLoader
|
||||
*/
|
||||
private static ColorUIResource parseColorRgbOrRgba( boolean hasAlpha, List<String> params,
|
||||
Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if( hasAlpha && params.size() == 2 ) {
|
||||
// syntax rgba(color,alpha), which allows adding alpha to any color
|
||||
@@ -897,7 +924,9 @@ class UIDefaultsLoader
|
||||
* - lightness: a percentage 0-100%
|
||||
* - alpha: a percentage 0-100%
|
||||
*/
|
||||
private static ColorUIResource parseColorHslOrHsla( boolean hasAlpha, List<String> params ) {
|
||||
private static ColorUIResource parseColorHslOrHsla( boolean hasAlpha, List<String> params )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
int hue = parseInteger( params.get( 0 ), 0, 360, false );
|
||||
int saturation = parsePercentage( params.get( 1 ) );
|
||||
int lightness = parsePercentage( params.get( 2 ) );
|
||||
@@ -917,6 +946,7 @@ class UIDefaultsLoader
|
||||
*/
|
||||
private static Object parseColorHSLIncreaseDecrease( int hslIndex, boolean increase,
|
||||
List<String> params, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
String colorStr = params.get( 0 );
|
||||
int amount = parsePercentage( params.get( 1 ) );
|
||||
@@ -960,7 +990,9 @@ class UIDefaultsLoader
|
||||
* - amount: percentage 0-100%
|
||||
* - options: [derived] [lazy]
|
||||
*/
|
||||
private static Object parseColorFade( List<String> params, Function<String, String> resolver ) {
|
||||
private static Object parseColorFade( List<String> params, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
String colorStr = params.get( 0 );
|
||||
int amount = parsePercentage( params.get( 1 ) );
|
||||
boolean derived = false;
|
||||
@@ -994,7 +1026,9 @@ class UIDefaultsLoader
|
||||
* - angle: number of degrees to rotate
|
||||
* - options: [derived]
|
||||
*/
|
||||
private static Object parseColorSpin( List<String> params, Function<String, String> resolver ) {
|
||||
private static Object parseColorSpin( List<String> params, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
String colorStr = params.get( 0 );
|
||||
int amount = parseInteger( params.get( 1 ) );
|
||||
boolean derived = false;
|
||||
@@ -1022,6 +1056,7 @@ class UIDefaultsLoader
|
||||
*/
|
||||
private static Object parseColorChange( int hslIndex,
|
||||
List<String> params, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
String colorStr = params.get( 0 );
|
||||
int value = (hslIndex == 0)
|
||||
@@ -1050,7 +1085,9 @@ class UIDefaultsLoader
|
||||
* - weight: the weight (in range 0-100%) to mix the two colors
|
||||
* larger weight uses more of first color, smaller weight more of second color
|
||||
*/
|
||||
private static Object parseColorMix( String color1Str, List<String> params, Function<String, String> resolver ) {
|
||||
private static Object parseColorMix( String color1Str, List<String> params, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
int i = 0;
|
||||
if( color1Str == null )
|
||||
color1Str = params.get( i++ );
|
||||
@@ -1077,7 +1114,9 @@ class UIDefaultsLoader
|
||||
* - threshold: the threshold (in range 0-100%) to specify where the transition
|
||||
* from "dark" to "light" is (default is 43%)
|
||||
*/
|
||||
private static Object parseColorContrast( List<String> params, Function<String, String> resolver ) {
|
||||
private static Object parseColorContrast( List<String> params, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
String colorStr = params.get( 0 );
|
||||
String darkStr = params.get( 1 );
|
||||
String lightStr = params.get( 2 );
|
||||
@@ -1103,7 +1142,9 @@ class UIDefaultsLoader
|
||||
* the alpha of this color is used as weight to mix the two colors
|
||||
* - background: a background color (e.g. #f00) or a color function
|
||||
*/
|
||||
private static ColorUIResource parseColorOver( List<String> params, Function<String, String> resolver ) {
|
||||
private static ColorUIResource parseColorOver( List<String> params, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
String foregroundStr = params.get( 0 );
|
||||
String backgroundStr = params.get( 1 );
|
||||
|
||||
@@ -1127,6 +1168,7 @@ class UIDefaultsLoader
|
||||
|
||||
private static Object parseFunctionBaseColor( String colorStr, ColorFunction function,
|
||||
boolean derived, Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// parse base color
|
||||
String resolvedColorStr = resolver.apply( colorStr );
|
||||
@@ -1158,7 +1200,9 @@ class UIDefaultsLoader
|
||||
/**
|
||||
* Syntax: [normal] [bold|+bold|-bold] [italic|+italic|-italic] [<size>|+<incr>|-<decr>|<percent>%] [family[, family]] [$baseFontKey]
|
||||
*/
|
||||
private static Object parseFont( String value ) {
|
||||
private static Object parseFont( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
Object font = fontCache.get( value );
|
||||
if( font != null )
|
||||
return font;
|
||||
@@ -1256,7 +1300,9 @@ class UIDefaultsLoader
|
||||
return font;
|
||||
}
|
||||
|
||||
private static int parsePercentage( String value ) {
|
||||
private static int parsePercentage( String value )
|
||||
throws IllegalArgumentException, NumberFormatException
|
||||
{
|
||||
if( !value.endsWith( "%" ) )
|
||||
throw new NumberFormatException( "invalid percentage '" + value + "'" );
|
||||
|
||||
@@ -1272,7 +1318,9 @@ class UIDefaultsLoader
|
||||
return val;
|
||||
}
|
||||
|
||||
private static Boolean parseBoolean( String value ) {
|
||||
private static Boolean parseBoolean( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
switch( value ) {
|
||||
case "false": return false;
|
||||
case "true": return true;
|
||||
@@ -1280,13 +1328,17 @@ class UIDefaultsLoader
|
||||
throw new IllegalArgumentException( "invalid boolean '" + value + "'" );
|
||||
}
|
||||
|
||||
private static Character parseCharacter( String value ) {
|
||||
private static Character parseCharacter( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if( value.length() != 1 )
|
||||
throw new IllegalArgumentException( "invalid character '" + value + "'" );
|
||||
return value.charAt( 0 );
|
||||
}
|
||||
|
||||
private static Integer parseInteger( String value, int min, int max, boolean allowPercentage ) {
|
||||
private static Integer parseInteger( String value, int min, int max, boolean allowPercentage )
|
||||
throws IllegalArgumentException, NumberFormatException
|
||||
{
|
||||
if( allowPercentage && value.endsWith( "%" ) ) {
|
||||
int percent = parsePercentage( value );
|
||||
return (max * percent) / 100;
|
||||
@@ -1298,7 +1350,9 @@ class UIDefaultsLoader
|
||||
return integer;
|
||||
}
|
||||
|
||||
private static Integer parseInteger( String value ) {
|
||||
private static Integer parseInteger( String value )
|
||||
throws NumberFormatException
|
||||
{
|
||||
try {
|
||||
return Integer.parseInt( value );
|
||||
} catch( NumberFormatException ex ) {
|
||||
@@ -1306,7 +1360,9 @@ class UIDefaultsLoader
|
||||
}
|
||||
}
|
||||
|
||||
private static Number parseIntegerOrFloat( String value ) {
|
||||
private static Number parseIntegerOrFloat( String value )
|
||||
throws NumberFormatException
|
||||
{
|
||||
try {
|
||||
return Integer.parseInt( value );
|
||||
} catch( NumberFormatException ex ) {
|
||||
@@ -1318,7 +1374,9 @@ class UIDefaultsLoader
|
||||
}
|
||||
}
|
||||
|
||||
private static Float parseFloat( String value ) {
|
||||
private static Float parseFloat( String value )
|
||||
throws NumberFormatException
|
||||
{
|
||||
try {
|
||||
return Float.parseFloat( value );
|
||||
} catch( NumberFormatException ex ) {
|
||||
@@ -1326,35 +1384,45 @@ class UIDefaultsLoader
|
||||
}
|
||||
}
|
||||
|
||||
private static ActiveValue parseScaledInteger( String value ) {
|
||||
private static ActiveValue parseScaledInteger( String value )
|
||||
throws NumberFormatException
|
||||
{
|
||||
int val = parseInteger( value );
|
||||
return t -> {
|
||||
return UIScale.scale( val );
|
||||
};
|
||||
}
|
||||
|
||||
private static ActiveValue parseScaledFloat( String value ) {
|
||||
private static ActiveValue parseScaledFloat( String value )
|
||||
throws NumberFormatException
|
||||
{
|
||||
float val = parseFloat( value );
|
||||
return t -> {
|
||||
return UIScale.scale( val );
|
||||
};
|
||||
}
|
||||
|
||||
private static ActiveValue parseScaledInsets( String value ) {
|
||||
private static ActiveValue parseScaledInsets( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
Insets insets = parseInsets( value );
|
||||
return t -> {
|
||||
return UIScale.scale( insets );
|
||||
};
|
||||
}
|
||||
|
||||
private static ActiveValue parseScaledDimension( String value ) {
|
||||
private static ActiveValue parseScaledDimension( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
Dimension dimension = parseDimension( value );
|
||||
return t -> {
|
||||
return UIScale.scale( dimension );
|
||||
};
|
||||
}
|
||||
|
||||
private static Object parseGrayFilter( String value ) {
|
||||
private static Object parseGrayFilter( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
List<String> numbers = StringUtils.split( value, ',', true, false );
|
||||
try {
|
||||
int brightness = Integer.parseInt( numbers.get( 0 ) );
|
||||
@@ -1415,7 +1483,7 @@ class UIDefaultsLoader
|
||||
return value;
|
||||
}
|
||||
|
||||
private static void throwMissingParametersException( String value ) {
|
||||
throw new IllegalArgumentException( "missing parameters in function '" + value + "'" );
|
||||
private static IllegalArgumentException newMissingParametersException( String value ) {
|
||||
return new IllegalArgumentException( "missing parameters in function '" + value + "'" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,15 +100,15 @@ public class FlatStylingSupport
|
||||
|
||||
/** @since 2 */
|
||||
public interface StyleableUI {
|
||||
Map<String, Class<?>> getStyleableInfos( JComponent c );
|
||||
/** @since 2.5 */ Object getStyleableValue( JComponent c, String key );
|
||||
Map<String, Class<?>> getStyleableInfos( JComponent c ) throws IllegalArgumentException;
|
||||
/** @since 2.5 */ Object getStyleableValue( JComponent c, String key ) throws IllegalArgumentException;
|
||||
}
|
||||
|
||||
/** @since 2 */
|
||||
public interface StyleableBorder {
|
||||
Object applyStyleProperty( String key, Object value );
|
||||
Map<String, Class<?>> getStyleableInfos();
|
||||
/** @since 2.5 */ Object getStyleableValue( String key );
|
||||
Map<String, Class<?>> getStyleableInfos() throws IllegalArgumentException;
|
||||
/** @since 2.5 */ Object getStyleableValue( String key ) throws IllegalArgumentException;
|
||||
}
|
||||
|
||||
/** @since 2.5 */
|
||||
@@ -135,7 +135,9 @@ public class FlatStylingSupport
|
||||
return getStyle( c ) != null || getStyleClass( c ) != null;
|
||||
}
|
||||
|
||||
public static Object getResolvedStyle( JComponent c, String type ) {
|
||||
public static Object getResolvedStyle( JComponent c, String type )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
Object style = getStyle( c );
|
||||
Object styleClass = getStyleClass( c );
|
||||
Object styleForClasses = getStyleForClasses( styleClass, type );
|
||||
@@ -175,7 +177,9 @@ public class FlatStylingSupport
|
||||
* @param type the type of the component
|
||||
* @return the styles
|
||||
*/
|
||||
public static Object getStyleForClasses( Object styleClass, String type ) {
|
||||
public static Object getStyleForClasses( Object styleClass, String type )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if( styleClass == null )
|
||||
return null;
|
||||
|
||||
@@ -198,7 +202,9 @@ public class FlatStylingSupport
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Object getStyleForClass( String styleClass, String type ) {
|
||||
private static Object getStyleForClass( String styleClass, String type )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
return joinStyles(
|
||||
UIManager.get( "[style]." + styleClass ),
|
||||
UIManager.get( "[style]" + type + '.' + styleClass ) );
|
||||
@@ -218,7 +224,9 @@ public class FlatStylingSupport
|
||||
* @return new joined style
|
||||
*/
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public static Object joinStyles( Object style1, Object style2 ) {
|
||||
public static Object joinStyles( Object style1, Object style2 )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if( style1 == null )
|
||||
return style2;
|
||||
if( style2 == null )
|
||||
@@ -380,7 +388,9 @@ public class FlatStylingSupport
|
||||
return map;
|
||||
}
|
||||
|
||||
private static Object parseValue( String key, String value ) {
|
||||
private static Object parseValue( String key, String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// simple reference
|
||||
if( value.startsWith( "$" ) )
|
||||
return UIManager.get( value.substring( 1 ) );
|
||||
@@ -475,7 +485,9 @@ public class FlatStylingSupport
|
||||
}
|
||||
}
|
||||
|
||||
private static Object applyToField( Field f, Object obj, Object value, boolean useMethodHandles ) {
|
||||
private static Object applyToField( Field f, Object obj, Object value, boolean useMethodHandles )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
checkValidField( f );
|
||||
|
||||
if( useMethodHandles && obj instanceof StyleableLookupProvider ) {
|
||||
@@ -505,7 +517,9 @@ public class FlatStylingSupport
|
||||
}
|
||||
}
|
||||
|
||||
private static Object getFieldValue( Field f, Object obj, boolean useMethodHandles ) {
|
||||
private static Object getFieldValue( Field f, Object obj, boolean useMethodHandles )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
checkValidField( f );
|
||||
|
||||
if( useMethodHandles && obj instanceof StyleableLookupProvider ) {
|
||||
@@ -530,7 +544,9 @@ public class FlatStylingSupport
|
||||
return new IllegalArgumentException( "failed to access field '" + f.getDeclaringClass().getName() + "." + f.getName() + "'", ex );
|
||||
}
|
||||
|
||||
private static void checkValidField( Field f ) {
|
||||
private static void checkValidField( Field f )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if( !isValidField( f ) )
|
||||
throw new IllegalArgumentException( "field '" + f.getDeclaringClass().getName() + "." + f.getName() + "' is final or static" );
|
||||
}
|
||||
@@ -540,7 +556,9 @@ public class FlatStylingSupport
|
||||
return (modifiers & (Modifier.FINAL|Modifier.STATIC)) == 0 && !f.isSynthetic();
|
||||
}
|
||||
|
||||
private static Field getStyleableField( StyleableField styleableField ) {
|
||||
private static Field getStyleableField( StyleableField styleableField )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
String fieldName = styleableField.fieldName();
|
||||
if( fieldName.isEmpty() )
|
||||
fieldName = styleableField.key();
|
||||
@@ -648,6 +666,7 @@ public class FlatStylingSupport
|
||||
|
||||
static Object applyToAnnotatedObjectOrBorder( Object obj, String key, Object value,
|
||||
JComponent c, AtomicBoolean borderShared )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
try {
|
||||
return applyToAnnotatedObject( obj, key, value );
|
||||
@@ -696,7 +715,9 @@ public class FlatStylingSupport
|
||||
};
|
||||
}
|
||||
|
||||
static Border cloneBorder( Border border ) {
|
||||
static Border cloneBorder( Border border )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
Class<? extends Border> borderClass = border.getClass();
|
||||
try {
|
||||
return borderClass.getDeclaredConstructor().newInstance();
|
||||
@@ -705,7 +726,9 @@ public class FlatStylingSupport
|
||||
}
|
||||
}
|
||||
|
||||
static Icon cloneIcon( Icon icon ) {
|
||||
static Icon cloneIcon( Icon icon )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
Class<? extends Icon> iconClass = icon.getClass();
|
||||
try {
|
||||
return iconClass.getDeclaredConstructor().newInstance();
|
||||
@@ -718,11 +741,15 @@ public class FlatStylingSupport
|
||||
* Returns a map of all fields annotated with {@link Styleable}.
|
||||
* The key is the name of the field and the value the type of the field.
|
||||
*/
|
||||
public static Map<String, Class<?>> getAnnotatedStyleableInfos( Object obj ) {
|
||||
public static Map<String, Class<?>> getAnnotatedStyleableInfos( Object obj )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
return getAnnotatedStyleableInfos( obj, null );
|
||||
}
|
||||
|
||||
public static Map<String, Class<?>> getAnnotatedStyleableInfos( Object obj, Border border ) {
|
||||
public static Map<String, Class<?>> getAnnotatedStyleableInfos( Object obj, Border border )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
Map<String, Class<?>> infos = new StyleableInfosMap<>();
|
||||
collectAnnotatedStyleableInfos( obj, infos );
|
||||
collectStyleableInfos( border, infos );
|
||||
@@ -733,7 +760,9 @@ public class FlatStylingSupport
|
||||
* Search for all fields annotated with {@link Styleable} and add them to the given map.
|
||||
* The key is the name of the field and the value the type of the field.
|
||||
*/
|
||||
public static void collectAnnotatedStyleableInfos( Object obj, Map<String, Class<?>> infos ) {
|
||||
public static void collectAnnotatedStyleableInfos( Object obj, Map<String, Class<?>> infos )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
HashSet<String> processedFields = new HashSet<>();
|
||||
Class<?> cls = obj.getClass();
|
||||
|
||||
@@ -811,7 +840,9 @@ public class FlatStylingSupport
|
||||
infos.put( keyPrefix.concat( e.getKey() ), e.getValue() );
|
||||
}
|
||||
|
||||
public static Object getAnnotatedStyleableValue( Object obj, String key ) {
|
||||
public static Object getAnnotatedStyleableValue( Object obj, String key )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
String fieldName = keyToFieldName( key );
|
||||
Class<?> cls = obj.getClass();
|
||||
|
||||
@@ -878,7 +909,9 @@ public class FlatStylingSupport
|
||||
extends LinkedHashMap<K,V>
|
||||
{
|
||||
@Override
|
||||
public V put( K key, V value ) {
|
||||
public V put( K key, V value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
V oldValue = super.put( key, value );
|
||||
if( oldValue != null )
|
||||
throw new IllegalArgumentException( "duplicate key '" + key + "'" );
|
||||
|
||||
@@ -50,12 +50,15 @@ public class UIDefaultsLoaderAccessor
|
||||
public static Object NULL = ValueType.NULL;
|
||||
public static Object LAZY = ValueType.LAZY;
|
||||
|
||||
public static String resolveValue( String value, Function<String, String> propertiesGetter ) {
|
||||
public static String resolveValue( String value, Function<String, String> propertiesGetter )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
return UIDefaultsLoader.resolveValue( value, propertiesGetter );
|
||||
}
|
||||
|
||||
public static Object parseValue( String key, String value, Object[] resultValueType,
|
||||
Function<String, String> resolver )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
ValueType[] resultValueType2 = new ValueType[1];
|
||||
Object result = UIDefaultsLoader.parseValue( key, value, null,
|
||||
@@ -64,7 +67,9 @@ public class UIDefaultsLoaderAccessor
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int parseColorRGBA( String value ) {
|
||||
public static int parseColorRGBA( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
return UIDefaultsLoader.parseColorRGBA( value );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ class FlatSyntaxTextAreaActions
|
||||
dialog.setVisible( true );
|
||||
|
||||
lastLocation = dialog.getLocation();
|
||||
} catch( BadLocationException | IndexOutOfBoundsException | NumberFormatException ex ) {
|
||||
} catch( BadLocationException | IndexOutOfBoundsException | IllegalArgumentException ex ) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,9 @@ class FlatThemePropertiesSupport
|
||||
this.basePropertyProvider = basePropertyProvider;
|
||||
}
|
||||
|
||||
private String resolveValue( String value ) {
|
||||
private String resolveValue( String value )
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
return UIDefaultsLoaderAccessor.resolveValue( value, propertiesGetter );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user