1 /* 2 * Copyright (c) 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 package javafx.scene.control.test.tabpane; 26 27 import javafx.event.ActionEvent; 28 import javafx.event.Event; 29 import javafx.event.EventHandler; 30 import javafx.factory.*; 31 import javafx.scene.Node; 32 import javafx.scene.Scene; 33 import javafx.scene.control.*; 34 import javafx.scene.control.test.utils.CommonPropertiesScene; 35 import javafx.scene.control.test.utils.ptables.*; 36 import javafx.scene.control.test.utils.ptables.NodeControllerFactory.NodesStorage; 37 import static javafx.scene.control.test.utils.ptables.NodesChoserFactory.*; 38 import javafx.scene.layout.ColumnConstraints; 39 import javafx.scene.layout.GridPane; 40 import javafx.scene.layout.HBox; 41 import javafx.scene.layout.Pane; 42 import javafx.scene.layout.VBox; 43 import test.javaclient.shared.InteroperabilityApp; 44 import test.javaclient.shared.Utils; 45 46 /** 47 * @author Alexander Kirov 48 */ 49 public class NewTabPaneApp extends InteroperabilityApp { 50 51 public final static String TESTED_TABPANE_ID = "TESTED_TABPANE_ID"; 52 public final static String RESET_BUTTON_ID = "RESET_TABPANE_BUTTON_ID"; 53 public final static String RESET_SOFTLY_BUTTON_ID = "RESET_SOFTLY_BUTTON_ID"; 54 public final static String TABPANE_ADD_INDEX_TEXT_FIELD_ID = "TABPANE_ADD_INDEX_TEXT_FIELD_ID"; 55 public final static String NEW_TAB_ID_TEXT_FIELD_ID = "TAB_ID"; 56 public final static String FOCUS_RECEIVING_BUTTON_ID = "FOCUS_RECEIVING_BUTTON_ID"; 57 public final static String TAB_CLOSE_REQUEST_EVENT = "TAB_CLOSE_REQUEST_EVENT"; 58 public final static String VETO_CHECKBOX_ID = "VETO_CHECKBOX_ID"; 59 60 public static void main(String[] args) { 61 Utils.launch(NewTabPaneApp.class, args); 62 } 63 64 @Override 65 protected Scene getScene() { 66 Utils.setTitleToStage(stage, "TabPaneTestApp"); 67 NewTabPaneApp.TabPaneScene tabPaneScene = new NewTabPaneApp.TabPaneScene(); 68 Utils.addBrowser(tabPaneScene); 69 return tabPaneScene; 70 } 71 72 class TabPaneScene extends CommonPropertiesScene { 73 74 //VBox which contain tested TabPane. 75 Pane pane; 76 //TabPane to be tested. 77 TabPane testedTabPane; 78 TabPaneWithControl tabPane; 79 private PropertiesTable tb; 80 81 public TabPaneScene() { 82 super("Tab pane tests", 800, 600); 83 84 prepareScene(); 85 } 86 87 @Override 88 public final void prepareScene() { 89 pane = new Pane(); 90 pane.setMinSize(220, 220); 91 pane.setPrefSize(220, 220); 92 pane.setStyle("-fx-border-color : red;"); 93 94 testedTabPane = new TabPane(); 95 testedTabPane.setId(TESTED_TABPANE_ID); 96 pane.getChildren().add(testedTabPane); 97 98 tb = new PropertiesTable(testedTabPane); 99 PropertyTablesFactory.explorePropertiesList(testedTabPane, tb); 100 101 Button btnResetHardly = new Button("Reset"); 102 btnResetHardly.setId(RESET_BUTTON_ID); 103 btnResetHardly.setOnAction(new EventHandler<ActionEvent>() { 104 public void handle(ActionEvent t) { 105 HBox hb = (HBox) getRoot(); 106 hb.getChildren().clear(); 107 prepareMainSceneStructure(); 108 prepareScene(); 109 } 110 }); 111 112 Button btnResetSoftly = new Button("Reset softly"); 113 btnResetSoftly.setId(RESET_SOFTLY_BUTTON_ID); 114 btnResetSoftly.setOnAction(new EventHandler<ActionEvent>() { 115 public void handle(ActionEvent t) { 116 117 tb.refresh(); 118 119 TabPane newInstance = new TabPane(); 120 while (testedTabPane.getTabs().size() != 0) { 121 testedTabPane.getTabs().remove(0); 122 } 123 124 testedTabPane.setSide(newInstance.getSide()); 125 testedTabPane.setPrefHeight(newInstance.getPrefHeight()); 126 testedTabPane.setMinHeight(newInstance.getMinHeight()); 127 testedTabPane.setMaxHeight(newInstance.getMaxHeight()); 128 testedTabPane.setPrefWidth(newInstance.getPrefWidth()); 129 testedTabPane.setMinWidth(newInstance.getMinWidth()); 130 testedTabPane.setMaxWidth(newInstance.getMaxWidth()); 131 testedTabPane.setVisible(newInstance.isVisible()); 132 testedTabPane.setDisable(newInstance.isDisable()); 133 testedTabPane.setContextMenu(newInstance.getContextMenu()); 134 135 tabPane.removePropertiesTablesExceptFirstOnes(1); 136 } 137 }); 138 139 tabPane = new TabPaneWithControl("TabPane", tb); 140 141 142 143 VBox vb = new VBox(); 144 vb.setSpacing(5); 145 vb.getChildren().addAll( 146 btnResetHardly, 147 btnResetSoftly, 148 getControlsForTabCreation(tabPane), 149 getButtonForFocus()); 150 151 setTestedControl(testedTabPane); 152 setControllersContent(vb); 153 setPropertiesContent(tabPane); 154 } 155 156 private Button getButtonForFocus() { 157 Button b = new Button("empty button"); 158 b.setId("FOCUS_RECEIVING_BUTTON_ID"); 159 return b; 160 } 161 162 /** 163 * 164 * @return controls which set parameters and create the new tab 165 */ 166 private Pane getControlsForTabCreation(final TabPaneWithControl tabPane) { 167 168 GridPane grid = new GridPane(); 169 170 grid.setStyle("-fx-border-color:DARKBLUE"); 171 grid.setHgap(5); 172 grid.setVgap(5); 173 174 ColumnConstraints column1 = new ColumnConstraints(); 175 column1.setPercentWidth(40); 176 ColumnConstraints column2 = new ColumnConstraints(); 177 column2.setPercentWidth(60); 178 179 grid.getColumnConstraints().addAll(column1, column2); 180 //row #1 181 grid.add(new Label("Tab ID"), 0, 0); 182 final TextField newTabId = new TextField("ID"); 183 newTabId.setPrefWidth(40d); 184 newTabId.setId(NEW_TAB_ID_TEXT_FIELD_ID); 185 grid.add(newTabId, 1, 0); 186 187 //row #2 188 grid.add(new Label("Index"), 0, 1); 189 final TextField newTabIndex = new TextField("0"); 190 newTabIndex.setId(TABPANE_ADD_INDEX_TEXT_FIELD_ID); 191 newTabIndex.setPrefWidth(40); 192 grid.add(newTabIndex, 1, 1); 193 194 //row #3 195 grid.add(new Label("Content"), 0, 2); 196 final ChoiceBox<NodeFactory> cb = new ChoiceBox<NodeFactory>(); 197 cb.setId(NODE_CHOSER_CHOICE_BOX_ID); 198 cb.getItems().addAll(ControlsFactory.filteredValues()); 199 cb.getItems().addAll(Shapes.values()); 200 cb.getItems().addAll(Panes.values()); 201 grid.add(cb, 1, 2); 202 203 //row #4 204 /* 205 * If true then there will be created a properties pane 206 * for tab content each time a tab is added 207 */ 208 final CheckBox createPropsTab = new CheckBox("Create additional panes\n with content properties"); 209 grid.add(createPropsTab, 0, 3, 2, 1); 210 211 //row #5 212 /* 213 * If true then there will be created a properties pane 214 * for tab content each time a tab is added 215 */ 216 final CheckBox vetoOnClose = new CheckBox("Veto tab request on close."); 217 vetoOnClose.setId(VETO_CHECKBOX_ID); 218 grid.add(vetoOnClose, 0, 4, 2, 1); 219 220 //row #6 221 Button actionButton = new Button("Create new tab"); 222 actionButton.setId(NODE_CHOOSER_ACTION_BUTTON_ID); 223 224 final NodesChoserFactory.NodeAction<Node> handler = new NodesChoserFactory.NodeAction<Node>() { 225 @Override 226 public void execute(Node node) { 227 Tab tab = new Tab(); 228 229 tab.setId(newTabId.getText()); 230 tab.setText(newTabId.getText()); 231 tab.setContent(node); 232 233 final NodesStorage fullController = NodeControllerFactory.createFullController(tab, tabPane); 234 fullController.pt.addCounter(TAB_CLOSE_REQUEST_EVENT); 235 236 tab.setOnCloseRequest(new EventHandler<Event>() { 237 private boolean useVeto = vetoOnClose.isSelected(); 238 239 public void handle(Event t) { 240 fullController.pt.incrementCounter(TAB_CLOSE_REQUEST_EVENT); 241 242 if (useVeto) { 243 t.consume(); 244 } 245 } 246 }); 247 248 tabPane.addPropertiesTable(newTabId.getText(), fullController); 249 testedTabPane.getTabs().add(Integer.parseInt(newTabIndex.getText()), tab); 250 251 if (createPropsTab.isSelected()) { 252 tabPane.addPropertiesTable(node.getClass().getSimpleName(), NodeControllerFactory.createFullController(node, tabPane)); 253 } 254 } 255 }; 256 257 actionButton.setOnAction(new EventHandler<ActionEvent>() { 258 public void handle(ActionEvent t) { 259 handler.execute(cb.getSelectionModel().getSelectedItem().createNode()); 260 } 261 }); 262 grid.add(actionButton, 0, 5, 2, 1); 263 264 return grid; 265 } 266 } 267 }