changeset 5902:5c5f089af5e3

Ensemble8: Fix for RT-34447 DatePicker Control in Ensemble8 - don't open stage for DatePicker
author Alexander Kouznetsov
date Tue, 03 Dec 2013 19:45:35 -0800
parents 43d9f4f38db1
children a91fae01ca00
files apps/samples/Ensemble8/src/generated/java/ensemble/generated/Samples.java apps/samples/Ensemble8/src/samples/java/ensemble/samples/controls/datepicker/DatePickerApp.java
diffstat 2 files changed, 40 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/apps/samples/Ensemble8/src/generated/java/ensemble/generated/Samples.java	Tue Dec 03 18:54:48 2013 -0800
+++ b/apps/samples/Ensemble8/src/generated/java/ensemble/generated/Samples.java	Tue Dec 03 19:45:35 2013 -0800
@@ -42,7 +42,7 @@
     private static final SampleInfo SAMPLE_35 = new SampleInfo("Check Box","An example of CheckBoxes in various states. ","/Controls/Check Box","/ensemble/samples/controls/checkbox","ensemble.samples.controls.checkbox.CheckBoxApp","/ensemble/samples/controls/checkbox/preview.png",new String[]{"/ensemble/samples/controls/checkbox/CheckBoxApp.java",},new String[]{"javafx.scene.control.CheckBox",},new String[]{},new String[]{"/Controls/Radiobutton/Radio Button",},"/ensemble/samples/controls/checkbox/CheckBoxApp.java",new PlaygroundProperty[]{},new ConditionalFeature[]{},true);
     private static final SampleInfo SAMPLE_36 = new SampleInfo("ChoiceBox","An example of a ChoiceBox with several options. The ChoiceBox control displays a default or current selection, with an icon to click that expands the list for a selection. ","/Controls/ChoiceBox","/ensemble/samples/controls/choicebox","ensemble.samples.controls.choicebox.ChoiceBoxApp","/ensemble/samples/controls/choicebox/preview.png",new String[]{"/ensemble/samples/controls/choicebox/ChoiceBoxApp.java",},new String[]{"javafx.scene.control.ChoiceBox",},new String[]{},new String[]{},"/ensemble/samples/controls/choicebox/ChoiceBoxApp.java",new PlaygroundProperty[]{},new ConditionalFeature[]{},true);
     private static final SampleInfo SAMPLE_37 = new SampleInfo("ColorPicker","A sample that demonstrates the ColorPicker. ","/Controls/ColorPicker","/ensemble/samples/controls/colorpicker","ensemble.samples.controls.colorpicker.ColorPickerApp","/ensemble/samples/controls/colorpicker/preview.png",new String[]{"/ensemble/samples/controls/colorpicker/ColorPickerApp.java",},new String[]{"javafx.scene.control.ColorPicker",},new String[]{},new String[]{},"/ensemble/samples/controls/colorpicker/ColorPickerApp.java",new PlaygroundProperty[]{},new ConditionalFeature[]{},false);
