1 /* 2 * Copyright (c) 2010, 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 test.javafx.scene.shape; 27 28 import com.sun.javafx.geom.transform.BaseTransform; 29 import com.sun.javafx.sg.prism.NGNode; 30 import com.sun.javafx.sg.prism.NGRectangle; 31 import test.com.sun.javafx.test.TestHelper; 32 import javafx.geometry.Bounds; 33 import test.javafx.scene.NodeTest; 34 import javafx.scene.paint.Paint; 35 import javafx.scene.shape.Rectangle; 36 import org.junit.Test; 37 38 import static test.com.sun.javafx.test.TestHelper.assertSimilar; 39 import static org.junit.Assert.*; 40 41 public class RectangleTest { 42 43 @Test public void testPropertyPropagation_visible() throws Exception { 44 final Rectangle node = new StubRectangle(); 45 NodeTest.testBooleanPropertyPropagation(node, "visible", false, true); 46 } 47 48 @Test public void testPropertyPropagation_x() throws Exception { 49 final Rectangle node = new StubRectangle(); 50 NodeTest.testDoublePropertyPropagation(node, "x", 100, 200); 51 } 52 53 @Test public void testPropertyPropagation_y() throws Exception { 54 final Rectangle node = new StubRectangle(); 55 NodeTest.testDoublePropertyPropagation(node, "y", 100, 200); 56 } 57 58 @Test public void testPropertyPropagation_width() throws Exception { 59 final Rectangle node = new StubRectangle(); 60 NodeTest.testDoublePropertyPropagation(node, "width", 100, 200); 61 } 62 63 @Test public void testPropertyPropagation_height() throws Exception { 64 final Rectangle node = new StubRectangle(); 65 NodeTest.testDoublePropertyPropagation(node, "height", 100, 200); 66 } 67 68 @Test public void testPropertyPropagation_arcWidth() throws Exception { 69 final Rectangle node = new StubRectangle(); 70 NodeTest.testDoublePropertyPropagation(node, "arcWidth", 100, 200); 71 } 72 73 @Test public void testPropertyPropagation_arcHeight() throws Exception { 74 final Rectangle node = new StubRectangle(); 75 NodeTest.testDoublePropertyPropagation(node, "arcHeight", 100, 200); 76 } 77 78 @Test public void testBoundPropertySync_X() throws Exception { 79 NodeTest.assertDoublePropertySynced( 80 new StubRectangle(200.0, 100.0), 81 "x", "x", 10.0); 82 } 83 84 @Test public void testBoundPropertySync_Y() throws Exception { 85 NodeTest.assertDoublePropertySynced( 86 new StubRectangle(200.0, 100.0), 87 "y", "y", 20.0); 88 } 89 90 @Test public void testBoundPropertySync_Width() throws Exception { 91 NodeTest.assertDoublePropertySynced( 92 new StubRectangle(200.0, 100.0), 93 "width", "width", 300.0); 94 } 95 96 @Test public void testBoundPropertySync_Height() throws Exception { 97 NodeTest.assertDoublePropertySynced( 98 new StubRectangle(200.0, 100.0), 99 "height", "height", 200.0); 100 } 101 102 @Test public void testBoundPropertySync_ArcWidth() throws Exception { 103 NodeTest.assertDoublePropertySynced( 104 new StubRectangle(200.0, 100.0), 105 "arcWidth", "arcWidth", 10.0); 106 } 107 108 @Test public void testBoundPropertySync_ArcHeight() throws Exception { 109 NodeTest.assertDoublePropertySynced( 110 new StubRectangle(200.0, 100.0), 111 "arcHeight", "arcHeight", 30.0); 112 } 113 114 115 @Test 116 public void testTransformedBounds_rotation() { 117 Rectangle r = new StubRectangle(50, 100, 10, 20); 118 r.setArcHeight(5); 119 r.setArcWidth(10); 120 Bounds original = r.getBoundsInParent(); 121 r.setRotate(90); 122 assertSimilar(TestHelper.box(45, 105, 123 original.getHeight(), original.getWidth()), r.getBoundsInParent()); 124 } 125 126 @Test public void toStringShouldReturnNonEmptyString() { 127 String s = new StubRectangle().toString(); 128 assertNotNull(s); 129 assertFalse(s.isEmpty()); 130 } 131 132 public static final class StubRectangle extends Rectangle { 133 public StubRectangle() { 134 super(); 135 } 136 137 public StubRectangle(double width, double height) { 138 super(width, height); 139 } 140 141 public StubRectangle(double width, double height, Paint fill) { 142 super(width, height, fill); 143 } 144 145 public StubRectangle(double x, double y, double width, double height) { 146 super(x, y, width, height); 147 } 148 149 @Override 150 protected NGNode impl_createPeer() { 151 return new StubNGRectangle(); 152 } 153 } 154 155 public static final class StubNGRectangle extends NGRectangle { 156 // for tests 157 private float x; 158 private float y; 159 private float width; 160 private float height; 161 private float arcWidth; 162 private float arcHeight; 163 164 public void setX(float x) {this.x = x;} 165 public void setY(float y) {this.y = y;} 166 public void setWidth(float width) {this.width = width;} 167 public void setHeight(float height) {this.height = height;} 168 public void setArcWidth(float arcWidth) {this.arcWidth = arcWidth;} 169 public void setArcHeight(float arcHeight) {this.arcHeight = arcHeight;} 170 public float getArcHeight() {return arcHeight;} 171 public float getArcWidth() {return arcWidth;} 172 public float getHeight() {return height;} 173 public float getWidth() {return width;} 174 public float getX() {return x;} 175 public float getY() {return y;} 176 177 @Override 178 public void updateRectangle(float x, float y, float width, float height, float arcWidth, float arcHeight) { 179 this.x = x; 180 this.y = y; 181 this.width = width; 182 this.height = height; 183 this.arcWidth = arcWidth; 184 this.arcHeight = arcHeight; 185 } 186 187 private BaseTransform transformMatrix; 188 @Override 189 public void setTransformMatrix(BaseTransform tx) { 190 super.setTransformMatrix(tx); 191 this.transformMatrix = tx; 192 } 193 194 public BaseTransform getTransformMatrix() { 195 return transformMatrix; 196 } 197 } 198 }