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.javafx.scene;
27
28 import javafx.css.converter.PaintConverter;
29 import javafx.css.converter.SizeConverter;
30 import com.sun.javafx.geom.BaseBounds;
31 import com.sun.javafx.geom.transform.BaseTransform;
32 import com.sun.javafx.jmx.MXNodeAlgorithm;
33 import com.sun.javafx.jmx.MXNodeAlgorithmContext;
34 import com.sun.javafx.sg.prism.NGGroup;
35 import com.sun.javafx.sg.prism.NGNode;
36 import javafx.beans.property.*;
37 import javafx.css.*;
38 import javafx.scene.paint.Color;
39 import javafx.scene.paint.Paint;
40
41 import java.util.ArrayList;
42 import java.util.List;
43 import javafx.scene.Node;
44 import test.com.sun.javafx.scene.CSSNodeHelper;
45
46 public class CSSNode extends Node {
47 static {
48 CSSNodeHelper.setCSSNodeAccessor(new CSSNodeHelper.CSSNodeAccessor() {
49 @Override
50 public NGNode doCreatePeer(Node node) {
51 return ((CSSNode) node).doCreatePeer();
52 }
53 });
54 }
55
56 {
57 // To initialize the class helper at the begining each constructor of this class
58 CSSNodeHelper.initHelper(this);
59 }
60
61 public CSSNode() {
62 setContentSize(100);
63 }
64
65 /**
66 * This variable can be set from CSS and represents the fill
67 */
68 private ObjectProperty<Paint> fill;
69 public ObjectProperty<Paint> fillProperty() {
70 if (fill == null) {
71 fill = new StyleableObjectProperty<Paint>(Color.BLACK) {
72
135 * this can be font-based, absolute, or percentage based. The CSSNode has
136 * a contentSize:Number variable which is used when padding is based on
137 * a percentage
138 */
139 private FloatProperty padding;
140
141 public final void setPadding(float value) {
142 paddingProperty().set(value);
143 }
144
145 public final float getPadding() {
146 return padding == null ? 0.0F : padding.get();
147 }
148
149 public FloatProperty paddingProperty() {
150 if (padding == null) {
151 padding = new StyleableFloatProperty() {
152
153 @Override
154 protected void invalidated() {
155 impl_geomChanged();
156 }
157
158 @Override
159 public Object getBean() {
160 return CSSNode.this;
161 }
162
163 @Override
164 public String getName() {
165 return "padding";
166 }
167
168 @Override
169 public CssMetaData getCssMetaData() {
170 return StyleableProperties.PADDING;
171 }
172 };
173 }
174 return padding;
175 }
177 /**
178 * Used only when padding is specified as a percentage, as it is a
179 * percentage of the content size.
180 */
181 private FloatProperty contentSize;
182
183 public final void setContentSize(float value) {
184 contentSizeProperty().set(value);
185 }
186
187 public final float getContentSize() {
188 return contentSize == null ? 0.0F : contentSize.get();
189 }
190
191 public FloatProperty contentSizeProperty() {
192 if (contentSize == null) {
193 contentSize = new SimpleFloatProperty() {
194
195 @Override
196 protected void invalidated() {
197 impl_geomChanged();
198 }
199 };
200 }
201 return contentSize;
202 }
203
204 /**
205 * A pseudoclass state for this Node. It cannot be styled, but can
206 * be used as a pseudoclass
207 */
208 private PseudoClass SPECIAL_PSEUDO_CLASS = PseudoClass.getPseudoClass("special");
209 private BooleanProperty special;
210 public final void setSpecial(boolean value) {
211 specialProperty().set(value);
212 }
213
214 public final boolean isSpecial() {
215 return special == null ? false : special.get();
216 }
217
219 if (special == null) {
220 special = new SimpleBooleanProperty() {
221
222 @Override
223 protected void invalidated() {
224 pseudoClassStateChanged(SPECIAL_PSEUDO_CLASS, get());
225 }
226 };
227 }
228 return special;
229 }
230
231 /*
232 * These vars are used solely for the sake of testing.
233 */
234
235 public boolean reapply = false;
236 public boolean processCalled = false;
237 public boolean applyCalled = false;
238
239 @Override
240 public BaseBounds impl_computeGeomBounds(BaseBounds bounds, BaseTransform tx) {
241 if (bounds != null) {
242 bounds = bounds.deriveWithNewBounds(0, 0, 0,
243 getContentSize() + getPadding() + getPadding(), getContentSize() + getPadding() + getPadding(), 0);
244 }
245 return bounds;
246 }
247
248 @Override
249 protected boolean impl_computeContains(double localX, double localY) {
250 // TODO: Missing code.
251 return false;
252 }
253
254 private NGNode doCreatePeer() {
255 return new NGGroup();
256 }
257
258 public static class StyleableProperties {
259
260 public static final CssMetaData<CSSNode,Paint> FILL =
261 new CssMetaData<CSSNode,Paint>("fill", PaintConverter.getInstance()) {
262
263 @Override
264 public boolean isSettable(CSSNode n) {
265 return n.fill == null || !n.fill.isBound();
266 }
267
268 @Override
269 public StyleableProperty<Paint> getStyleableProperty(CSSNode n) {
313
314 /**
315 * @return The CssMetaData associated with this class, which may include the
316 * CssMetaData of its super classes.
317 */
318 public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
319 return StyleableProperties.STYLEABLES;
320 }
321
322 /**
323 * {@inheritDoc}
324 *
325 */
326
327
328 @Override
329 public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
330 return getClassCssMetaData();
331 }
332
333 /**
334 * @treatAsPrivate Implementation detail
335 */
336 @Override
337 public Object impl_processMXNode(MXNodeAlgorithm alg, MXNodeAlgorithmContext ctx) {
338 return null;
339 }
340 }
|
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.javafx.scene;
27
28 import javafx.css.converter.PaintConverter;
29 import javafx.css.converter.SizeConverter;
30 import com.sun.javafx.geom.BaseBounds;
31 import com.sun.javafx.geom.transform.BaseTransform;
32 import com.sun.javafx.jmx.MXNodeAlgorithm;
33 import com.sun.javafx.jmx.MXNodeAlgorithmContext;
34 import com.sun.javafx.scene.NodeHelper;
35 import com.sun.javafx.sg.prism.NGGroup;
36 import com.sun.javafx.sg.prism.NGNode;
37 import javafx.beans.property.*;
38 import javafx.css.*;
39 import javafx.scene.paint.Color;
40 import javafx.scene.paint.Paint;
41
42 import java.util.ArrayList;
43 import java.util.List;
44 import javafx.scene.Node;
45 import test.com.sun.javafx.scene.CSSNodeHelper;
46
47 public class CSSNode extends Node {
48 static {
49 CSSNodeHelper.setCSSNodeAccessor(new CSSNodeHelper.CSSNodeAccessor() {
50 @Override
51 public NGNode doCreatePeer(Node node) {
52 return ((CSSNode) node).doCreatePeer();
53 }
54
55 @Override
56 public BaseBounds doComputeGeomBounds(Node node,
57 BaseBounds bounds, BaseTransform tx) {
58 return ((CSSNode) node).doComputeGeomBounds(bounds, tx);
59 }
60
61 @Override
62 public boolean doComputeContains(Node node, double localX, double localY) {
63 return ((CSSNode) node).doComputeContains(localX, localY);
64 }
65
66 @Override
67 public Object doProcessMXNode(Node node, MXNodeAlgorithm alg, MXNodeAlgorithmContext ctx) {
68 return ((CSSNode) node).doProcessMXNode(alg, ctx);
69 }
70 });
71 }
72
73 {
74 // To initialize the class helper at the begining each constructor of this class
75 CSSNodeHelper.initHelper(this);
76 }
77
78 public CSSNode() {
79 setContentSize(100);
80 }
81
82 /**
83 * This variable can be set from CSS and represents the fill
84 */
85 private ObjectProperty<Paint> fill;
86 public ObjectProperty<Paint> fillProperty() {
87 if (fill == null) {
88 fill = new StyleableObjectProperty<Paint>(Color.BLACK) {
89
152 * this can be font-based, absolute, or percentage based. The CSSNode has
153 * a contentSize:Number variable which is used when padding is based on
154 * a percentage
155 */
156 private FloatProperty padding;
157
158 public final void setPadding(float value) {
159 paddingProperty().set(value);
160 }
161
162 public final float getPadding() {
163 return padding == null ? 0.0F : padding.get();
164 }
165
166 public FloatProperty paddingProperty() {
167 if (padding == null) {
168 padding = new StyleableFloatProperty() {
169
170 @Override
171 protected void invalidated() {
172 NodeHelper.geomChanged(CSSNode.this);
173 }
174
175 @Override
176 public Object getBean() {
177 return CSSNode.this;
178 }
179
180 @Override
181 public String getName() {
182 return "padding";
183 }
184
185 @Override
186 public CssMetaData getCssMetaData() {
187 return StyleableProperties.PADDING;
188 }
189 };
190 }
191 return padding;
192 }
194 /**
195 * Used only when padding is specified as a percentage, as it is a
196 * percentage of the content size.
197 */
198 private FloatProperty contentSize;
199
200 public final void setContentSize(float value) {
201 contentSizeProperty().set(value);
202 }
203
204 public final float getContentSize() {
205 return contentSize == null ? 0.0F : contentSize.get();
206 }
207
208 public FloatProperty contentSizeProperty() {
209 if (contentSize == null) {
210 contentSize = new SimpleFloatProperty() {
211
212 @Override
213 protected void invalidated() {
214 NodeHelper.geomChanged(CSSNode.this);
215 }
216 };
217 }
218 return contentSize;
219 }
220
221 /**
222 * A pseudoclass state for this Node. It cannot be styled, but can
223 * be used as a pseudoclass
224 */
225 private PseudoClass SPECIAL_PSEUDO_CLASS = PseudoClass.getPseudoClass("special");
226 private BooleanProperty special;
227 public final void setSpecial(boolean value) {
228 specialProperty().set(value);
229 }
230
231 public final boolean isSpecial() {
232 return special == null ? false : special.get();
233 }
234
236 if (special == null) {
237 special = new SimpleBooleanProperty() {
238
239 @Override
240 protected void invalidated() {
241 pseudoClassStateChanged(SPECIAL_PSEUDO_CLASS, get());
242 }
243 };
244 }
245 return special;
246 }
247
248 /*
249 * These vars are used solely for the sake of testing.
250 */
251
252 public boolean reapply = false;
253 public boolean processCalled = false;
254 public boolean applyCalled = false;
255
256 /*
257 * Note: This method MUST only be called via its accessor method.
258 */
259 private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx) {
260 if (bounds != null) {
261 bounds = bounds.deriveWithNewBounds(0, 0, 0,
262 getContentSize() + getPadding() + getPadding(), getContentSize() + getPadding() + getPadding(), 0);
263 }
264 return bounds;
265 }
266
267 /*
268 * Note: This method MUST only be called via its accessor method.
269 */
270 private boolean doComputeContains(double localX, double localY) {
271 // TODO: Missing code.
272 return false;
273 }
274
275 private NGNode doCreatePeer() {
276 return new NGGroup();
277 }
278
279 public static class StyleableProperties {
280
281 public static final CssMetaData<CSSNode,Paint> FILL =
282 new CssMetaData<CSSNode,Paint>("fill", PaintConverter.getInstance()) {
283
284 @Override
285 public boolean isSettable(CSSNode n) {
286 return n.fill == null || !n.fill.isBound();
287 }
288
289 @Override
290 public StyleableProperty<Paint> getStyleableProperty(CSSNode n) {
334
335 /**
336 * @return The CssMetaData associated with this class, which may include the
337 * CssMetaData of its super classes.
338 */
339 public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
340 return StyleableProperties.STYLEABLES;
341 }
342
343 /**
344 * {@inheritDoc}
345 *
346 */
347
348
349 @Override
350 public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
351 return getClassCssMetaData();
352 }
353
354 /*
355 * Note: This method MUST only be called via its accessor method.
356 */
357 private Object doProcessMXNode(MXNodeAlgorithm alg, MXNodeAlgorithmContext ctx) {
358 return null;
359 }
360 }
|