All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.guigarage.css.DefaultPropertyBasedCssMetaData Maven / Gradle / Ivy

There is a newer version: 0.7
Show newest version
package com.guigarage.css;

import javafx.beans.property.Property;
import javafx.css.StyleConverter;
import javafx.css.Styleable;
import javafx.css.StyleableProperty;

/**
 * A CssMetaData class that is bound to a specific property that is part of a Styleable instance.
 * @param  Type of the Styleable instance
 * @param  Value type of the property
 */
public class DefaultPropertyBasedCssMetaData extends AbstractPropertyBasedCssMetaData {

    /**
     * Default Constructor
     *
     * @param property name of the CSS property
     * @param converter the StyleConverter used to convert the CSS parsed value to a Java object.
     * @param propertyName Name of the property field in the Styleable class
     * @param defaultValue The default value of the corresponding StyleableProperty
     */
    public DefaultPropertyBasedCssMetaData(String property, StyleConverter converter, String propertyName, V defaultValue) {
        super(property, converter, propertyName, defaultValue);
    }

    protected  & StyleableProperty> T getProperty(S styleable) {
        try {
            return (T) styleable.getClass().getMethod(getPropertyName() + "Property").invoke(styleable);
        } catch (Exception e) {
            throw new RuntimeException("Can't get StyleableProperty", e);
        }
    }
}