-    private static final SampleInfo SAMPLE_38 = new SampleInfo("DatePicker","A sample that demonstrates the DatePicker. The sample uses a new Stage for the DatePicker to allow changing of locales. ","/Controls/DatePicker","/ensemble/samples/controls/datepicker","ensemble.samples.controls.datepicker.DatePickerApp","/ensemble/samples/controls/datepicker/preview.png",new String[]{"/ensemble/samples/controls/datepicker/DatePickerApp.java",},new String[]{"javafx.scene.control.DateCell","javafx.scene.control.DatePicker",},new String[]{},new String[]{},"/ensemble/samples/controls/datepicker/DatePickerApp.java",new PlaygroundProperty[]{},new ConditionalFeature[]{},false);
+    private static final SampleInfo SAMPLE_38 = new SampleInfo("DatePicker","A sample that demonstrates the DatePicker. There is an option to switch locales and see how DatePicker control picks it up. ","/Controls/DatePicker","/ensemble/samples/controls/datepicker","ensemble.samples.controls.datepicker.DatePickerApp","/ensemble/samples/controls/datepicker/preview.png",new String[]{"/ensemble/samples/controls/datepicker/DatePickerApp.java",},new String[]{"javafx.scene.control.DateCell","javafx.scene.control.DatePicker",},new String[]{},new String[]{},"/ensemble/samples/controls/datepicker/DatePickerApp.java",new PlaygroundProperty[]{},new ConditionalFeature[]{},false);
     private static final SampleInfo SAMPLE_39 = new SampleInfo("HyperLink","A sample that shows a simple hyperlink and a hyperlink with an image. ","/Controls/HyperLink","/ensemble/samples/controls/hyperlink","ensemble.samples.controls.hyperlink.HyperLinkApp","/ensemble/samples/controls/hyperlink/preview.png",new String[]{"/ensemble/samples/shared-resources/icon-48x48.png","/ensemble/samples/controls/hyperlink/HyperLinkApp.java",},new String[]{"javafx.scene.control.Hyperlink",},new String[]{},new String[]{},"/ensemble/samples/controls/hyperlink/HyperLinkApp.java",new PlaygroundProperty[]{},new ConditionalFeature[]{},true);
     private static final SampleInfo SAMPLE_40 = new SampleInfo("Menu","An example of a menu bar. The example includes use of the system bar, if the current platform supports a system bar. ","/Controls/Menu","/ensemble/samples/controls/menu","ensemble.samples.controls.menu.MenuApp","/ensemble/samples/controls/menu/preview.png",new String[]{"/ensemble/samples/shared-resources/menuInfo.png","/ensemble/samples/controls/menu/MenuApp.java",},new String[]{"javafx.scene.control.MenuBar","javafx.scene.control.Menu","javafx.scene.control.MenuItem",},new String[]{},new String[]{},"/ensemble/samples/controls/menu/MenuApp.java",new PlaygroundProperty[]{},new ConditionalFeature[]{},false);
     private static final SampleInfo SAMPLE_41 = new SampleInfo("Pagination","A sample that demonstrates pagination. ","/Controls/Pagination","/ensemble/samples/controls/pagination","ensemble.samples.controls.pagination.PaginationApp","/ensemble/samples/controls/pagination/preview.png",new String[]{"/ensemble/samples/shared-resources/Animal1.jpg","/ensemble/samples/shared-resources/Animal2.jpg","/ensemble/samples/shared-resources/Animal3.jpg","/ensemble/samples/shared-resources/Animal4.jpg","/ensemble/samples/shared-resources/Animal5.jpg","/ensemble/samples/shared-resources/Animal6.jpg","/ensemble/samples/shared-resources/Animal7.jpg","/ensemble/samples/controls/pagination/PaginationApp.java",},new String[]{"javafx.scene.control.Pagination",},new String[]{},new String[]{},"/ensemble/samples/controls/pagination/PaginationApp.java",new PlaygroundProperty[]{},new ConditionalFeature[]{},true);
--- a/apps/samples/Ensemble8/src/samples/java/ensemble/samples/controls/datepicker/DatePickerApp.java	Tue Dec 03 18:54:48 2013 -0800
+++ b/apps/samples/Ensemble8/src/samples/java/ensemble/samples/controls/datepicker/DatePickerApp.java	Tue Dec 03 19:45:35 2013 -0800
@@ -31,18 +31,13 @@
  */
 package ensemble.samples.controls.datepicker;
 
+
 import java.time.LocalDate;
-import java.util.Iterator;
 import java.util.Locale;
 import javafx.application.Application;
-import javafx.beans.value.ChangeListener;
-import javafx.beans.value.ObservableValue;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
-import javafx.event.ActionEvent;
-import javafx.event.EventHandler;
 import javafx.geometry.Pos;
-import javafx.scene.Group;
 import javafx.scene.Parent;
 import javafx.scene.Scene;
 import javafx.scene.control.CheckMenuItem;
@@ -52,8 +47,6 @@
 import javafx.scene.control.MenuBar;
 import javafx.scene.control.MenuItem;
 import javafx.scene.control.RadioMenuItem;
-import javafx.scene.control.Toggle;
-import javafx.scene.control.ToggleButton;
 import javafx.scene.control.ToggleGroup;
 import javafx.scene.control.Tooltip;
 import javafx.scene.layout.HBox;
@@ -62,9 +55,10 @@
 import javafx.stage.Stage;
 import javafx.util.Callback;
 
