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 = TabPaneBuilder.create().id(TESTED_TABPANE_ID).build(); 95 pane.getChildren().add(testedTabPane); 96 97 tb = new PropertiesTable(testedTabPane); 98 PropertyTablesFactory.explorePropertiesList(testedTabPane, tb); 99 100 Button btnResetHardly = ButtonBuilder.create().id(RESET_BUTTON_ID).text("Reset").build(); 101 btnResetHardly.setOnAction(new EventHandler<ActionEvent>() { 102 public void handle(ActionEvent t) { 103 HBox hb = (HBox) getRoot(); 104 hb.getChildren().clear(); 105 prepareMainSceneStructure(); 106 prepareScene(); 107 } 108 }); 109 110 Button btnResetSoftly = ButtonBuilder.create().id(RESET_SOFTLY_BUTTON_ID).text("Reset softly").build(); 111 btnResetSoftly.setOnAction(new EventHandler<ActionEvent>() { 112 public void handle(ActionEvent t) { 113 114 tb.refresh(); 115 116 TabPane newInstance = new TabPane(); 117 while (testedTabPane.getTabs().size() != 0) { 118 testedTabPane.getTabs().remove(0); 119 } 120 121 testedTabPane.setSide(newInstance.getSide()); 122 testedTabPane.setPrefHeight(newInstance.getPrefHeight()); 123 testedTabPane.setMinHeight(newInstance.getMinHeight()); 124 testedTabPane.setMaxHeight(newInstance.getMaxHeight()); 125 testedTabPane.setPrefWidth(newInstance.getPrefWidth()); 126 testedTabPane.setMinWidth(newInstance.getMinWidth()); 127 testedTabPane.setMaxWidth(newInstance.getMaxWidth()); 128 testedTabPane.setVisible(newInstance.isVisible()); 129 testedTabPane.setDisable(newInstance.isDisable()); 130 testedTabPane.setContextMenu(newInstance.getContextMenu()); 131 132 tabPane.removePropertiesTablesExceptFirstOnes(1); 133 } 134 }); 135 136 tabPane = new TabPaneWithControl("TabPane", tb); 137 138 139 140 VBox vb = new VBox(); 141 vb.setSpacing(5); 142 vb.getChildren().addAll( 143 btnResetHardly, 144 btnResetSoftly, 145 getControlsForTabCreation(tabPane), 146 getButtonForFocus()); 147 148 setTestedControl(testedTabPane); 149 setControllersContent(vb); 150 setPropertiesContent(tabPane); 151 } 152 153 private Button getButtonForFocus() { 154 Button b = new Button("empty button"); 155 b.setId("FOCUS_RECEIVING_BUTTON_ID"); 156 return b; 157 } 158 159 /** 160 * 161 * @return controls which set parameters and create the new tab 162 */ 163 private Pane getControlsForTabCreation(final TabPaneWithControl tabPane) { 164 165 GridPane grid = new GridPane(); 166 167 grid.setStyle("-fx-border-color:DARKBLUE"); 168 grid.setHgap(5); 169 grid.setVgap(5); 170 171 ColumnConstraints column1 = new ColumnConstraints(); 172 column1.setPercentWidth(40); 173 ColumnConstraints column2 = new ColumnConstraints(); 174 column2.setPercentWidth(60); 175 176 grid.getColumnConstraints().addAll(column1, column2); 177 //row #1 178 grid.add(new Label("Tab ID"), 0, 0); 179 final TextField newTabId = TextFieldBuilder.create() 180 .id(NEW_TAB_ID_TEXT_FIELD_ID) 181 .text("ID") 182 .prefWidth(40d) 183 .build(); 184 grid.add(newTabId, 1, 0); 185 186 //row #2 187 grid.add(new Label("Index"), 0, 1); 188 final TextField newTabIndex = TextFieldBuilder.create() 189 .id(TABPANE_ADD_INDEX_TEXT_FIELD_ID) 190 .text("0") 191 .prefWidth(40) 192 .build(); 193 grid.add(newTabIndex, 1, 1); 194 195 //row #3 196 grid.add(new Label("Content"), 0, 2); 197 final ChoiceBox<NodeFactory> cb = new ChoiceBox<NodeFactory>(); 198 cb.setId(NODE_CHOSER_CHOICE_BOX_ID); 199 cb.getItems().addAll(ControlsFactory.filteredValues()); 200 cb.getItems().addAll(Shapes.values()); 201 cb.getItems().addAll(Panes.values()); 202 grid.add(cb, 1, 2); 203 204 //row #4 205 /* 206 * If true then there will be created a properties pane 207 * for tab content each time a tab is added 208 */ 209 final CheckBox createPropsTab = CheckBoxBuilder 210 .create() 211 .text("Create additional panes\n with content properties") 212 .build(); 213 grid.add(createPropsTab, 0, 3, 2, 1); 214 215 //row #5 216 /* 217 * If true then there will be created a properties pane 218 * for tab content each time a tab is added 219 */ 220 final CheckBox vetoOnClose = CheckBoxBuilder 221 .create() 222 .text("Veto tab request on close.") 223 .id(VETO_CHECKBOX_ID) 224 .build(); 225 grid.add(vetoOnClose, 0, 4, 2, 1); 226 227 //row #6 228 Button actionButton = new Button("Create new tab"); 229 actionButton.setId(NODE_CHOOSER_ACTION_BUTTON_ID); 230 231 final NodesChoserFactory.NodeAction<Node> handler = new NodesChoserFactory.NodeAction<Node>() { 232 @Override 233 public void execute(Node node) { 234 Tab tab = new Tab(); 235 236 tab.setId(newTabId.getText()); 237 tab.setText(newTabId.getText()); 238 tab.setContent(node); 239 240 final NodesStorage fullController = NodeControllerFactory.createFullController(tab, tabPane); 241 fullController.pt.addCounter(TAB_CLOSE_REQUEST_EVENT); 242 243 tab.setOnCloseRequest(new EventHandler<Event>() { 244 private boolean useVeto = vetoOnClose.isSelected(); 245 246 public void handle(Event t) { 247 fullController.pt.incrementCounter(TAB_CLOSE_REQUEST_EVENT); 248 249 if (useVeto) { 250 t.consume(); 251 } 252 } 253 }); 254 255 tabPane.addPropertiesTable(newTabId.getText(), fullController); 256 testedTabPane.getTabs().add(Integer.parseInt(newTabIndex.getText()), tab); 257 258 if (createPropsTab.isSelected()) { 259 tabPane.addPropertiesTable(node.getClass().getSimpleName(), NodeControllerFactory.createFullController(node, tabPane)); 260 } 261 } 262 }; 263 264 actionButton.setOnAction(new EventHandler<ActionEvent>() { 265 public void handle(ActionEvent t) { 266 handler.execute(cb.getSelectionModel().getSelectedItem().createNode()); 267 } 268 }); 269 grid.add(actionButton, 0, 5, 2, 1); 270 271 return grid; 272 } 273 } 274 }