1 /* 2 * Copyright (c) 2010, 2014, 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.control; 27 28 import com.sun.javafx.scene.control.infrastructure.StageLoader; 29 import javafx.css.CssMetaData; 30 import static com.sun.javafx.scene.control.infrastructure.ControlTestUtils.*; 31 32 import com.sun.javafx.pgstub.StubToolkit; 33 import com.sun.javafx.scene.control.skin.SplitPaneSkin; 34 import com.sun.javafx.tk.Toolkit; 35 import javafx.application.Platform; 36 import javafx.beans.property.DoubleProperty; 37 import javafx.beans.property.ObjectProperty; 38 import javafx.beans.property.SimpleDoubleProperty; 39 import javafx.beans.property.SimpleObjectProperty; 40 import javafx.css.StyleableProperty; 41 import javafx.geometry.Orientation; 42 import javafx.scene.Scene; 43 import javafx.scene.layout.AnchorPane; 44 import javafx.scene.layout.StackPane; 45 import javafx.scene.layout.VBox; 46 import javafx.stage.Stage; 47 import static org.junit.Assert.*; 48 49 50 import org.junit.Before; 51 import org.junit.Ignore; 52 import org.junit.Test; 53 54 /** 55 * 56 * @author srikalyc 57 */ 58 public class SplitPaneTest { 59 private SplitPane splitPane;//Empty string 60 private SplitPane.Divider divider1; 61 private SplitPane.Divider divider2; 62 private Toolkit tk; 63 private Scene scene; 64 private Stage stage; 65 private StackPane root; 66 67 @Before public void setup() { 68 tk = (StubToolkit)Toolkit.getToolkit();//This step is not needed (Just to make sure StubToolkit is loaded into VM) 69 splitPane = new SplitPane(); 70 splitPane.setSkin(new SplitPaneSkin(splitPane)); 71 divider1 = new SplitPane.Divider(); 72 divider2 = new SplitPane.Divider(); 73 74 root = new StackPane(); 75 scene = new Scene(root); 76 stage = new Stage(); 77 stage.setScene(scene); 78 } 79 80 /********************************************************************* 81 * Helper methods (NOTE TESTS) * 82 ********************************************************************/ 83 private void add2NodesToSplitPane() { 84 splitPane.getItems().add(new Button("Button One")); 85 splitPane.getItems().add(new Button("Button Two")); 86 } 87 private void add3NodesToSplitPane() { 88 add2NodesToSplitPane(); 89 splitPane.getItems().add(new Button("Button Three")); 90 } 91 92 private void add4NodesToSplitPane() { 93 add3NodesToSplitPane(); 94 splitPane.getItems().add(new Button("Button Four")); 95 } 96 97 private void show() { 98 stage.show(); 99 } 100 101 102 private double convertDividerPostionToAbsolutePostion(double pos, double edge) { 103 return (Math.round(pos * edge)) - 3; // 3 is half the divider width. 104 } 105 106 /********************************************************************* 107 * Tests for default values * 108 ********************************************************************/ 109 110 @Test public void defaultConstructorShouldSetStyleClassTo_splitpane() { 111 assertStyleClassContains(splitPane, "split-pane"); 112 } 113 114 @Test public void defaultFocusTraversibleIsFalse() { 115 assertFalse(splitPane.isFocusTraversable()); 116 } 117 118 @Test public void defaultOrientation() { 119 assertSame(splitPane.getOrientation(), Orientation.HORIZONTAL); 120 } 121 122 @Test public void defaultDividerPosition() { 123 assertEquals(divider1.getPosition(), 0.5, 0.0); 124 } 125 126 @Test public void defaultPositionOf_N_DividersAddedToSplitPaneWhenNewNodeAreAdded() { 127 add4NodesToSplitPane(); 128 assertEquals(splitPane.getDividers().get(0).getPosition(), 0.5, 0.0); 129 assertEquals(splitPane.getDividers().get(1).getPosition(), 0.5, 0.0); 130 assertEquals(splitPane.getDividers().get(1).getPosition(), 0.5, 0.0); 131 } 132 133 /********************************************************************* 134 * Tests for property binding * 135 ********************************************************************/ 136 137 @Test public void checkHBarPolicyPropertyBind() { 138 ObjectProperty objPr = new SimpleObjectProperty<Orientation>(Orientation.VERTICAL); 139 splitPane.orientationProperty().bind(objPr); 140 assertSame("orientationProperty cannot be bound", splitPane.orientationProperty().getValue(), Orientation.VERTICAL); 141 objPr.setValue(Orientation.HORIZONTAL); 142 assertSame("orientationProperty cannot be bound", splitPane.orientationProperty().getValue(), Orientation.HORIZONTAL); 143 } 144 145 @Test public void checkDividerPositionPropertyBind() { 146 DoubleProperty objPr = new SimpleDoubleProperty(0.6); 147 divider1.positionProperty().bind(objPr); 148 assertEquals("positionProperty cannot be bound", divider1.positionProperty().getValue(), 0.6, 0.0); 149 objPr.setValue(0.9); 150 assertEquals("positionProperty cannot be bound", divider1.positionProperty().getValue(), 0.9, 0.0); 151 } 152 153 @Test public void checkOrientationPropertyBind() { 154 ObjectProperty objPr = new SimpleObjectProperty<Orientation>(Orientation.HORIZONTAL); 155 splitPane.orientationProperty().bind(objPr); 156 assertSame("orientationProperty cannot be bound", splitPane.orientationProperty().getValue(), Orientation.HORIZONTAL); 157 objPr.setValue(Orientation.VERTICAL); 158 assertSame("orientationProperty cannot be bound", splitPane.orientationProperty().getValue(), Orientation.VERTICAL); 159 } 160 161 @Test public void orientationPropertyHasBeanReference() { 162 assertSame(splitPane, splitPane.orientationProperty().getBean()); 163 } 164 165 @Test public void orientationPropertyHasName() { 166 assertEquals("orientation", splitPane.orientationProperty().getName()); 167 } 168 169 @Test public void positionPropertyHasBeanReference() { 170 assertSame(divider1, divider1.positionProperty().getBean()); 171 } 172 173 @Test public void positionPropertyHasName() { 174 assertEquals("position", divider1.positionProperty().getName()); 175 } 176 177 178 179 /********************************************************************* 180 * Check for Pseudo classes * 181 ********************************************************************/ 182 @Test public void settingVerticalOrientationSetsVerticalPseudoClass() { 183 splitPane.setOrientation(Orientation.VERTICAL); 184 assertPseudoClassExists(splitPane, "vertical"); 185 assertPseudoClassDoesNotExist(splitPane, "horizontal"); 186 } 187 188 @Test public void clearingVerticalOrientationClearsVerticalPseudoClass() { 189 splitPane.setOrientation(Orientation.VERTICAL); 190 splitPane.setOrientation(Orientation.HORIZONTAL); 191 assertPseudoClassDoesNotExist(splitPane, "vertical"); 192 assertPseudoClassExists(splitPane, "horizontal"); 193 } 194 195 @Test public void settingHorizontalOrientationSetsHorizontalPseudoClass() { 196 splitPane.setOrientation(Orientation.HORIZONTAL); 197 assertPseudoClassExists(splitPane, "horizontal"); 198 assertPseudoClassDoesNotExist(splitPane, "vertical"); 199 } 200 201 @Test public void clearingHorizontalOrientationClearsHorizontalPseudoClass() { 202 splitPane.setOrientation(Orientation.HORIZONTAL); 203 splitPane.setOrientation(Orientation.VERTICAL); 204 assertPseudoClassDoesNotExist(splitPane, "horizontal"); 205 assertPseudoClassExists(splitPane, "vertical"); 206 } 207 208 209 210 /********************************************************************* 211 * CSS related Tests * 212 ********************************************************************/ 213 @Test public void whenOrientationIsBound_impl_cssSettable_ReturnsFalse() { 214 CssMetaData styleable = ((StyleableProperty)splitPane.orientationProperty()).getCssMetaData(); 215 assertTrue(styleable.isSettable(splitPane)); 216 ObjectProperty<Orientation> other = new SimpleObjectProperty<Orientation>(Orientation.VERTICAL); 217 splitPane.orientationProperty().bind(other); 218 assertFalse(styleable.isSettable(splitPane)); 219 } 220 221 @Test public void whenOrientationIsSpecifiedViaCSSAndIsNotBound_impl_cssSettable_ReturnsTrue() { 222 CssMetaData styleable = ((StyleableProperty)splitPane.orientationProperty()).getCssMetaData(); 223 assertTrue(styleable.isSettable(splitPane)); 224 } 225 226 @Test public void canSpecifyOrientationViaCSS() { 227 ((StyleableProperty)splitPane.orientationProperty()).applyStyle(null, Orientation.VERTICAL); 228 assertSame(Orientation.VERTICAL, splitPane.getOrientation()); 229 } 230 231 /********************************************************************* 232 * Miscellaneous Tests * 233 ********************************************************************/ 234 @Test public void setOrientationAndSeeValueIsReflectedInModel() { 235 splitPane.setOrientation(Orientation.HORIZONTAL); 236 assertSame(splitPane.orientationProperty().getValue(), Orientation.HORIZONTAL); 237 } 238 239 @Test public void setOrientationAndSeeValue() { 240 splitPane.setOrientation(Orientation.VERTICAL); 241 assertSame(splitPane.getOrientation(), Orientation.VERTICAL); 242 } 243 244 @Test public void setPositionAndSeeValueIsReflectedInModel() { 245 divider1.setPosition(0.2); 246 assertEquals(divider1.positionProperty().getValue(), 0.2, 0.0); 247 } 248 249 @Test public void setPositionAndSeeValue() { 250 divider1.setPosition(0.3); 251 assertEquals(divider1.getPosition(), 0.3, 0.0); 252 } 253 254 @Test public void addingNnodesToSplitPaneCreatesNminus1Dividers() { 255 add3NodesToSplitPane(); 256 assertNotNull(splitPane.getDividers()); 257 assertEquals(splitPane.getDividers().size(), 2, 0.0); 258 } 259 260 @Test public void setMultipleDividerPositionsAndValidate() { 261 add3NodesToSplitPane(); 262 splitPane.setDividerPosition(0, 0.4); 263 splitPane.setDividerPosition(1, 0.6); 264 assertNotNull(splitPane.getDividers()); 265 assertEquals(splitPane.getDividers().size(), 2, 0.0); 266 assertEquals(splitPane.getDividers().get(0).getPosition(), 0.4, 0.0); 267 assertEquals(splitPane.getDividers().get(1).getPosition(), 0.6, 0.0); 268 } 269 270 @Test public void addingNonExistantDividerPositionToSplitPaneCachesItAndAppliesWhenNewNodeAreAdded() { 271 add2NodesToSplitPane(); 272 splitPane.setDividerPosition(2, 0.4);//2 is a non existant divider position, but still position value 0.4 is cached 273 274 splitPane.getItems().add(new Button("Button Three")); 275 splitPane.getItems().add(new Button("Button Four")); 276 assertNotNull(splitPane.getDividers()); 277 assertEquals(splitPane.getDividers().size(), 3, 0.0); 278 assertEquals(splitPane.getDividers().get(2).getPosition(), 0.4, 0.0); 279 } 280 281 @Test public void zeroDivider() { 282 StackPane spCenter = new StackPane(); 283 splitPane.getItems().addAll(spCenter); 284 285 root.setPrefSize(400, 400); 286 root.getChildren().add(splitPane); 287 show(); 288 289 root.applyCss(); 290 root.autosize(); 291 root.layout(); 292 293 assertEquals(0, splitPane.getDividers().size()); 294 assertEquals(398, spCenter.getLayoutBounds().getWidth(), 1e-100); 295 } 296 297 @Test public void oneDividerPanelsAreEquallySized() { 298 StackPane spLeft = new StackPane(); 299 StackPane spRight = new StackPane(); 300 301 splitPane.getItems().addAll(spLeft, spRight); 302 303 root.setPrefSize(400, 400); 304 root.getChildren().add(splitPane); 305 show(); 306 307 root.applyCss(); 308 root.autosize(); 309 root.layout(); 310 311 double w = 398; // The width minus the insets. 312 double pos[] = splitPane.getDividerPositions(); 313 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 314 315 assertEquals(196, p0, 1e-100); 316 assertEquals(196, spLeft.getLayoutBounds().getWidth(), 1e-100); 317 assertEquals(196, spRight.getLayoutBounds().getWidth(), 1e-100); 318 } 319 320 @Test public void twoDividersHaveTheSamePosition() { 321 StackPane spLeft = new StackPane(); 322 StackPane spCenter = new StackPane(); 323 StackPane spRight = new StackPane(); 324 325 splitPane.getItems().addAll(spLeft, spCenter, spRight); 326 327 root.setPrefSize(400, 400); 328 root.getChildren().add(splitPane); 329 show(); 330 331 root.applyCss(); 332 root.autosize(); 333 root.layout(); 334 335 double w = 398; // The width minus the insets. 336 double pos[] = splitPane.getDividerPositions(); 337 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 338 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 339 340 assertEquals(196, p0, 1e-100); 341 assertEquals(202, p1, 1e-100); 342 assertEquals(196, spLeft.getLayoutBounds().getWidth(), 1e-100); 343 assertEquals(0, spCenter.getLayoutBounds().getWidth(), 1e-100); 344 assertEquals(190, spRight.getLayoutBounds().getWidth(), 1e-100); 345 } 346 347 @Test public void twoDividersHaveTheDifferentPositions() { 348 StackPane spLeft = new StackPane(); 349 StackPane spCenter = new StackPane(); 350 StackPane spRight = new StackPane(); 351 352 splitPane.setDividerPosition(0, 0.20); 353 splitPane.setDividerPosition(1, 0.80); 354 splitPane.getItems().addAll(spLeft, spCenter, spRight); 355 356 root.setPrefSize(400, 400); 357 root.getChildren().add(splitPane); 358 show(); 359 360 root.applyCss(); 361 root.autosize(); 362 root.layout(); 363 364 double w = 398; // The width minus the insets. 365 double pos[] = splitPane.getDividerPositions(); 366 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 367 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 368 369 assertEquals(77, p0, 1e-100); 370 assertEquals(315, p1, 1e-100); 371 assertEquals(77, spLeft.getLayoutBounds().getWidth(), 1e-100); 372 assertEquals(232, spCenter.getLayoutBounds().getWidth(), 1e-100); 373 assertEquals(77, spRight.getLayoutBounds().getWidth(), 1e-100); 374 } 375 376 @Test public void threePanelsAllAreSetToMin() { 377 StackPane spLeft = new StackPane(); 378 StackPane spCenter = new StackPane(); 379 StackPane spRight = new StackPane(); 380 381 spLeft.setMinWidth(28); 382 spCenter.setMinWidth(29); 383 spRight.setMinWidth(29); 384 385 splitPane.setDividerPosition(0, 0.20); 386 splitPane.setDividerPosition(1, 0.80); 387 splitPane.getItems().addAll(spLeft, spCenter, spRight); 388 389 root.setPrefSize(100, 100); 390 root.getChildren().add(splitPane); 391 show(); 392 393 root.applyCss(); 394 root.autosize(); 395 root.layout(); 396 397 double w = 98; // The width minus the insets. 398 double pos[] = splitPane.getDividerPositions(); 399 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 400 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 401 402 assertEquals(28, p0, 1e-100); 403 assertEquals(63, p1, 1e-100); 404 assertEquals(28, spLeft.getLayoutBounds().getWidth(), 1e-100); 405 assertEquals(29, spCenter.getLayoutBounds().getWidth(), 1e-100); 406 assertEquals(29, spRight.getLayoutBounds().getWidth(), 1e-100); 407 } 408 409 @Test public void threePanelsAllAreSetToMax() { 410 StackPane spLeft = new StackPane(); 411 StackPane spCenter = new StackPane(); 412 StackPane spRight = new StackPane(); 413 414 spLeft.setMaxWidth(28); 415 spCenter.setMaxWidth(29); 416 spRight.setMaxWidth(29); 417 418 splitPane.setDividerPosition(0, 0.20); 419 splitPane.setDividerPosition(1, 0.80); 420 splitPane.getItems().addAll(spLeft, spCenter, spRight); 421 422 root.setPrefSize(100, 100); 423 root.getChildren().add(splitPane); 424 show(); 425 426 root.applyCss(); 427 root.autosize(); 428 root.layout(); 429 430 double w = 98; // The width minus the insets. 431 double pos[] = splitPane.getDividerPositions(); 432 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 433 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 434 435 assertEquals(28, p0, 1e-100); 436 assertEquals(63, p1, 1e-100); 437 assertEquals(28, spLeft.getLayoutBounds().getWidth(), 1e-100); 438 assertEquals(29, spCenter.getLayoutBounds().getWidth(), 1e-100); 439 assertEquals(29, spRight.getLayoutBounds().getWidth(), 1e-100); 440 } 441 442 @Test public void threePanelsSetToMinMaxMin() { 443 StackPane spLeft = new StackPane(); 444 StackPane spCenter = new StackPane(); 445 StackPane spRight = new StackPane(); 446 447 spLeft.setMinWidth(28); 448 spCenter.setMaxWidth(29); 449 spRight.setMinWidth(29); 450 451 splitPane.setDividerPosition(0, 0.20); 452 splitPane.setDividerPosition(1, 0.80); 453 splitPane.getItems().addAll(spLeft, spCenter, spRight); 454 455 root.setPrefSize(100, 100); 456 root.getChildren().add(splitPane); 457 show(); 458 459 root.applyCss(); 460 root.autosize(); 461 root.layout(); 462 463 double w = 98; // The width minus the insets. 464 double pos[] = splitPane.getDividerPositions(); 465 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 466 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 467 468 assertEquals(28, p0, 1e-100); 469 assertEquals(63, p1, 1e-100); 470 assertEquals(28, spLeft.getLayoutBounds().getWidth(), 1e-100); 471 assertEquals(29, spCenter.getLayoutBounds().getWidth(), 1e-100); 472 assertEquals(29, spRight.getLayoutBounds().getWidth(), 1e-100); 473 } 474 475 @Test public void setDividerLessThanMin() { 476 StackPane spLeft = new StackPane(); 477 StackPane spRight = new StackPane(); 478 479 spLeft.setMinWidth(80); 480 splitPane.getItems().addAll(spLeft, spRight); 481 splitPane.setDividerPositions(0); 482 483 root.setPrefSize(100, 100); 484 root.getChildren().add(splitPane); 485 show(); 486 487 root.applyCss(); 488 root.autosize(); 489 root.layout(); 490 491 double w = 98; // The width minus the insets. 492 double pos[] = splitPane.getDividerPositions(); 493 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 494 495 assertEquals(80, p0, 1e-100); 496 assertEquals(80, spLeft.getLayoutBounds().getWidth(), 1e-100); 497 assertEquals(12, spRight.getLayoutBounds().getWidth(), 1e-100); 498 } 499 500 @Test public void setDividerGreaterThanMax() { 501 StackPane spLeft = new StackPane(); 502 StackPane spRight = new StackPane(); 503 504 spLeft.setMaxWidth(80); 505 splitPane.getItems().addAll(spLeft, spRight); 506 splitPane.setDividerPositions(1.5); 507 508 root.setPrefSize(100, 100); 509 root.getChildren().add(splitPane); 510 show(); 511 512 root.applyCss(); 513 root.autosize(); 514 root.layout(); 515 516 double w = 98; // The width minus the insets. 517 double pos[] = splitPane.getDividerPositions(); 518 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 519 520 assertEquals(80, p0, 1e-100); 521 assertEquals(80, spLeft.getLayoutBounds().getWidth(), 1e-100); 522 assertEquals(12, spRight.getLayoutBounds().getWidth(), 1e-100); 523 } 524 525 @Test public void setTwoDividerGreaterThanMax() { 526 StackPane spLeft = new StackPane(); 527 StackPane spCenter = new StackPane(); 528 StackPane spRight = new StackPane(); 529 530 splitPane.getItems().addAll(spLeft, spCenter, spRight); 531 splitPane.setDividerPositions(1.5, 1.5); 532 533 root.setPrefSize(100, 100); 534 root.getChildren().add(splitPane); 535 show(); 536 537 root.applyCss(); 538 root.autosize(); 539 root.layout(); 540 541 double w = 98; // The width minus the insets. 542 double pos[] = splitPane.getDividerPositions(); 543 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 544 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 545 546 assertEquals(86, p0, 1e-100); 547 assertEquals(92, p1, 1e-100); 548 assertEquals(86, spLeft.getLayoutBounds().getWidth(), 1e-100); 549 assertEquals(0, spCenter.getLayoutBounds().getWidth(), 1e-100); 550 assertEquals(0, spRight.getLayoutBounds().getWidth(), 1e-100); 551 } 552 553 @Test public void checkDividerPositions_RT18805() { 554 Button l = new Button("Left Button"); 555 Button c = new Button("Center Button"); 556 Button r = new Button("Left Button"); 557 558 StackPane spLeft = new StackPane(); 559 StackPane spCenter = new StackPane(); 560 StackPane spRight = new StackPane(); 561 562 spLeft.getChildren().add(l); 563 spCenter.getChildren().add(c); 564 spRight.getChildren().add(r); 565 566 spLeft.setMinWidth(100); 567 spLeft.setMaxWidth(150); 568 spRight.setMaxWidth(100); 569 spRight.setMaxWidth(150); 570 571 splitPane.getItems().addAll(spLeft, spCenter, spRight); 572 573 root.setPrefSize(600, 400); 574 root.getChildren().add(splitPane); 575 show(); 576 577 root.applyCss(); 578 root.autosize(); 579 root.layout(); 580 581 double w = 598; // The width minus the insets. 582 double pos[] = splitPane.getDividerPositions(); 583 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 584 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 585 586 assertEquals(150, p0, 1e-100); 587 assertEquals(442, p1, 1e-100); 588 assertEquals(150, spLeft.getLayoutBounds().getWidth(), 1e-100); 589 assertEquals(286, spCenter.getLayoutBounds().getWidth(), 1e-100); 590 assertEquals(150, spRight.getLayoutBounds().getWidth(), 1e-100); 591 } 592 593 @Test public void growSplitPaneBy5px_RT18855() { 594 StackPane spLeft = new StackPane(); 595 StackPane spCenter = new StackPane(); 596 StackPane spRight = new StackPane(); 597 598 spLeft.setMinWidth(77); 599 spRight.setMinWidth(77); 600 601 splitPane.setDividerPosition(0, 0.20); 602 splitPane.setDividerPosition(1, 0.80); 603 splitPane.getItems().addAll(spLeft, spCenter, spRight); 604 605 root.setPrefSize(400, 400); 606 root.getChildren().add(splitPane); 607 show(); 608 609 root.applyCss(); 610 root.autosize(); 611 root.layout(); 612 613 double w = 398; // The width minus the insets. 614 double pos[] = splitPane.getDividerPositions(); 615 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 616 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 617 618 assertEquals(77, p0, 1e-100); 619 assertEquals(315, p1, 1e-100); 620 assertEquals(77, spLeft.getLayoutBounds().getWidth(), 1e-100); 621 assertEquals(232, spCenter.getLayoutBounds().getWidth(), 1e-100); 622 assertEquals(77, spRight.getLayoutBounds().getWidth(), 1e-100); 623 624 root.applyCss(); 625 root.resize(405, 400); 626 root.layout(); 627 628 w = 403; 629 pos = splitPane.getDividerPositions(); 630 p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 631 p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 632 633 assertEquals(78, p0, 1e-100); 634 assertEquals(319, p1, 1e-100); 635 assertEquals(78, spLeft.getLayoutBounds().getWidth(), 1e-100); 636 assertEquals(235, spCenter.getLayoutBounds().getWidth(), 1e-100); 637 assertEquals(78, spRight.getLayoutBounds().getWidth(), 1e-100); 638 } 639 640 @Test public void growSplitPaneBy5pxWithFixedDividers_RT18806() { 641 StackPane spLeft = new StackPane(); 642 StackPane spCenter = new StackPane(); 643 StackPane spRight = new StackPane(); 644 645 spLeft.setMinWidth(77); 646 spRight.setMinWidth(77); 647 648 splitPane.setDividerPosition(0, 0.20); 649 splitPane.setDividerPosition(1, 0.80); 650 splitPane.getItems().addAll(spLeft, spCenter, spRight); 651 652 SplitPane.setResizableWithParent(spLeft, false); 653 SplitPane.setResizableWithParent(spRight, false); 654 655 root.setPrefSize(400, 400); 656 root.getChildren().add(splitPane); 657 show(); 658 659 root.applyCss(); 660 root.autosize(); 661 root.layout(); 662 663 double w = 398; // The width minus the insets. 664 double pos[] = splitPane.getDividerPositions(); 665 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 666 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 667 668 assertEquals(77, p0, 1e-100); 669 assertEquals(315, p1, 1e-100); 670 assertEquals(77, spLeft.getLayoutBounds().getWidth(), 1e-100); 671 assertEquals(232, spCenter.getLayoutBounds().getWidth(), 1e-100); 672 assertEquals(77, spRight.getLayoutBounds().getWidth(), 1e-100); 673 674 root.applyCss(); 675 root.resize(405, 400); 676 root.layout(); 677 678 w = 403; 679 pos = splitPane.getDividerPositions(); 680 p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 681 p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 682 683 assertEquals(77, p0, 1e-100); 684 assertEquals(320, p1, 1e-100); 685 assertEquals(77, spLeft.getLayoutBounds().getWidth(), 1e-100); 686 assertEquals(237, spCenter.getLayoutBounds().getWidth(), 1e-100); 687 assertEquals(77, spRight.getLayoutBounds().getWidth(), 1e-100); 688 } 689 690 @Test public void resizeSplitPaneAllPanesAreSetToMax() { 691 StackPane spLeft = new StackPane(); 692 StackPane spCenter = new StackPane(); 693 StackPane spRight = new StackPane(); 694 695 spLeft.setMaxWidth(28); 696 spCenter.setMaxWidth(29); 697 spRight.setMaxWidth(29); 698 699 splitPane.setDividerPosition(0, 0.20); 700 splitPane.setDividerPosition(1, 0.80); 701 splitPane.getItems().addAll(spLeft, spCenter, spRight); 702 703 root.setPrefSize(100, 100); 704 root.getChildren().add(splitPane); 705 show(); 706 707 root.applyCss(); 708 root.autosize(); 709 root.layout(); 710 711 double w = 98; // The width minus the insets. 712 double pos[] = splitPane.getDividerPositions(); 713 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 714 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 715 716 assertEquals(28, p0, 1e-100); 717 assertEquals(63, p1, 1e-100); 718 assertEquals(28, spLeft.getLayoutBounds().getWidth(), 1e-100); 719 assertEquals(29, spCenter.getLayoutBounds().getWidth(), 1e-100); 720 assertEquals(29, spRight.getLayoutBounds().getWidth(), 1e-100); 721 722 root.applyCss(); 723 root.resize(405, 400); 724 root.layout(); 725 726 w = 403; 727 pos = splitPane.getDividerPositions(); 728 p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 729 p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 730 731 assertEquals(28, p0, 1e-100); 732 assertEquals(63, p1, 1e-100); 733 assertEquals(28, spLeft.getLayoutBounds().getWidth(), 1e-100); 734 assertEquals(29, spCenter.getLayoutBounds().getWidth(), 1e-100); 735 assertEquals(29, spRight.getLayoutBounds().getWidth(), 1e-100); 736 } 737 738 /* 739 * Vertical SplitPane 740 */ 741 @Test public void oneDividerPanelsAreEquallySized_VerticalSplitPane() { 742 StackPane spLeft = new StackPane(); 743 StackPane spRight = new StackPane(); 744 745 splitPane.setOrientation(Orientation.VERTICAL); 746 splitPane.getItems().addAll(spLeft, spRight); 747 748 root.setPrefSize(400, 400); 749 root.getChildren().add(splitPane); 750 show(); 751 752 root.applyCss(); 753 root.autosize(); 754 root.layout(); 755 756 double h = 398; // The width minus the insets. 757 double pos[] = splitPane.getDividerPositions(); 758 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 759 760 assertEquals(196, p0, 1e-100); 761 assertEquals(196, spLeft.getLayoutBounds().getHeight(), 1e-100); 762 assertEquals(196, spRight.getLayoutBounds().getHeight(), 1e-100); 763 } 764 765 @Test public void twoDividersHaveTheSamePosition_VerticalSplitPane() { 766 StackPane spLeft = new StackPane(); 767 StackPane spCenter = new StackPane(); 768 StackPane spRight = new StackPane(); 769 770 splitPane.setOrientation(Orientation.VERTICAL); 771 splitPane.getItems().addAll(spLeft, spCenter, spRight); 772 773 root.setPrefSize(400, 400); 774 root.getChildren().add(splitPane); 775 show(); 776 777 root.applyCss(); 778 root.autosize(); 779 root.layout(); 780 781 double h = 398; // The width minus the insets. 782 double pos[] = splitPane.getDividerPositions(); 783 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 784 double p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 785 786 assertEquals(196, p0, 1e-100); 787 assertEquals(202, p1, 1e-100); 788 assertEquals(196, spLeft.getLayoutBounds().getHeight(), 1e-100); 789 assertEquals(0, spCenter.getLayoutBounds().getHeight(), 1e-100); 790 assertEquals(190, spRight.getLayoutBounds().getHeight(), 1e-100); 791 } 792 793 @Test public void twoDividersHaveTheDifferentPositions_VerticalSplitPane() { 794 StackPane spLeft = new StackPane(); 795 StackPane spCenter = new StackPane(); 796 StackPane spRight = new StackPane(); 797 798 splitPane.setOrientation(Orientation.VERTICAL); 799 splitPane.setDividerPosition(0, 0.20); 800 splitPane.setDividerPosition(1, 0.80); 801 splitPane.getItems().addAll(spLeft, spCenter, spRight); 802 803 root.setPrefSize(400, 400); 804 root.getChildren().add(splitPane); 805 show(); 806 807 root.applyCss(); 808 root.autosize(); 809 root.layout(); 810 811 double h = 398; // The width minus the insets. 812 double pos[] = splitPane.getDividerPositions(); 813 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 814 double p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 815 816 assertEquals(77, p0, 1e-100); 817 assertEquals(315, p1, 1e-100); 818 assertEquals(77, spLeft.getLayoutBounds().getHeight(), 1e-100); 819 assertEquals(232, spCenter.getLayoutBounds().getHeight(), 1e-100); 820 assertEquals(77, spRight.getLayoutBounds().getHeight(), 1e-100); 821 } 822 823 @Test public void threePanelsAllAreSetToMin_VerticalSplitPane() { 824 StackPane spLeft = new StackPane(); 825 StackPane spCenter = new StackPane(); 826 StackPane spRight = new StackPane(); 827 828 spLeft.setMinHeight(28); 829 spCenter.setMinHeight(29); 830 spRight.setMinHeight(29); 831 832 splitPane.setOrientation(Orientation.VERTICAL); 833 splitPane.setDividerPosition(0, 0.20); 834 splitPane.setDividerPosition(1, 0.80); 835 splitPane.getItems().addAll(spLeft, spCenter, spRight); 836 837 root.setPrefSize(100, 100); 838 root.getChildren().add(splitPane); 839 show(); 840 841 root.applyCss(); 842 root.autosize(); 843 root.layout(); 844 845 double h = 98; // The width minus the insets. 846 double pos[] = splitPane.getDividerPositions(); 847 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 848 double p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 849 850 assertEquals(28, p0, 1e-100); 851 assertEquals(63, p1, 1e-100); 852 assertEquals(28, spLeft.getLayoutBounds().getHeight(), 1e-100); 853 assertEquals(29, spCenter.getLayoutBounds().getHeight(), 1e-100); 854 assertEquals(29, spRight.getLayoutBounds().getHeight(), 1e-100); 855 } 856 857 @Test public void threePanelsAllAreSetToMax_VerticalSplitPane() { 858 StackPane spLeft = new StackPane(); 859 StackPane spCenter = new StackPane(); 860 StackPane spRight = new StackPane(); 861 862 spLeft.setMaxHeight(28); 863 spCenter.setMaxHeight(29); 864 spRight.setMaxHeight(29); 865 866 splitPane.setOrientation(Orientation.VERTICAL); 867 splitPane.setDividerPosition(0, 0.20); 868 splitPane.setDividerPosition(1, 0.80); 869 splitPane.getItems().addAll(spLeft, spCenter, spRight); 870 871 root.setPrefSize(100, 100); 872 root.getChildren().add(splitPane); 873 show(); 874 875 root.applyCss(); 876 root.autosize(); 877 root.layout(); 878 879 double h = 98; // The width minus the insets. 880 double pos[] = splitPane.getDividerPositions(); 881 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 882 double p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 883 884 assertEquals(28, p0, 1e-100); 885 assertEquals(63, p1, 1e-100); 886 assertEquals(28, spLeft.getLayoutBounds().getHeight(), 1e-100); 887 assertEquals(29, spCenter.getLayoutBounds().getHeight(), 1e-100); 888 assertEquals(29, spRight.getLayoutBounds().getHeight(), 1e-100); 889 } 890 891 @Test public void threePanelsSetToMinMaxMin_VerticalSplitPane() { 892 StackPane spLeft = new StackPane(); 893 StackPane spCenter = new StackPane(); 894 StackPane spRight = new StackPane(); 895 896 spLeft.setMinHeight(28); 897 spCenter.setMaxHeight(29); 898 spRight.setMinHeight(29); 899 900 splitPane.setOrientation(Orientation.VERTICAL); 901 splitPane.setDividerPosition(0, 0.20); 902 splitPane.setDividerPosition(1, 0.80); 903 splitPane.getItems().addAll(spLeft, spCenter, spRight); 904 905 root.setPrefSize(100, 100); 906 root.getChildren().add(splitPane); 907 show(); 908 909 root.applyCss(); 910 root.autosize(); 911 root.layout(); 912 913 double h = 98; // The width minus the insets. 914 double pos[] = splitPane.getDividerPositions(); 915 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 916 double p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 917 918 assertEquals(28, p0, 1e-100); 919 assertEquals(63, p1, 1e-100); 920 assertEquals(28, spLeft.getLayoutBounds().getHeight(), 1e-100); 921 assertEquals(29, spCenter.getLayoutBounds().getHeight(), 1e-100); 922 assertEquals(29, spRight.getLayoutBounds().getHeight(), 1e-100); 923 } 924 925 @Test public void setDividerLessThanMin_VerticalSplitPane() { 926 StackPane spLeft = new StackPane(); 927 StackPane spRight = new StackPane(); 928 929 spLeft.setMinHeight(80); 930 931 splitPane.setOrientation(Orientation.VERTICAL); 932 splitPane.getItems().addAll(spLeft, spRight); 933 splitPane.setDividerPositions(0); 934 935 root.setPrefSize(100, 100); 936 root.getChildren().add(splitPane); 937 show(); 938 939 root.applyCss(); 940 root.autosize(); 941 root.layout(); 942 943 double h = 98; // The width minus the insets. 944 double pos[] = splitPane.getDividerPositions(); 945 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 946 947 assertEquals(80, p0, 1e-100); 948 assertEquals(80, spLeft.getLayoutBounds().getHeight(), 1e-100); 949 assertEquals(12, spRight.getLayoutBounds().getHeight(), 1e-100); 950 } 951 952 @Test public void setDividerGreaterThanMax_VerticalSplitPane() { 953 StackPane spLeft = new StackPane(); 954 StackPane spRight = new StackPane(); 955 956 spLeft.setMaxHeight(80); 957 958 splitPane.setOrientation(Orientation.VERTICAL); 959 splitPane.getItems().addAll(spLeft, spRight); 960 splitPane.setDividerPositions(1.5); 961 962 root.setPrefSize(100, 100); 963 root.getChildren().add(splitPane); 964 show(); 965 966 root.applyCss(); 967 root.autosize(); 968 root.layout(); 969 970 double h = 98; // The width minus the insets. 971 double pos[] = splitPane.getDividerPositions(); 972 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 973 974 assertEquals(80, p0, 1e-100); 975 assertEquals(80, spLeft.getLayoutBounds().getHeight(), 1e-100); 976 assertEquals(12, spRight.getLayoutBounds().getHeight(), 1e-100); 977 } 978 979 @Test public void setTwoDividerGreaterThanMax_VerticalSplitPane() { 980 StackPane spLeft = new StackPane(); 981 StackPane spCenter = new StackPane(); 982 StackPane spRight = new StackPane(); 983 984 splitPane.setOrientation(Orientation.VERTICAL); 985 splitPane.getItems().addAll(spLeft, spCenter, spRight); 986 splitPane.setDividerPositions(1.5, 1.5); 987 988 root.setPrefSize(100, 100); 989 root.getChildren().add(splitPane); 990 show(); 991 992 root.applyCss(); 993 root.autosize(); 994 root.layout(); 995 996 double h = 98; // The height minus the insets. 997 double pos[] = splitPane.getDividerPositions(); 998 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 999 double p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 1000 1001 assertEquals(86, p0, 1e-100); 1002 assertEquals(92, p1, 1e-100); 1003 assertEquals(86, spLeft.getLayoutBounds().getHeight(), 1e-100); 1004 assertEquals(0, spCenter.getLayoutBounds().getHeight(), 1e-100); 1005 assertEquals(0, spRight.getLayoutBounds().getHeight(), 1e-100); 1006 } 1007 1008 @Test public void checkDividerPositions_RT18805_VerticalSplitPane() { 1009 Button l = new Button("Left Button"); 1010 Button c = new Button("Center Button"); 1011 Button r = new Button("Left Button"); 1012 1013 StackPane spLeft = new StackPane(); 1014 StackPane spCenter = new StackPane(); 1015 StackPane spRight = new StackPane(); 1016 1017 spLeft.getChildren().add(l); 1018 spCenter.getChildren().add(c); 1019 spRight.getChildren().add(r); 1020 1021 spLeft.setMinHeight(100); 1022 spLeft.setMaxHeight(150); 1023 spRight.setMaxHeight(100); 1024 spRight.setMaxHeight(150); 1025 1026 splitPane.setOrientation(Orientation.VERTICAL); 1027 splitPane.getItems().addAll(spLeft, spCenter, spRight); 1028 1029 root.setPrefSize(400, 600); 1030 root.getChildren().add(splitPane); 1031 show(); 1032 1033 root.applyCss(); 1034 root.autosize(); 1035 root.layout(); 1036 1037 double h = 598; // The height minus the insets. 1038 double pos[] = splitPane.getDividerPositions(); 1039 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 1040 double p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 1041 1042 assertEquals(150, p0, 1e-100); 1043 assertEquals(442, p1, 1e-100); 1044 assertEquals(150, spLeft.getLayoutBounds().getHeight(), 1e-100); 1045 assertEquals(286, spCenter.getLayoutBounds().getHeight(), 1e-100); 1046 assertEquals(150, spRight.getLayoutBounds().getHeight(), 1e-100); 1047 } 1048 1049 @Test public void growSplitPaneBy5px_RT18855_VerticalSplitPane() { 1050 StackPane spLeft = new StackPane(); 1051 StackPane spCenter = new StackPane(); 1052 StackPane spRight = new StackPane(); 1053 1054 spLeft.setMinHeight(77); 1055 spRight.setMinHeight(77); 1056 1057 splitPane.setOrientation(Orientation.VERTICAL); 1058 splitPane.setDividerPosition(0, 0.20); 1059 splitPane.setDividerPosition(1, 0.80); 1060 splitPane.getItems().addAll(spLeft, spCenter, spRight); 1061 1062 root.setPrefSize(400, 400); 1063 root.getChildren().add(splitPane); 1064 show(); 1065 1066 root.applyCss(); 1067 root.autosize(); 1068 root.layout(); 1069 1070 double h = 398; // The height minus the insets. 1071 double pos[] = splitPane.getDividerPositions(); 1072 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 1073 double p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 1074 1075 assertEquals(77, p0, 1e-100); 1076 assertEquals(315, p1, 1e-100); 1077 assertEquals(77, spLeft.getLayoutBounds().getHeight(), 1e-100); 1078 assertEquals(232, spCenter.getLayoutBounds().getHeight(), 1e-100); 1079 assertEquals(77, spRight.getLayoutBounds().getHeight(), 1e-100); 1080 1081 root.applyCss(); 1082 root.resize(400, 405); 1083 root.layout(); 1084 1085 h = 403; 1086 pos = splitPane.getDividerPositions(); 1087 p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 1088 p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 1089 1090 assertEquals(78, p0, 1e-100); 1091 assertEquals(319, p1, 1e-100); 1092 assertEquals(78, spLeft.getLayoutBounds().getHeight(), 1e-100); 1093 assertEquals(235, spCenter.getLayoutBounds().getHeight(), 1e-100); 1094 assertEquals(78, spRight.getLayoutBounds().getHeight(), 1e-100); 1095 } 1096 1097 @Test public void growSplitPaneBy5pxWithFixedDividers_RT18806_VerticalSplitPane() { 1098 StackPane spLeft = new StackPane(); 1099 StackPane spCenter = new StackPane(); 1100 StackPane spRight = new StackPane(); 1101 1102 spLeft.setMinHeight(77); 1103 spRight.setMinHeight(77); 1104 1105 splitPane.setOrientation(Orientation.VERTICAL); 1106 splitPane.setDividerPosition(0, 0.20); 1107 splitPane.setDividerPosition(1, 0.80); 1108 splitPane.getItems().addAll(spLeft, spCenter, spRight); 1109 1110 SplitPane.setResizableWithParent(spLeft, false); 1111 SplitPane.setResizableWithParent(spRight, false); 1112 1113 root.setPrefSize(400, 400); 1114 root.getChildren().add(splitPane); 1115 show(); 1116 1117 root.applyCss(); 1118 root.autosize(); 1119 root.layout(); 1120 1121 double h = 398; // The height minus the insets. 1122 double pos[] = splitPane.getDividerPositions(); 1123 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 1124 double p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 1125 1126 assertEquals(77, p0, 1e-100); 1127 assertEquals(315, p1, 1e-100); 1128 assertEquals(77, spLeft.getLayoutBounds().getHeight(), 1e-100); 1129 assertEquals(232, spCenter.getLayoutBounds().getHeight(), 1e-100); 1130 assertEquals(77, spRight.getLayoutBounds().getHeight(), 1e-100); 1131 1132 root.applyCss(); 1133 root.resize(400, 405); 1134 root.layout(); 1135 1136 h = 403; 1137 pos = splitPane.getDividerPositions(); 1138 p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 1139 p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 1140 1141 assertEquals(77, p0, 1e-100); 1142 assertEquals(320, p1, 1e-100); 1143 assertEquals(77, spLeft.getLayoutBounds().getHeight(), 1e-100); 1144 assertEquals(237, spCenter.getLayoutBounds().getHeight(), 1e-100); 1145 assertEquals(77, spRight.getLayoutBounds().getHeight(), 1e-100); 1146 } 1147 1148 @Test public void resizeSplitPaneAllPanesAreSetToMax_VerticalSplitPane() { 1149 StackPane spLeft = new StackPane(); 1150 StackPane spCenter = new StackPane(); 1151 StackPane spRight = new StackPane(); 1152 1153 spLeft.setMaxHeight(28); 1154 spCenter.setMaxHeight(29); 1155 spRight.setMaxHeight(29); 1156 1157 splitPane.setOrientation(Orientation.VERTICAL); 1158 splitPane.setDividerPosition(0, 0.20); 1159 splitPane.setDividerPosition(1, 0.80); 1160 splitPane.getItems().addAll(spLeft, spCenter, spRight); 1161 1162 root.setPrefSize(100, 100); 1163 root.getChildren().add(splitPane); 1164 show(); 1165 1166 root.applyCss(); 1167 root.autosize(); 1168 root.layout(); 1169 1170 double h = 98; // The height minus the insets. 1171 double pos[] = splitPane.getDividerPositions(); 1172 double p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 1173 double p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 1174 1175 assertEquals(28, p0, 1e-100); 1176 assertEquals(63, p1, 1e-100); 1177 assertEquals(28, spLeft.getLayoutBounds().getHeight(), 1e-100); 1178 assertEquals(29, spCenter.getLayoutBounds().getHeight(), 1e-100); 1179 assertEquals(29, spRight.getLayoutBounds().getHeight(), 1e-100); 1180 1181 root.applyCss(); 1182 root.resize(400, 405); 1183 root.layout(); 1184 1185 h = 403; 1186 pos = splitPane.getDividerPositions(); 1187 p0 = convertDividerPostionToAbsolutePostion(pos[0], h); 1188 p1 = convertDividerPostionToAbsolutePostion(pos[1], h); 1189 1190 assertEquals(28, p0, 1e-100); 1191 assertEquals(63, p1, 1e-100); 1192 assertEquals(28, spLeft.getLayoutBounds().getHeight(), 1e-100); 1193 assertEquals(29, spCenter.getLayoutBounds().getHeight(), 1e-100); 1194 assertEquals(29, spRight.getLayoutBounds().getHeight(), 1e-100); 1195 } 1196 1197 @Test public void positionDividersWithANonResizablePanel_RT22929() { 1198 StackPane spLeft = new StackPane(); 1199 StackPane spCenter = new StackPane(); 1200 StackPane spRight = new StackPane(); 1201 1202 spRight.setMinWidth(20); 1203 spRight.setPrefWidth(20); 1204 spRight.setMaxWidth(30); 1205 1206 splitPane.setDividerPosition(0, 0.50); 1207 splitPane.setDividerPosition(1, 0.50); 1208 splitPane.getItems().addAll(spLeft, spCenter, spRight); 1209 1210 root.setPrefSize(100, 100); 1211 root.getChildren().add(splitPane); 1212 show(); 1213 1214 root.applyCss(); 1215 root.autosize(); 1216 root.layout(); 1217 1218 double w = 98; // The width minus the insets. 1219 double pos[] = splitPane.getDividerPositions(); 1220 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 1221 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 1222 1223 assertEquals(46, p0, 1e-100); 1224 assertEquals(62, p1, 1e-100); 1225 assertEquals(46, spLeft.getLayoutBounds().getWidth(), 1e-100); 1226 assertEquals(10, spCenter.getLayoutBounds().getWidth(), 1e-100); 1227 assertEquals(30, spRight.getLayoutBounds().getWidth(), 1e-100); 1228 1229 splitPane.setDividerPosition(0, 0.20); 1230 root.layout(); 1231 1232 pos = splitPane.getDividerPositions(); 1233 p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 1234 p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 1235 assertEquals(17, p0, 1e-100); 1236 assertEquals(62, p1, 1e-100); 1237 1238 splitPane.setDividerPosition(1, 0.25); 1239 root.layout(); 1240 1241 pos = splitPane.getDividerPositions(); 1242 p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 1243 p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 1244 assertEquals(17, p0, 1e-100); 1245 assertEquals(62, p1, 1e-100); 1246 } 1247 1248 @Test public void threeDividersHaveTheSamePosition() { 1249 StackPane sp1 = new StackPane(); 1250 StackPane sp2 = new StackPane(); 1251 StackPane sp3 = new StackPane(); 1252 StackPane sp4 = new StackPane(); 1253 1254 splitPane.getItems().addAll(sp1, sp2, sp3, sp4); 1255 1256 root.setPrefSize(400, 400); 1257 root.getChildren().add(splitPane); 1258 show(); 1259 1260 root.applyCss(); 1261 root.autosize(); 1262 root.layout(); 1263 1264 double w = 398; // The width minus the insets. 1265 double pos[] = splitPane.getDividerPositions(); 1266 double p0 = convertDividerPostionToAbsolutePostion(pos[0], w); 1267 double p1 = convertDividerPostionToAbsolutePostion(pos[1], w); 1268 double p2 = convertDividerPostionToAbsolutePostion(pos[2], w); 1269 1270 assertEquals(190, p0, 1e-100); 1271 assertEquals(196, p1, 1e-100); 1272 assertEquals(202, p2, 1e-100); 1273 assertEquals(190, sp1.getLayoutBounds().getWidth(), 1e-100); 1274 assertEquals(0, sp2.getLayoutBounds().getWidth(), 1e-100); 1275 assertEquals(0, sp3.getLayoutBounds().getWidth(), 1e-100); 1276 assertEquals(190, sp4.getLayoutBounds().getWidth(), 1e-100); 1277 } 1278 1279 @Test public void addItemsInRunLater_RT23063() { 1280 final SplitPane sp = new SplitPane(); 1281 Stage st = new Stage(); 1282 st.setScene(new Scene(sp, 2000, 2000)); 1283 st.show(); 1284 1285 Runnable runnable = () -> { 1286 StackPane rightsp = new StackPane(); 1287 Label right = new Label("right"); 1288 rightsp.getChildren().add(right); 1289 1290 StackPane leftsp = new StackPane(); 1291 Label left = new Label("left"); 1292 leftsp.getChildren().add(left); 1293 1294 sp.getItems().addAll(rightsp, leftsp); 1295 }; 1296 Platform.runLater(runnable); 1297 1298 sp.applyCss(); 1299 sp.resize(400, 400); 1300 sp.layout(); 1301 1302 assertEquals(1, sp.getDividerPositions().length); 1303 1304 double pos[] = sp.getDividerPositions(); 1305 double p0 = convertDividerPostionToAbsolutePostion(pos[0], 398); 1306 assertEquals(196, p0, 1e-100); 1307 } 1308 1309 @Test public void test_rt_36392() { 1310 AnchorPane item0 = new AnchorPane(); 1311 item0.setId("xxx"); 1312 1313 VBox item1 = new VBox(); 1314 item1.setId("myvbox"); 1315 1316 SplitPane splitPane = new SplitPane(); 1317 splitPane.getItems().addAll(item0, item1); 1318 1319 AnchorPane page = new AnchorPane(); 1320 page.setId("AnchorPane"); 1321 page.getChildren().add(splitPane); 1322 1323 StageLoader sl = new StageLoader(page); 1324 1325 VBox myvbox = (VBox) page.lookup("#myvbox"); 1326 myvbox.getChildren().add(new Button("Hello world !!!")); 1327 1328 sl.dispose(); 1329 } 1330 }