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