1 /* 2 * Copyright (c) 2011, 2015, 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.javafx.scene.bounds; 27 28 import com.sun.javafx.sg.prism.NGNode; 29 import com.sun.javafx.sg.prism.NGRectangle; 30 import javafx.beans.property.FloatProperty; 31 import javafx.beans.property.SimpleFloatProperty; 32 import javafx.scene.Node; 33 34 import com.sun.javafx.jmx.MXNodeAlgorithm; 35 import com.sun.javafx.jmx.MXNodeAlgorithmContext; 36 import test.com.sun.javafx.scene.bounds.PerfNodeHelper; 37 38 /** 39 * A special node used for performance tests to make sure that the minimum 40 * amount of bounds computation work happens as possible. 41 */ 42 public class PerfNode extends Node { 43 static { 44 // This is used by classes in different packages to get access to 45 // private and package private methods. 46 PerfNodeHelper.setPerfNodeAccessor(new PerfNodeHelper.PerfNodeAccessor() { 47 @Override 48 public NGNode doCreatePeer(Node node) { 49 return ((PerfNode) node).doCreatePeer(); 50 } 51 }); 52 } 53 54 { 55 // To initialize the class helper at the begining each constructor of this class 56 PerfNodeHelper.initHelper(this); 57 } 58 public PerfNode() { 59 } 60 61 public PerfNode(float x, float y, float width, float height) { 62 setX(x); 63 setY(y); 64 setWidth(width); 65 setHeight(height); 66 } 67 private FloatProperty x; 68 69 public final void setX(float value) { 70 xProperty().set(value); 71 } 72 73 public final float getX() { 74 return x == null ? 0 : x.get(); 75 } 76 77 public FloatProperty xProperty() { 78 if (x == null) { 79 x = new SimpleFloatProperty() { 80 81 @Override 82 protected void invalidated() { 83 impl_geomChanged(); 84 } 85 }; 86 } 87 return x; 88 } 89 private FloatProperty y; 90 91 public final void setY(float value) { 92 yProperty().set(value); 93 } 94 95 public final float getY() { 96 return y == null ? 0 : y.get(); 97 } 98 99 public FloatProperty yProperty() { 100 if (y == null) { 101 y = new SimpleFloatProperty() { 102 103 @Override 104 protected void invalidated() { 105 impl_geomChanged(); 106 } 107 }; 108 } 109 return y; 110 } 111 private FloatProperty width; 112 113 public final void setWidth(float value) { 114 widthProperty().set(value); 115 } 116 117 public final float getWidth() { 118 return width == null ? 100 : width.get(); 119 } 120 121 public FloatProperty widthProperty() { 122 if (width == null) { 123 width = new SimpleFloatProperty() { 124 125 @Override 126 protected void invalidated() { 127 impl_storeWidth(width, get()); 128 } 129 }; 130 } 131 return width; 132 } 133 134 protected void impl_storeWidth(FloatProperty model, float value) { 135 impl_geomChanged(); 136 } 137 138 private FloatProperty height; 139 140 public final void setHeight(float value) { 141 heightProperty().set(value); 142 } 143 144 public final float getHeight() { 145 return height == null ? 100 : height.get(); 146 } 147 148 public FloatProperty heightProperty() { 149 if (height == null) { 150 height = new SimpleFloatProperty() { 151 152 @Override 153 protected void invalidated() { 154 impl_storeHeight(height, get()); 155 } 156 }; 157 } 158 return height; 159 } 160 161 protected void impl_storeHeight(FloatProperty model, float value) { 162 impl_geomChanged(); 163 } 164 165 int geomComputeCount = 0; 166 167 public com.sun.javafx.geom.BaseBounds impl_computeGeomBounds(com.sun.javafx.geom.BaseBounds bounds, com.sun.javafx.geom.transform.BaseTransform tx) { 168 geomComputeCount++; 169 bounds = bounds.deriveWithNewBounds(0, 0, 0, 100, 100, 0); 170 return bounds; 171 } 172 173 @Override 174 protected boolean impl_computeContains(double localX, double localY) { 175 // Stub 176 return false; 177 } 178 179 private NGNode doCreatePeer() { 180 return new NGRectangle(); 181 } 182 183 @Override 184 public Object impl_processMXNode(MXNodeAlgorithm alg, MXNodeAlgorithmContext ctx) { 185 return null; 186 } 187 }