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 
  26 package javafx.scene.layout;
  27 
  28 import static org.junit.Assert.assertEquals;
  29 import static org.junit.Assert.assertNull;
  30 import javafx.geometry.HPos;
  31 import javafx.geometry.Insets;
  32 import javafx.geometry.Orientation;
  33 import javafx.geometry.Pos;
  34 import javafx.geometry.VPos;
  35 import javafx.scene.Node;
  36 import javafx.scene.shape.Rectangle;
  37 import org.junit.Before;
  38 
  39 import org.junit.Test;
  40 
  41 
  42 public class FlowPaneTest {
  43     FlowPane flowpane;
  44 
  45     @Before public void setUp() {
  46         this.flowpane = new FlowPane();
  47     }
  48 
  49     @Test public void testFlowPaneDefaults() {
  50         assertEquals(Orientation.HORIZONTAL, flowpane.getOrientation());
  51         assertEquals(0, flowpane.getHgap(), 1e-100);
  52         assertEquals(0, flowpane.getVgap(), 1e-100);
  53         assertEquals(Pos.TOP_LEFT, flowpane.getAlignment());
  54         assertEquals(VPos.CENTER, flowpane.getRowValignment());
  55         assertEquals(HPos.LEFT, flowpane.getColumnHalignment());
  56         assertEquals(400, flowpane.getPrefWrapLength(), 1e-100);
  57     }
  58 
  59     @Test public void testFlowPaneNulls() {
  60         flowpane.setAlignment(null);
  61         flowpane.setColumnHalignment(null);
  62         flowpane.setRowValignment(null);
  63         flowpane.setOrientation(null);
  64 
  65         // this musn't throw NPE
  66         flowpane.autosize();
  67         flowpane.layout();
  68 
  69         assertNull(flowpane.getOrientation());
  70         assertNull(flowpane.getAlignment());
  71         assertNull(flowpane.getRowValignment());
  72         assertNull(flowpane.getColumnHalignment());
  73         assertNull(flowpane.orientationProperty().get());
  74         assertNull(flowpane.alignmentProperty().get());
  75         assertNull(flowpane.rowValignmentProperty().get());
  76         assertNull(flowpane.columnHalignmentProperty().get());
  77     }
  78 
  79     @Test public void testSimpleFlowPane() {
  80         for(int i = 0; i < 3; i++) { // 6 children
  81             MockResizable child1 = new MockResizable(100,200);
  82             Rectangle child2 = new Rectangle(100, 100);
  83             flowpane.getChildren().addAll(child1, child2);
  84         }
  85 
  86         assertEquals(100, flowpane.minWidth(-1), 1e-100);
  87         assertEquals(900, flowpane.minHeight(100), 1e-100);
  88         assertEquals(400, flowpane.prefWidth(-1), 1e-100);
  89         assertEquals(400, flowpane.prefHeight(-1), 1e-100);
  90 
  91         flowpane.autosize();
  92         flowpane.layout();
  93 
  94         // test a handful
  95         Node first = flowpane.getChildren().get(0);
  96         Node last = flowpane.getChildren().get(5);
  97 
  98         assertEquals(0, first.getLayoutX(), 1e-100);
  99         assertEquals(0, first.getLayoutY(), 1e-100);
 100         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 101         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 102         assertEquals(100, last.getLayoutX(), 1e-100);
 103         assertEquals(250, last.getLayoutY(), 1e-100);
 104         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 105         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 106 
 107         flowpane.resize(800,800);
 108         flowpane.layout();
 109         assertEquals(0, first.getLayoutX(), 1e-100);
 110         assertEquals(0, first.getLayoutY(), 1e-100);
 111         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 112         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 113         assertEquals(500, last.getLayoutX(), 1e-100);
 114         assertEquals(50, last.getLayoutY(), 1e-100);
 115         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 116         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 117     }
 118 
 119     @Test public void testEmptyHorizontalFlowPaneMinWidthIsZero() {
 120         FlowPane flowpane = new FlowPane();
 121 
 122         assertEquals(0, flowpane.minWidth(-1), 0);
 123     }
 124 
 125     @Test public void testEmptyHorizontalFlowPaneMinHeightIsZero() {
 126         FlowPane flowpane = new FlowPane();
 127 
 128         assertEquals(0, flowpane.minHeight(-1), 0);
 129     }
 130 
 131     @Test public void testEmptyVerticalFlowPaneMinWidthIsZero() {
 132         FlowPane flowpane = new FlowPane(Orientation.VERTICAL);
 133 
 134         assertEquals(0, flowpane.minWidth(-1), 0);
 135     }
 136 
 137     @Test public void testEmptyVerticalFlowPaneMinHeightIsZero() {
 138         FlowPane flowpane = new FlowPane(Orientation.VERTICAL);
 139 
 140         assertEquals(0, flowpane.minHeight(-1), 0);
 141     }
 142 
 143     @Test public void testHorizontalFlowPaneAlignmentTopLeft() {
 144         for(int i = 0; i < 3; i++) {
 145             MockResizable child1 = new MockResizable(100,200);
 146             Rectangle child2 = new Rectangle(100, 100);
 147             flowpane.getChildren().addAll(child1, child2);
 148         }
 149         flowpane.setAlignment(Pos.TOP_LEFT);
 150 
 151         flowpane.resize(450,450);
 152         flowpane.layout();
 153 
 154         // test a handful
 155         Node first = flowpane.getChildren().get(0);
 156         Node last = flowpane.getChildren().get(5);
 157 
 158         assertEquals(0, first.getLayoutX(), 1e-100);
 159         assertEquals(0, first.getLayoutY(), 1e-100);
 160         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 161         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 162         assertEquals(100, last.getLayoutX(), 1e-100);
 163         assertEquals(250, last.getLayoutY(), 1e-100);
 164         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 165         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 166     }
 167 
 168     @Test public void testHorizontalFlowPaneAlignmentTopCenter() {
 169         for(int i = 0; i < 3; i++) {
 170             MockResizable child1 = new MockResizable(100,200);
 171             Rectangle child2 = new Rectangle(100, 100);
 172             flowpane.getChildren().addAll(child1, child2);
 173         }
 174         flowpane.setAlignment(Pos.TOP_CENTER);
 175 
 176         flowpane.resize(450,450);
 177         flowpane.layout();
 178 
 179         // test a handful
 180         Node first = flowpane.getChildren().get(0);
 181         Node last = flowpane.getChildren().get(5);
 182 
 183         assertEquals(25, first.getLayoutX(), 1e-100);
 184         assertEquals(0, first.getLayoutY(), 1e-100);
 185         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 186         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 187         assertEquals(225, last.getLayoutX(), 1e-100);
 188         assertEquals(250, last.getLayoutY(), 1e-100);
 189         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 190         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 191     }
 192 
 193     @Test public void testHorizontalFlowPaneAlignmentTopRight() {
 194         for(int i = 0; i < 3; i++) {
 195             MockResizable child1 = new MockResizable(100,200);
 196             Rectangle child2 = new Rectangle(100, 100);
 197             flowpane.getChildren().addAll(child1, child2);
 198         }
 199         flowpane.setAlignment(Pos.TOP_RIGHT);
 200 
 201         flowpane.resize(450,450);
 202         flowpane.layout();
 203 
 204         // test a handful
 205         Node first = flowpane.getChildren().get(0);
 206         Node last = flowpane.getChildren().get(5);
 207 
 208         assertEquals(50, first.getLayoutX(), 1e-100);
 209         assertEquals(0, first.getLayoutY(), 1e-100);
 210         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 211         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 212         assertEquals(350, last.getLayoutX(), 1e-100);
 213         assertEquals(250, last.getLayoutY(), 1e-100);
 214         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 215         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 216     }
 217 
 218     @Test public void testHorizontalFlowPaneAlignmentCenterLeft() {
 219         for(int i = 0; i < 3; i++) {
 220             MockResizable child1 = new MockResizable(100,200);
 221             Rectangle child2 = new Rectangle(100, 100);
 222             flowpane.getChildren().addAll(child1, child2);
 223         }
 224         flowpane.setAlignment(Pos.CENTER_LEFT);
 225 
 226         flowpane.resize(450,450);
 227         flowpane.layout();
 228 
 229         // test a handful
 230         Node first = flowpane.getChildren().get(0);
 231         Node last = flowpane.getChildren().get(5);
 232 
 233         assertEquals(0, first.getLayoutX(), 1e-100);
 234         assertEquals(25, first.getLayoutY(), 1e-100);
 235         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 236         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 237         assertEquals(100, last.getLayoutX(), 1e-100);
 238         assertEquals(275, last.getLayoutY(), 1e-100);
 239         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 240         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 241     }
 242 
 243     @Test public void testHorizontalFlowPaneAlignmentCenter() {
 244         for(int i = 0; i < 3; i++) {
 245             MockResizable child1 = new MockResizable(100,200);
 246             Rectangle child2 = new Rectangle(100, 100);
 247             flowpane.getChildren().addAll(child1, child2);
 248         }
 249         flowpane.setAlignment(Pos.CENTER);
 250 
 251         flowpane.resize(450,450);
 252         flowpane.layout();
 253 
 254         // test a handful
 255         Node first = flowpane.getChildren().get(0);
 256         Node last = flowpane.getChildren().get(5);
 257 
 258         assertEquals(25, first.getLayoutX(), 1e-100);
 259         assertEquals(25, first.getLayoutY(), 1e-100);
 260         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 261         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 262         assertEquals(225, last.getLayoutX(), 1e-100);
 263         assertEquals(275, last.getLayoutY(), 1e-100);
 264         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 265         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 266     }
 267 
 268     @Test public void testHorizontalFlowPaneAlignmentCenterRight() {
 269         for(int i = 0; i < 3; i++) {
 270             MockResizable child1 = new MockResizable(100,200);
 271             Rectangle child2 = new Rectangle(100, 100);
 272             flowpane.getChildren().addAll(child1, child2);
 273         }
 274         flowpane.setAlignment(Pos.CENTER_RIGHT);
 275 
 276         flowpane.resize(450,450);
 277         flowpane.layout();
 278 
 279         // test a handful
 280         Node first = flowpane.getChildren().get(0);
 281         Node last = flowpane.getChildren().get(5);
 282 
 283         assertEquals(50, first.getLayoutX(), 1e-100);
 284         assertEquals(25, first.getLayoutY(), 1e-100);
 285         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 286         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 287         assertEquals(350, last.getLayoutX(), 1e-100);
 288         assertEquals(275, last.getLayoutY(), 1e-100);
 289         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 290         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 291     }
 292 
 293     @Test public void testHorizontalFlowPaneAlignmentBottomLeft() {
 294         for(int i = 0; i < 3; i++) {
 295             MockResizable child1 = new MockResizable(100,200);
 296             Rectangle child2 = new Rectangle(100, 100);
 297             flowpane.getChildren().addAll(child1, child2);
 298         }
 299         flowpane.setAlignment(Pos.BOTTOM_LEFT);
 300 
 301         flowpane.resize(450,450);
 302         flowpane.layout();
 303 
 304         // test a handful
 305         Node first = flowpane.getChildren().get(0);
 306         Node last = flowpane.getChildren().get(5);
 307 
 308         assertEquals(0, first.getLayoutX(), 1e-100);
 309         assertEquals(50, first.getLayoutY(), 1e-100);
 310         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 311         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 312         assertEquals(100, last.getLayoutX(), 1e-100);
 313         assertEquals(300, last.getLayoutY(), 1e-100);
 314         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 315         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 316     }
 317 
 318     @Test public void testHorizontalFlowPaneAlignmentBottomCenter() {
 319         for(int i = 0; i < 3; i++) {
 320             MockResizable child1 = new MockResizable(100,200);
 321             Rectangle child2 = new Rectangle(100, 100);
 322             flowpane.getChildren().addAll(child1, child2);
 323         }
 324         flowpane.setAlignment(Pos.BOTTOM_CENTER);
 325 
 326         flowpane.resize(450,450);
 327         flowpane.layout();
 328 
 329         // test a handful
 330         Node first = flowpane.getChildren().get(0);
 331         Node last = flowpane.getChildren().get(5);
 332 
 333         assertEquals(25, first.getLayoutX(), 1e-100);
 334         assertEquals(50, first.getLayoutY(), 1e-100);
 335         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 336         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 337         assertEquals(225, last.getLayoutX(), 1e-100);
 338         assertEquals(300, last.getLayoutY(), 1e-100);
 339         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 340         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 341     }
 342 
 343     @Test public void testHorizontalFlowPaneAlignmentBottomRight() {
 344         for(int i = 0; i < 3; i++) {
 345             MockResizable child1 = new MockResizable(100,200);
 346             Rectangle child2 = new Rectangle(100, 100);
 347             flowpane.getChildren().addAll(child1, child2);
 348         }
 349         flowpane.setAlignment(Pos.BOTTOM_RIGHT);
 350 
 351         flowpane.resize(450,450);
 352         flowpane.layout();
 353 
 354         // test a handful
 355         Node first = flowpane.getChildren().get(0);
 356         Node last = flowpane.getChildren().get(5);
 357 
 358         assertEquals(50, first.getLayoutX(), 1e-100);
 359         assertEquals(50, first.getLayoutY(), 1e-100);
 360         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 361         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 362         assertEquals(350, last.getLayoutX(), 1e-100);
 363         assertEquals(300, last.getLayoutY(), 1e-100);
 364         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 365         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 366     }
 367 
 368     @Test public void testVerticalFlowPaneAlignmentTopLeft() {
 369         flowpane.setOrientation(Orientation.VERTICAL);
 370 
 371         for(int i = 0; i < 3; i++) {
 372             MockResizable child1 = new MockResizable(200,300);
 373             Rectangle child2 = new Rectangle(100, 100);
 374             flowpane.getChildren().addAll(child1, child2);
 375         }
 376         flowpane.setAlignment(Pos.TOP_LEFT);
 377 
 378         flowpane.resize(700,600);
 379         flowpane.layout();
 380 
 381         // test a handful
 382         Node first = flowpane.getChildren().get(0);
 383         Node last = flowpane.getChildren().get(5);
 384 
 385         assertEquals(0, first.getLayoutX(), 1e-100);
 386         assertEquals(0, first.getLayoutY(), 1e-100);
 387         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 388         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 389         assertEquals(400, last.getLayoutX(), 1e-100);
 390         assertEquals(300, last.getLayoutY(), 1e-100);
 391         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 392         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 393     }
 394 
 395     @Test public void testVerticalFlowPaneAlignmentTopCenter() {
 396         flowpane.setOrientation(Orientation.VERTICAL);
 397 
 398         for(int i = 0; i < 3; i++) {
 399             MockResizable child1 = new MockResizable(200,300);
 400             Rectangle child2 = new Rectangle(100, 100);
 401             flowpane.getChildren().addAll(child1, child2);
 402         }
 403         flowpane.setAlignment(Pos.TOP_CENTER);
 404 
 405         flowpane.resize(700,600);
 406         flowpane.layout();
 407 
 408         // test a handful
 409         Node first = flowpane.getChildren().get(0);
 410         Node last = flowpane.getChildren().get(5);
 411 
 412         assertEquals(50, first.getLayoutX(), 1e-100);
 413         assertEquals(0, first.getLayoutY(), 1e-100);
 414         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 415         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 416         assertEquals(450, last.getLayoutX(), 1e-100);
 417         assertEquals(300, last.getLayoutY(), 1e-100);
 418         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 419         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 420     }
 421 
 422     @Test public void testVerticalFlowPaneAlignmentTopRight() {
 423         flowpane.setOrientation(Orientation.VERTICAL);
 424 
 425         for(int i = 0; i < 3; i++) {
 426             MockResizable child1 = new MockResizable(200,300);
 427             Rectangle child2 = new Rectangle(100, 100);
 428             flowpane.getChildren().addAll(child1, child2);
 429         }
 430         flowpane.setAlignment(Pos.TOP_RIGHT);
 431 
 432         flowpane.resize(700,600);
 433         flowpane.layout();
 434 
 435         // test a handful
 436         Node first = flowpane.getChildren().get(0);
 437         Node last = flowpane.getChildren().get(5);
 438 
 439         assertEquals(100, first.getLayoutX(), 1e-100);
 440         assertEquals(0, first.getLayoutY(), 1e-100);
 441         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 442         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 443         assertEquals(500, last.getLayoutX(), 1e-100);
 444         assertEquals(300, last.getLayoutY(), 1e-100);
 445         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 446         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 447     }
 448 
 449     @Test public void testVerticalFlowPaneAlignmentCenterLeft() {
 450         flowpane.setOrientation(Orientation.VERTICAL);
 451 
 452         for(int i = 0; i < 3; i++) {
 453             MockResizable child1 = new MockResizable(200,300);
 454             Rectangle child2 = new Rectangle(100, 100);
 455             flowpane.getChildren().addAll(child1, child2);
 456         }
 457         flowpane.setAlignment(Pos.CENTER_LEFT);
 458 
 459         flowpane.resize(700,600);
 460         flowpane.layout();
 461 
 462         // test a handful
 463         Node first = flowpane.getChildren().get(0);
 464         Node last = flowpane.getChildren().get(5);
 465 
 466         assertEquals(0, first.getLayoutX(), 1e-100);
 467         assertEquals(100, first.getLayoutY(), 1e-100);
 468         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 469         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 470         assertEquals(400, last.getLayoutX(), 1e-100);
 471         assertEquals(400, last.getLayoutY(), 1e-100);
 472         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 473         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 474     }
 475 
 476     @Test public void testVerticalFlowPaneAlignmentCenter() {
 477         flowpane.setOrientation(Orientation.VERTICAL);
 478 
 479         for(int i = 0; i < 3; i++) {
 480             MockResizable child1 = new MockResizable(200,300);
 481             Rectangle child2 = new Rectangle(100, 100);
 482             flowpane.getChildren().addAll(child1, child2);
 483         }
 484         flowpane.setAlignment(Pos.CENTER);
 485 
 486         flowpane.resize(700,600);
 487         flowpane.layout();
 488 
 489         // test a handful
 490         Node first = flowpane.getChildren().get(0);
 491         Node last = flowpane.getChildren().get(5);
 492 
 493         assertEquals(50, first.getLayoutX(), 1e-100);
 494         assertEquals(100, first.getLayoutY(), 1e-100);
 495         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 496         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 497         assertEquals(450, last.getLayoutX(), 1e-100);
 498         assertEquals(400, last.getLayoutY(), 1e-100);
 499         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 500         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 501     }
 502 
 503     @Test public void testVerticalFlowPaneAlignmentCenterRight() {
 504         flowpane.setOrientation(Orientation.VERTICAL);
 505 
 506         for(int i = 0; i < 3; i++) {
 507             MockResizable child1 = new MockResizable(200,300);
 508             Rectangle child2 = new Rectangle(100, 100);
 509             flowpane.getChildren().addAll(child1, child2);
 510         }
 511         flowpane.setAlignment(Pos.CENTER_RIGHT);
 512 
 513         flowpane.resize(700,600);
 514         flowpane.layout();
 515 
 516         // test a handful
 517         Node first = flowpane.getChildren().get(0);
 518         Node last = flowpane.getChildren().get(5);
 519 
 520         assertEquals(100, first.getLayoutX(), 1e-100);
 521         assertEquals(100, first.getLayoutY(), 1e-100);
 522         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 523         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 524         assertEquals(500, last.getLayoutX(), 1e-100);
 525         assertEquals(400, last.getLayoutY(), 1e-100);
 526         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 527         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 528     }
 529 
 530     @Test public void testVerticalFlowPaneAlignmentBottomLeft() {
 531         flowpane.setOrientation(Orientation.VERTICAL);
 532 
 533         for(int i = 0; i < 3; i++) {
 534             MockResizable child1 = new MockResizable(200,300);
 535             Rectangle child2 = new Rectangle(100, 100);
 536             flowpane.getChildren().addAll(child1, child2);
 537         }
 538         flowpane.setAlignment(Pos.BOTTOM_LEFT);
 539 
 540         flowpane.resize(700,600);
 541         flowpane.layout();
 542 
 543         // test a handful
 544         Node first = flowpane.getChildren().get(0);
 545         Node last = flowpane.getChildren().get(5);
 546 
 547         assertEquals(0, first.getLayoutX(), 1e-100);
 548         assertEquals(200, first.getLayoutY(), 1e-100);
 549         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 550         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 551         assertEquals(400, last.getLayoutX(), 1e-100);
 552         assertEquals(500, last.getLayoutY(), 1e-100);
 553         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 554         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 555     }
 556 
 557     @Test public void testVerticalFlowPaneAlignmentBottomCenter() {
 558         flowpane.setOrientation(Orientation.VERTICAL);
 559 
 560         for(int i = 0; i < 3; i++) {
 561             MockResizable child1 = new MockResizable(200,300);
 562             Rectangle child2 = new Rectangle(100, 100);
 563             flowpane.getChildren().addAll(child1, child2);
 564         }
 565         flowpane.setAlignment(Pos.BOTTOM_CENTER);
 566 
 567         flowpane.resize(700,600);
 568         flowpane.layout();
 569 
 570         // test a handful
 571         Node first = flowpane.getChildren().get(0);
 572         Node last = flowpane.getChildren().get(5);
 573 
 574         assertEquals(50, first.getLayoutX(), 1e-100);
 575         assertEquals(200, first.getLayoutY(), 1e-100);
 576         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 577         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 578         assertEquals(450, last.getLayoutX(), 1e-100);
 579         assertEquals(500, last.getLayoutY(), 1e-100);
 580         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 581         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 582     }
 583 
 584     @Test public void testVerticalFlowPaneAlignmentBottomRight() {
 585         flowpane.setOrientation(Orientation.VERTICAL);
 586 
 587         for(int i = 0; i < 3; i++) {
 588             MockResizable child1 = new MockResizable(200,300);
 589             Rectangle child2 = new Rectangle(100, 100);
 590             flowpane.getChildren().addAll(child1, child2);
 591         }
 592         flowpane.setAlignment(Pos.BOTTOM_RIGHT);
 593 
 594         flowpane.resize(700,600);
 595         flowpane.layout();
 596 
 597         // test a handful
 598         Node first = flowpane.getChildren().get(0);
 599         Node last = flowpane.getChildren().get(5);
 600 
 601         assertEquals(100, first.getLayoutX(), 1e-100);
 602         assertEquals(200, first.getLayoutY(), 1e-100);
 603         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 604         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 605         assertEquals(500, last.getLayoutX(), 1e-100);
 606         assertEquals(500, last.getLayoutY(), 1e-100);
 607         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 608         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 609     }
 610 
 611     @Test public void testHorizontalFlowPaneRowVAlignmentTop() {
 612         for(int i = 0; i < 3; i++) {
 613             MockResizable child1 = new MockResizable(100,200);
 614             Rectangle child2 = new Rectangle(100, 100);
 615             flowpane.getChildren().addAll(child1, child2);
 616         }
 617         flowpane.setRowValignment(VPos.TOP);
 618 
 619         flowpane.resize(450,450);
 620         flowpane.layout();
 621 
 622         // test a handful
 623         Node first = flowpane.getChildren().get(0);
 624         Node last = flowpane.getChildren().get(5);
 625 
 626         assertEquals(0, first.getLayoutX(), 1e-100);
 627         assertEquals(0, first.getLayoutY(), 1e-100);
 628         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 629         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 630         assertEquals(100, last.getLayoutX(), 1e-100);
 631         assertEquals(200, last.getLayoutY(), 1e-100);
 632         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 633         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 634     }
 635 
 636     @Test public void testHorizontalFlowPaneRowVAlignmentCenter() {
 637         for(int i = 0; i < 3; i++) {
 638             MockResizable child1 = new MockResizable(100,200);
 639             Rectangle child2 = new Rectangle(100, 100);
 640             flowpane.getChildren().addAll(child1, child2);
 641         }
 642         flowpane.setRowValignment(VPos.CENTER);
 643 
 644         flowpane.resize(450,450);
 645         flowpane.layout();
 646 
 647         // test a handful
 648         Node first = flowpane.getChildren().get(0);
 649         Node last = flowpane.getChildren().get(5);
 650 
 651         assertEquals(0, first.getLayoutX(), 1e-100);
 652         assertEquals(0, first.getLayoutY(), 1e-100);
 653         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 654         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 655         assertEquals(100, last.getLayoutX(), 1e-100);
 656         assertEquals(250, last.getLayoutY(), 1e-100);
 657         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 658         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 659     }
 660 
 661     @Test public void testHorizontalFlowPaneRowVAlignmentBaseline() {
 662         for(int i = 0; i < 3; i++) {
 663             MockResizable child1 = new MockResizable(100,200); //baseline=190
 664             Rectangle child2 = new Rectangle(100, 100);
 665             flowpane.getChildren().addAll(child1, child2);
 666         }
 667         flowpane.setRowValignment(VPos.BASELINE);
 668 
 669         flowpane.resize(450,450);
 670         flowpane.layout();
 671 
 672         // test a handful
 673         Node first = flowpane.getChildren().get(0);
 674         Node last = flowpane.getChildren().get(5);
 675 
 676         assertEquals(0, first.getLayoutX(), 1e-100);
 677         assertEquals(0, first.getLayoutY(), 1e-100);
 678         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 679         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 680         assertEquals(100, last.getLayoutX(), 1e-100);
 681         assertEquals(290, last.getLayoutY(), 1e-100);
 682         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 683         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 684     }
 685 
 686     @Test public void testHorizontalFlowPaneRowVAlignmentBottom() {
 687         for(int i = 0; i < 3; i++) {
 688             MockResizable child1 = new MockResizable(100,200);
 689             Rectangle child2 = new Rectangle(100, 100);
 690             flowpane.getChildren().addAll(child1, child2);
 691         }
 692         flowpane.setRowValignment(VPos.BOTTOM);
 693 
 694         flowpane.resize(450,450);
 695         flowpane.layout();
 696 
 697         // test a handful
 698         Node first = flowpane.getChildren().get(0);
 699         Node last = flowpane.getChildren().get(5);
 700 
 701         assertEquals(0, first.getLayoutX(), 1e-100);
 702         assertEquals(0, first.getLayoutY(), 1e-100);
 703         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 704         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 705         assertEquals(100, last.getLayoutX(), 1e-100);
 706         assertEquals(300, last.getLayoutY(), 1e-100);
 707         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 708         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 709     }
 710 
 711     @Test public void testVerticalFlowPaneRowHAlignmentLeft() {
 712         flowpane.setOrientation(Orientation.VERTICAL);
 713 
 714         for(int i = 0; i < 3; i++) {
 715             MockResizable child1 = new MockResizable(200,300);
 716             Rectangle child2 = new Rectangle(100, 100);
 717             flowpane.getChildren().addAll(child1, child2);
 718         }
 719         flowpane.setColumnHalignment(HPos.LEFT);
 720 
 721         flowpane.resize(600,800);
 722         flowpane.layout();
 723 
 724         // test a handful
 725         Node first = flowpane.getChildren().get(0);
 726         Node last = flowpane.getChildren().get(5);
 727 
 728         assertEquals(0, first.getLayoutX(), 1e-100);
 729         assertEquals(0, first.getLayoutY(), 1e-100);
 730         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 731         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 732         assertEquals(200, last.getLayoutX(), 1e-100);
 733         assertEquals(300, last.getLayoutY(), 1e-100);
 734         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 735         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 736     }
 737 
 738     @Test public void testVerticalFlowPaneRowHAlignmentCenter() {
 739         flowpane.setOrientation(Orientation.VERTICAL);
 740 
 741         for(int i = 0; i < 3; i++) {
 742             MockResizable child1 = new MockResizable(200,300);
 743             Rectangle child2 = new Rectangle(100, 100);
 744             flowpane.getChildren().addAll(child1, child2);
 745         }
 746         flowpane.setColumnHalignment(HPos.CENTER);
 747 
 748         flowpane.resize(600,800);
 749         flowpane.layout();
 750 
 751         // test a handful
 752         Node first = flowpane.getChildren().get(0);
 753         Node last = flowpane.getChildren().get(5);
 754 
 755         assertEquals(0, first.getLayoutX(), 1e-100);
 756         assertEquals(0, first.getLayoutY(), 1e-100);
 757         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 758         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 759         assertEquals(250, last.getLayoutX(), 1e-100);
 760         assertEquals(300, last.getLayoutY(), 1e-100);
 761         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 762         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 763     }
 764 
 765     @Test public void testVerticalFlowPaneRowHAlignmentRight() {
 766         flowpane.setOrientation(Orientation.VERTICAL);
 767 
 768         for(int i = 0; i < 3; i++) {
 769             MockResizable child1 = new MockResizable(200,300);
 770             Rectangle child2 = new Rectangle(100, 100);
 771             flowpane.getChildren().addAll(child1, child2);
 772         }
 773         flowpane.setColumnHalignment(HPos.RIGHT);
 774 
 775         flowpane.resize(600,800);
 776         flowpane.layout();
 777 
 778         // test a handful
 779         Node first = flowpane.getChildren().get(0);
 780         Node last = flowpane.getChildren().get(5);
 781 
 782         assertEquals(0, first.getLayoutX(), 1e-100);
 783         assertEquals(0, first.getLayoutY(), 1e-100);
 784         assertEquals(200, first.getLayoutBounds().getWidth(), 1e-100);
 785         assertEquals(300, first.getLayoutBounds().getHeight(), 1e-100);
 786         assertEquals(300, last.getLayoutX(), 1e-100);
 787         assertEquals(300, last.getLayoutY(), 1e-100);
 788         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 789         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 790     }
 791     
 792     @Test public void testFlowPaneSetMarginConstraint() {
 793         MockResizable child1 = new MockResizable(100,200, 300,400, 500,600);
 794 
 795         assertNull(FlowPane.getMargin(child1));
 796         
 797         Insets margin = new Insets(10,20,30,40);
 798         FlowPane.setMargin(child1, margin);
 799         assertEquals(margin, FlowPane.getMargin(child1));
 800 
 801         FlowPane.setMargin(child1, null);
 802         assertNull(FlowPane.getMargin(child1));
 803     }
 804 
 805     @Test public void testFlowPaneMarginConstraint() {
 806         for(int i = 0; i < 3; i++) {
 807             MockResizable child1 = new MockResizable(100,200);
 808             Rectangle child2 = new Rectangle(100, 100);
 809             flowpane.getChildren().addAll(child1, child2);
 810         }
 811 
 812         // test a handful
 813         Node first = flowpane.getChildren().get(0);
 814         Node last = flowpane.getChildren().get(5);
 815 
 816         FlowPane.setMargin(first, new Insets(10,20,30,40));
 817 
 818         assertEquals(100, flowpane.minWidth(-1), 1e-100);
 819         assertEquals(940, flowpane.minHeight(100), 1e-100);
 820         assertEquals(400, flowpane.prefWidth(-1), 1e-100);
 821         assertEquals(440, flowpane.prefHeight(-1), 1e-100);
 822 
 823         flowpane.autosize();
 824         flowpane.layout();
 825 
 826         assertEquals(40, first.getLayoutX(), 1e-100);
 827         assertEquals(10, first.getLayoutY(), 1e-100);
 828         assertEquals(100, first.getLayoutBounds().getWidth(), 1e-100);
 829         assertEquals(200, first.getLayoutBounds().getHeight(), 1e-100);
 830         assertEquals(200, last.getLayoutX(), 1e-100);
 831         assertEquals(290, last.getLayoutY(), 1e-100);
 832         assertEquals(100, last.getLayoutBounds().getWidth(), 1e-100);
 833         assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100);
 834     }
 835 
 836     // FlowPane does not shrink their children to be smaller than their preferred sizes 
 837     @Test public void testHorizontalFlowPaneFitsChildWithinHeightIfPossible() {
 838         MockResizable child = new MockResizable(10,20, 200,200, 500,500);
 839 
 840         flowpane.getChildren().add(child);
 841 
 842         flowpane.resize(100,100);
 843         flowpane.layout();
 844 
 845         assertEquals(200, child.getWidth(), 1e-100);
 846         assertEquals(200, child.getHeight(), 1e-100);
 847     }
 848 
 849     @Test public void testVerticalFlowPaneFitsChildWithinWidthIfPossible() {
 850         flowpane.setOrientation(Orientation.VERTICAL);
 851         MockResizable child = new MockResizable(10,20, 200,200, 500,500);
 852 
 853         flowpane.getChildren().add(child);
 854 
 855         flowpane.resize(100,100);
 856         System.out.println("******************");
 857         flowpane.layout();
 858         System.out.println("*****************");
 859 
 860         assertEquals(200, child.getWidth(), 1e-100);
 861         assertEquals(200, child.getHeight(), 1e-100);
 862     }
 863 }