/* * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package javafx.css; import com.sun.javafx.css.converters.FontConverter; import com.sun.javafx.css.converters.SizeConverter; import com.sun.javafx.css.converters.StringConverter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; /** * An partial implementation of CssMetaData for Font properties which * includes the font sub-properties: weight, style, family and size. * @param S The type of Styleable * @since JavaFX 8.0 */ public abstract class FontCssMetaData extends CssMetaData { /** * The property name is concatenated with "-weight", * "-style", "-family" and "-size" to * create the sub-properties. For example, * {@code new FontCssMetaData("-fx-font", Font.getDefault());} * will create a CssMetaData for "-fx-font" with * sub-properties: "-fx-font-weight", * "-fx-font-style", "-fx-font-family" * and "-fx-font-size" * @param property * @param initial */ /** * The property name is concatenated with "-weight", * "-style", "-family" and "-size" to * create the sub-properties. For example, * {@code new FontCssMetaData("-fx-font", Font.getDefault());} * will create a CssMetaData for "-fx-font" with * sub-properties: "-fx-font-weight", * "-fx-font-style", "-fx-font-family" * and "-fx-font-size" * @param property * @param initial */ public FontCssMetaData(String property, Font initial) { super(property, FontConverter.getInstance(), initial, true, createSubProperties(property, initial)); } private static List> createSubProperties(String property, Font initial) { final List> subProperties = new ArrayList<>(); final Font defaultFont = initial != null ? initial : Font.getDefault(); final CssMetaData FAMILY = new CssMetaData(property.concat("-family"), StringConverter.getInstance(), defaultFont.getFamily(), true) { @Override public boolean isSettable(S styleable) { return false; } @Override public StyleableProperty getStyleableProperty(S styleable) { return null; } }; subProperties.add(FAMILY); final CssMetaData SIZE = new CssMetaData(property.concat("-size"), SizeConverter.getInstance(), defaultFont.getSize(), true) { @Override public boolean isSettable(S styleable) { return false; } @Override public StyleableProperty getStyleableProperty(S styleable) { return null; } }; subProperties.add(SIZE); final CssMetaData STYLE = new CssMetaData(property.concat("-style"), FontConverter.FontStyleConverter.getInstance(), FontPosture.REGULAR, true) { @Override public boolean isSettable(S styleable) { return false; } @Override public StyleableProperty getStyleableProperty(S styleable) { return null; } }; subProperties.add(STYLE); final CssMetaData WEIGHT = new CssMetaData(property.concat("-weight"), FontConverter.FontWeightConverter.getInstance(), FontWeight.NORMAL, true) { @Override public boolean isSettable(S styleable) { return false; } @Override public StyleableProperty getStyleableProperty(S styleable) { return null; } }; subProperties.add(WEIGHT); return Collections.>unmodifiableList(subProperties); } }