javafx.css

## Class StyleConverter<F,T>

- java.lang.Object
- - javafx.css.StyleConverter<F,T>

-     public class StyleConverter<F,T>
      extends Object

  Converter converts `ParsedValue&tl;F,T&gt;` 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.
  Since:
    JavaFX 8.0
  See Also:
    `ParsedValue`, `StyleableProperty`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StyleConverter()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `T` | `convert(ParsedValue<F,T> value, Font font)` Convert from the parsed CSS value to the target property type.
    `static StyleConverter<String,Boolean>` | `getBooleanConverter()`
    `static StyleConverter<String,Color>` | `getColorConverter()`
    `static StyleConverter<?,Duration>` | `getDurationConverter()`
    `static StyleConverter<ParsedValue[],Effect>` | `getEffectConverter()`
    `static <E extends Enum<E>> StyleConverter<String,? extends Enum<?>>` | `getEnumConverter(Class<E> enumClass)`
    `static StyleConverter<ParsedValue[],Font>` | `getFontConverter()`
    `static StyleConverter<ParsedValue[],Insets>` | `getInsetsConverter()`
    `static StyleConverter<ParsedValue<?,Paint>,Paint>` | `getPaintConverter()`
    `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.
    `static StyleConverter<String,String>` | `getStringConverter()` A converter for quoted strings which may have embedded unicode characters.
    `static StyleConverter<ParsedValue[],String>` | `getUrlConverter()` A converter for URL strings.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StyleConverter

          public StyleConverter()

  - ### Method Detail

    - #### convert

          public T convert(ParsedValue<F,T> value,
                           Font font)

      Convert from the parsed CSS value to the target property type.
      Parameters:
        `value` - The `ParsedValue` to convert
        `font` - The `Font` to use when converting a relative value.

    - #### getBooleanConverter

          public static StyleConverter<String,Boolean> getBooleanConverter()

      Returns:
        A `StyleConverter` that converts "true" or "false" to `Boolean`
      See Also:
        `Boolean.valueOf(java.lang.String)`

    - #### getDurationConverter

          public static StyleConverter<?,Duration> getDurationConverter()

      Returns:
        A `StyleConverter` that converts a String representation of a duration to a `Duration`
      Since:
        JavaFX 8u40

    - #### getColorConverter

          public static StyleConverter<String,Color> getColorConverter()

      Returns:
        A `StyleConverter` that converts a String representation of a web color to a `Color`
      See Also:
        `Color.web(java.lang.String)`

    - #### getEffectConverter

          public static StyleConverter<ParsedValue[],Effect> getEffectConverter()

      Returns:
        A `StyleConverter` that converts a parsed representation of an `Effect` to an `Effect`
      See Also:
        `Effect`

    - #### getEnumConverter

          public static <E extends Enum<E>> StyleConverter<String,? extends Enum<?>> getEnumConverter(Class<E> enumClass)

      Returns:
        A `StyleConverter` that converts a String representation of an `Enum` to an `Enum`
      See Also:
        `Enum.valueOf(java.lang.Class, java.lang.String)`

    - #### getFontConverter

          public static StyleConverter<ParsedValue[],Font> getFontConverter()

      Returns:
        A `StyleConverter` that converts a parsed representation of a `Font` to an `Font`.
      See Also:
        `Font.font(java.lang.String, javafx.scene.text.FontWeight, javafx.scene.text.FontPosture, double)`

    - #### getInsetsConverter

          public static StyleConverter<ParsedValue[],Insets> getInsetsConverter()

      Returns:
        A `StyleConverter` that converts a [<length> | <percentage>]{1,4} to an `Insets`.

    - #### getPaintConverter

          public static StyleConverter<ParsedValue<?,Paint>,Paint> getPaintConverter()

      Returns:
        A `StyleConverter` that converts a parsed representation of a `Paint` to a `Paint`.

    - #### 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 over-ridden 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 `StyleConverter` that converts a parsed representation of a CSS length or number value to a `Number` that is an instance of `Double`.

    - #### getStringConverter

          public static StyleConverter<String,String> getStringConverter()

      A converter for quoted strings which may have embedded unicode characters.
      Returns:
        A `StyleConverter` that converts a representation of a CSS string value to a `String`.

    - #### getUrlConverter

          public static StyleConverter<ParsedValue[],String> getUrlConverter()

      A converter for URL strings.
      Returns:
        A `StyleConverter` that converts a representation of a CSS URL value to a `String`.

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2008, 2017, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.