1 /* 2 * Copyright (c) 2010, 2018, 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.control; 27 28 import com.sun.javafx.scene.SceneHelper; 29 import static test.com.sun.javafx.scene.control.infrastructure.ControlTestUtils.assertPseudoClassDoesNotExist; 30 import static test.com.sun.javafx.scene.control.infrastructure.ControlTestUtils.assertPseudoClassExists; 31 import static test.com.sun.javafx.scene.control.infrastructure.ControlTestUtils.assertStyleClassContains; 32 import static org.junit.Assert.assertEquals; 33 import static org.junit.Assert.assertFalse; 34 import static org.junit.Assert.assertNotNull; 35 import static org.junit.Assert.assertNull; 36 import static org.junit.Assert.assertSame; 37 import static org.junit.Assert.assertTrue; 38 39 import test.com.sun.javafx.scene.control.infrastructure.StageLoader; 40 import javafx.application.Platform; 41 import javafx.beans.property.BooleanProperty; 42 import javafx.beans.property.DoubleProperty; 43 import javafx.beans.property.ObjectProperty; 44 import javafx.beans.property.SimpleBooleanProperty; 45 import javafx.beans.property.SimpleDoubleProperty; 46 import javafx.beans.property.SimpleObjectProperty; 47 import javafx.beans.value.ChangeListener; 48 import javafx.css.CssMetaData; 49 import javafx.css.StyleableProperty; 50 import javafx.event.Event; 51 import javafx.geometry.Bounds; 52 import javafx.geometry.Side; 53 import javafx.scene.Group; 54 import javafx.scene.Scene; 55 import javafx.scene.input.KeyEvent; 56 import javafx.scene.input.MouseEvent; 57 import javafx.scene.layout.StackPane; 58 import javafx.scene.layout.VBox; 59 import javafx.stage.Stage; 60 61 import org.junit.Before; 62 import org.junit.Ignore; 63 import org.junit.Test; 64 65 import test.com.sun.javafx.pgstub.StubToolkit; 66 import test.com.sun.javafx.scene.control.infrastructure.KeyEventFirer; 67 import test.com.sun.javafx.scene.control.infrastructure.MouseEventGenerator; 68 import javafx.scene.control.skin.TabPaneSkin; 69 import com.sun.javafx.scene.input.KeyCodeMap; 70 import com.sun.javafx.tk.Toolkit; 71 72 import java.util.Arrays; 73 import java.util.HashMap; 74 import java.util.LinkedList; 75 import java.util.List; 76 import java.util.Map; 77 import javafx.scene.control.Button; 78 import javafx.scene.control.ScrollPane; 79 import javafx.scene.control.SingleSelectionModel; 80 import javafx.scene.control.SingleSelectionModelShim; 81 import javafx.scene.control.SplitPane; 82 import javafx.scene.control.Tab; 83 import javafx.scene.control.TabPane; 84 import javafx.scene.control.TabPaneShim; 85 86 public class TabPaneTest { 87 private TabPane tabPane;//Empty string 88 private Toolkit tk; 89 private SingleSelectionModel<Tab> sm; 90 private Tab tab1; 91 private Tab tab2; 92 private Tab tab3; 93 private Scene scene; 94 private Stage stage; 95 private StackPane root; 96 97 @Before public void setup() { 98 tk = (StubToolkit)Toolkit.getToolkit();//This step is not needed (Just to make sure StubToolkit is loaded into VM) 99 tabPane = new TabPane(); 100 tab1 = new Tab("one"); 101 tab2 = new Tab("two"); 102 tab3 = new Tab("three"); 103 sm = TabPaneShim.getTabPane_abPaneSelectionModel(tabPane); 104 root = new StackPane(); 105 scene = new Scene(root); 106 stage = new Stage(); 107 stage.setScene(scene); 108 } 109 110 /********************************************************************* 111 * Helper methods * 112 ********************************************************************/ 113 114 private void show() { 115 stage.show(); 116 stage.requestFocus(); 117 } 118 119 /********************************************************************* 120 * Tests for default values * 121 ********************************************************************/ 122 123 @Test public void defaultConstructorShouldSetStyleClassTo_tabpane() { 124 assertStyleClassContains(tabPane, "tab-pane"); 125 } 126 127 @Test public void defaultConstructorSelectionModelNotNull() { 128 assertNotNull(tabPane.getSelectionModel()); 129 } 130 131 @Test public void defaultConstructorInitialTabsEmpty() { 132 assertNotNull(tabPane.getTabs()); 133 assertEquals(tabPane.getTabs().size(), 0.0, 0.0); 134 } 135 136 @Test public void defaultSideIsTop() { 137 assertSame(tabPane.getSide(), Side.TOP); 138 } 139 140 @Test public void defaultConstructorTabClosingPolicy() { 141 assertNotNull(tabPane.getTabClosingPolicy()); 142 assertSame(tabPane.getTabClosingPolicy(), TabPane.TabClosingPolicy.SELECTED_TAB); 143 } 144 145 @Test public void defaultConstructorRotateGraphic() { 146 assertFalse(tabPane.isRotateGraphic()); 147 } 148 149 @Test public void defaultTabMinWidth() { 150 assertEquals(tabPane.getTabMinWidth(), 0.0, 0.0); 151 } 152 153 @Test public void defaultTabMaxWidth() { 154 assertEquals(tabPane.getTabMaxWidth(), Double.MAX_VALUE, 0.0); 155 } 156 157 @Test public void defaultTabMinHeight() { 158 assertEquals(tabPane.getTabMinHeight(), 0.0, 0.0); 159 } 160 161 @Test public void defaultTabMaxHeight() { 162 assertEquals(tabPane.getTabMaxHeight(), Double.MAX_VALUE, 0.0); 163 } 164 165 @Test public void defaultSelectionModelEmpty() { 166 assertTrue(tabPane.getSelectionModel().isEmpty()); 167 } 168 169 @Test public void initialBoundsInParentMatchesWidthAndHeight() { 170 TabPane testPane = new TabPane(); 171 testPane.resize(400, 400); 172 testPane.setSkin(new TabPaneSkin(testPane)); 173 Bounds boundsInParent = testPane.getBoundsInParent(); 174 assertEquals(testPane.getWidth(), boundsInParent.getWidth(), 0.0); 175 assertEquals(testPane.getHeight(), boundsInParent.getHeight(), 0.0); 176 } 177 178 /********************************************************************* 179 * Tests for property binding * 180 ********************************************************************/ 181 182 @Test public void checkSelectionModelPropertyBind() { 183 ObjectProperty objPr = new SimpleObjectProperty<SingleSelectionModel<Tab>>(null); 184 tabPane.selectionModelProperty().bind(objPr); 185 assertNull("selectionModel cannot be bound", tabPane.selectionModelProperty().getValue()); 186 objPr.setValue(sm); 187 assertSame("selectionModel cannot be bound", tabPane.selectionModelProperty().getValue(), sm); 188 } 189 190 @Test public void checkSidePropertyBind() { 191 ObjectProperty objPr = new SimpleObjectProperty<Side>(Side.BOTTOM); 192 tabPane.sideProperty().bind(objPr); 193 assertSame("side cannot be bound", tabPane.sideProperty().getValue(), Side.BOTTOM); 194 objPr.setValue(Side.RIGHT); 195 assertSame("side cannot be bound", tabPane.sideProperty().getValue(), Side.RIGHT); 196 } 197 198 @Test public void checkTabClosingPropertyBind() { 199 ObjectProperty objPr = new SimpleObjectProperty<TabPane.TabClosingPolicy>(TabPane.TabClosingPolicy.UNAVAILABLE); 200 tabPane.tabClosingPolicyProperty().bind(objPr); 201 assertSame("side cannot be bound", tabPane.tabClosingPolicyProperty().getValue(), TabPane.TabClosingPolicy.UNAVAILABLE); 202 objPr.setValue(TabPane.TabClosingPolicy.ALL_TABS); 203 assertSame("side cannot be bound", tabPane.tabClosingPolicyProperty().getValue(), TabPane.TabClosingPolicy.ALL_TABS); 204 } 205 206 @Test public void checkRotateGraphicsPropertyBind() { 207 BooleanProperty objPr = new SimpleBooleanProperty(false); 208 tabPane.rotateGraphicProperty().bind(objPr); 209 assertFalse("rotateGraphic cannot be bound", tabPane.rotateGraphicProperty().getValue()); 210 objPr.setValue(true); 211 assertTrue("rotateGraphic cannot be bound", tabPane.rotateGraphicProperty().getValue()); 212 } 213 214 @Test public void checkTabMinWidthPropertyBind() { 215 DoubleProperty objPr = new SimpleDoubleProperty(2.0); 216 tabPane.tabMinWidthProperty().bind(objPr); 217 assertEquals("tabMinWidthProperty cannot be bound", tabPane.tabMinWidthProperty().getValue(), 2.0, 0.0); 218 objPr.setValue(5.0); 219 assertEquals("tabMinWidthProperty cannot be bound", tabPane.tabMinWidthProperty().getValue(), 5.0, 0.0); 220 } 221 222 @Test public void checkTabMaxWidthPropertyBind() { 223 DoubleProperty objPr = new SimpleDoubleProperty(2.0); 224 tabPane.tabMaxWidthProperty().bind(objPr); 225 assertEquals("tabMaxWidthProperty cannot be bound", tabPane.tabMaxWidthProperty().getValue(), 2.0, 0.0); 226 objPr.setValue(5.0); 227 assertEquals("tabMaxWidthProperty cannot be bound", tabPane.tabMaxWidthProperty().getValue(), 5.0, 0.0); 228 } 229 230 231 @Test public void checkTabMinHeightPropertyBind() { 232 DoubleProperty objPr = new SimpleDoubleProperty(2.0); 233 tabPane.tabMinHeightProperty().bind(objPr); 234 assertEquals("tabMinHeightProperty cannot be bound", tabPane.tabMinHeightProperty().getValue(), 2.0, 0.0); 235 objPr.setValue(5.0); 236 assertEquals("tabMinHeightProperty cannot be bound", tabPane.tabMinHeightProperty().getValue(), 5.0, 0.0); 237 } 238 239 @Test public void checkTabMaxHeightPropertyBind() { 240 DoubleProperty objPr = new SimpleDoubleProperty(2.0); 241 tabPane.tabMaxHeightProperty().bind(objPr); 242 assertEquals("tabMaxHeightProperty cannot be bound", tabPane.tabMaxHeightProperty().getValue(), 2.0, 0.0); 243 objPr.setValue(5.0); 244 assertEquals("tabMaxHeightProperty cannot be bound", tabPane.tabMaxHeightProperty().getValue(), 5.0, 0.0); 245 } 246 247 @Test public void selectionModelPropertyHasBeanReference() { 248 assertSame(tabPane, tabPane.selectionModelProperty().getBean()); 249 } 250 251 @Test public void selectionModelPropertyHasName() { 252 assertEquals("selectionModel", tabPane.selectionModelProperty().getName()); 253 } 254 255 @Test public void sidePropertyHasBeanReference() { 256 assertSame(tabPane, tabPane.sideProperty().getBean()); 257 } 258 259 @Test public void sidePropertyHasName() { 260 assertEquals("side", tabPane.sideProperty().getName()); 261 } 262 263 @Test public void tabClosingPolicyPropertyHasBeanReference() { 264 assertSame(tabPane, tabPane.tabClosingPolicyProperty().getBean()); 265 } 266 267 @Test public void tabClosingPolicyPropertyHasName() { 268 assertEquals("tabClosingPolicy", tabPane.tabClosingPolicyProperty().getName()); 269 } 270 271 @Test public void rotateGraphicPropertyHasBeanReference() { 272 assertSame(tabPane, tabPane.rotateGraphicProperty().getBean()); 273 } 274 275 @Test public void rotateGraphicPropertyHasName() { 276 assertEquals("rotateGraphic", tabPane.rotateGraphicProperty().getName()); 277 } 278 279 @Test public void tabMinWidthPropertyHasBeanReference() { 280 assertSame(tabPane, tabPane.tabMinWidthProperty().getBean()); 281 } 282 283 @Test public void tabMinWidthPropertyHasName() { 284 assertEquals("tabMinWidth", tabPane.tabMinWidthProperty().getName()); 285 } 286 287 @Test public void tabMaxWidthPropertyHasBeanReference() { 288 assertSame(tabPane, tabPane.tabMaxWidthProperty().getBean()); 289 } 290 291 @Test public void tabMaxWidthPropertyHasName() { 292 assertEquals("tabMaxWidth", tabPane.tabMaxWidthProperty().getName()); 293 } 294 295 @Test public void tabMinHeightPropertyHasBeanReference() { 296 assertSame(tabPane, tabPane.tabMinHeightProperty().getBean()); 297 } 298 299 @Test public void tabMinHeightPropertyHasName() { 300 assertEquals("tabMinHeight", tabPane.tabMinHeightProperty().getName()); 301 } 302 303 @Test public void tabMaxHeightPropertyHasBeanReference() { 304 assertSame(tabPane, tabPane.tabMaxHeightProperty().getBean()); 305 } 306 307 @Test public void tabMaxHeightPropertyHasName() { 308 assertEquals("tabMaxHeight", tabPane.tabMaxHeightProperty().getName()); 309 } 310 311 312 /********************************************************************* 313 * Check for Pseudo classes * 314 ********************************************************************/ 315 316 @Test public void settingSideSetsPseudoClass() { 317 tabPane.setSide(Side.BOTTOM); 318 assertPseudoClassExists(tabPane, "bottom"); 319 assertPseudoClassDoesNotExist(tabPane, "top"); 320 assertPseudoClassDoesNotExist(tabPane, "left"); 321 assertPseudoClassDoesNotExist(tabPane, "right"); 322 } 323 324 @Test public void clearingSideClearsPseudoClass() { 325 tabPane.setSide(Side.BOTTOM); 326 tabPane.setSide(Side.LEFT); 327 assertPseudoClassExists(tabPane, "left"); 328 assertPseudoClassDoesNotExist(tabPane, "bottom"); 329 assertPseudoClassDoesNotExist(tabPane, "top"); 330 assertPseudoClassDoesNotExist(tabPane, "right"); 331 } 332 333 334 /********************************************************************* 335 * CSS related Tests * 336 ********************************************************************/ 337 338 @Test public void whenTabMinWidthIsBound_impl_cssSettable_ReturnsFalse() { 339 CssMetaData styleable = ((StyleableProperty)tabPane.tabMinWidthProperty()).getCssMetaData(); 340 assertTrue(styleable.isSettable(tabPane)); 341 DoubleProperty other = new SimpleDoubleProperty(30.0); 342 tabPane.tabMinWidthProperty().bind(other); 343 assertFalse(styleable.isSettable(tabPane)); 344 } 345 346 @Test public void whenTabMinWidthIsSpecifiedViaCSSAndIsNotBound_impl_cssSettable_ReturnsTrue() { 347 CssMetaData styleable = ((StyleableProperty)tabPane.tabMinWidthProperty()).getCssMetaData(); 348 assertTrue(styleable.isSettable(tabPane)); 349 } 350 351 @Test public void canSpecifyTabMinWidthViaCSS() { 352 ((StyleableProperty)tabPane.tabMinWidthProperty()).applyStyle(null, 34.0); 353 assertEquals(34.0, tabPane.getTabMinWidth(), 0.0); 354 } 355 356 @Test public void whenTabMaxWidthIsBound_impl_cssSettable_ReturnsFalse() { 357 CssMetaData styleable = ((StyleableProperty)tabPane.tabMaxWidthProperty()).getCssMetaData(); 358 assertTrue(styleable.isSettable(tabPane)); 359 DoubleProperty other = new SimpleDoubleProperty(30.0); 360 tabPane.tabMaxWidthProperty().bind(other); 361 assertFalse(styleable.isSettable(tabPane)); 362 } 363 364 @Test public void whenTabMaxWidthIsSpecifiedViaCSSAndIsNotBound_impl_cssSettable_ReturnsTrue() { 365 CssMetaData styleable = ((StyleableProperty)tabPane.tabMaxWidthProperty()).getCssMetaData(); 366 assertTrue(styleable.isSettable(tabPane)); 367 } 368 369 @Test public void canSpecifyTabMaxWidthViaCSS() { 370 ((StyleableProperty)tabPane.tabMaxWidthProperty()).applyStyle(null, 34.0); 371 assertEquals(34.0, tabPane.getTabMaxWidth(), 0.0); 372 } 373 374 @Test public void whenTabMinHeightIsBound_impl_cssSettable_ReturnsFalse() { 375 CssMetaData styleable = ((StyleableProperty)tabPane.tabMinHeightProperty()).getCssMetaData(); 376 assertTrue(styleable.isSettable(tabPane)); 377 DoubleProperty other = new SimpleDoubleProperty(30.0); 378 tabPane.tabMinHeightProperty().bind(other); 379 assertFalse(styleable.isSettable(tabPane)); 380 } 381 382 @Test public void whenTabMinHeightIsSpecifiedViaCSSAndIsNotBound_impl_cssSettable_ReturnsTrue() { 383 CssMetaData styleable = ((StyleableProperty)tabPane.tabMinHeightProperty()).getCssMetaData(); 384 assertTrue(styleable.isSettable(tabPane)); 385 } 386 387 @Test public void canSpecifyTabMinHeightViaCSS() { 388 ((StyleableProperty)tabPane.tabMinHeightProperty()).applyStyle(null, 34.0); 389 assertEquals(34.0, tabPane.getTabMinHeight(), 0.0); 390 } 391 392 @Test public void whenTabMaxHeightIsBound_impl_cssSettable_ReturnsFalse() { 393 CssMetaData styleable = ((StyleableProperty)tabPane.tabMaxHeightProperty()).getCssMetaData(); 394 assertTrue(styleable.isSettable(tabPane)); 395 DoubleProperty other = new SimpleDoubleProperty(30.0); 396 tabPane.tabMaxHeightProperty().bind(other); 397 assertFalse(styleable.isSettable(tabPane)); 398 } 399 400 @Test public void whenTabMaxHeightIsSpecifiedViaCSSAndIsNotBound_impl_cssSettable_ReturnsTrue() { 401 CssMetaData styleable = ((StyleableProperty)tabPane.tabMaxHeightProperty()).getCssMetaData(); 402 assertTrue(styleable.isSettable(tabPane)); 403 } 404 405 @Test public void canSpecifyTabMaxHeightViaCSS() { 406 ((StyleableProperty)tabPane.tabMaxHeightProperty()).applyStyle(null, 34.0); 407 assertEquals(34.0, tabPane.getTabMaxHeight(), 0.0); 408 } 409 410 411 /********************************************************************* 412 * Miscellaneous Tests * 413 ********************************************************************/ 414 415 @Test public void setSelectionModelAndSeeValueIsReflectedInModel() { 416 tabPane.setSelectionModel(sm); 417 assertSame(tabPane.selectionModelProperty().getValue(), sm); 418 } 419 420 @Test public void setselectionModelAndSeeValue() { 421 tabPane.setSelectionModel(sm); 422 assertSame(tabPane.getSelectionModel(), sm); 423 } 424 425 @Test public void setSideAndSeeValueIsReflectedInModel() { 426 tabPane.setSide(Side.BOTTOM); 427 assertSame(tabPane.sideProperty().getValue(), Side.BOTTOM); 428 } 429 430 @Test public void setSideAndSeeValue() { 431 tabPane.setSide(Side.LEFT); 432 assertSame(tabPane.getSide(), Side.LEFT); 433 } 434 435 @Test public void setTabClosingPolicyAndSeeValueIsReflectedInModel() { 436 tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); 437 assertSame(tabPane.tabClosingPolicyProperty().getValue(), TabPane.TabClosingPolicy.ALL_TABS); 438 } 439 440 @Test public void setTabClosingPolicyAndSeeValue() { 441 tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE); 442 assertSame(tabPane.getTabClosingPolicy(), TabPane.TabClosingPolicy.UNAVAILABLE); 443 } 444 445 @Test public void setTabDragPolicyAndSeeValueIsReflectedInModel() { 446 tabPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER); 447 assertSame(TabPane.TabDragPolicy.REORDER, tabPane.tabDragPolicyProperty().getValue()); 448 449 tabPane.setTabDragPolicy(TabPane.TabDragPolicy.FIXED); 450 assertSame(TabPane.TabDragPolicy.FIXED, tabPane.tabDragPolicyProperty().getValue()); 451 } 452 453 @Test public void setTabDragPolicyAndSeeValue() { 454 tabPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER); 455 assertSame(TabPane.TabDragPolicy.REORDER, tabPane.getTabDragPolicy()); 456 457 tabPane.setTabDragPolicy(TabPane.TabDragPolicy.FIXED); 458 assertSame(TabPane.TabDragPolicy.FIXED, tabPane.getTabDragPolicy()); 459 } 460 461 @Test public void setRotateGraphicAndSeeValueIsReflectedInModel() { 462 tabPane.setRotateGraphic(true); 463 assertTrue(tabPane.rotateGraphicProperty().getValue()); 464 } 465 466 @Test public void setRotateGraphicAndSeeValue() { 467 tabPane.setRotateGraphic(true); 468 assertTrue(tabPane.isRotateGraphic()); 469 } 470 471 @Test public void setTabMinWidthAndSeeValueIsReflectedInModel() { 472 tabPane.setTabMinWidth(30.0); 473 assertEquals(tabPane.tabMinWidthProperty().getValue(), 30.0, 0.0); 474 } 475 476 @Test public void setTabMinWidthAndSeeValue() { 477 tabPane.setTabMinWidth(30.0); 478 assertEquals(tabPane.getTabMinWidth(), 30.0, 0.0); 479 } 480 481 @Test public void setTabMaxWidthAndSeeValueIsReflectedInModel() { 482 tabPane.setTabMaxWidth(30.0); 483 assertEquals(tabPane.tabMaxWidthProperty().getValue(), 30.0, 0.0); 484 } 485 486 @Test public void setTabMaxWidthAndSeeValue() { 487 tabPane.setTabMaxWidth(30.0); 488 assertEquals(tabPane.getTabMaxWidth(), 30.0, 0.0); 489 } 490 491 @Test public void setTabMinHeightAndSeeValueIsReflectedInModel() { 492 tabPane.setTabMinHeight(30.0); 493 assertEquals(tabPane.tabMinHeightProperty().getValue(), 30.0, 0.0); 494 } 495 496 @Test public void setTabMinHeightAndSeeValue() { 497 tabPane.setTabMinHeight(30.0); 498 assertEquals(tabPane.getTabMinHeight(), 30.0, 0.0); 499 } 500 501 @Test public void setTabMaxHeightAndSeeValueIsReflectedInModel() { 502 tabPane.setTabMaxHeight(30.0); 503 assertEquals(tabPane.tabMaxHeightProperty().getValue(), 30.0, 0.0); 504 } 505 506 @Test public void setTabMaxHeightAndSeeValue() { 507 tabPane.setTabMaxHeight(30.0); 508 assertEquals(tabPane.getTabMaxHeight(), 30.0, 0.0); 509 } 510 511 @Test public void addTabsCheckItemCountInSelectionModel() { 512 tabPane.getTabs().add(tab1); 513 tabPane.getTabs().add(tab2); 514 assertEquals(SingleSelectionModelShim.getItemCount(tabPane.getSelectionModel()), 2.0, 0.0); 515 } 516 517 @Test public void addTabsCheckItemInSelectionModel() { 518 tabPane.getTabs().add(tab1); 519 tabPane.getTabs().add(tab2); 520 assertSame(SingleSelectionModelShim.getModelItem(tabPane.getSelectionModel(), 0), tab1); 521 assertSame(SingleSelectionModelShim.getModelItem(tabPane.getSelectionModel(), 1), tab2); 522 } 523 524 @Test public void addTabsCheckSelectUsingObjInSelectionModel() { 525 tabPane.getTabs().add(tab1); 526 tabPane.getTabs().add(tab2); 527 tabPane.getSelectionModel().select(tab1); 528 assertTrue(tabPane.getSelectionModel().isSelected(0)); 529 } 530 531 @Test public void addTabsCheckSelectUsingIndexInSelectionModel() { 532 tabPane.getTabs().add(tab1); 533 tabPane.getTabs().add(tab2); 534 tabPane.getSelectionModel().select(1); 535 assertTrue(tabPane.getSelectionModel().isSelected(1)); 536 } 537 538 @Test public void addTabsCheckClearAndSelectUsingIndexInSelectionModel() { 539 tabPane.getTabs().add(tab1); 540 tabPane.getTabs().add(tab2); 541 tabPane.getSelectionModel().clearAndSelect(1); 542 assertTrue(tabPane.getSelectionModel().isSelected(1)); 543 } 544 545 @Test public void addTabsCheckSelectMultipleItemsAndClearOneItemInSelectionModel() { 546 tabPane.getTabs().add(tab1); 547 tabPane.getTabs().add(tab2); 548 tabPane.getSelectionModel().select(0); 549 tabPane.getSelectionModel().select(1); 550 tabPane.getSelectionModel().clearSelection(0); 551 assertFalse(tabPane.getSelectionModel().isSelected(0)); 552 assertTrue(tabPane.getSelectionModel().isSelected(1)); 553 } 554 555 @Test public void addTabsCheckSelectMultipleItemsAndClearAllSelectionInSelectionModel() { 556 tabPane.getTabs().add(tab1); 557 tabPane.getTabs().add(tab2); 558 tabPane.getSelectionModel().select(0); 559 tabPane.getSelectionModel().select(1); 560 tabPane.getSelectionModel().clearSelection(); 561 assertFalse(tabPane.getSelectionModel().isSelected(0)); 562 assertFalse(tabPane.getSelectionModel().isSelected(1)); 563 assertTrue(tabPane.getSelectionModel().isEmpty()); 564 } 565 566 @Test public void addTabsCheckSelectUsingIteratorKindOfMethodsInSelectionModel() { 567 tabPane.getTabs().add(tab1); 568 tabPane.getTabs().add(tab2); 569 tabPane.getSelectionModel().selectFirst(); 570 assertTrue(tabPane.getSelectionModel().isSelected(0)); 571 assertFalse(tabPane.getSelectionModel().isSelected(1)); 572 tabPane.getSelectionModel().selectNext(); 573 assertFalse(tabPane.getSelectionModel().isSelected(0)); 574 assertTrue(tabPane.getSelectionModel().isSelected(1)); 575 tabPane.getSelectionModel().clearSelection(); 576 tabPane.getSelectionModel().selectLast(); 577 assertFalse(tabPane.getSelectionModel().isSelected(0)); 578 assertTrue(tabPane.getSelectionModel().isSelected(1)); 579 tabPane.getSelectionModel().selectPrevious(); 580 assertTrue(tabPane.getSelectionModel().isSelected(0)); 581 assertFalse(tabPane.getSelectionModel().isSelected(1)); 582 } 583 584 @Test public void flipTabOrder_RT20156() { 585 tabPane.setSkin(new TabPaneSkin(tabPane)); 586 tabPane.getTabs().add(tab1); 587 tabPane.getTabs().add(tab2); 588 tabPane.getTabs().add(tab3); 589 590 assertEquals("one", tabPane.getTabs().get(0).getText()); 591 assertEquals("two", tabPane.getTabs().get(1).getText()); 592 assertEquals("three", tabPane.getTabs().get(2).getText()); 593 594 final int lastTabIndex = tabPane.getTabs().size()-1; 595 final Tab lastTab = tabPane.getTabs().get(lastTabIndex); 596 tabPane.getTabs().remove(lastTabIndex); 597 tabPane.getTabs().add(0, lastTab); 598 599 assertEquals("three", tabPane.getTabs().get(0).getText()); 600 assertEquals("one", tabPane.getTabs().get(1).getText()); 601 assertEquals("two", tabPane.getTabs().get(2).getText()); 602 assertTrue(tabPane.getSelectionModel().isSelected(1)); 603 } 604 605 @Test public void disableAllTabs() { 606 tabPane.setSkin(new TabPaneSkin(tabPane)); 607 tabPane.getTabs().add(tab1); 608 tabPane.getTabs().add(tab2); 609 tabPane.getTabs().add(tab3); 610 611 tab1.setDisable(true); 612 tab2.setDisable(true); 613 tab3.setDisable(true); 614 615 assertEquals(0, tabPane.getSelectionModel().getSelectedIndex()); 616 assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem()); 617 } 618 619 @Test public void disableFirstTabs() { 620 tabPane.setSkin(new TabPaneSkin(tabPane)); 621 tabPane.getTabs().add(tab1); 622 tabPane.getTabs().add(tab2); 623 tabPane.getTabs().add(tab3); 624 625 tab1.setDisable(true); 626 assertEquals(0, tabPane.getSelectionModel().getSelectedIndex()); 627 assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem()); 628 } 629 630 @Test public void disableATabAndSelectItByIndex() { 631 tabPane.setSkin(new TabPaneSkin(tabPane)); 632 tabPane.getTabs().add(tab1); 633 tabPane.getTabs().add(tab2); 634 tabPane.getTabs().add(tab3); 635 636 tab2.setDisable(true); 637 tabPane.getSelectionModel().select(1); 638 assertEquals(1, tabPane.getSelectionModel().getSelectedIndex()); 639 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 640 } 641 642 @Test public void selectByIndexADisableTab() { 643 tabPane.setSkin(new TabPaneSkin(tabPane)); 644 tabPane.getTabs().add(tab1); 645 tabPane.getTabs().add(tab2); 646 tabPane.getTabs().add(tab3); 647 648 tabPane.getSelectionModel().select(1); 649 tab2.setDisable(true); 650 assertEquals(1, tabPane.getSelectionModel().getSelectedIndex()); 651 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 652 assertTrue(tab2.isDisable()); 653 } 654 655 @Test public void disableATabAndSelectItByTab() { 656 tabPane.setSkin(new TabPaneSkin(tabPane)); 657 tabPane.getTabs().add(tab1); 658 tabPane.getTabs().add(tab2); 659 tabPane.getTabs().add(tab3); 660 661 tab2.setDisable(true); 662 tabPane.getSelectionModel().select(tab2); 663 assertEquals(1, tabPane.getSelectionModel().getSelectedIndex()); 664 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 665 } 666 667 @Test public void selectByTabADisableTab() { 668 tabPane.setSkin(new TabPaneSkin(tabPane)); 669 tabPane.getTabs().add(tab1); 670 tabPane.getTabs().add(tab2); 671 tabPane.getTabs().add(tab3); 672 673 tabPane.getSelectionModel().select(tab2); 674 tab2.setDisable(true); 675 assertEquals(1, tabPane.getSelectionModel().getSelectedIndex()); 676 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 677 assertTrue(tab2.isDisable()); 678 } 679 680 @Test public void navigateOverDisableTab() { 681 tabPane.getTabs().add(tab1); 682 tabPane.getTabs().add(tab2); 683 tabPane.getTabs().add(tab3); 684 685 root.getChildren().add(tabPane); 686 show(); 687 tabPane.requestFocus(); 688 689 assertTrue(tabPane.isFocused()); 690 691 tab2.setDisable(true); 692 assertEquals(0, tabPane.getSelectionModel().getSelectedIndex()); 693 assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem()); 694 assertTrue(tab2.isDisable()); 695 696 KeyEventFirer keyboard = new KeyEventFirer(tabPane); 697 keyboard.doRightArrowPress(); 698 699 assertEquals(2, tabPane.getSelectionModel().getSelectedIndex()); 700 assertEquals(tab3, tabPane.getSelectionModel().getSelectedItem()); 701 702 keyboard.doLeftArrowPress(); 703 704 assertEquals(0, tabPane.getSelectionModel().getSelectedIndex()); 705 assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem()); 706 } 707 708 @Ignore 709 @Test public void mousePressSelectsATab_RT20476() { 710 tabPane.getTabs().add(tab1); 711 tabPane.getTabs().add(tab2); 712 tabPane.getTabs().add(tab3); 713 714 tab1.setContent(new Button("TAB1")); 715 tab2.setContent(new Button("TAB2")); 716 tab3.setContent(new Button("TAB3")); 717 718 root.getChildren().add(tabPane); 719 show(); 720 721 root.applyCss(); 722 root.resize(300, 300); 723 root.layout(); 724 725 tk.firePulse(); 726 assertTrue(tabPane.isFocused()); 727 728 double xval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinX(); 729 double yval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinY(); 730 731 SceneHelper.processMouseEvent(scene, 732 MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval+75, yval+20)); 733 tk.firePulse(); 734 735 assertEquals(1, tabPane.getSelectionModel().getSelectedIndex()); 736 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 737 } 738 739 private int counter = 0; 740 @Ignore 741 @Test public void setOnSelectionChangedFiresTwice_RT21089() { 742 tabPane.getTabs().add(tab1); 743 tabPane.getTabs().add(tab2); 744 745 tab1.setContent(new Button("TAB1")); 746 tab2.setContent(new Button("TAB2")); 747 748 root.getChildren().add(tabPane); 749 show(); 750 751 root.applyCss(); 752 root.resize(300, 300); 753 root.layout(); 754 755 tk.firePulse(); 756 assertTrue(tabPane.isFocused()); 757 758 tab2.setOnSelectionChanged(event -> { 759 assertEquals(0, counter++); 760 }); 761 762 double xval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinX(); 763 double yval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinY(); 764 765 SceneHelper.processMouseEvent(scene, 766 MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval+75, yval+20)); 767 tk.firePulse(); 768 769 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 770 771 SceneHelper.processMouseEvent(scene, 772 MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval+75, yval+20)); 773 tk.firePulse(); 774 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 775 } 776 777 @Test public void unableToSelectNextTabWhenFirstTabIsClosed_RT22326() { 778 tabPane.getTabs().add(tab1); 779 tabPane.getTabs().add(tab2); 780 tabPane.getTabs().add(tab3); 781 782 assertEquals("one", tabPane.getTabs().get(0).getText()); 783 assertEquals("two", tabPane.getTabs().get(1).getText()); 784 assertEquals("three", tabPane.getTabs().get(2).getText()); 785 786 tabPane.getTabs().remove(tab1); 787 788 assertEquals(2, tabPane.getTabs().size()); 789 assertEquals(0, tabPane.getSelectionModel().getSelectedIndex()); 790 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 791 tabPane.getSelectionModel().selectNext(); 792 assertEquals(tab3, tabPane.getSelectionModel().getSelectedItem()); 793 } 794 795 @Test public void removeFirstTabNextTabShouldBeSelected() { 796 tabPane.getTabs().add(tab1); 797 tabPane.getTabs().add(tab2); 798 tabPane.getTabs().add(tab3); 799 800 assertEquals("one", tabPane.getTabs().get(0).getText()); 801 assertEquals("two", tabPane.getTabs().get(1).getText()); 802 assertEquals("three", tabPane.getTabs().get(2).getText()); 803 804 tabPane.getTabs().remove(tab1); 805 806 assertEquals(2, tabPane.getTabs().size()); 807 assertEquals(0, tabPane.getSelectionModel().getSelectedIndex()); 808 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 809 } 810 811 @Test public void selectionModelShouldNotBeNullWhenClosingFirstTab_RT22925() { 812 tabPane.getTabs().add(tab1); 813 tabPane.getTabs().add(tab2); 814 tabPane.getTabs().add(tab3); 815 816 tabPane.getSelectionModel().selectedItemProperty().addListener((ov, t, t1) -> { 817 assertEquals(t.getText(), "one"); 818 assertEquals(t1.getText(), "two"); 819 }); 820 821 assertEquals("one", tabPane.getTabs().get(0).getText()); 822 assertEquals("two", tabPane.getTabs().get(1).getText()); 823 assertEquals("three", tabPane.getTabs().get(2).getText()); 824 825 tabPane.getTabs().remove(tab1); 826 827 assertEquals(2, tabPane.getTabs().size()); 828 assertEquals(0, tabPane.getSelectionModel().getSelectedIndex()); 829 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 830 } 831 832 833 boolean button1Focused = false; 834 @Test public void focusTraversalShouldLookInsideEmbeddedEngines() { 835 836 Button b1 = new Button("Button1"); 837 final ChangeListener<Boolean> focusListener = (observable, oldVal, newVal) -> { 838 button1Focused = true; 839 }; 840 b1.focusedProperty().addListener(focusListener); 841 842 final ScrollPane sp = new ScrollPane(); 843 final VBox vbox1 = new VBox(); 844 vbox1.setSpacing(10); 845 vbox1.setTranslateX(10); 846 vbox1.setTranslateY(10); 847 vbox1.getChildren().addAll(b1); 848 tab1.setContent(vbox1); 849 sp.setContent(vbox1); 850 tab1.setContent(sp); 851 tabPane.getTabs().add(tab1); 852 853 tabPane.getTabs().add(tab2); 854 855 final Scene scene1 = new Scene(new Group(), 400, 400); 856 ((Group)scene1.getRoot()).getChildren().add(tabPane); 857 858 stage.setScene(scene1); 859 stage.show(); 860 stage.requestFocus(); 861 862 final KeyEvent tabEvent = new KeyEvent(KeyEvent.KEY_PRESSED, "", "", KeyCodeMap.valueOf(0x09), 863 false, false, false, false); 864 Platform.runLater(() -> { 865 tabPane.requestFocus(); 866 Event.fireEvent(tabPane, tabEvent); 867 868 }); 869 870 assertTrue(button1Focused); 871 872 } 873 874 @Test public void test_rt_35013() { 875 SplitPane splitPane = new SplitPane(); 876 splitPane.getItems().addAll(new Button("Button1"), new Button("Button2")); 877 878 TabPane tabPane = new TabPane(); 879 Tab emptyTab; 880 Tab splitTab = new Tab("SplitPane Tab"); 881 splitTab.setContent(splitPane); 882 tabPane.getTabs().addAll(emptyTab = new Tab("Empty Tab"), splitTab); 883 884 StageLoader sl = new StageLoader(tabPane); 885 886 tabPane.getSelectionModel().select(emptyTab); 887 Toolkit.getToolkit().firePulse(); 888 assertFalse(splitPane.getParent().isVisible()); 889 890 tabPane.getSelectionModel().select(splitTab); 891 Toolkit.getToolkit().firePulse(); 892 assertTrue(splitPane.getParent().isVisible()); 893 894 sl.dispose(); 895 } 896 897 @Test public void test_rt_36456_default_selectionMovesBackwardOne() { 898 Tab tab0 = new Tab("Tab 0"); 899 Tab tab1 = new Tab("Tab 1"); 900 Tab tab2 = new Tab("Tab 2"); 901 902 TabPane tabPane = new TabPane(); 903 tabPane.getTabs().addAll(tab0, tab1, tab2); 904 tabPane.getSelectionModel().select(tab1); 905 906 StageLoader sl = new StageLoader(tabPane); 907 908 assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem()); 909 tabPane.getTabs().remove(tab1); 910 assertEquals(tab0, tabPane.getSelectionModel().getSelectedItem()); 911 912 sl.dispose(); 913 } 914 915 @Test public void test_rt_36456_selectionMovesBackwardTwoSkippingDisabledTab() { 916 Tab tab0 = new Tab("Tab 0"); 917 Tab tab1 = new Tab("Tab 1"); 918 tab1.setDisable(true); 919 Tab tab2 = new Tab("Tab 2"); 920 921 TabPane tabPane = new TabPane(); 922 tabPane.getTabs().addAll(tab0, tab1, tab2); 923 tabPane.getSelectionModel().select(tab2); 924 925 StageLoader sl = new StageLoader(tabPane); 926 927 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 928 tabPane.getTabs().remove(tab2); 929 930 // selection should jump from tab2 to tab0, as tab1 is disabled 931 assertEquals(tab0, tabPane.getSelectionModel().getSelectedItem()); 932 933 sl.dispose(); 934 } 935 936 @Test public void test_rt_36456_selectionMovesForwardOne() { 937 Tab tab0 = new Tab("Tab 0"); 938 tab0.setDisable(true); 939 Tab tab1 = new Tab("Tab 1"); 940 Tab tab2 = new Tab("Tab 2"); 941 942 TabPane tabPane = new TabPane(); 943 tabPane.getTabs().addAll(tab0, tab1, tab2); 944 tabPane.getSelectionModel().select(tab1); 945 946 StageLoader sl = new StageLoader(tabPane); 947 948 assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem()); 949 tabPane.getTabs().remove(tab1); 950 951 // selection should move to the next non-disabled tab - in this case tab2 952 assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem()); 953 954 sl.dispose(); 955 } 956 957 @Test public void test_rt_36456_selectionMovesForwardTwoSkippingDisabledTab() { 958 Tab tab0 = new Tab("Tab 0"); 959 Tab tab1 = new Tab("Tab 1"); 960 tab1.setDisable(true); 961 Tab tab2 = new Tab("Tab 2"); 962 963 TabPane tabPane = new TabPane(); 964 tabPane.getTabs().addAll(tab0, tab1, tab2); 965 tabPane.getSelectionModel().select(tab0); 966 967 StageLoader sl = new StageLoader(tabPane); 968 969 Tab selectedTab = tabPane.getSelectionModel().getSelectedItem(); 970 assertEquals(tab0, selectedTab); 971 tabPane.getTabs().remove(tab0); 972 973 // selection should move to the next non-disabled tab - in this case tab2 974 selectedTab = tabPane.getSelectionModel().getSelectedItem(); 975 assertEquals(tab2.getText() + " != " + tab2.getText(), tab2, selectedTab); 976 977 sl.dispose(); 978 } 979 980 @Test public void test_rt_36908() { 981 TabPane pane = new TabPane(); 982 final Tab disabled = new Tab("Disabled"); 983 disabled.setDisable(true); 984 985 Tab tab1 = new Tab("Tab 1"); 986 Tab tab2 = new Tab("Tab 2"); 987 pane.getTabs().addAll(disabled, tab1, tab2); 988 989 assertEquals(1, pane.getSelectionModel().getSelectedIndex()); 990 assertEquals(tab1, pane.getSelectionModel().getSelectedItem()); 991 } 992 993 @Test public void test_rt_24658() { 994 Button btn = new Button("Button"); 995 final Tab disabled = new Tab("Disabled"); 996 disabled.setContent(btn); 997 998 TabPane pane = new TabPane(); 999 pane.getTabs().addAll(disabled); 1000 1001 assertEquals(0, pane.getSelectionModel().getSelectedIndex()); 1002 assertEquals(disabled, pane.getSelectionModel().getSelectedItem()); 1003 assertFalse(btn.isDisabled()); 1004 1005 disabled.setDisable(true); 1006 assertTrue(btn.isDisabled()); 1007 1008 disabled.setDisable(false); 1009 assertFalse(btn.isDisabled()); 1010 } 1011 1012 @Test public void test_rt_38382_noAddToTabPane() { 1013 test_rt_38382(false); 1014 } 1015 1016 @Test public void test_rt_38382_addToTabPane() { 1017 test_rt_38382(true); 1018 } 1019 1020 public void test_rt_38382(boolean addToTabPane) { 1021 final List<String> names = Arrays.asList( 1022 "Biomass", 1023 "Exploitable Population Biomass", 1024 "MSY", 1025 "Yield", 1026 "Recruitment", 1027 "Catch", 1028 "Effort"); 1029 final Map<Tab, List<String>> fooMap = new HashMap<>(); 1030 final List<Tab> tabList = new LinkedList<>(); 1031 for (String name : names) { 1032 final Tab tab = new Tab(); 1033 tab.setText(name); 1034 fooMap.put(tab, new LinkedList<>()); 1035 tabList.add(tab); 1036 } 1037 TabPane tabPane = new TabPane(); 1038 1039 if (addToTabPane) { 1040 tabPane.getTabs().setAll(tabList); 1041 } 1042 1043 fooMap.entrySet().forEach(entry -> { 1044 final Tab tab = entry.getKey(); 1045 assertTrue(tabList.contains(tab)); 1046 assertTrue(fooMap.containsKey(tab)); 1047 }); 1048 } 1049 1050 // Test for JDK-8189424 1051 int selectionChangeCount = 0; 1052 @Test public void testTabClosingEventAndSelectionChange() { 1053 Tab t1 = new Tab(""); 1054 Tab t2 = new Tab(""); 1055 tabPane.getTabs().add(t1); 1056 tabPane.getTabs().add(t2); 1057 tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); 1058 1059 tabPane.getSelectionModel().selectedItemProperty().addListener((ov, oldTab, newTab) -> { 1060 selectionChangeCount++; 1061 }); 1062 t1.setOnCloseRequest((event) -> { 1063 event.consume(); 1064 tabPane.getTabs().remove(t1); 1065 }); 1066 1067 root.getChildren().add(tabPane); 1068 show(); 1069 1070 root.applyCss(); 1071 root.resize(300, 300); 1072 root.layout(); 1073 1074 tk.firePulse(); 1075 assertTrue(tabPane.isFocused()); 1076 1077 tabPane.getSelectionModel().select(t1); 1078 1079 double xval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinX(); 1080 double yval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinY(); 1081 1082 SceneHelper.processMouseEvent(scene, 1083 MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval + 19, yval + 17)); 1084 tk.firePulse(); 1085 SceneHelper.processMouseEvent(scene, 1086 MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_RELEASED, xval + 19, yval + 17)); 1087 tk.firePulse(); 1088 1089 assertEquals(1, tabPane.getTabs().size()); 1090 assertEquals(t2, tabPane.getSelectionModel().getSelectedItem()); 1091 assertEquals(1, selectionChangeCount); 1092 1093 tabPane.getTabs().remove(t2); 1094 } 1095 1096 // Test for JDK-8193495 1097 @Test public void testQuickRemoveAddTab() { 1098 int tabHeaderMinWidth = 200; 1099 int tabHeaderMinHeight = 50; 1100 tabPane.setMaxSize(400, 200); 1101 tabPane.setTabMinWidth(tabHeaderMinWidth); 1102 tabPane.setTabMinHeight(tabHeaderMinHeight); 1103 tabPane.getTabs().addAll(tab1, tab2, tab3); 1104 tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE); 1105 1106 root.getChildren().add(tabPane); 1107 show(); 1108 tabPane.requestFocus(); 1109 tk.firePulse(); 1110 assertTrue(tabPane.isFocused()); 1111 1112 tabPane.getTabs().add(1, tabPane.getTabs().remove(0)); 1113 tk.firePulse(); 1114 tabPane.getSelectionModel().select(tab1); 1115 tk.firePulse(); 1116 1117 double xval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinX(); 1118 double yval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinY(); 1119 1120 SceneHelper.processMouseEvent(scene, 1121 MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval + 19, yval + 17)); 1122 tk.firePulse(); 1123 SceneHelper.processMouseEvent(scene, 1124 MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval + 19, yval + 17)); 1125 tk.firePulse(); 1126 1127 assertEquals("Tabpane should have 3 tabs.", 3, tabPane.getTabs().size()); 1128 assertEquals("tab2 should be at index 0.", tab2, tabPane.getSelectionModel().getSelectedItem()); 1129 } 1130 1131 }