1 /* 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.javafx.css; 27 28 import javafx.css.converter.SizeConverter; 29 import java.util.ArrayList; 30 import java.util.Collections; 31 import java.util.List; 32 import javafx.beans.property.DoubleProperty; 33 import javafx.css.CssMetaData; 34 import javafx.css.Styleable; 35 import javafx.css.StyleableDoubleProperty; 36 import javafx.css.StyleableProperty; 37 38 /** Test Node with styleable property but no getClassCssMetaData method */ 39 public class TestNode extends TestNodeBase { 40 41 private DoubleProperty xyzzy; 42 private DoubleProperty xyzzyProperty() { 43 if (xyzzy == null) { 44 xyzzy = new StyleableDoubleProperty(.5) { 45 46 @Override 47 public Object getBean() { 48 return TestNode.this; 49 } 50 51 @Override 52 public String getName() { 53 return "xyzzy"; 54 } 55 56 @Override 57 public CssMetaData<TestNode, Number> getCssMetaData() { 58 return StyleableProperties.XYZZY; 59 } 60 61 }; 62 } 63 return xyzzy; 64 } 65 66 public void setXyzzy(double number) { 67 xyzzyProperty().set(number); 68 } 69 70 public double getXyzzy() { 71 return (xyzzy == null ? .5 : xyzzy.get()); 72 } 73 74 public TestNode() { 75 super(); 76 } 77 78 public static class StyleableProperties { 79 80 public static final CssMetaData<TestNode, Number> XYZZY = 81 new CssMetaData<TestNode, Number>("-fx-xyzzy", 82 SizeConverter.getInstance(), 83 .5) { 84 85 @Override 86 public boolean isSettable(TestNode node) { 87 return node.xyzzy == null || !node.xyzzy.isBound(); 88 } 89 90 @Override 91 public StyleableProperty<Number> getStyleableProperty(TestNode node) { 92 return (StyleableProperty<Number>)node.xyzzyProperty(); 93 } 94 95 }; 96 97 private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES; 98 static { 99 final List<CssMetaData<? extends Styleable, ?>> styleables = 100 new ArrayList<CssMetaData<? extends Styleable, ?>>(TestNodeBase.getClassCssMetaData()); 101 styleables.add(XYZZY); 102 STYLEABLES = Collections.unmodifiableList(styleables); 103 } 104 } 105 106 /** 107 * @return The CssMetaData associated with this class, which may include the 108 * CssMetaData of its super classes. 109 */ 110 public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() { 111 return StyleableProperties.STYLEABLES; 112 } 113 114 /** 115 * {@inheritDoc} 116 * 117 */ 118 119 120 @Override 121 public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() { 122 return getClassCssMetaData(); 123 } 124 125 }