1 /* 2 * Copyright (c) 2011, 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 package javafx.scene; 26 27 import javafx.scene.layout.MockRegion; 28 import javafx.scene.layout.Pane; 29 import javafx.scene.shape.Rectangle; 30 import static org.junit.Assert.assertEquals; 31 import org.junit.Test; 32 33 public class PaneTest { 34 35 36 @Test 37 public void testPrefWidthWithResizableChild() { 38 Pane pane = new Pane(); 39 40 javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150); 41 pane.getChildren().add(region); 42 pane.layout(); 43 44 assertEquals(100, pane.prefWidth(-1), 0); 45 } 46 47 @Test 48 public void testPrefHeightWithResizableChild() { 49 Pane pane = new Pane(); 50 51 javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150); 52 pane.getChildren().add(region); 53 pane.layout(); 54 55 assertEquals(150, pane.prefHeight(-1), 0); 56 } 57 58 @Test 59 public void testMinAndPreferredSizes() { 60 Pane pane = new Pane(); 61 Rectangle rect = new Rectangle(50,50); 62 pane.getChildren().add(rect); 63 64 rect.relocate(0, 0); 65 66 pane.layout(); 67 68 //min size is always equal to insets 69 assertEquals(0, pane.minWidth(-1), 1e-100); 70 assertEquals(0, pane.minHeight(-1), 1e-100); 71 assertEquals(50, pane.prefWidth(-1), 1e-100); 72 assertEquals(50, pane.prefHeight(-1), 1e-100); 73 74 rect.setWidth(100); 75 76 assertEquals(0, pane.minWidth(-1), 1e-100); 77 assertEquals(0, pane.minHeight(-1), 1e-100); 78 assertEquals(100, pane.prefWidth(-1), 1e-100); 79 assertEquals(50, pane.prefHeight(-1), 1e-100); 80 81 rect.setHeight(200); 82 83 assertEquals(0, pane.minWidth(-1), 1e-100); 84 assertEquals(0, pane.minHeight(-1), 1e-100); 85 assertEquals(100, pane.prefWidth(-1), 1e-100); 86 assertEquals(200, pane.prefHeight(-1), 1e-100); 87 } 88 89 @Test 90 public void testPrefSizeRespectsBounds() { 91 Pane pane = new Pane(); 92 Node n1 = new MockRegion(100, 100, 10, 10, 1000, 1000); 93 n1.relocate(10, 0); 94 Node n2 = new MockRegion(0, 0, 200, 200, 100, 100); 95 n2.relocate(0, 20); 96 97 pane.getChildren().addAll(n1, n2); 98 99 pane.layout(); 100 101 assertEquals(110, pane.prefWidth(-1), 1e-100); 102 assertEquals(120, pane.prefHeight(-1), 1e-100); 103 } 104 105 }