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