APIdia Launch Partner
Top Description Fields Constructors Methods
javafx.css

public abstract Class CssMetaData<S extends Styleable, V>

extends Object
Class Inheritance
Known Direct Subclasses
javafx.css.FontCssMetaData, javafx.css.StyleablePropertyFactory.SimpleCssMetaData, com.sun.javafx.css.SubCssMetaData, com.sun.javafx.css.TransitionDefinitionCssMetaData
Type Parameters
<S>
The type of Styleable
<V>
The type into which the parsed value is converted.
Imports
java.util.Collections, .List, javafx.scene.Node

A CssMetaData instance provides information about the CSS style and provides the hooks that allow CSS to set a property value. It encapsulates the CSS property name, the type into which the CSS value is converted, and the default value of the property.

CssMetaData is the bridge between a value that can be represented syntactically in a .css file, and a StyleableProperty. There is a one-to-one correspondence between a CssMetaData and a StyleableProperty. Typically, the CssMetaData of a Node will include the CssMetaData of its ancestors. For example, the CssMetaData of a Rectangle includes the CssMetaData of Shape and also of Node. During CSS processing, the CSS engine iterates over the Node's CssMetaData, looks up the parsed value of each property, converts the parsed value, and sets the value on the StyleableProperty.

The method Node#getCssMetaData() is called to obtain the List<CssMetaData>. This method is called frequently and it is prudent to return a static list rather than creating the list on each call. By convention, node classes that have CssMetaData will implement a static method getClassCssMetaData() and it is customary to have getCssMetaData() simply return getClassCssMetaData(). The purpose of getClassCssMetaData() is to allow sub-classes to easily include the CssMetaData of some ancestor.

The StyleablePropertyFactory greatly simplifies creating a StyleableProperty and its corresponding CssMetaData.

This example is a typical implementation.


private DoubleProperty gapProperty = new StyleableDoubleProperty(0) {
    @Override
     public CssMetaData<MyWidget,Number> getCssMetaData() {
         return GAP_META_DATA;
     }

     @Override
     public Object getBean() {
         return MyWidget.this;
     }

     @Override
     public String getName() {
         return "gap";
     }
};

private static final CssMetaData GAP_META_DATA =
    new CssMetaData<MyWidget,Number>("-my-gap", StyleConverter.getSizeConverter(), 0d) {

       @Override
       public boolean isSettable(MyWidget node) {
           return node.gapProperty == null || !node.gapProperty.isBound();
       }

       @Override
       public StyleableProperty<Number> getStyleableProperty(MyWidget node) {
           return (StyleableProperty<Number>)node.gapProperty;
       }
};

private static final List<CssMetaData<? extends Node, ?>> cssMetaDataList;
static {
    List<CssMetaData<? extends Node, ?>> temp =
        new ArrayList<CssMetaData<? extends Node, ?>>(Control.getClassCssMetaData());
    temp.add(GAP_META_DATA);
    cssMetaDataList = Collections.unmodifiableList(temp);
}

public static List<CssMetaData<? extends Node, ?>> getClassCssMetaData() {
    return cssMetaDataList;
}

@Override
public List<CssMetaData<? extends Node, ?>> getCssMetaData() {
    return getClassCssMetaData();
}
Since
JavaFX 8.0
See Also
javafx.css.StyleablePropertyFactory

Field Summary

Modifier and TypeField and Description
private final StyleConverter<?, V>
private final boolean
private final V
private final String
private final List<CssMetaData<? extends Styleable, ?>>

Constructor Summary

AccessConstructor and Description
protected
CssMetaData(final String
the CSS property
property
,
final StyleConverter<?, V>
the StyleConverter used to convert the CSS parsed value to a Java object.
converter
,
final V
The initial or default value of the corresponding StyleableProperty
initialValue
,
boolean
true if this property uses CSS inheritance
inherits
,
final List<CssMetaData<? extends Styleable, ?>>
the sub-properties of this property. For example, the -fx-font property has the sub-properties -fx-font-family, -fx-font-size, -fx-font-weight, and -fx-font-style.
subProperties
)

