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 = AccordionBuilder.create().id(TESTED_ACCORDION_ID).build();
  82 
  83             PropertiesTable tb = new PropertiesTable(testedAccordion);
  84             PropertyTablesFactory.explorePropertiesList(testedAccordion, tb);
  85 
  86             final TabPaneWithControl tabPane = new TabPaneWithControl("Accordion", tb);
  87 
  88             final TextField tf = TextFieldBuilder.create().id(ACCORDION_ADD_INDEX_TEXT_FIELD_ID).text("0").prefWidth(40).build();
  89 
  90             HBox nodeshb = new NodesChoserFactory("Add!", new NodesChoserFactory.NodeAction<Node>() {
  91 
  92                 @Override
  93                 public void execute(Node node) {
  94                     TitledPane tp = new TitledPane(node.getClass().getSimpleName(), node);
  95                     testedAccordion.getPanes().add(Integer.parseInt(tf.getText()), tp);
  96                     tabPane.addPropertiesTable(node.getClass().getSimpleName(), NodeControllerFactory.createFullController(node, tabPane));
  97                     tabPane.addPropertiesTable(tp.getClass().getSimpleName(), NodeControllerFactory.createFullController(tp, tabPane));
  98                 }
  99             }, tf);
 100 
 101             pane.setMinSize(220, 220);
 102             pane.setPrefSize(220, 220);
 103             pane.setStyle("-fx-border-color : red;");
 104             pane.getChildren().add(testedAccordion);
 105 
 106             VBox vb = new VBox();
 107             vb.setSpacing(5);
 108 
 109             HBox hb = (HBox) getRoot();
 110             hb.setPadding(new Insets(5, 5, 5, 5));
 111             hb.setStyle("-fx-border-color : green;");
 112 
 113             Button resetButton = ButtonBuilder.create().id(RESET_BUTTON_ID).text("Reset").build();
 114             resetButton.setOnAction(new EventHandler<ActionEvent>() {
 115 
 116                 public void handle(ActionEvent t) {
 117                     HBox hb = (HBox) getRoot();
 118                     hb.getChildren().clear();
 119                     prepareScene();
 120                 }
 121             });
 122 
 123             final ToggleButton compactStateToggle = new ToggleButton("Compact");
 124             compactStateToggle.setSelected(true);
 125             compactStateToggle.selectedProperty().addListener(new ChangeListener<Boolean>() {
 126 
 127                 public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
 128                     if (t1) {
 129                         compactStateToggle.setText("Compact");
 130                         pane.setMinSize(220, 220);
 131                         pane.setPrefSize(220, 220);
 132                         AccordionScene.this.getWindow().setWidth(1200);
 133                         AccordionScene.this.getWindow().setHeight(700);
 134                     } else {
 135                         compactStateToggle.setText("Free");
 136                         pane.setMinSize(600, 600);
 137                         pane.setPrefSize(600, 600);
 138                         AccordionScene.this.getWindow().setWidth(800);
 139                         AccordionScene.this.getWindow().setHeight(600);
 140                     }
 141                 }
 142             });
 143 
 144 
 145             vb.getChildren().addAll(new Label("Pane with tested Accordion"), pane, resetButton, compactStateToggle, nodeshb);
 146 
 147             hb.getChildren().addAll(vb, tabPane);
 148         }
 149     }
 150 }