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.textinput;
  26 
  27 import javafx.event.ActionEvent;
  28 import javafx.event.EventHandler;
  29 import javafx.geometry.Insets;
  30 import javafx.scene.control.*;
  31 import javafx.scene.control.test.utils.CommonPropertiesScene;
  32 import javafx.scene.control.test.utils.ptables.PropertiesTable;
  33 import javafx.scene.control.test.utils.ptables.PropertyTablesFactory;
  34 import javafx.scene.control.test.utils.ptables.SpecialTablePropertiesProvider;
  35 import javafx.scene.layout.HBox;
  36 import javafx.scene.layout.Pane;
  37 import javafx.scene.layout.VBox;
  38 import test.javaclient.shared.InteroperabilityApp;
  39 import test.javaclient.shared.Utils;
  40 
  41 /**
  42  * @author Alexander Kirov
  43  */
  44 public abstract class TextControlApp extends InteroperabilityApp {
  45 
  46     public final static String ADD_TEXT_BUTTON_ID = "ADD_TEXT_BUTTON_ID";
  47     public final static String TESTED_TEXT_INPUT_CONTROL_ID = "TESTED_CONTROL_ID";
  48     public final static String RESET_BUTTON_ID = "RESET_BUTTON_ID";
  49 
  50     public abstract class TextInputScene extends CommonPropertiesScene {
  51 
  52         PropertiesTable tb;
  53         //Control to be tested.
  54         TextInputControl testedTextInput;
  55 
  56         public TextInputScene() {
  57             super("TextInput", 800, 600);
  58 
  59             prepareScene();
  60         }
  61 
  62         public abstract void setNewControl();
  63 
  64         public abstract void resetControl();
  65 
  66         public abstract void addControlSpecificButtons(Pane pane);
  67 
  68         @Override
  69         final protected void prepareScene() {
  70             setNewControl();
  71             tb = new PropertiesTable(testedTextInput);
  72             testedTextInput.setId(TESTED_TEXT_INPUT_CONTROL_ID);
  73 
  74             PropertyTablesFactory.explorePropertiesList(testedTextInput, tb);
  75             SpecialTablePropertiesProvider.provideForControl(testedTextInput, tb);
  76 
  77             VBox vb = new VBox();
  78             vb.setSpacing(5);
  79 
  80             HBox hb = (HBox) getRoot();
  81             hb.setPadding(new Insets(5, 5, 5, 5));
  82             hb.setStyle("-fx-border-color : green;");
  83 
  84             Button resetButton = new Button("RESET");
  85             resetButton.setId(RESET_BUTTON_ID);
  86             resetButton.setOnAction(new EventHandler<ActionEvent>() {
  87                 public void handle(ActionEvent t) {
  88                     tb.refresh();
  89                     resetControl();
  90                 }
  91             });
  92             VBox resetButtonsHBox = new VBox(5);
  93             resetButtonsHBox.getChildren().addAll(resetButton);
  94             vb.getChildren().addAll(resetButtonsHBox);
  95             addControlDependentProperties();
  96             addControlSpecificButtons(vb);
  97             setTestedControl(testedTextInput);
  98             setControllersContent(vb);
  99             setPropertiesContent(tb);
 100         }
 101         
 102         protected void addControlDependentProperties() {}
 103     }
 104 
 105     protected void setTitle() {
 106         Utils.setTitleToStage(stage, "TextInputTestApp");
 107     }
 108 }