S
- The type of StyleableV
- The type into which the parsed value is converted.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();
}
StyleablePropertyFactory
Modifier | Constructor and Description |
---|---|
protected |
CssMetaData(String property,
StyleConverter<?,V> converter)
Construct a CssMetaData with the given parameters, initialValue is
null, inherit is set to false, and no sub-properties.
|
protected |
CssMetaData(String property,
StyleConverter<?,V> converter,
V initialValue)
Construct a CssMetaData with the given parameters, inherit set to
false and no sub-properties.
|
protected |
CssMetaData(String property,
StyleConverter<?,V> converter,
V initialValue,
boolean inherits)
Construct a CssMetaData with the given parameters and no sub-properties.
|
protected |
CssMetaData(String property,
StyleConverter<?,V> converter,
V initialValue,
boolean inherits,
List<CssMetaData<? extends Styleable,?>> subProperties)
Construct a CssMetaData with the given parameters and no sub-properties.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Two CssMetaData objects are considered to be equal if their
property values are equal. |
StyleConverter<?,V> |
getConverter() |
V |
getInitialValue(S styleable)
The initial value of a CssMetaData corresponds to the default
value of the StyleableProperty in code.
|
String |
getProperty() |
abstract StyleableProperty<V> |
getStyleableProperty(S styleable)
Return the corresponding
StyleableProperty for the given Node. |
List<CssMetaData<? extends Styleable,?>> |
getSubProperties()
The sub-properties refers to the constituent properties of this property,
if any.
|
int |
hashCode() |
boolean |
isInherits()
If true, the value of this property is the same as
the parent's computed value of this property.
|
abstract boolean |
isSettable(S styleable)
Check to see if the corresponding property on the given Node is
settable.
|
void |
set(S styleable,
V value,
StyleOrigin origin)
Deprecated.
This method is no longer called from CSS code.
Use
StyleableProperty.applyStyle(javafx.css.StyleOrigin, java.lang.Object) |
String |
toString() |
protected CssMetaData(String property, StyleConverter<?,V> converter, V initialValue, boolean inherits, List<CssMetaData<? extends Styleable,?>> subProperties)
property
- the CSS propertyconverter
- the StyleConverter used to convert the CSS parsed value to a Java object.initialValue
- The initial or default value of the corresponding StyleablePropertyinherits
- true if this property uses CSS inheritancesubProperties
- 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.protected CssMetaData(String property, StyleConverter<?,V> converter, V initialValue, boolean inherits)
property
- the CSS propertyconverter
- the StyleConverter used to convert the CSS parsed value to a Java object.initialValue
- The initial or default value of the corresponding StyleablePropertyinherits
- true if this property uses CSS inheritanceprotected CssMetaData(String property, StyleConverter<?,V> converter, V initialValue)
property
- the CSS propertyconverter
- the StyleConverter used to convert the CSS parsed value to a Java object.initialValue
- The initial or default value of the corresponding StyleablePropertyprotected CssMetaData(String property, StyleConverter<?,V> converter)
property
- the CSS propertyconverter
- the StyleConverter used to convert the CSS parsed value to a Java object.@Deprecated public void set(S styleable, V value, StyleOrigin origin)
StyleableProperty.applyStyle(javafx.css.StyleOrigin, java.lang.Object)
styleable
- The Styleable on which the property value is being setvalue
- The value to which the property is setpublic abstract boolean isSettable(S styleable)
styleable
- The Styleable on which the property value is being setpublic abstract StyleableProperty<V> getStyleableProperty(S styleable)
StyleableProperty
for the given Node.
Note that calling this method will cause the property to be expanded.styleable
- The Styleable for which the property is returnedpublic final String getProperty()
public final StyleConverter<?,V> getConverter()
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.
public final List<CssMetaData<? extends Styleable,?>> getSubProperties()
public final boolean isInherits()
public boolean equals(Object obj)
property
values are equal.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.