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.slider;
  26 
  27 import javafx.event.ActionEvent;
  28 import javafx.event.EventHandler;
  29 import javafx.scene.Scene;
  30 import javafx.scene.control.Button;

  31 import javafx.scene.control.Slider;

  32 import javafx.scene.control.test.utils.CommonPropertiesScene;
  33 import javafx.scene.control.test.utils.ptables.PropertiesTable;
  34 import javafx.scene.control.test.utils.ptables.PropertyTablesFactory;
  35 import javafx.scene.control.test.utils.ptables.SpecialTablePropertiesProvider;
  36 import javafx.scene.control.test.utils.ptables.StaticLogger;
  37 import javafx.scene.layout.HBox;
  38 import javafx.scene.layout.VBox;
  39 import javafx.util.StringConverter;
  40 import test.javaclient.shared.InteroperabilityApp;
  41 import test.javaclient.shared.Utils;
  42 
  43 /**
  44  * @author Alexander Kirov
  45  */
  46 public class SliderNewApp extends InteroperabilityApp {
  47 
  48     public final static String TESTED_SLIDER_ID = "TESTED_SLIDER_ID";
  49     public final static String RESET_BUTTON_ID = "RESET_SLIDER_BUTTON_ID";
  50     public final static String VALUE_CHANGING_COUNTER = "VALUE_CHANGING_COUNTER";
  51     public final static String APPLY_CUSTOM_LABEL_FORMATTER = "APPLY_CUSTOM_LABEL_FORMATTER";
  52 
  53     public static void main(String[] args) {
  54         Utils.launch(SliderNewApp.class, args);
  55     }
  56 
  57     @Override
  58     protected Scene getScene() {
  59         Utils.setTitleToStage(stage, "SliderTestApp");
  60         return new SliderScene();
  61     }
  62 
  63     class SliderScene extends CommonPropertiesScene {
  64 
  65         PropertiesTable tb;
  66         //Slider to be tested.
  67         Slider testedSlider;
  68 
  69         public SliderScene() {
  70             super("Slider", 800, 600);
  71 
  72             prepareScene();
  73         }
  74 
  75         @Override
  76         final protected void prepareScene() {
  77             testedSlider = new Slider();
  78             testedSlider.setId(TESTED_SLIDER_ID);
  79 
  80             tb = new PropertiesTable(testedSlider);
  81             PropertyTablesFactory.explorePropertiesList(testedSlider, tb);
  82             SpecialTablePropertiesProvider.provideForControl(testedSlider, tb);
  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                     HBox hb = (HBox) getRoot();
  89                     hb.getChildren().clear();
  90                     prepareMainSceneStructure();
  91                     prepareScene();
  92                 }
  93             });
  94 
  95             Button setCustomConverter = new Button("ApplyCsustomConverter");
  96             setCustomConverter.setId(APPLY_CUSTOM_LABEL_FORMATTER);
  97             setCustomConverter.setOnAction(new EventHandler<ActionEvent>() {
  98                 public void handle(ActionEvent t) {
  99                     testedSlider.setLabelFormatter(new CustomConverter());
 100                     StaticLogger.log("\nCustom logger set.\n");
 101                 }
 102             });
 103 
 104             VBox vb = new VBox();
 105             vb.setSpacing(5);
 106             vb.getChildren().addAll(resetButton, setCustomConverter);
 107             setControllersContent(vb);
 108             setTestedControl(testedSlider);
 109             setPropertiesContent(tb);
 110         }
 111     }
 112 
 113     class CustomConverter extends StringConverter<java.lang.Double> {
 114 
 115         @Override
 116         public String toString(Double t) {
 117             return "Ok.";
 118         }
 119 
 120         @Override
 121         public Double fromString(String string) {
 122             return 10.0;
 123         }
 124     }
 125 }
--- EOF ---