1 /*
2 * Copyright (c) 2010, 2016, 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
1013 final Map<Tab, List<String>> fooMap = new HashMap<>();
1014 final List<Tab> tabList = new LinkedList<>();
1015 for (String name : names) {
1016 final Tab tab = new Tab();
1017 tab.setText(name);
1018 fooMap.put(tab, new LinkedList<>());
1019 tabList.add(tab);
1020 }
1021 TabPane tabPane = new TabPane();
1022
1023 if (addToTabPane) {
1024 tabPane.getTabs().setAll(tabList);
1025 }
1026
1027 fooMap.entrySet().forEach(entry -> {
1028 final Tab tab = entry.getKey();
1029 assertTrue(tabList.contains(tab));
1030 assertTrue(fooMap.containsKey(tab));
1031 });
1032 }
1033 }
|
1 /*
2 * Copyright (c) 2010, 2017, 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
1013 final Map<Tab, List<String>> fooMap = new HashMap<>();
1014 final List<Tab> tabList = new LinkedList<>();
1015 for (String name : names) {
1016 final Tab tab = new Tab();
1017 tab.setText(name);
1018 fooMap.put(tab, new LinkedList<>());
1019 tabList.add(tab);
1020 }
1021 TabPane tabPane = new TabPane();
1022
1023 if (addToTabPane) {
1024 tabPane.getTabs().setAll(tabList);
1025 }
1026
1027 fooMap.entrySet().forEach(entry -> {
1028 final Tab tab = entry.getKey();
1029 assertTrue(tabList.contains(tab));
1030 assertTrue(fooMap.containsKey(tab));
1031 });
1032 }
1033
1034 // Test for JDK-8189424
1035 int selectionChangeCount = 0;
1036 @Test public void testTabClosingEventAndSelectionChange() {
1037 Tab t1 = new Tab("");
1038 Tab t2 = new Tab("");
1039 tabPane.getTabs().add(t1);
1040 tabPane.getTabs().add(t2);
1041 tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS);
1042
1043 tabPane.getSelectionModel().selectedItemProperty().addListener((ov, oldTab, newTab) -> {
1044 selectionChangeCount++;
1045 });
1046 t1.setOnCloseRequest((event) -> {
1047 event.consume();
1048 tabPane.getTabs().remove(t1);
1049 });
1050
1051 root.getChildren().add(tabPane);
1052 show();
1053
1054 root.applyCss();
1055 root.resize(300, 300);
1056 root.layout();
1057
1058 tk.firePulse();
1059 assertTrue(tabPane.isFocused());
1060
1061 tabPane.getSelectionModel().select(t1);
1062
1063 double xval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinX();
1064 double yval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinY();
1065
1066 SceneHelper.processMouseEvent(scene,
1067 MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval + 19, yval + 17));
1068 tk.firePulse();
1069 SceneHelper.processMouseEvent(scene,
1070 MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_RELEASED, xval + 19, yval + 17));
1071 tk.firePulse();
1072
1073 assertEquals(1, tabPane.getTabs().size());
1074 assertEquals(t2, tabPane.getSelectionModel().getSelectedItem());
1075 assertEquals(1, selectionChangeCount);
1076
1077 tabPane.getTabs().remove(t2);
1078 }
1079
1080 }
|