/*******************************************************************************
 * Copyright (c) 2015-2016 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.csstudio.display.builder.representation.javafx.sandbox;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/** Spinner demo
 *
 *  @author Kay Kasemir
 *  @author Amanda Carpenter
 */
@SuppressWarnings("nls")
public class SpinnerDemo extends Application
{
    public static void main(final String[] args)
    {
        launch(args);
    }

    @Override
    public void start(final Stage stage)
    {
        final Label label = new Label("Demo:");

        SpinnerValueFactory<Double> svf = new SpinnerValueFactory.DoubleSpinnerValueFactory(0, 1000);
        Spinner<Double> spinner = new Spinner<>();
        spinner.setValueFactory(svf);
        //??? do this later
        /*svf.setConverter(
                new StringConverter<Double>()
                {
                    @Override
                    public Double fromString(String string) {
                        //value should be VNumber, parse returns double or long
                        return FormatOptionHandler.parse(model_widget.runtimeValue().getValue(), string);
                    }
                    @Override
                    public String toString(Double object) {
                        //use FormatOptionHandler.format()
                        return null;
                    }
                });*/
        spinner.editorProperty().getValue().setStyle("-fx-text-fill:" + "black");
        spinner.editorProperty().getValue().setBackground(
                new Background(new BackgroundFill(Color.AZURE, CornerRadii.EMPTY, Insets.EMPTY)));

        //spinner.getStyleClass().add(Spinner.STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL);
        //int x = spinner.getStyleClass().indexOf(Spinner.STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL);
        //if (x > 0) spinner.getStyleClass().remove(x);

        spinner.setEditable(true);
        spinner.setPrefWidth(80);
        //how to exit spinner?

        spinner.valueProperty().addListener((prop, old, value) ->
        {
            System.out.println("Value: " + value);
        });

        final HBox root = new HBox(label, spinner);

        final Scene scene = new Scene(root, 800, 700);
        stage.setScene(scene);
        stage.setTitle("Spinner Demo");

        stage.show();
    }
}

@@ -1544,673 +1544,8 @@
 );%0D%0A
-        //??? do this later%0D%0A        /*svf.setConverter(%0D%0A                new StringConverter%3CDouble%3E()%0D%0A                %7B%0D%0A                    @Override%0D%0A                    public Double fromString(String string) %7B%0D%0A                        //value should be VNumber, parse returns double or long%0D%0A                        return FormatOptionHandler.parse(model_widget.runtimeValue().getValue(), string);%0D%0A                    %7D%0D%0A                    @Override%0D%0A                    public String toString(Double object) %7B%0D%0A                        //use FormatOptionHandler.format()%0D%0A                        return null;%0D%0A                    %7D%0D%0A                %7D);*/%0D%0A
     
@@ -1619,24 +1619,24 @@
  %22black%22);%0D%0A
+
         spin
@@ -1781,24 +1781,26 @@
 MPTY)));%0D%0A%0D%0A
+%0D%0A
         //sp
@@ -2060,24 +2060,24 @@
 ble(true);%0D%0A
+
         spin
@@ -2102,40 +2102,8 @@
 0);%0D
-%0A        //how to exit spinner?%0D
 %0A%0D%0A 

clean up comments