Class CssMetaData<S extends Styleable,V>
- Type Parameters:
-
S- The type of Styleable -
V- The type into which the parsed value is converted.
- Direct Known Subclasses:
FontCssMetaData
public abstract class CssMetaData<S extends Styleable,V> extends Object
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:
Constructor Summary
| Modifier | Constructor | Description |
|---|---|---|
protected |
Construct a CssMetaData with the given parameters, initialValue is null, inherit is set to false, and no sub-properties. |
|
protected |
Construct a CssMetaData with the given parameters, inherit set to false and no sub-properties. |
|
protected |
Construct a CssMetaData with the given parameters and no sub-properties. |
|
protected |
Construct a CssMetaData with the given parameters and no sub-properties. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
equals |
Two CssMetaData objects are considered to be equal if their property values are equal. |
final StyleConverter<?, |
getConverter() |
Gets the CSS converter that handles conversion from a CSS value to a Java Object. |
V |
getInitialValue |
The initial value of a CssMetaData corresponds to the default value of the StyleableProperty in code. |
final String |
getProperty() |
Gets the CSS property name. |
abstract StyleableProperty<V> |
getStyleableProperty |
Return the corresponding StyleableProperty for the given Node. |
final List<CssMetaData<? extends Styleable, |
getSubProperties() |
The sub-properties refers to the constituent properties of this property, if any. |
final boolean |
isInherits() |
If true, the value of this property is the same as the parent's computed value of this property. |
abstract boolean |
isSettable |
Check to see if the corresponding property on the given Node is settable. |
void |
set |
Deprecated. This method is no longer called from CSS code. |
Constructor Details
CssMetaData
protected CssMetaData(String property, StyleConverter<?,V> converter, V initialValue, boolean inherits, List<CssMetaData<? extends Styleable,?>> subProperties)
- Parameters:
-
property- the CSS property -
converter- the StyleConverter used to convert the CSS parsed value to a Java object. -
initialValue- The initial or default value of the corresponding StyleableProperty -
inherits- true if this property uses CSS inheritance -
subProperties- 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.
CssMetaData
protected CssMetaData(String property, StyleConverter<?,V> converter, V initialValue, boolean inherits)
- Parameters:
-
property- the CSS property -
converter- the StyleConverter used to convert the CSS parsed value to a Java object. -
initialValue- The initial or default value of the corresponding StyleableProperty -
inherits- true if this property uses CSS inheritance
CssMetaData
protected CssMetaData(String property, StyleConverter<?,V> converter, V initialValue)
- Parameters:
-
property- the CSS property -
converter- the StyleConverter used to convert the CSS parsed value to a Java object. -
initialValue- The initial or default value of the corresponding StyleableProperty
CssMetaData
protected CssMetaData(String property, StyleConverter<?,V> converter)
- Parameters:
-
property- the CSS property -
converter- the StyleConverter used to convert the CSS parsed value to a Java object.
Method Details
set
@Deprecated(since="8") public void set(S styleable, V value, StyleOrigin origin)
StyleableProperty.applyStyle(javafx.css.StyleOrigin, java.lang.Object)
- Parameters:
-
styleable- The Styleable on which the property value is being set -
value- The value to which the property is set -
origin- the origin
isSettable
public abstract boolean isSettable(S styleable)
- Parameters:
-
styleable- The Styleable on which the property value is being set - Returns:
- true if the property can be set.
getStyleableProperty
public abstract StyleableProperty<V> getStyleableProperty(S styleable)
StyleableProperty for the given Node. Note that calling this method will cause the property to be expanded.- Parameters:
-
styleable- The Styleable for which the property is returned - Returns:
- The StyleableProperty corresponding to this CssMetaData for the given Styleable
getProperty
public final String getProperty()
- Returns:
- the CSS property name
getConverter
public final StyleConverter<?,V> getConverter()
- Returns:
- the CSS converter
getInitialValue
public V getInitialValue(S styleable)
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- the styleable - Returns:
- The initial value of the property, possibly null
getSubProperties
public final List<CssMetaData<? extends Styleable,?>> getSubProperties()
- Returns:
- the list of sub-properties
isInherits
public final boolean isInherits()
- Returns:
- false by default unless inherits is true
- See Also:
equals
public boolean equals(Object obj)
property values are equal.- Overrides:
-
equalsin classObject - Returns:
- true if the obj is equaled, false otherwise
© 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.