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.colorpicker;
  26 
  27 import java.util.ArrayList;
  28 import java.util.Arrays;
  29 import java.util.List;
  30 import javafx.event.ActionEvent;
  31 import javafx.event.Event;
  32 import javafx.event.EventHandler;
  33 import javafx.geometry.Insets;
  34 import javafx.geometry.Pos;
  35 import javafx.scene.Scene;
  36 import javafx.scene.control.*;
  37 import javafx.scene.control.test.utils.CommonPropertiesScene;
  38 import javafx.scene.control.test.utils.ptables.PropertiesTable;
  39 import javafx.scene.layout.HBox;
  40 import javafx.scene.layout.Pane;
  41 import javafx.scene.layout.VBox;
  42 import javafx.scene.paint.Color;
  43 import test.javaclient.shared.InteroperabilityApp;
  44 import test.javaclient.shared.Utils;
  45 
  46 /**
  47  * @author Alexander Kirov
  48  */
  49 public class ColorPickerApp extends InteroperabilityApp {
  50 
  51     public final static String TESTED_COLORPICKER_ID = "TESTED_COLORPICKER_ID";
  52     public final static String HARD_RESET_BUTTON_ID = "HARD_RESET_COLORPICKER_BUTTON_ID";
  53     public final static String SOFT_RESET_BUTTON_ID = "SOFT_RESET_COLORPICKER_BUTTON_ID";
  54     public final static String SET_COLOR_TEXT_FIELD_ID = "SET_COLOR_TEXT_FIELD_ID";
  55     public final static String SET_COLOR_BUTTON_ID = "SET_COLOR_BUTTON_ID";
  56     public final static List<Color> predefinedColors = new ArrayList<Color>();
  57 
  58     public static void main(String[] args) {
  59         Utils.launch(ColorPickerApp.class, args);
  60     }
  61 
  62     @Override
  63     protected Scene getScene() {
  64         Utils.setTitleToStage(stage, "ColorPickerTestApp");
  65         return new ColorPickerScene();
  66     }
  67 
  68     class ColorPickerScene extends CommonPropertiesScene {
  69 
  70         //VBox which contain tested color picker.
  71         Pane pane;
  72         PropertiesTable tb;
  73         //Color picker to be tested.
  74         ColorPicker testedColorPicker;
  75 
  76         public ColorPickerScene() {
  77             super("ColorPicker", 800, 600);
  78 
  79             prepareScene();
  80         }
  81 
  82         @Override
  83         final protected void prepareScene() {
  84             predefinedColors.add(Color.WHITE);
  85             predefinedColors.add(Color.BLACK);
  86             predefinedColors.add(Color.BLUE);
  87 
  88             Utils.addBrowser(this);
  89             pane = new Pane();
  90             testedColorPicker = new ColorPicker();
  91             testedColorPicker.setId(TESTED_COLORPICKER_ID);
  92 
  93             tb = new PropertiesTable(testedColorPicker);
  94 
  95             tb.addStringLine(testedColorPicker.promptTextProperty(), "prompt text");
  96 
  97             tb.addBooleanPropertyLine(testedColorPicker.armedProperty());
  98             tb.addBooleanPropertyLine(testedColorPicker.focusTraversableProperty());
  99 
 100             tb.addBooleanPropertyLine(testedColorPicker.visibleProperty());
 101 
 102             tb.addObjectEnumPropertyLine(testedColorPicker.blendModeProperty(), Arrays.asList(javafx.scene.effect.BlendMode.values()), testedColorPicker);
 103             tb.addObjectEnumPropertyLine(testedColorPicker.valueProperty(), predefinedColors, testedColorPicker);
 104 
 105             tb.addDoublePropertyLine(testedColorPicker.prefWidthProperty(), -100, 400, 100);
 106             tb.addDoublePropertyLine(testedColorPicker.prefHeightProperty(), -100, 400, 100);
 107 
 108             tb.addDoublePropertyLine(testedColorPicker.rotateProperty(), -100, 400, 100);
 109 
 110             tb.addDoublePropertyLine(testedColorPicker.translateXProperty(), -1, 15, 0);
 111             tb.addDoublePropertyLine(testedColorPicker.scaleXProperty(), -1, 4, 1);
 112             tb.addDoublePropertyLine(testedColorPicker.scaleYProperty(), -1, 4, 1);
 113             tb.addDoublePropertyLine(testedColorPicker.scaleZProperty(), -1, 4, 1);
 114 
 115             tb.addSimpleListener(testedColorPicker.widthProperty(), testedColorPicker);
 116             tb.addSimpleListener(testedColorPicker.heightProperty(), testedColorPicker);
 117 
 118             tb.addSimpleListener(testedColorPicker.focusedProperty(), testedColorPicker);
 119             tb.addSimpleListener(testedColorPicker.pressedProperty(), testedColorPicker);
 120             tb.addSimpleListener(testedColorPicker.showingProperty(), testedColorPicker);
 121             tb.addSimpleListener(testedColorPicker.sceneProperty(), testedColorPicker);
 122 
 123             tb.addStringLine(testedColorPicker.promptTextProperty(), "prompt");
 124 
 125             pane.setMinSize(240, 240);
 126             pane.setPrefSize(240, 240);
 127             pane.setStyle("-fx-border-color : red;");
 128             pane.getChildren().add(testedColorPicker);
 129 
 130             VBox vb = new VBox();
 131             vb.setSpacing(5);
 132 
 133             HBox hb = (HBox) getRoot();
 134             hb.setPadding(new Insets(5, 5, 5, 5));
 135             hb.setStyle("-fx-border-color : green;");
 136 
 137             Button hardResetButton = ButtonBuilder.create().id(HARD_RESET_BUTTON_ID).text("Hard reset").build();
 138             hardResetButton.setOnAction(new EventHandler<ActionEvent>() {
 139                 public void handle(ActionEvent t) {
 140                     HBox hb = (HBox) getRoot();
 141                     hb.getChildren().clear();
 142                     prepareMainSceneStructure();
 143                     prepareScene();
 144                 }
 145             });
 146 
 147             Button softResetButton = ButtonBuilder.create().id(SOFT_RESET_BUTTON_ID).text("Soft reset").build();
 148             softResetButton.setOnAction(new EventHandler<ActionEvent>() {
 149                 public void handle(ActionEvent t) {
 150                     tb.refresh();
 151                     ColorPicker newOne = new ColorPicker();
 152                     testedColorPicker.setValue(newOne.getValue());
 153                 }
 154             });
 155 
 156             HBox resetButtonsHBox = new HBox();
 157             resetButtonsHBox.getChildren().addAll(hardResetButton, softResetButton);
 158             resetButtonsHBox.setAlignment(Pos.CENTER);
 159 
 160             VBox vb1 = new VBox(5);
 161             vb1.getChildren().addAll(resetButtonsHBox, setColorHbox());
 162 
 163             setTestedControl(testedColorPicker);
 164             setControllersContent(vb1);
 165             setPropertiesContent(tb);
 166         }
 167 
 168         private HBox setColorHbox() {
 169             HBox hb = new HBox();
 170             Label lb = new Label("Set color");
 171             final TextField colorTf = TextFieldBuilder.create().prefWidth(100).id(SET_COLOR_TEXT_FIELD_ID).build();
 172             Button bt = ButtonBuilder.create().text("Set!").id(SET_COLOR_BUTTON_ID).build();
 173             bt.setOnAction(new EventHandler() {
 174                 public void handle(Event t) {
 175                     testedColorPicker.setValue(Color.web(colorTf.getText()));
 176                 }
 177             });
 178             hb.getChildren().addAll(lb, colorTf, bt);
 179             hb.setAlignment(Pos.CENTER);
 180             return hb;
 181         }
 182     }
 183 }