Construct a CssMetaData with the given parameters and no sub-properties.

protected
CssMetaData(final String
the CSS property
property
,
final StyleConverter<?, V>
the StyleConverter used to convert the CSS parsed value to a Java object.
converter
,
final V
The initial or default value of the corresponding StyleableProperty
initialValue
,
boolean
true if this property uses CSS inheritance
inherits
)

Construct a CssMetaData with the given parameters and no sub-properties.

protected
CssMetaData(final String
the CSS property
property
,
final StyleConverter<?, V>
the StyleConverter used to convert the CSS parsed value to a Java object.
converter
,
final V
The initial or default value of the corresponding StyleableProperty
initialValue
)

Construct a CssMetaData with the given parameters, inherit set to false and no sub-properties.

protected
CssMetaData(final String
the CSS property
property
,
final StyleConverter<?, V>
the StyleConverter used to convert the CSS parsed value to a Java object.
converter
)

Construct a CssMetaData with the given parameters, initialValue is null, inherit is set to false, and no sub-properties.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the obj is equaled, false otherwise
equals
(Object obj)

Overrides java.lang.Object.equals.

Two CssMetaData objects are considered to be equal if their property values are equal.

public final StyleConverter<?, V>

Returns:

the CSS converter
getConverter
()

Gets the CSS converter that handles conversion from a CSS value to a Java Object.

public V

Returns:

The initial value of the property, possibly null
getInitialValue
(S
the styleable
styleable
)

The initial value of a CssMetaData corresponds to the default value of the StyleableProperty in code.

public final String

Returns:

the CSS property name
getProperty
()

Gets the CSS property name.

public abstract StyleableProperty<V>

Returns:

The StyleableProperty corresponding to this CssMetaData for the given Styleable
getStyleableProperty
(S
The Styleable for which the property is returned
styleable
)

Return the corresponding StyleableProperty for the given Node.

public final List<CssMetaData<? extends Styleable, ?>>

Returns:

the list of sub-properties
getSubProperties
()

The sub-properties refers to the constituent properties of this property, if any.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public final boolean

Returns:

false by default unless inherits is true
isInherits
()

If true, the value of this property is the same as the parent's computed value of this property.

public abstract boolean

Returns:

true if the property can be set.
isSettable
(S
The Styleable on which the property value is being set
styleable
)

Check to see if the corresponding property on the given Node is settable.

public void
set(S
The Styleable on which the property value is being set
styleable
,
V
The value to which the property is set
value
,
StyleOrigin
the origin
origin
)
Deprecated since 8. This method is no longer called from CSS code.

Sets the value of the corresponding property on the given Node.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

converterback to summary
private final StyleConverter<?, V> converter
inheritsback to summary
private final boolean inherits
initialValueback to summary
private final V initialValue
propertyback to summary
private final String property
subPropertiesback to summary
private final List<CssMetaData<? extends Styleable, ?>> subProperties

Constructor Detail

CssMetaDataback to summary
protected CssMetaData(final String property, final StyleConverter<?, V> converter, final V initialValue, boolean inherits, final List<CssMetaData<? extends Styleable, ?>> subProperties)

Construct a CssMetaData with the given parameters and no sub-properties.

Parameters
property:String

the CSS property

converter:StyleConverter<?, V>

the StyleConverter used to convert the CSS parsed value to a Java object.

initialValue:V

The initial or default value of the corresponding StyleableProperty

inherits:boolean

true if this property uses CSS inheritance

subProperties:List<CssMetaData<? extends Styleable, ?>>

the sub-properties of this property. For example, the -fx-font property has the sub-properties -fx-font-family, -fx-font-size, -fx-font-weight, and -fx-font-style.

CssMetaDataback to summary
protected CssMetaData(final String property, final StyleConverter<?, V> converter, final V initialValue, boolean inherits)

