F
- the type of the parsed valueT
- the converted type of the ParsedValueImplpublic class StyleConverter<F,T>
extends java.lang.Object
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)
ParsedValue
,
StyleableProperty
Modifier and Type | Class and Description |
---|---|
static class |
StyleConverter.StringStore
The StringStore class
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<ParsedValue,java.lang.Object> |
cache |
private static java.util.Map<java.lang.String,StyleConverter<?,?>> |
tmap |
Constructor and Description |
---|
StyleConverter() |
Modifier and Type | Method and Description |
---|---|
protected void |
cacheValue(ParsedValue key,
java.lang.Object value)
Cache the value for the specified key.
|
static void |
clearCache()
Clear the cache.
|
T |
convert(java.util.Map<CssMetaData<? extends Styleable,?>,java.lang.Object> convertedValues)
Convert from the constituent values to the target property type.
|
T |
convert(ParsedValue<F,T> value,
Font font)
Convert from the parsed CSS value to the target property type.
|
static StyleConverter<java.lang.String,java.lang.Boolean> |
getBooleanConverter()
Return a
StyleConverter that converts "true" or "false" to Boolean . |
protected T |
getCachedValue(ParsedValue key)
Get the cached value for the specified key.
|
static StyleConverter<java.lang.String,Color> |
getColorConverter()
Return a
StyleConverter that converts a String representation of
a web color to a Color . |
static StyleConverter<?,Duration> |
getDurationConverter()
Return a
StyleConverter that converts a String representation of
a duration to a Duration . |
static StyleConverter<ParsedValue[],Effect> |
getEffectConverter()
Return a
StyleConverter that converts a parsed representation
of an Effect to an Effect |
static <E extends java.lang.Enum<E>> |
getEnumConverter(java.lang.Class<E> enumClass)
Return a
StyleConverter that converts a String representation
of an Enum to an Enum . |
static StyleConverter<ParsedValue[],Font> |
getFontConverter()
Return a
StyleConverter that converts a parsed representation
of a Font to an Font . |
static StyleConverter<ParsedValue[],Insets> |
getInsetsConverter()
Return a
StyleConverter that converts a [<length> |
<percentage>]{1,4} to an Insets . |
(package private) static StyleConverter<?,?> |
getInstance(java.lang.String converterClass) |
static StyleConverter<ParsedValue<?,Paint>,Paint> |
getPaintConverter()
Return a
StyleConverter that converts a parsed representation
of a Paint to a Paint . |
static StyleConverter<?,java.lang.Number> |
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<java.lang.String,java.lang.String> |
getStringConverter()
A converter for quoted strings which may have embedded unicode characters.
|
static StyleConverter<ParsedValue[],java.lang.String> |
getUrlConverter()
A converter for URL strings.
|
static StyleConverter<?,?> |
readBinary(java.io.DataInputStream is,
java.lang.String[] strings)
Read binary data stream.
|
void |
writeBinary(java.io.DataOutputStream os,
StyleConverter.StringStore sstore)
Write binary data.
|
private static java.util.Map<ParsedValue,java.lang.Object> cache
private static java.util.Map<java.lang.String,StyleConverter<?,?>> tmap
public T convert(ParsedValue<F,T> value, Font font)
value
- The ParsedValue
to convertfont
- The Font
to use when converting a
relative
value.public static StyleConverter<java.lang.String,java.lang.Boolean> getBooleanConverter()
StyleConverter
that converts "true" or "false" to Boolean
.StyleConverter
that converts "true" or "false" to Boolean
Boolean.valueOf(java.lang.String)
public static StyleConverter<?,Duration> getDurationConverter()
StyleConverter
that converts a String representation of
a duration to a Duration
.StyleConverter
that converts a String
representation of a duration to a Duration
public static StyleConverter<java.lang.String,Color> getColorConverter()
StyleConverter
that converts a String representation of
a web color to a Color
.StyleConverter
that converts a String
representation of a web color to a Color
Color#web(java.lang.String)
public static StyleConverter<ParsedValue[],Effect> getEffectConverter()
StyleConverter
that converts a parsed representation
of an Effect
to an Effect
StyleConverter
that converts a parsed representation
of an Effect
to an Effect
Effect
public static <E extends java.lang.Enum<E>> StyleConverter<java.lang.String,E> getEnumConverter(java.lang.Class<E> enumClass)
StyleConverter
that converts a String representation
of an Enum
to an Enum
.E
- the type of the Enum
enumClass
- the enum ClassStyleConverter
that converts a String representation
of an Enum
to an Enum
Enum.valueOf(java.lang.Class, java.lang.String)
public static StyleConverter<ParsedValue[],Font> getFontConverter()
StyleConverter
that converts a parsed representation
of a Font
to an Font
.StyleConverter
that converts a parsed representation
of a Font
to an Font
Font#font(java.lang.String, javafx.scene.text.FontWeight, javafx.scene.text.FontPosture, double)
public static StyleConverter<ParsedValue[],Insets> getInsetsConverter()
StyleConverter
that converts a [<length> |
<percentage>]{1,4} to an Insets
.StyleConverter
that converts a [<length> |
<percentage>]{1,4} to an Insets
public static StyleConverter<ParsedValue<?,Paint>,Paint> getPaintConverter()
StyleConverter
that converts a parsed representation
of a Paint
to a Paint
.StyleConverter
that converts a parsed representation
of a Paint
to a Paint
public static StyleConverter<?,java.lang.Number> getSizeConverter()
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);
}
}
StyleConverter
that converts a parsed representation
of a CSS length or number value to a Number
that is an instance
of Double
public static StyleConverter<java.lang.String,java.lang.String> getStringConverter()
StyleConverter
that converts a representation of a
CSS string value to a String
public static StyleConverter<ParsedValue[],java.lang.String> getUrlConverter()
StyleConverter
that converts a representation of a
CSS URL value to a String
public T convert(java.util.Map<CssMetaData<? extends Styleable,?>,java.lang.Object> convertedValues)
convertedValues
- the constituent valuespublic void writeBinary(java.io.DataOutputStream os, StyleConverter.StringStore sstore) throws java.io.IOException
os
- the data output streamsstore
- the string storejava.io.IOException
- the exceptionpublic static void clearCache()
protected T getCachedValue(ParsedValue key)
key
- the keyprotected void cacheValue(ParsedValue key, java.lang.Object value)
key
- the keyvalue
- the valuepublic static StyleConverter<?,?> readBinary(java.io.DataInputStream is, java.lang.String[] strings) throws java.io.IOException
is
- the data input streamstrings
- the stringsjava.io.IOException
- the exceptionstatic StyleConverter<?,?> getInstance(java.lang.String converterClass)