/* * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javafx.css; import javafx.css.converter.EnumConverter; import javafx.beans.property.Property; import javafx.geometry.Insets; import javafx.scene.effect.Effect; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import javafx.scene.text.Font; import javafx.util.Duration; import javafx.util.Pair; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.function.Function; /** * Methods for creating instances of StyleableProperty with corresponding CssMetaData created behind the scenes. * These methods greatly reduce the amount of boiler-plate code needed to implement the StyleableProperty * and CssMetaData. * These methods take a Function<? extends Styleable, StyleableProperty<?>> which returns a * reference to the property itself. See the example below. Note that for efficient use of memory and for better * CSS performance, creating the StyleablePropertyFactory as a static member, as shown below, is recommended. *
 public final class MyButton extends Button {

     private static final{@literal StyleablePropertyFactory} FACTORY = new{@literal StyleablePropertyFactory<>}(Button.getClassCssMetaData());

     MyButton(String labelText) {
         super(labelText);
         getStyleClass().add("my-button");
     }

     // Typical JavaFX property implementation
     public{@literal ObservableValue} selectedProperty() { return ({@literal ObservableValue})selected; }
     public final boolean isSelected() { return selected.getValue(); }
     public final void setSelected(boolean isSelected) { selected.setValue(isSelected); }

     // StyleableProperty implementation reduced to one line
     private final{@literal StyleableProperty} selected =
         FACTORY.createStyleableBooleanProperty(this, "selected", "-my-selected", s{@literal ->} s.selected);

    {@literal @}Override
     public{@literal List>} getControlCssMetaData() {
         return FACTORY.getCssMetaData();
     }

 }
 * 
*

The example above is the simplest use of StyleablePropertyFactory. But, this use does not provide the * static CssMetaData that is useful for {@code getClassCssMetaData()}, which is described in the javadoc for * {@link CssMetaData)}. Static CssMetaData can, however, be created via StyleablePropertyFactory methods * and will be returned by the methods which create StyleableProperty instances, as the example below illustrates. * Note that the static method getClassCssMetaData() is a convention used throughout the JavaFX code base * but the getClassCssMetaData() method itself is not used at runtime.

*
 public final class MyButton extends Button {

     private static final{@literal StyleablePropertyFactory} FACTORY =
         new{@literal StyleablePropertyFactory<>}(Button.getClassCssMetaData());

     private static final{@literal CssMetaData} SELECTED =
         FACTORY.createBooleanCssMetaData("-my-selected", s{@literal ->} s.selected, false, false);

     MyButton(String labelText) {
         super(labelText);
         getStyleClass().add("my-button");
     }

     // Typical JavaFX property implementation
     public{@literal ObservableValue} selectedProperty() { return ({@literal ObservableValue})selected; }
     public final boolean isSelected() { return selected.getValue(); }
     public final void setSelected(boolean isSelected) { selected.setValue(isSelected); }

     // StyleableProperty implementation reduced to one line
     private final{@literal StyleableProperty} selected =
         new SimpleStyleableBooleanProperty(SELECTED, this, "selected");

     public static {@literal List>} getClassCssMetaData() {
         return FACTORY.getCssMetaData();
     }

     {@literal @}Override
     public{@literal List>} getControlCssMetaData() {
         return FACTORY.getCssMetaData();
     }

 }
 * 
*

The same can be accomplished with an inner-class. The previous example called {@code new SimpleStyleableBooleanProperty} * to create the selected property. This example uses the factory to access the CssMetaData * that was created along with the anonymous inner-class. For all intents and purposes, the two examples are the same.

*
 public final class MyButton extends Button {

     private static final{@literal StyleablePropertyFactory} FACTORY =
         new{@literal StyleablePropertyFactory<>}(Button.getClassCssMetaData()) {
         {
             createBooleanCssMetaData("-my-selected", s{@literal ->} s.selected, false, false);
         }
     }


     MyButton(String labelText) {
         super(labelText);
         getStyleClass().add("my-button");
     }

     // Typical JavaFX property implementation
     public{@literal ObservableValue} selectedProperty() { return ({@literal ObservableValue})selected; }
     public final boolean isSelected() { return selected.getValue(); }
     public final void setSelected(boolean isSelected) { selected.setValue(isSelected); }

     // StyleableProperty implementation reduced to one line
     private final{@literal StyleableProperty} selected =
         new SimpleStyleableBooleanProperty(this, "selected", "my-selected");

     public static {@literal List>} getClassCssMetaData() {
         return FACTORY.getCssMetaData();
     }

     {@literal @}Override
     public{@literal List>} getControlCssMetaData() {
         return FACTORY.getCssMetaData();
     }

 }
 * 
*

Caveats:

* The only option for creating a StyleableProperty with a number value is to create a StyleableProperty<Number>. * The return value from the getValue() method of the StyleableProperty is a Number. Therefore, * the get method of the JavaFX property needs to call the correct value method for the return type. * For example, *
     public ObservableValue offsetProperty() { return (ObservableValue)offset; }
     public Double getOffset() { return offset.getValue().doubleValue(); }
     public void setOffset(Double value) { offset.setValue(value); }
     private final StyleableProperty offset = FACTORY.createStyleableNumberProperty(this, "offset", "-my-offset", s -> ((MyButton)s).offset);
 * 
*
* @param The type of Styleable * @since JavaFX 8u40 */ public class StyleablePropertyFactory { /** * The constructor is passed the CssMetaData of the parent class of <S>, typically by calling the * static getClassCssMetaData() method of the parent. * @param parentCssMetaData The CssMetaData of the parent class of <S>, or null. */ public StyleablePropertyFactory(List> parentCssMetaData) { this.metaDataList = new ArrayList<>(); this.unmodifiableMetaDataList = Collections.unmodifiableList(this.metaDataList); if (parentCssMetaData != null) this.metaDataList.addAll(parentCssMetaData); this.metaDataMap = new HashMap<>(); } /** * Get the CssMetaData for the given Styleable. For a Node other than a Control, this method should be * called from the {@link javafx.css.Styleable#getCssMetaData()} method. For a Control, this method should be called * from the {@link javafx.scene.control.Control#getControlCssMetaData()} method. */ public final List> getCssMetaData() { return unmodifiableMetaDataList; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // StyleableProperty // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a StyleableProperty<Boolean> with initial value and inherit flag. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Boolean> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Boolean> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes */ public final StyleableProperty createStyleableBooleanProperty( S styleable, String propertyName, String cssProperty, Function> function, boolean initialValue, boolean inherits) { CssMetaData cssMetaData = createBooleanCssMetaData(cssProperty, function, initialValue, inherits); return new SimpleStyleableBooleanProperty(cssMetaData, styleable, propertyName, initialValue); } /** * Create a StyleableProperty<Boolean> with initial value. The inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Boolean> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Boolean> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. */ public final StyleableProperty createStyleableBooleanProperty( S styleable, String propertyName, String cssProperty, Function> function, boolean initialValue) { return createStyleableBooleanProperty(styleable, propertyName, cssProperty, function, initialValue, false); } /** * Create a StyleableProperty<Boolean>. The initialValue and inherit flag default to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Boolean> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Boolean> that was created by this method call. */ public final StyleableProperty createStyleableBooleanProperty( S styleable, String propertyName, String cssProperty, Function> function) { return createStyleableBooleanProperty(styleable, propertyName, cssProperty, function, false, false); } /** * Create a StyleableProperty<Boolean> using previously created CssMetaData for the given cssProperty. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Boolean> * @param cssProperty The CSS property name * @throws java.lang.IllegalArgumentException if cssProperty is null or empty * @throws java.util.NoSuchElementException if the CssMetaData for cssProperty was not created prior to this method invocation */ public final StyleableProperty createStyleableBooleanProperty( S styleable, String propertyName, String cssProperty) { if (cssProperty == null || cssProperty.isEmpty()) { throw new IllegalArgumentException("cssProperty cannot be null or empty string"); } @SuppressWarnings("unchecked") CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Boolean.class, cssProperty); return new SimpleStyleableBooleanProperty(cssMetaData, styleable, propertyName, cssMetaData.getInitialValue(styleable)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // create StyleableProperty // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a StyleableProperty<Color> with initial value and inherit flag. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Color> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Color> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes */ public final StyleableProperty createStyleableColorProperty( S styleable, String propertyName, String cssProperty, Function> function, Color initialValue, boolean inherits) { CssMetaData cssMetaData = createColorCssMetaData(cssProperty, function, initialValue, inherits); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, initialValue); } /** * Create a StyleableProperty<Color> with initial value. The inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Color> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Color> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. */ public final StyleableProperty createStyleableColorProperty( S styleable, String propertyName, String cssProperty, Function> function, Color initialValue) { return createStyleableColorProperty(styleable, propertyName, cssProperty, function, initialValue, false); } /** * Create a StyleableProperty<Color>. The initial value defaults to Color.BLACK and the * inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Color> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Color> that was created by this method call. */ public final StyleableProperty createStyleableColorProperty( S styleable, String propertyName, String cssProperty, Function> function) { return createStyleableColorProperty(styleable, propertyName, cssProperty, function, Color.BLACK, false); } /** * Create a StyleableProperty<Color> using previously created CssMetaData for the given cssProperty. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Color> * @param cssProperty The CSS property name * @throws java.lang.IllegalArgumentException if cssProperty is null or empty * @throws java.util.NoSuchElementException if the CssMetaData for cssProperty was not created prior to this method invocation */ public final StyleableProperty createStyleableColorProperty( S styleable, String propertyName, String cssProperty) { if (cssProperty == null || cssProperty.isEmpty()) { throw new IllegalArgumentException("cssProperty cannot be null or empty string"); } @SuppressWarnings("unchecked") CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Color.class, cssProperty); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, cssMetaData.getInitialValue(styleable)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // create StyleableProperty // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a StyleableProperty<Duration> with initial value and inherit flag. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Duration> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Duration> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes */ public final StyleableProperty createStyleableDurationProperty( S styleable, String propertyName, String cssProperty, Function> function, Duration initialValue, boolean inherits) { CssMetaData cssMetaData = createDurationCssMetaData(cssProperty, function, initialValue, inherits); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, initialValue); } /** * Create a StyleableProperty<Duration> with initial value. The inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Duration> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Duration> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. */ public final StyleableProperty createStyleableDurationProperty( S styleable, String propertyName, String cssProperty, Function> function, Duration initialValue) { return createStyleableDurationProperty(styleable, propertyName, cssProperty, function, initialValue, false); } /** * Create a StyleableProperty<Duration>. The initial value defaults to Duration.BLACK and the * inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Duration> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Duration> that was created by this method call. */ public final StyleableProperty createStyleableDurationProperty( S styleable, String propertyName, String cssProperty, Function> function) { return createStyleableDurationProperty(styleable, propertyName, cssProperty, function, Duration.UNKNOWN, false); } /** * Create a StyleableProperty<Duration> using previously created CssMetaData for the given cssProperty. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Duration> * @param cssProperty The CSS property name * @throws java.lang.IllegalArgumentException if cssProperty is null or empty * @throws java.util.NoSuchElementException if the CssMetaData for cssProperty was not created prior to this method invocation */ public final StyleableProperty createStyleableDurationProperty( S styleable, String propertyName, String cssProperty) { if (cssProperty == null || cssProperty.isEmpty()) { throw new IllegalArgumentException("cssProperty cannot be null or empty string"); } @SuppressWarnings("unchecked") CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Duration.class, cssProperty); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, cssMetaData.getInitialValue(styleable)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // create StyleableProperty // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a StyleableProperty<Effect> with initial value and inherit flag. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Effect> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Effect> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes */ public final StyleableProperty createStyleableEffectProperty( S styleable, String propertyName, String cssProperty, Function> function, E initialValue, boolean inherits) { CssMetaData cssMetaData = createEffectCssMetaData(cssProperty, function, initialValue, inherits); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, initialValue); } /** * Create a StyleableProperty<Effect> with initial value. The inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Effect> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Effect> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. */ public final StyleableProperty createStyleableEffectProperty( S styleable, String propertyName, String cssProperty, Function> function, E initialValue) { return createStyleableEffectProperty(styleable, propertyName, cssProperty, function, initialValue, false); } /** * Create a StyleableProperty<Effect>. The initial value is null and the inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Effect> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Effect> that was created by this method call. */ public final StyleableProperty createStyleableEffectProperty( S styleable, String propertyName, String cssProperty, Function> function) { return createStyleableEffectProperty(styleable, propertyName, cssProperty, function, null, false); } /** * Create a StyleableProperty<Effect> using previously created CssMetaData for the given cssProperty. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Effect> * @param cssProperty The CSS property name * @throws java.lang.IllegalArgumentException if cssProperty is null or empty * @throws java.util.NoSuchElementException if the CssMetaData for cssProperty was not created prior to this method invocation */ public final StyleableProperty createStyleableEffectProperty( S styleable, String propertyName, String cssProperty) { if (cssProperty == null || cssProperty.isEmpty()) { throw new IllegalArgumentException("cssProperty cannot be null or empty string"); } @SuppressWarnings("unchecked") CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Effect.class, cssProperty); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, cssMetaData.getInitialValue(styleable)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // create StyleableProperty> // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a StyleableProperty<E extends Enum<E>> with initial value and inherit flag. * The enumClass parameter is the Class of the Enum that is the value of the property. For example, *
     *     private static final StyleablePropertyFactory<MyControl> FACTORY = new StyleablePropertyFactory<>();
     *     StyleableProperty<Orientation> orientation =
     *         FACTORY.createStyleableEnumProperty(
     *             this, 
     *             "orientation", 
     *             "-my-orientation", 
     *             s -> ((MyControl)s).orientation,
     *             Orientation.class,
     *             Orientation.HORIZONTAL,
     *             false);
     * 
* @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<E extends Enum<E>> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<E extends Enum<E>> that was created by this method call. * @param enumClass The Enum class that is the type of the StyleableProperty<E extends Enum<E>>. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes */ public final > StyleableProperty createStyleableEnumProperty( S styleable, String propertyName, String cssProperty, Function> function, Class enumClass, E initialValue, boolean inherits) { CssMetaData cssMetaData = createEnumCssMetaData(enumClass, cssProperty, function, initialValue, inherits); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, initialValue); } /** * Create a StyleableProperty<E extends Enum<E>> with initial value. The inherit flag defaults to false. * The enumClass parameter is the Class of the Enum that is the value of the property. For example, *
     *     private static final StyleablePropertyFactory<MyControl> FACTORY = new StyleablePropertyFactory<>();
     *     StyleableProperty<Orientation> orientation =
     *         FACTORY.createStyleableEnumProperty(
     *             this, 
     *             "orientation", 
     *             "-my-orientation", 
     *             s -> ((MyControl)s).orientation,
     *             Orientation.class,
     *             Orientation.HORIZONTAL);
     * 
* @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<E extends Enum<E>> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<E extends Enum<E>> that was created by this method call. * @param enumClass The Enum class that is the type of the StyleableProperty<E extends Enum<E>>. * @param initialValue The initial value of the property. CSS may reset the property to this value. */ public final > StyleableProperty createStyleableEnumProperty( S styleable, String propertyName, String cssProperty, Function> function, Class enumClass, E initialValue) { return createStyleableEnumProperty(styleable, propertyName, cssProperty, function, enumClass, initialValue, false); } /** * Create a StyleableProperty<E extends Enum<E>>. The initial value is null and inherit flag defaults to false. * The enumClass parameter is the Class of the Enum that is the value of the property. For example, *
     *     private static final StyleablePropertyFactory<MyControl> FACTORY = new StyleablePropertyFactory<>();
     *     StyleableProperty<Orientation> orientation =
     *         FACTORY.createStyleableEnumProperty(
     *             this, 
     *             "orientation", 
     *             "-my-orientation", 
     *             s -> ((MyControl)s).orientation,
     *             Orientation.class);
     * 
* @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<E extends Enum<E>> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<E extends Enum<E>> that was created by this method call. * @param enumClass The Enum class that is the type of the StyleableProperty<E extends Enum<E>>. */ public final > StyleableProperty createStyleableEnumProperty( S styleable, String propertyName, String cssProperty, Function> function, Class enumClass) { return createStyleableEnumProperty(styleable, propertyName, cssProperty, function, enumClass, null, false); } /** * Create a StyleableProperty<E extends Enum<E>> using previously created CssMetaData for the given cssProperty. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<E extends Enum<E>> * @param cssProperty The CSS property name * @throws java.lang.IllegalArgumentException if cssProperty is null or empty * @throws java.util.NoSuchElementException if the CssMetaData for cssProperty was not created prior to this method invocation */ public final > StyleableProperty createStyleableEffectProperty( S styleable, String propertyName, String cssProperty, Class enumClass) { if (cssProperty == null || cssProperty.isEmpty()) { throw new IllegalArgumentException("cssProperty cannot be null or empty string"); } @SuppressWarnings("unchecked") CssMetaData cssMetaData = (CssMetaData)getCssMetaData(enumClass, cssProperty); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, cssMetaData.getInitialValue(styleable)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // create StyleableProperty // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a StyleableProperty<Font> with initial value and inherit flag. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Font> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Font> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes */ public final StyleableProperty createStyleableFontProperty( S styleable, String propertyName, String cssProperty, Function> function, Font initialValue, boolean inherits) { CssMetaData cssMetaData = createFontCssMetaData(cssProperty, function, initialValue, inherits); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, initialValue); } /** * Create a StyleableProperty<Font> with initial value. The inherit flag defaults to true. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Font> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Font> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. */ public final StyleableProperty createStyleableFontProperty( S styleable, String propertyName, String cssProperty, Function> function, Font initialValue) { return createStyleableFontProperty(styleable, propertyName, cssProperty, function, initialValue, true); } /** * Create a StyleableProperty<Font>. The initial value defaults to {@link javafx.scene.text.Font#getDefault()} * and the inherit flag defaults to true. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Font> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Font> that was created by this method call. */ public final StyleableProperty createStyleableFontProperty( S styleable, String propertyName, String cssProperty, Function> function) { return createStyleableFontProperty(styleable, propertyName, cssProperty, function, Font.getDefault(), true); } /** * Create a StyleableProperty<Font> using previously created CssMetaData for the given cssProperty. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Font> * @param cssProperty The CSS property name * @throws java.lang.IllegalArgumentException if cssProperty is null or empty * @throws java.util.NoSuchElementException if the CssMetaData for cssProperty was not created prior to this method invocation */ public final StyleableProperty createStyleableFontProperty( S styleable, String propertyName, String cssProperty) { if (cssProperty == null || cssProperty.isEmpty()) { throw new IllegalArgumentException("cssProperty cannot be null or empty string"); } @SuppressWarnings("unchecked") CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Font.class, cssProperty); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, cssMetaData.getInitialValue(styleable)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // create StyleableProperty // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a StyleableProperty<Inset> with initial value and inherit flag. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Inset> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Inset> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes */ public final StyleableProperty createStyleableInsetsProperty( S styleable, String propertyName, String cssProperty, Function> function, Insets initialValue, boolean inherits) { CssMetaData cssMetaData = createInsetsCssMetaData(cssProperty, function, initialValue, inherits); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, initialValue); } /** * Create a StyleableProperty<Inset> with initial value. The inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Inset> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Inset> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. */ public final StyleableProperty createStyleableInsetsProperty( S styleable, String propertyName, String cssProperty, Function> function, Insets initialValue) { return createStyleableInsetsProperty(styleable, propertyName, cssProperty, function, initialValue, false); } /** * Create a StyleableProperty<Inset>. The initial value is {@link Insets#EMPTY} and the inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Inset> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Inset> that was created by this method call. */ public final StyleableProperty createStyleableInsetsProperty( S styleable, String propertyName, String cssProperty, Function> function) { return createStyleableInsetsProperty(styleable, propertyName, cssProperty, function, Insets.EMPTY, false); } /** * Create a StyleableProperty<Insets> using previously created CssMetaData for the given cssProperty. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Insets> * @param cssProperty The CSS property name * @throws java.lang.IllegalArgumentException if cssProperty is null or empty * @throws java.util.NoSuchElementException if the CssMetaData for cssProperty was not created prior to this method invocation */ public final StyleableProperty createStyleableInsetsProperty( S styleable, String propertyName, String cssProperty) { if (cssProperty == null || cssProperty.isEmpty()) { throw new IllegalArgumentException("cssProperty cannot be null or empty string"); } @SuppressWarnings("unchecked") CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Insets.class, cssProperty); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, cssMetaData.getInitialValue(styleable)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // create StyleableProperty // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a StyleableProperty<Paint> with initial value and inherit flag. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Paint> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Paint> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes */ public final StyleableProperty createStyleablePaintProperty( S styleable, String propertyName, String cssProperty, Function> function, Paint initialValue, boolean inherits) { CssMetaData cssMetaData = createPaintCssMetaData(cssProperty, function, initialValue, inherits); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, initialValue); } /** * Create a StyleableProperty<Paint> with initial value. The inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Paint> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Paint> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. */ public final StyleableProperty createStyleablePaintProperty( S styleable, String propertyName, String cssProperty, Function> function, Paint initialValue) { return createStyleablePaintProperty(styleable, propertyName, cssProperty, function, initialValue, false); } /** * Create a StyleableProperty<Paint>. The initial value defautls to Color.BLACK and the inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Paint> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Paint> that was created by this method call. */ public final StyleableProperty createStyleablePaintProperty( S styleable, String propertyName, String cssProperty, Function> function) { return createStyleablePaintProperty(styleable, propertyName, cssProperty, function, Color.BLACK, false); } /** * Create a StyleableProperty<Paint> using previously created CssMetaData for the given cssProperty. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Paint> * @param cssProperty The CSS property name * @throws java.lang.IllegalArgumentException if cssProperty is null or empty * @throws java.util.NoSuchElementException if the CssMetaData for cssProperty was not created prior to this method invocation */ public final StyleableProperty createStyleablePaintProperty( S styleable, String propertyName, String cssProperty) { if (cssProperty == null || cssProperty.isEmpty()) { throw new IllegalArgumentException("cssProperty cannot be null or empty string"); } @SuppressWarnings("unchecked") CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Paint.class, cssProperty); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, cssMetaData.getInitialValue(styleable)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // create StyleableProperty // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a StyleableProperty<Number> with initial value and inherit flag. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Number> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Number> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes */ public final StyleableProperty createStyleableNumberProperty( S styleable, String propertyName, String cssProperty, Function> function, Number initialValue, boolean inherits) { CssMetaData cssMetaData = createSizeCssMetaData(cssProperty, function, initialValue, inherits); return new SimpleStyleableObjectProperty<>(cssMetaData, styleable, propertyName, initialValue); } /** * Create a StyleableProperty<Number> with initial value. The inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Number> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Number> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. */ public final StyleableProperty createStyleableNumberProperty( S styleable, String propertyName, String cssProperty, Function> function, Number initialValue) { return createStyleableNumberProperty(styleable, propertyName, cssProperty, function, initialValue, false); } /** * Create a StyleableProperty<Number>. The initial value defaults to zero. The inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Number> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<Number> that was created by this method call. */ public final StyleableProperty createStyleableNumberProperty( S styleable, String propertyName, String cssProperty, Function> function) { return createStyleableNumberProperty(styleable, propertyName, cssProperty, function, 0d, false); } /** * Create a StyleableProperty<Number> using previously created CssMetaData for the given cssProperty. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<Number> * @param cssProperty The CSS property name * @throws java.lang.IllegalArgumentException if cssProperty is null or empty * @throws java.util.NoSuchElementException if the CssMetaData for cssProperty was not created prior to this method invocation */ public final StyleableProperty createStyleableNumberProperty( S styleable, String propertyName, String cssProperty) { if (cssProperty == null || cssProperty.isEmpty()) { throw new IllegalArgumentException("cssProperty cannot be null or empty string"); } @SuppressWarnings("unchecked") CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Number.class, cssProperty); return new SimpleStyleableObjectProperty(cssMetaData, styleable, propertyName, cssMetaData.getInitialValue(styleable)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // create StyleableProperty // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a StyleableProperty<String> with initial value and inherit flag. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<String> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<String> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes */ public final StyleableProperty createStyleableStringProperty( S styleable, String propertyName, String cssProperty, Function> function, String initialValue, boolean inherits) { CssMetaData cssMetaData = createStringCssMetaData(cssProperty, function, initialValue, inherits); return new SimpleStyleableStringProperty(cssMetaData, styleable, propertyName, initialValue); } /** * Create a StyleableProperty<String> with initial value. The inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<String> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<String> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. */ public final StyleableProperty createStyleableStringProperty( S styleable, String propertyName, String cssProperty, Function> function, String initialValue) { return createStyleableStringProperty(styleable, propertyName, cssProperty, function, initialValue, false); } /** * Create a StyleableProperty<String>. The initial value defaults to null and the inherit flag defaults to false. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<String> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<String> that was created by this method call. */ public final StyleableProperty createStyleableStringProperty( S styleable, String propertyName, String cssProperty, Function> function) { return createStyleableStringProperty(styleable, propertyName, cssProperty, function, null, false); } /** * Create a StyleableProperty<String> using previously created CssMetaData for the given cssProperty. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<String> * @param cssProperty The CSS property name * @throws java.lang.IllegalArgumentException if cssProperty is null or empty * @throws java.util.NoSuchElementException if the CssMetaData for cssProperty was not created prior to this method invocation */ public final StyleableProperty createStyleableStringProperty( S styleable, String propertyName, String cssProperty) { if (cssProperty == null || cssProperty.isEmpty()) { throw new IllegalArgumentException("cssProperty cannot be null or empty string"); } @SuppressWarnings("unchecked") CssMetaData cssMetaData = (CssMetaData)getCssMetaData(String.class, cssProperty); return new SimpleStyleableStringProperty(cssMetaData, styleable, propertyName, cssMetaData.getInitialValue(styleable)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // create StyleableProperty where String is a URL // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a StyleableProperty<String> with initial value and inherit flag. Here, the String value represents * a URL converted from a CSS url(""). * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<String> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<String> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes */ public final StyleableProperty createStyleableUrlProperty( S styleable, String propertyName, String cssProperty, Function> function, String initialValue, boolean inherits) { CssMetaData cssMetaData = createUrlCssMetaData(cssProperty, function, initialValue, inherits); return new SimpleStyleableStringProperty(cssMetaData, styleable, propertyName, initialValue); } /** * Create a StyleableProperty<String> with initial value. The inherit flag defaults to false. * Here, the String value represents a URL converted from a * CSS url(""). * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<String> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<String> that was created by this method call. * @param initialValue The initial value of the property. CSS may reset the property to this value. */ public final StyleableProperty createStyleableUrlProperty( S styleable, String propertyName, String cssProperty, Function> function, String initialValue) { return createStyleableUrlProperty(styleable, propertyName, cssProperty, function, initialValue, false); } /** * Create a StyleableProperty<String> with initial value. The inherit flag defaults to false. * Here, the String value represents a URL converted from a * CSS url(""). * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<String> * @param cssProperty The CSS property name * @param function A function that returns the StyleableProperty<String> that was created by this method call. */ public final StyleableProperty createStyleableUrlProperty( S styleable, String propertyName, String cssProperty, Function> function) { return createStyleableUrlProperty(styleable, propertyName, cssProperty, function, null, false); } /** * Create a StyleableProperty<String> using previously created CssMetaData for the given cssProperty. * @param styleable The this reference of the returned property. This is also the property bean. * @param propertyName The field name of the StyleableProperty<String> * @param cssProperty The CSS property name * @throws java.lang.IllegalArgumentException if cssProperty is null or empty * @throws java.util.NoSuchElementException if the CssMetaData for cssProperty was not created prior to this method invocation */ public final StyleableProperty createStyleableUrlProperty( S styleable, String propertyName, String cssProperty) { if (cssProperty == null || cssProperty.isEmpty()) { throw new IllegalArgumentException("cssProperty cannot be null or empty string"); } @SuppressWarnings("unchecked") CssMetaData cssMetaData = (CssMetaData)getCssMetaData(String.class, cssProperty); return new SimpleStyleableStringProperty(cssMetaData, styleable, propertyName, cssMetaData.getInitialValue(styleable)); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // create CssMetaData // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a CssMetaData<S, Boolean> with initial value, and inherit flag. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Boolean> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createBooleanCssMetaData(final String property, final Function> function, final boolean initialValue, final boolean inherits) { if (property == null || property.isEmpty()) { throw new IllegalArgumentException("property cannot be null or empty string"); } if (function == null) { throw new IllegalArgumentException("function cannot be null"); } @SuppressWarnings("unchecked") // getCssMetaData checks and will throw a ClassCastException CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Boolean.class, property, key -> { final StyleConverter converter = StyleConverter.getBooleanConverter(); return new SimpleCssMetaData(key, function, converter, initialValue, inherits); }); return cssMetaData; } /** * Create a CssMetaData<S, Boolean> with initial value, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Boolean> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createBooleanCssMetaData(final String property, final Function> function, final boolean initialValue) { return createBooleanCssMetaData(property, function, initialValue, false); } /** * Create a CssMetaData<S, Boolean> with initial value and inherit flag both defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Boolean> that corresponds to this CssMetaData. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createBooleanCssMetaData(final String property, final Function> function) { return createBooleanCssMetaData(property, function, false, false); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // create CssMetaData // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a CssMetaData<S, Color> with initial value, and inherit flag. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Color> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createColorCssMetaData(final String property, final Function> function, final Color initialValue, final boolean inherits) { if (property == null || property.isEmpty()) { throw new IllegalArgumentException("property cannot be null or empty string"); } if (function == null) { throw new IllegalArgumentException("function cannot be null"); } @SuppressWarnings("unchecked") // getCssMetaData checks and will throw a ClassCastException CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Color.class, property, key -> { final StyleConverter converter = StyleConverter.getColorConverter(); return new SimpleCssMetaData(property, function, converter, initialValue, inherits); }); return cssMetaData; } /** * Create a CssMetaData<S, Color> with initial value, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Color> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createColorCssMetaData(final String property, final Function> function, final Color initialValue) { return createColorCssMetaData(property, function, initialValue, false); } /** * Create a CssMetaData<S, Color> with initial value of Color.BLACK, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Color> that corresponds to this CssMetaData. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createColorCssMetaData(final String property, final Function> function) { return createColorCssMetaData(property, function, Color.BLACK, false); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // create CssMetaData // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a CssMetaData<S, Duration> with initial value, and inherit flag. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Duration> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createDurationCssMetaData(final String property, final Function> function, final Duration initialValue, final boolean inherits) { if (property == null || property.isEmpty()) { throw new IllegalArgumentException("property cannot be null or empty string"); } if (function == null) { throw new IllegalArgumentException("function cannot be null"); } @SuppressWarnings("unchecked") // getCssMetaData checks and will throw a ClassCastException CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Duration.class, property, key -> { final StyleConverter converter = StyleConverter.getDurationConverter(); return new SimpleCssMetaData(property, function, converter, initialValue, inherits); }); return cssMetaData; } /** * Create a CssMetaData<S, Duration> with initial value, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Duration> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createDurationCssMetaData(final String property, final Function> function, final Duration initialValue) { return createDurationCssMetaData(property, function, initialValue, false); } /** * Create a CssMetaData<S, Duration> with initial value of Duration.BLACK, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Duration> that corresponds to this CssMetaData. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createDurationCssMetaData(final String property, final Function> function) { return createDurationCssMetaData(property, function, Duration.UNKNOWN, false); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // create CssMetaData // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a CssMetaData<S, Effect> with initial value, and inherit flag. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Effect> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createEffectCssMetaData(final String property, final Function> function, final E initialValue, final boolean inherits) { if (property == null || property.isEmpty()) { throw new IllegalArgumentException("property cannot be null or empty string"); } if (function == null) { throw new IllegalArgumentException("function cannot be null"); } @SuppressWarnings("unchecked") // getCssMetaData checks and will throw a ClassCastException CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Effect.class, property, key -> { final StyleConverter converter = StyleConverter.getEffectConverter(); return new SimpleCssMetaData(property, function, converter, initialValue, inherits); }); return cssMetaData; } /** * Create a CssMetaData<S, Effect> with initial value, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Effect> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createEffectCssMetaData(final String property, final Function> function, final E initialValue) { return createEffectCssMetaData(property, function, initialValue, false); } /** * Create a CssMetaData<S, Effect> with initial value of null, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Effect> that corresponds to this CssMetaData. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createEffectCssMetaData(final String property, final Function> function) { return createEffectCssMetaData(property, function, null, false); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // create CssMetaData // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a CssMetaData<S, Enum> with initial value, and inherit flag. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Enum> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final > CssMetaData createEnumCssMetaData(Class enumClass, final String property, final Function> function, final E initialValue, final boolean inherits) { if (property == null || property.isEmpty()) { throw new IllegalArgumentException("property cannot be null or empty string"); } if (function == null) { throw new IllegalArgumentException("function cannot be null"); } @SuppressWarnings("unchecked") // getCssMetaData checks and will throw a ClassCastException CssMetaData cssMetaData = (CssMetaData)getCssMetaData(enumClass, property, key -> { final EnumConverter converter = new EnumConverter(enumClass); return new SimpleCssMetaData(property, function, converter, initialValue, inherits); }); return cssMetaData; } /** * Create a CssMetaData<S, Enum> with initial value, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Enum> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final > CssMetaData createEnumCssMetaData(Class enumClass, final String property, final Function> function, final E initialValue) { return createEnumCssMetaData(enumClass, property, function, initialValue, false); } /** * Create a CssMetaData<S, Enum> with initial value of null, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Enum> that corresponds to this CssMetaData. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final > CssMetaData createEnumCssMetaData(Class enumClass, final String property, final Function> function) { return createEnumCssMetaData(enumClass, property, function, null, false); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // create CssMetaData // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a CssMetaData<S, Font> with initial value, and inherit flag. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Font> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createFontCssMetaData(final String property, final Function> function, final Font initialValue, final boolean inherits) { if (property == null || property.isEmpty()) { throw new IllegalArgumentException("property cannot be null or empty string"); } if (function == null) { throw new IllegalArgumentException("function cannot be null"); } @SuppressWarnings("unchecked") // getCssMetaData checks and will throw a ClassCastException CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Font.class, property, key -> { final StyleConverter converter = StyleConverter.getFontConverter(); return new SimpleCssMetaData(property, function, converter, initialValue, inherits); }); return cssMetaData; } /** * Create a CssMetaData<S, Font> with initial value, and inherit flag defaulting to true. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Font> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createFontCssMetaData(final String property, final Function> function, final Font initialValue) { return createFontCssMetaData(property, function, initialValue, true); } /** * Create a CssMetaData<S, Font> with initial value of {@link javafx.scene.text.Font#getDefault()}, and inherit flag defaulting to true. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Font> that corresponds to this CssMetaData. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createFontCssMetaData(final String property, final Function> function) { return createFontCssMetaData(property, function, Font.getDefault(), true); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // create CssMetaData // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a CssMetaData<S, Insets> with initial value, and inherit flag. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Insets> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createInsetsCssMetaData(final String property, final Function> function, final Insets initialValue, final boolean inherits) { if (property == null || property.isEmpty()) { throw new IllegalArgumentException("property cannot be null or empty string"); } if (function == null) { throw new IllegalArgumentException("function cannot be null"); } @SuppressWarnings("unchecked") // getCssMetaData checks and will throw a ClassCastException CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Insets.class, property, key -> { final StyleConverter converter = StyleConverter.getInsetsConverter(); return new SimpleCssMetaData(property, function, converter, initialValue, inherits); }); return cssMetaData; } /** * Create a CssMetaData<S, Insets> with initial value, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Insets> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createInsetsCssMetaData(final String property, final Function> function, final Insets initialValue) { return createInsetsCssMetaData(property, function, initialValue, false); } /** * Create a CssMetaData<S, Insets> with initial value of {@link javafx.geometry.Insets.EMPTY}, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Insets> that corresponds to this CssMetaData. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createInsetsCssMetaData(final String property, final Function> function) { return createInsetsCssMetaData(property, function, Insets.EMPTY, false); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // create CssMetaData // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a CssMetaData<S, Paint> with initial value, and inherit flag. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Paint> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createPaintCssMetaData(final String property, final Function> function, final Paint initialValue, final boolean inherits) { if (property == null || property.isEmpty()) { throw new IllegalArgumentException("property cannot be null or empty string"); } if (function == null) { throw new IllegalArgumentException("function cannot be null"); } @SuppressWarnings("unchecked") // getCssMetaData checks and will throw a ClassCastException CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Paint.class, property, key -> { final StyleConverter,Paint> converter = StyleConverter.getPaintConverter(); return new SimpleCssMetaData(property, function, converter, initialValue, inherits); }); return cssMetaData; } /** * Create a CssMetaData<S, Paint> with initial value, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Paint> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createPaintCssMetaData(final String property, final Function> function, final Paint initialValue) { return createPaintCssMetaData(property, function, initialValue, false); } /** * Create a CssMetaData<S, Paint> with initial value of Color.BLACK, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Paint> that corresponds to this CssMetaData. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createPaintCssMetaData(final String property, final Function> function) { return createPaintCssMetaData(property, function, Color.BLACK, false); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // create CssMetaData // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a CssMetaData<S, Number> with initial value, and inherit flag. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Number> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createSizeCssMetaData(final String property, final Function> function, final Number initialValue, final boolean inherits) { if (property == null || property.isEmpty()) { throw new IllegalArgumentException("property cannot be null or empty string"); } if (function == null) { throw new IllegalArgumentException("function cannot be null"); } @SuppressWarnings("unchecked") // getCssMetaData checks and will throw a ClassCastException CssMetaData cssMetaData = (CssMetaData)getCssMetaData(Number.class, property, key -> { final StyleConverter converter = StyleConverter.getSizeConverter(); return new SimpleCssMetaData(property, function, converter, initialValue, inherits); }); return cssMetaData; } /** * Create a CssMetaData<S, Number> with initial value, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Number> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createSizeCssMetaData(final String property, final Function> function, final Number initialValue) { return createSizeCssMetaData(property, function, initialValue, false); } /** * Create a CssMetaData<S, Number> with initial value of 0d, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<Number> that corresponds to this CssMetaData. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createSizeCssMetaData(final String property, final Function> function) { return createSizeCssMetaData(property, function, 0d, false); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // create CssMetaData // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a CssMetaData<S, String> with initial value, and inherit flag. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<String> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createStringCssMetaData(final String property, final Function> function, final String initialValue, final boolean inherits) { if (property == null || property.isEmpty()) { throw new IllegalArgumentException("property cannot be null or empty string"); } if (function == null) { throw new IllegalArgumentException("function cannot be null"); } @SuppressWarnings("unchecked") // getCssMetaData checks and will throw a ClassCastException CssMetaData cssMetaData = (CssMetaData)getCssMetaData(String.class, property, key -> { final StyleConverter converter = StyleConverter.getStringConverter(); return new SimpleCssMetaData(property, function, converter, initialValue, inherits); }); return cssMetaData; } /** * Create a CssMetaData<S, String> with initial value, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<String> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createStringCssMetaData(final String property, final Function> function, final String initialValue) { return createStringCssMetaData(property, function, initialValue, false); } /** * Create a CssMetaData<S, String> with initial value of null, and inherit flag defaulting to false. * @param property The CSS property name. * @param function A function that returns the StyleableProperty<String> that corresponds to this CssMetaData. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createStringCssMetaData(final String property, final Function> function) { return createStringCssMetaData(property, function, null, false); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // create CssMetaData // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * Create a CssMetaData<S, String> with initial value, and inherit flag. * Here, the String value represents a URL converted from a * CSS url(""). * @param property The CSS property name. * @param function A function that returns the StyleableProperty<String> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @param inherits Whether or not the CSS style can be inherited by child nodes * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createUrlCssMetaData(final String property, final Function> function, final String initialValue, final boolean inherits) { if (property == null || property.isEmpty()) { throw new IllegalArgumentException("property cannot be null or empty string"); } if (function == null) { throw new IllegalArgumentException("function cannot be null"); } @SuppressWarnings("unchecked") // getCssMetaData checks and will throw a ClassCastException CssMetaData cssMetaData = (CssMetaData)getCssMetaData(java.net.URL.class, property, key -> { final StyleConverter converter = StyleConverter.getUrlConverter(); return new SimpleCssMetaData(property, function, converter, initialValue, inherits); }); return cssMetaData; } /** * Create a CssMetaData<S, String> with initial value, and inherit flag defaulting to false. * Here, the String value represents a URL converted from a * CSS url(""). * @param property The CSS property name. * @param function A function that returns the StyleableProperty<String> that corresponds to this CssMetaData. * @param initialValue The initial value of the property. CSS may reset the property to this value. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createUrlCssMetaData(final String property, final Function> function, final String initialValue) { return createUrlCssMetaData(property, function, initialValue, false); } /** * Create a CssMetaData<S, String> with initial value of null, and inherit flag defaulting to false. * Here, the String value represents a URL converted from a * CSS url(""). * @param property The CSS property name. * @param function A function that returns the StyleableProperty<String> that corresponds to this CssMetaData. * @throws java.lang.IllegalArgumentException if property is null or an empty string, or function is null. */ public final CssMetaData createUrlCssMetaData(final String property, final Function> function) { return createUrlCssMetaData(property, function, null, false); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // SimpleCssMetaData is an implementation of CssMetaData that uses a Function> // // to get the StyleableProperty from the Styleable. This is the function that is passed in on the // various create methods. // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private static class SimpleCssMetaData extends CssMetaData { SimpleCssMetaData( final String property, final Function> function, final StyleConverter converter, final V initialValue, final boolean inherits) { super(property, converter, initialValue, inherits); this.function = function; } private final Function> function; public final boolean isSettable(S styleable) { final StyleableProperty prop = getStyleableProperty(styleable); if (prop instanceof Property) { return !((Property)prop).isBound(); } // can't set this property if getStyleableProperty returns null! return prop != null; } /** {@inheritDoc} */ @Override public final StyleableProperty getStyleableProperty(S styleable) { if (styleable != null) { StyleableProperty property = function.apply(styleable); return property; } return null; } } // for testing only void clearDataForTesting() { metaDataMap.clear(); metaDataList.clear(); } private CssMetaData getCssMetaData(final Class ofClass, String property) { return getCssMetaData(ofClass, property, null); } private CssMetaData getCssMetaData(final Class ofClass, String property, final Function> createFunction) { final String key = property.toLowerCase(); Pair> entry = metaDataMap.get(key); if (entry != null) { if (entry.getKey() == ofClass) { return entry.getValue(); } else { throw new ClassCastException("CssMetaData value is not " + ofClass + ": " + entry.getValue()); } } else if (createFunction == null) { throw new NoSuchElementException("No CssMetaData for " + key); } // Entry was null CssMetaData cssMetaData = createFunction.apply(key); metaDataMap.put(key, new Pair(ofClass, cssMetaData)); metaDataList.add(cssMetaData); return cssMetaData; } private final Map>> metaDataMap; private final List> unmodifiableMetaDataList; private final List> metaDataList; }