Construct a CssMetaData with the given parameters and no sub-properties.

Parameters
property:String

the CSS property

converter:StyleConverter<?, V>

the StyleConverter used to convert the CSS parsed value to a Java object.

initialValue:V

The initial or default value of the corresponding StyleableProperty

inherits:boolean

true if this property uses CSS inheritance

CssMetaDataback to summary
protected CssMetaData(final String property, final StyleConverter<?, V> converter, final V initialValue)

Construct a CssMetaData with the given parameters, inherit set to false and no sub-properties.

Parameters
property:String

the CSS property

converter:StyleConverter<?, V>

the StyleConverter used to convert the CSS parsed value to a Java object.

initialValue:V

The initial or default value of the corresponding StyleableProperty

CssMetaDataback to summary
protected CssMetaData(final String property, final StyleConverter<?, V> converter)

Construct a CssMetaData with the given parameters, initialValue is null, inherit is set to false, and no sub-properties.

Parameters
property:String

the CSS property

converter:StyleConverter<?, V>

the StyleConverter used to convert the CSS parsed value to a Java object.

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Two CssMetaData objects are considered to be equal if their property values are equal.

Returns:boolean

true if the obj is equaled, false otherwise

Annotations
@Override
getConverterback to summary
public final StyleConverter<?, V> getConverter()

Gets the CSS converter that handles conversion from a CSS value to a Java Object.

Returns:StyleConverter<?, V>

the CSS converter

getInitialValueback to summary
public V getInitialValue(S styleable)

The initial value of a CssMetaData corresponds to the default value of the StyleableProperty in code. For example, the default value of Shape.fill is Color.BLACK and the initialValue of Shape.StyleableProperties.FILL is also Color.BLACK.

There may be exceptions to this, however. The initialValue may depend on the state of the Node. A ScrollBar has a default orientation of horizontal. If the ScrollBar is vertical, however, this method should return Orientation.VERTICAL. Otherwise, a vertical ScrollBar would be incorrectly set to a horizontal ScrollBar when the initial value is applied.

Parameters
styleable:S

the styleable

Returns:V

The initial value of the property, possibly null

getPropertyback to summary
public final String getProperty()

Gets the CSS property name.

Returns:String

the CSS property name

getStyleablePropertyback to summary
public abstract StyleableProperty<V> getStyleableProperty(S styleable)

Return the corresponding StyleableProperty for the given Node. Note that calling this method will cause the property to be expanded.

Parameters
styleable:S

The Styleable for which the property is returned

Returns:StyleableProperty<V>

The StyleableProperty corresponding to this CssMetaData for the given Styleable

getSubPropertiesback to summary
public final List<CssMetaData<? extends Styleable, ?>> getSubProperties()

The sub-properties refers to the constituent properties of this property, if any. For example, "-fx-font-weight" is sub-property of "-fx-font".

Returns:List<CssMetaData<? extends Styleable, ?>>

the list of sub-properties

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
isInheritsback to summary
public final boolean isInherits()

If true, the value of this property is the same as the parent's computed value of this property.

Returns:boolean

false by default unless inherits is true

See Also
CSS Inheritance
isSettableback to summary
public abstract boolean isSettable(S styleable)

Check to see if the corresponding property on the given Node is settable. This method is called before any styles are looked up for the given property. It is abstract so that the code can check if the property is settable without expanding the property. Generally, the property is settable if it is not null or is not bound.

Parameters
styleable:S

The Styleable on which the property value is being set

Returns:boolean

true if the property can be set.

setback to summary
public void set(S styleable, V value, StyleOrigin origin)

Deprecated

since 8.

This method is no longer called from CSS code. Use StyleableProperty#applyStyle(javafx.css.StyleOrigin, java.lang.Object)

Sets the value of the corresponding property on the given Node.

Parameters
styleable:S

The Styleable on which the property value is being set

value:V

The value to which the property is set

origin:StyleOrigin

the origin

Annotations
@Deprecated
since:8
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override