Class StyleConverter<F,T>
java.lang.Object
javafx.css.StyleConverter<F,T>
- Type Parameters:
-
F- the type of the parsed value -
T- the converted type of the ParsedValueImpl
- Direct Known Subclasses:
-
BooleanConverter,ColorConverter,CursorConverter,DeriveColorConverter,DeriveSizeConverter,DurationConverter,DurationConverter.SequenceConverter,EffectConverter,EnumConverter,FontConverter,FontConverter.FontSizeConverter,FontConverter.FontStyleConverter,FontConverter.FontWeightConverter,InsetsConverter,InsetsConverter.SequenceConverter,LadderConverter,PaintConverter,PaintConverter.ImagePatternConverter,PaintConverter.LinearGradientConverter,PaintConverter.RadialGradientConverter,PaintConverter.RepeatingImagePatternConverter,PaintConverter.SequenceConverter,ShapeConverter,SizeConverter,SizeConverter.SequenceConverter,StopConverter,StringConverter,StringConverter.SequenceConverter,URLConverter,URLConverter.SequenceConverter
public class StyleConverter<F,T> extends Object
StyleConverter converts
ParsedValue<F,T> from type F to type T. The CssMetaData API requires a StyleConverter which is used when computing a value for the StyleableProperty. There are a number of predefined converters which are accessible by the static methods of this class. F is the type of the parsed value and T is the converted type of the ParsedValueImpl. For example, a converter from String to Color would be declared public Color convert(ParsedValueImpl<String,Color> value, Font font)
- Since:
- JavaFX 8.0
- See Also:
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
static class |
StyleConverter.StringStore |
The StringStore class. |
Constructor Summary
| Constructor | Description |
|---|---|
StyleConverter() |
Creates a StyleConverter. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
protected void |
cacheValue |
Cache the value for the specified key. |
static void |
clearCache() |
Clear the cache. |
T |
convert |
Convert from the constituent values to the target property type. |
T |
convert |
Convert from the parsed CSS value to the target property type. |
static StyleConverter |
getBooleanConverter() |
Return a StyleConverter that converts "true" or "false" to Boolean. |
protected T |
getCachedValue |
Get the cached value for the specified key. |
static StyleConverter |
getColorConverter() |
Return a StyleConverter that converts a String representation of a web color to a Color. |
static StyleConverter |
getDurationConverter() |
Return a StyleConverter that converts a String representation of a duration to a Duration. |
static StyleConverter |
getEffectConverter() |
Return a StyleConverter that converts a parsed representation of an Effect to an Effect
|
static <E extends Enum<E>> |
getEnumConverter |
Return a StyleConverter that converts a String representation of an Enum to an Enum. |
static StyleConverter |
getFontConverter() |
Return a StyleConverter that converts a parsed representation of a Font to an Font. |
static StyleConverter |
getInsetsConverter() |
Return a StyleConverter that converts a [<length> | <percentage>]{1,4} to an Insets. |
static StyleConverter |
getPaintConverter() |
Return a StyleConverter that converts a parsed representation of a Paint to a Paint. |
static StyleConverter |
getSizeConverter() |
CSS length and number values are parsed into a Size object that is converted to a Number before the value is applied. |
static StyleConverter |
getStringConverter() |
A converter for quoted strings which may have embedded unicode characters. |
static StyleConverter |
getUrlConverter() |
A converter for URL strings. |
static StyleConverter |
readBinary |
Read binary data stream. |
void |
writeBinary |
Write binary data. |
Constructor Details
StyleConverter
public StyleConverter()
Creates a
StyleConverter.Method Details
convert
public T convert(ParsedValue<F,T> value, Font font)
Convert from the parsed CSS value to the target property type.
- Parameters:
-
value- TheParsedValueto convert -
font- TheFontto use when converting a relative value. - Returns:
- the converted target property type
getBooleanConverter
public static StyleConverter<String,Boolean> getBooleanConverter()
Return a
StyleConverter that converts "true" or "false" to Boolean.- Returns:
- A
StyleConverterthat converts "true" or "false" toBoolean - See Also:
getDurationConverter
getColorConverter
public static StyleConverter<String,Color> getColorConverter()
Return a
StyleConverter that converts a String representation of a web color to a Color.- Returns:
- A
StyleConverterthat converts a String representation of a web color to aColor - See Also:
getEffectConverter
public static StyleConverter<ParsedValue[],Effect> getEffectConverter()
Return a
StyleConverter that converts a parsed representation of an Effect to an Effect
- Returns:
- A
StyleConverterthat converts a parsed representation of anEffectto anEffect - See Also:
getEnumConverter
public static <E extends Enum<E>> StyleConverter<String,E> getEnumConverter(Class<E> enumClass)
Return a
StyleConverter that converts a String representation of an Enum to an Enum.- Type Parameters:
-
E- the type of theEnum - Parameters:
-
enumClass- the enum Class - Returns:
- A
StyleConverterthat converts a String representation of anEnumto anEnum - See Also:
getFontConverter
public static StyleConverter<ParsedValue[],Font> getFontConverter()
Return a
StyleConverter that converts a parsed representation of a Font to an Font.- Returns:
- A
StyleConverterthat converts a parsed representation of aFontto anFont - See Also:
getInsetsConverter
public static StyleConverter<ParsedValue[],Insets> getInsetsConverter()
Return a
StyleConverter that converts a [<length> | <percentage>]{1,4} to an Insets.- Returns:
- A
StyleConverterthat converts a [<length> | <percentage>]{1,4} to anInsets
getPaintConverter
public static StyleConverter<ParsedValue<?,Paint>,Paint> getPaintConverter()
Return a
StyleConverter that converts a parsed representation of a Paint to a Paint.- Returns:
- A
StyleConverterthat converts a parsed representation of aPaintto aPaint
getSizeConverter
public static StyleConverter<?,Number> getSizeConverter()
CSS length and number values are parsed into a Size object that is converted to a Number before the value is applied. If the property is a
Number type other than Double, the set method of (CssMetaData can be overridden to convert the Number to the correct type. For example, if the property is an IntegerProperty:
@Override public void set(MyNode node, Number value, Origin origin) {
if (value != null) {
super.set(node, value.intValue(), origin);
} else {
super.set(node, value, origin);
}
}
- Returns:
- A
StyleConverterthat converts a parsed representation of a CSS length or number value to aNumberthat is an instance ofDouble
getStringConverter
public static StyleConverter<String,String> getStringConverter()
A converter for quoted strings which may have embedded unicode characters.
- Returns:
- A
StyleConverterthat converts a representation of a CSS string value to aString
getUrlConverter
public static StyleConverter<ParsedValue[],String> getUrlConverter()
A converter for URL strings.
- Returns:
- A
StyleConverterthat converts a representation of a CSS URL value to aString
convert
public T convert(Map<CssMetaData<? extends Styleable,?>,Object> convertedValues)
Convert from the constituent values to the target property type. Implemented by Types that have Keys with subKeys.
- Parameters:
-
convertedValues- the constituent values - Returns:
- the target property type
- Since:
- 9
writeBinary
public void writeBinary(DataOutputStream os, StyleConverter.StringStore sstore) throws IOException
Write binary data.
- Parameters:
-
os- the data output stream -
sstore- the string store - Throws:
-
IOException- the exception - Since:
- 9
clearCache
public static void clearCache()
Clear the cache.
- Since:
- 9
getCachedValue
protected T getCachedValue(ParsedValue key)
Get the cached value for the specified key.
- Parameters:
-
key- the key - Returns:
- the cached value
- Since:
- 9
cacheValue
protected void cacheValue(ParsedValue key, Object value)
Cache the value for the specified key.
- Parameters:
-
key- the key -
value- the value - Since:
- 9
readBinary
public static StyleConverter<?,?> readBinary(DataInputStream is, String[] strings) throws IOException
Read binary data stream.
- Parameters:
-
is- the data input stream -
strings- the strings - Returns:
- the style converter
- Throws:
-
IOException- the exception - Since:
- 9
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.