changeset 7962:c2041e3fd928

[SCENEBUILDER] Fix DTL-6768: Extend the Show Sample Data command to include Spinner control
author slions
date Wed, 03 Sep 2014 16:32:55 +0200
parents b4d2b1d973a6
children 3beaafe4b671
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/sampledata/AbstractSampleData.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/sampledata/SampleDataGenerator.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/sampledata/SpinnerSampleData.java
diffstat 3 files changed, 113 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/sampledata/AbstractSampleData.java	Wed Sep 03 17:16:54 2014 +0300
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/sampledata/AbstractSampleData.java	Wed Sep 03 16:32:55 2014 +0200
@@ -80,6 +80,11 @@
         Color.AZURE, Color.CHARTREUSE, Color.CRIMSON, Color.DARKCYAN
     };
     
+    private static final String[] alphabet = {
+        "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", //NOI18N
+        "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" //NOI18N
+    };
+    
     public abstract void applyTo(Object sceneGraphObject);
     public abstract void removeFrom(Object sceneGraphObject);
     
@@ -95,4 +100,8 @@
     protected static Color color(int index) {
         return colors[index % colors.length];
     }
+
+    protected static String alphabet(int index) {
+        return alphabet[index % alphabet.length];
+    }
 }
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/sampledata/SampleDataGenerator.java	Wed Sep 03 17:16:54 2014 +0300
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/sampledata/SampleDataGenerator.java	Wed Sep 03 16:32:55 2014 +0200
@@ -44,6 +44,7 @@
 import javafx.scene.control.ChoiceBox;
 import javafx.scene.control.ComboBox;
 import javafx.scene.control.ListView;
+import javafx.scene.control.Spinner;
 import javafx.scene.control.TableView;
 import javafx.scene.control.TreeTableView;
 import javafx.scene.control.TreeView;
@@ -144,6 +145,17 @@
                 } else {
                     newData = null;
                 }
+            } else if (sceneGraphClass == Spinner.class) {
+                final Spinner<?> spinner = (Spinner<?>) sceneGraphObject;
+                if (spinner.getValue() == null) {
+                    if (currentData instanceof SpinnerSampleData) {
+                        newData = currentData;
+                    } else {
+                        newData = new SpinnerSampleData();
+                    }
+                } else {
+                    newData = null;
+                }
             } else if (XYChartSampleData.isKnownXYChart(sceneGraphObject)) {
                 final XYChart<?,?> xyChart = (XYChart<?,?>) sceneGraphObject;
                 if (xyChart.getData().isEmpty()) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/fxom/sampledata/SpinnerSampleData.java	Wed Sep 03 16:32:55 2014 +0200
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2012, 2014, Oracle and/or its affiliates.
+ * All rights reserved. Use is subject to license terms.
+ *
+ * This file is available and licensed under the following license:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the distribution.
+ *  - Neither the name of Oracle Corporation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.oracle.javafx.scenebuilder.kit.fxom.sampledata;
+
+import java.util.ArrayList;
+import java.util.List;
+import javafx.scene.control.Spinner;
+import javafx.scene.control.SpinnerValueFactory;
+
+/**
+ *
+ */
+class SpinnerSampleData extends AbstractSampleData {
+
+    private final List<String> samples = new ArrayList<>();
+    private SpinnerValueFactory<String> valueFactory;
+    private int index = 0;
+    private static final int ALPHABET_SIZE = 26;
+
+    public SpinnerSampleData() {
+        for (int i = 0; i < ALPHABET_SIZE; i++) {
+            samples.add(alphabet(i));
+        }
+    }
+
+    /*
+     * AbstractSampleData
+     */
+    @Override
+    public void applyTo(Object sceneGraphObject) {
+        assert sceneGraphObject != null;
+
+        @SuppressWarnings("unchecked")
+        final Spinner<String> spinner = (Spinner<String>) sceneGraphObject;
+        valueFactory = spinner.getValueFactory();
+        spinner.setValueFactory(new SpinnerValueFactory<String>() {
+
+            @Override
+            public void decrement(int steps) {
+                index = Math.max((index - 1), 0);
+                setValue(samples.get(index));
+            }
+
+            @Override
+            public void increment(int steps) {
+                index = Math.min((index + 1), ALPHABET_SIZE - 1);
+                setValue(samples.get(index));
+            }
+        });
+        assert index == 0;
+        spinner.getValueFactory().setValue(samples.get(index));
+    }
+
+    @Override
+    public void removeFrom(Object sceneGraphObject) {
+        assert sceneGraphObject != null;
+
+        @SuppressWarnings("unchecked")
+        final Spinner<String> spinner = (Spinner<String>) sceneGraphObject;
+        spinner.setValueFactory(valueFactory);
+    }
+
+}