1 /* 2 * Copyright (c) 2011, 2018, 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 test.com.sun.javafx.css; 27 28 import javafx.css.converter.BooleanConverter; 29 import javafx.css.converter.SizeConverter; 30 import javafx.css.converter.StringConverter; 31 import java.util.ArrayList; 32 import java.util.Collections; 33 import java.util.List; 34 35 import com.sun.javafx.sg.prism.NGNode; 36 import javafx.beans.property.BooleanProperty; 37 import javafx.beans.property.DoubleProperty; 38 import javafx.beans.property.StringProperty; 39 import javafx.css.CssMetaData; 40 import javafx.css.StyleableBooleanProperty; 41 import javafx.css.StyleableDoubleProperty; 42 import javafx.css.StyleableStringProperty; 43 import javafx.scene.Node; 44 45 import com.sun.javafx.geom.BaseBounds; 46 import com.sun.javafx.geom.transform.BaseTransform; 47 import javafx.css.Styleable; 48 import javafx.css.StyleableProperty; 49 50 /** Test Node with styleable properties and an getClassCssMetaData method */ 51 public class TestNodeBase extends Node { 52 static { 53 // This is used by classes in different packages to get access to 54 // private and package private methods. 55 TestNodeBaseHelper.setTestNodeBaseAccessor(new TestNodeBaseHelper.TestNodeBaseAccessor() { 56 @Override 57 public NGNode doCreatePeer(Node node) { 58 return ((TestNodeBase) node).doCreatePeer(); 59 } 60 61 @Override 62 public BaseBounds doComputeGeomBounds(Node node, 63 BaseBounds bounds, BaseTransform tx) { 64 return ((TestNodeBase) node).doComputeGeomBounds(bounds, tx); 65 } 66 67 @Override 68 public boolean doComputeContains(Node node, double localX, double localY) { 69 return ((TestNodeBase) node).doComputeContains(localX, localY); 70 } 71 }); 72 } 73 74 protected TestNodeBase() { 75 TestNodeBaseHelper.initHelper(this); 76 } 77 78 private boolean doComputeContains(double d, double d1) { 79 throw new UnsupportedOperationException("Not supported yet."); 80 } 81 82 /* 83 * Note: This method MUST only be called via its accessor method. 84 */ 85 private BaseBounds doComputeGeomBounds(BaseBounds bb, BaseTransform bt) { 86 throw new UnsupportedOperationException("Not supported yet."); 87 } 88 89 private NGNode doCreatePeer() { 90 throw new UnsupportedOperationException("Not supported yet."); 91 } 92 93 private BooleanProperty test; 94 private BooleanProperty testProperty() { 95 if (test == null) { 96 test = new StyleableBooleanProperty(true) { 97 98 @Override 99 public Object getBean() { 100 return TestNodeBase.this; 101 } 102 103 @Override 104 public String getName() { 105 return "test"; 106 } 107 108 @Override 109 public CssMetaData getCssMetaData() { 110 return TestNodeBase.StyleableProperties.TEST; 111 } 112 113 }; 114 } 115 return test; 116 } 117 118 public void setTest(boolean value) { 119 testProperty().set(value); 120 } 121 122 public boolean getTest() { 123 return (test == null ? true : test.get()); 124 } 125 126 private StringProperty string; 127 private StringProperty stringProperty() { 128 if (string == null) { 129 string = new StyleableStringProperty("init string") { 130 131 @Override 132 public Object getBean() { 133 return TestNodeBase.this; 134 } 135 136 @Override 137 public String getName() { 138 return "string"; 139 } 140 141 @Override 142 public CssMetaData getCssMetaData() { 143 return TestNodeBase.StyleableProperties.STRING; 144 } 145 146 }; 147 } 148 return string; 149 } 150 151 public void setString(String value) { 152 stringProperty().set(value); 153 } 154 155 public String getString() { 156 return (string == null ? "init string" : string.get()); 157 } 158 159 private DoubleProperty doubleProperty; 160 private DoubleProperty doublePropertyProperty() { 161 if (doubleProperty == null) { 162 doubleProperty = new StyleableDoubleProperty(0) { 163 164 @Override 165 public Object getBean() { 166 return TestNodeBase.this; 167 } 168 169 @Override 170 public String getName() { 171 return "doubleProperty"; 172 } 173 174 @Override 175 public CssMetaData getCssMetaData() { 176 return TestNodeBase.StyleableProperties.DOUBLE_PROPERTY; 177 } 178 179 }; 180 } 181 return doubleProperty; 182 } 183 184 public void setDoubleProperty(double number) { 185 doublePropertyProperty().set(number); 186 } 187 188 public double getDoubleProperty() { 189 return (doubleProperty == null ? 0 : doubleProperty.get()); 190 } 191 192 193 public static class StyleableProperties { 194 public final static CssMetaData<TestNodeBase,Boolean> TEST = 195 new CssMetaData<TestNodeBase,Boolean>("-fx-test", 196 BooleanConverter.getInstance(), Boolean.TRUE) { 197 198 @Override 199 public boolean isSettable(TestNodeBase n) { 200 return n.test == null || !n.test.isBound(); 201 } 202 203 @Override 204 public StyleableProperty<Boolean> getStyleableProperty(TestNodeBase n) { 205 return (StyleableProperty)n.testProperty(); 206 } 207 }; 208 209 public final static CssMetaData<TestNodeBase,String> STRING = 210 new CssMetaData<TestNodeBase,String>("-fx-string", 211 StringConverter.getInstance(), "init string") { 212 213 @Override 214 public boolean isSettable(TestNodeBase n) { 215 return n.string == null || !n.string.isBound(); 216 } 217 218 @Override 219 public StyleableProperty<String> getStyleableProperty(TestNodeBase n) { 220 return (StyleableProperty)n.stringProperty(); 221 } 222 }; 223 224 public final static CssMetaData<TestNodeBase,Number> DOUBLE_PROPERTY = 225 new CssMetaData<TestNodeBase,Number>("-fx-double-property", 226 SizeConverter.getInstance(), 0) { 227 228 @Override 229 public boolean isSettable(TestNodeBase n) { 230 return n.doubleProperty == null || !n.doubleProperty.isBound(); 231 } 232 233 @Override 234 public StyleableProperty<Number> getStyleableProperty(TestNodeBase n) { 235 return (StyleableProperty)n.doublePropertyProperty(); 236 } 237 }; 238 239 static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES; 240 static { 241 List<CssMetaData<? extends Styleable, ?>> list = 242 new ArrayList<CssMetaData<? extends Styleable, ?>>(Node.getClassCssMetaData()); 243 Collections.addAll(list, 244 TEST, 245 STRING, 246 DOUBLE_PROPERTY 247 ); 248 STYLEABLES = Collections.unmodifiableList(list); 249 } 250 } 251 252 /** 253 * {@inheritDoc} 254 */ 255 public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() { 256 return StyleableProperties.STYLEABLES; 257 } 258 259 /** 260 * {@inheritDoc} 261 * 262 */ 263 264 265 @Override 266 public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() { 267 return getClassCssMetaData(); 268 } 269 }