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.Accordion; 26 27 import javafx.scene.control.test.utils.ptables.TabPaneWithControl; 28 import javafx.scene.control.test.utils.ptables.PropertyTablesFactory; 29 import javafx.scene.control.test.utils.ptables.PropertiesTable; 30 import javafx.scene.control.test.utils.ptables.NodesChoserFactory; 31 import javafx.scene.control.test.utils.ptables.NodeControllerFactory; 32 import javafx.beans.value.ChangeListener; 33 import javafx.beans.value.ObservableValue; 34 import javafx.event.ActionEvent; 35 import javafx.event.EventHandler; 36 import javafx.geometry.Insets; 37 import javafx.scene.Node; 38 import javafx.scene.Scene; 39 import javafx.scene.control.*; 40 import javafx.scene.control.test.utils.*; 41 import javafx.scene.layout.HBox; 42 import javafx.scene.layout.Pane; 43 import javafx.scene.layout.VBox; 44 import test.javaclient.shared.InteroperabilityApp; 45 import test.javaclient.shared.Utils; 46 47 /** 48 * @author Alexander Kirov 49 */ 50 public class NewAccordionApp extends InteroperabilityApp { 51 52 public final static String TESTED_ACCORDION_ID = "TESTED_ACCORDION_ID"; 53 public final static String RESET_BUTTON_ID = "RESET_ACCORDION_BUTTON_ID"; 54 public final String ACCORDION_ADD_INDEX_TEXT_FIELD_ID = "ACCORDION_ADD_INDEX_TEXT_FIELD_ID"; 55 56 public static void main(String[] args) { 57 Utils.launch(NewAccordionApp.class, args); 58 } 59 60 @Override 61 protected Scene getScene() { 62 Utils.setTitleToStage(stage, "AccordionTestApp"); 63 return new NewAccordionApp.AccordionScene(); 64 } 65 66 class AccordionScene extends Scene { 67 68 //VBox which contain tested Accordion. 69 Pane pane; 70 //Accordion to be tested. 71 Accordion testedAccordion; 72 73 public AccordionScene() { 74 super(new HBox(), 800, 600); 75 76 prepareScene(); 77 } 78 79 private void prepareScene() { 80 pane = new Pane(); 81 testedAccordion = new Accordion(); 82 testedAccordion.setId(TESTED_ACCORDION_ID); 83 84 PropertiesTable tb = new PropertiesTable(testedAccordion); 85 PropertyTablesFactory.explorePropertiesList(testedAccordion, tb); 86 87 final TabPaneWithControl tabPane = new TabPaneWithControl("Accordion", tb); 88 89 final TextField tf = new TextField("0"); 90 tf.setId(ACCORDION_ADD_INDEX_TEXT_FIELD_ID); 91 tf.setPrefWidth(40); 92 93 HBox nodeshb = new NodesChoserFactory("Add!", new NodesChoserFactory.NodeAction<Node>() { 94 95 @Override 96 public void execute(Node node) { 97 TitledPane tp = new TitledPane(node.getClass().getSimpleName(), node); 98 testedAccordion.getPanes().add(Integer.parseInt(tf.getText()), tp); 99 tabPane.addPropertiesTable(node.getClass().getSimpleName(), NodeControllerFactory.createFullController(node, tabPane)); 100 tabPane.addPropertiesTable(tp.getClass().getSimpleName(), NodeControllerFactory.createFullController(tp, tabPane)); 101 } 102 }, tf); 103 104 pane.setMinSize(220, 220); 105 pane.setPrefSize(220, 220); 106 pane.setStyle("-fx-border-color : red;"); 107 pane.getChildren().add(testedAccordion); 108 109 VBox vb = new VBox(); 110 vb.setSpacing(5); 111 112 HBox hb = (HBox) getRoot(); 113 hb.setPadding(new Insets(5, 5, 5, 5)); 114 hb.setStyle("-fx-border-color : green;"); 115 116 Button resetButton = new Button("Reset"); 117 resetButton.setId(RESET_BUTTON_ID); 118 resetButton.setOnAction(new EventHandler<ActionEvent>() { 119 120 public void handle(ActionEvent t) { 121 HBox hb = (HBox) getRoot(); 122 hb.getChildren().clear(); 123 prepareScene(); 124 } 125 }); 126 127 final ToggleButton compactStateToggle = new ToggleButton("Compact"); 128 compactStateToggle.setSelected(true); 129 compactStateToggle.selectedProperty().addListener(new ChangeListener<Boolean>() { 130 131 public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) { 132 if (t1) { 133 compactStateToggle.setText("Compact"); 134 pane.setMinSize(220, 220); 135 pane.setPrefSize(220, 220); 136 AccordionScene.this.getWindow().setWidth(1200); 137 AccordionScene.this.getWindow().setHeight(700); 138 } else { 139 compactStateToggle.setText("Free"); 140 pane.setMinSize(600, 600); 141 pane.setPrefSize(600, 600); 142 AccordionScene.this.getWindow().setWidth(800); 143 AccordionScene.this.getWindow().setHeight(600); 144 } 145 } 146 }); 147 148 149 vb.getChildren().addAll(new Label("Pane with tested Accordion"), pane, resetButton, compactStateToggle, nodeshb); 150 151 hb.getChildren().addAll(vb, tabPane); 152 } 153 } 154 }