+
 /**
- * A sample that demonstrates the DatePicker. The sample uses a new Stage for
- * the DatePicker to allow changing of locales. 
+ * A sample that demonstrates the DatePicker. There is an option to switch
+ * locales and see how DatePicker control picks it up.
  *
  * @sampleName DatePicker
  * @preview preview.png
@@ -78,9 +72,8 @@
     private MenuBar datePickerMenuBar;
     private final LocalDate today = LocalDate.now();
     private final LocalDate tomorrow = today.plusDays(1);
-    private Locale originalDefault;
-    private Stage myStage;
-    private Stage primStage;
+    private Locale originalLocale;
+    private HBox hbox;
     static {
         locales.addAll("en-US",
                 "ar-SA",
@@ -103,54 +96,27 @@
     }
 
     public Parent createContent() {
-        VBox buttonVbox = new VBox(8);
-        buttonVbox.setAlignment(Pos.CENTER);               
-        // Use a Button to create a new Stage that gives us an environment to switch Locales
-        final ToggleButton button = new ToggleButton("Open a  new Stage for DatePicker");
-        button.setPrefWidth(290);
-        button.setMaxWidth(ToggleButton.USE_PREF_SIZE);
-        button.setMinWidth(ToggleButton.USE_PREF_SIZE);
-        final ToggleButton closeButton = new ToggleButton("Close DatePicker Stage");
-        closeButton.setPrefWidth(290);
-        closeButton.setMaxWidth(ToggleButton.USE_PREF_SIZE);
-        closeButton.setMinWidth(ToggleButton.USE_PREF_SIZE);
+        Text datePickerText = new Text("Date:");
         
-        ToggleGroup group = new ToggleGroup();
-        button.setToggleGroup(group);
-        closeButton.setToggleGroup(group);
+        hbox = new HBox(18);
+        hbox.setAlignment(Pos.CENTER);
+        hbox.getChildren().add(datePickerText);
+        
+        createDatePicker();
+        
+        VBox vbox = new VBox(22);
+        vbox.getChildren().addAll(datePickerMenuBar, hbox);
+        vbox.setPrefSize(300, 200);
+        vbox.setMinSize(VBox.USE_PREF_SIZE, VBox.USE_PREF_SIZE);
+        return vbox;
+    }
 
-        group.selectedToggleProperty().addListener((observable, oldValue, selectedToggle) -> {
-            if (selectedToggle != null) {
-                if (((ToggleButton) selectedToggle).getText().equals("Open a  new Stage for DatePicker")) {
-                    if (myStage == null) {
-                        myStage = new Stage();
-                        Group rootGroup = new Group();
-                        Scene scene = new Scene(rootGroup, 300, 200);
-                        myStage.setScene(scene);
-                        myStage.centerOnScreen();
-                        myStage.initOwner(primStage);
-                        myStage.show();
-                        rootGroup.getChildren().add(createDatePickerSceneContent(myStage));
-                    }
-                } else {
-                    if (myStage != null) {
-                        myStage.close();
-                        myStage = null;
-                        if (originalDefault != null) {
-                            Locale.setDefault(originalDefault);
-                        }
-                        button.setDisable(false);
-                    }
-                }
-            }
-        });
-
-        buttonVbox.getChildren().addAll(button, closeButton);
-        return buttonVbox;
-    }
-    
-    private Parent createDatePickerSceneContent(Stage inStage) {
-        Text datePickerText = new Text("Date:");
+    private void createDatePicker() {
+        hbox.getChildren().remove(datePicker);
+        LocalDate value = null;
+        if (datePicker != null) {
+            value = datePicker.getValue();
+        }
         datePicker = new DatePicker();       
         // day cell factory
         final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
@@ -172,7 +138,7 @@
             }
         };
         //Create the menubar to experiment with the DatePicker
-        datePickerMenuBar = createMenuBar(inStage, dayCellFactory);
+        datePickerMenuBar = createMenuBar(dayCellFactory);
         // Listen for DatePicker actions
         datePicker.setOnAction(t -> {
             LocalDate isoDate = datePicker.getValue();
@@ -190,21 +156,13 @@
                 }
             }
         });
-
-
-        
-        HBox hbox = new HBox(18);
-        hbox.setAlignment(Pos.CENTER);
-        hbox.getChildren().addAll(datePickerText, datePicker);
-        
-        VBox vbox = new VBox(22);
-        vbox.getChildren().addAll(datePickerMenuBar, hbox);
-        vbox.setPrefSize(300, 200);
-        vbox.setMinSize(VBox.USE_PREF_SIZE, VBox.USE_PREF_SIZE);
-        return vbox;
+        hbox.getChildren().add(datePicker);
+        if (value != null) {
+            datePicker.setValue(value);
+        }
     }
 
-    private MenuBar createMenuBar(final Stage inStage, final Callback<DatePicker, DateCell> dayCellFac) {
+    private MenuBar createMenuBar(final Callback<DatePicker, DateCell> dayCellFac) {
         final MenuBar menuBar = new MenuBar();
         final ToggleGroup localeToggleGroup = new ToggleGroup();
         // Locales
@@ -245,13 +203,8 @@
             if (localeToggleGroup.getSelectedToggle() != null) {
                 String selectedLocale = ((RadioMenuItem) localeToggleGroup.getSelectedToggle()).getText();
                 Locale locale = Locale.forLanguageTag(selectedLocale.replace('_', '-'));
-                if (originalDefault == null) { //save original default Locale for restoration later
-                    originalDefault = Locale.getDefault();
-                }
                 Locale.setDefault(locale);
-               // sampleContent = createDatePickerSceneContent(inStage);
-                inStage.setScene(new Scene(createDatePickerSceneContent(inStage)));
-                inStage.show();
+                createDatePicker();
             }
         });
 
@@ -259,17 +212,20 @@
         return menuBar;
     }    
  
+    public void play() {
+        originalLocale = Locale.getDefault();
+    }
+    
     @Override
     public void stop() {
-        if (originalDefault != null) {
-            Locale.setDefault(originalDefault);
-        }
+        Locale.setDefault(originalLocale);
     }
+    
     @Override
     public void start(Stage primaryStage) throws Exception { 
-        primStage = primaryStage;
         primaryStage.setScene(new Scene(createContent()));      
         primaryStage.show();
+        play();
     }
     
     /**