modules/controls/src/main/java/javafx/scene/control/DatePicker.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


  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 
  26 package javafx.scene.control;
  27 
  28 // editor and converter code in sync with ComboBox 4858:e60e9a5396e6
  29 
  30 import java.time.LocalDate;
  31 import java.time.DateTimeException;
  32 import java.time.chrono.Chronology;
  33 import java.time.chrono.IsoChronology;
  34 import java.time.format.FormatStyle;
  35 import java.util.ArrayList;
  36 import java.util.Collections;
  37 import java.util.List;
  38 import java.util.Locale;
  39 
  40 import com.sun.javafx.scene.control.skin.ComboBoxListViewSkin;
  41 
  42 import javafx.beans.property.BooleanProperty;
  43 import javafx.beans.property.ObjectProperty;
  44 import javafx.beans.property.ReadOnlyObjectProperty;
  45 import javafx.beans.property.ReadOnlyObjectWrapper;
  46 import javafx.beans.property.SimpleObjectProperty;
  47 import javafx.beans.value.WritableValue;
  48 import javafx.css.CssMetaData;
  49 import javafx.css.Styleable;
  50 import javafx.css.StyleableBooleanProperty;
  51 import javafx.css.StyleableProperty;
  52 import javafx.scene.AccessibleAttribute;
  53 import javafx.scene.AccessibleRole;
  54 import javafx.util.Callback;
  55 import javafx.util.StringConverter;
  56 import javafx.util.converter.LocalDateStringConverter;
  57 
  58 import com.sun.javafx.css.converters.BooleanConverter;
  59 import com.sun.javafx.scene.control.skin.DatePickerSkin;
  60 import com.sun.javafx.scene.control.skin.resources.ControlResources;
  61 
  62 
  63 /**
  64  * The DatePicker control allows the user to enter a date as text or
  65  * to select a date from a calendar popup. The calendar is based on
  66  * either the standard ISO-8601 chronology or any of the other
  67  * chronology classes defined in the java.time.chrono package.
  68  *
  69  * <p>The {@link #valueProperty() value} property represents the
  70  * currently selected {@link java.time.LocalDate}.  An initial date can
  71  * be set via the {@link #DatePicker(java.time.LocalDate) constructor}
  72  * or by calling {@link #setValue(java.time.LocalDate) setValue()}.  The
  73  * default value is null.
  74  *
  75  * <pre><code>
  76  * final DatePicker datePicker = new DatePicker();
  77  * datePicker.setOnAction(new EventHandler() {
  78  *     public void handle(Event t) {
  79  *         LocalDate date = datePicker.getValue();


 399         }
 400     }
 401 
 402     // Create a symmetric (format/parse) converter with the default locale.
 403     private StringConverter<LocalDate> defaultConverter =
 404                 new LocalDateStringConverter(FormatStyle.SHORT, null, getChronology());
 405 
 406 
 407     // --- Editor
 408     /**
 409      * The editor for the DatePicker.
 410      *
 411      * @see javafx.scene.control.ComboBox#editorProperty
 412      */
 413     private ReadOnlyObjectWrapper<TextField> editor;
 414     public final TextField getEditor() {
 415         return editorProperty().get();
 416     }
 417     public final ReadOnlyObjectProperty<TextField> editorProperty() {
 418         if (editor == null) {
 419             editor = new ReadOnlyObjectWrapper<TextField>(this, "editor");
 420             editor.set(new ComboBoxListViewSkin.FakeFocusTextField());
 421         }
 422         return editor.getReadOnlyProperty();
 423     }
 424 
 425     /** {@inheritDoc} */
 426     @Override protected Skin<?> createDefaultSkin() {
 427         return new DatePickerSkin(this);
 428     }
 429 
 430 
 431     /***************************************************************************
 432      *                                                                         *
 433      * Stylesheet Handling                                                     *
 434      *                                                                         *
 435      **************************************************************************/
 436 
 437     private static final String DEFAULT_STYLE_CLASS = "date-picker";
 438 
 439      /**
 440       * @treatAsPrivate implementation detail




  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 
  26 package javafx.scene.control;
  27 
  28 // editor and converter code in sync with ComboBox 4858:e60e9a5396e6
  29 
  30 import java.time.LocalDate;
  31 import java.time.DateTimeException;
  32 import java.time.chrono.Chronology;
  33 import java.time.chrono.IsoChronology;
  34 import java.time.format.FormatStyle;
  35 import java.util.ArrayList;
  36 import java.util.Collections;
  37 import java.util.List;
  38 import java.util.Locale;
  39 
  40 import com.sun.javafx.scene.control.FakeFocusTextField;
  41 
  42 import javafx.beans.property.BooleanProperty;
  43 import javafx.beans.property.ObjectProperty;
  44 import javafx.beans.property.ReadOnlyObjectProperty;
  45 import javafx.beans.property.ReadOnlyObjectWrapper;
  46 import javafx.beans.property.SimpleObjectProperty;
  47 import javafx.beans.value.WritableValue;
  48 import javafx.css.CssMetaData;
  49 import javafx.css.Styleable;
  50 import javafx.css.StyleableBooleanProperty;
  51 import javafx.css.StyleableProperty;
  52 import javafx.scene.AccessibleAttribute;
  53 import javafx.scene.AccessibleRole;
  54 import javafx.util.Callback;
  55 import javafx.util.StringConverter;
  56 import javafx.util.converter.LocalDateStringConverter;
  57 
  58 import javafx.css.converter.BooleanConverter;
  59 import javafx.scene.control.skin.DatePickerSkin;
  60 import com.sun.javafx.scene.control.skin.resources.ControlResources;
  61 
  62 
  63 /**
  64  * The DatePicker control allows the user to enter a date as text or
  65  * to select a date from a calendar popup. The calendar is based on
  66  * either the standard ISO-8601 chronology or any of the other
  67  * chronology classes defined in the java.time.chrono package.
  68  *
  69  * <p>The {@link #valueProperty() value} property represents the
  70  * currently selected {@link java.time.LocalDate}.  An initial date can
  71  * be set via the {@link #DatePicker(java.time.LocalDate) constructor}
  72  * or by calling {@link #setValue(java.time.LocalDate) setValue()}.  The
  73  * default value is null.
  74  *
  75  * <pre><code>
  76  * final DatePicker datePicker = new DatePicker();
  77  * datePicker.setOnAction(new EventHandler() {
  78  *     public void handle(Event t) {
  79  *         LocalDate date = datePicker.getValue();


 399         }
 400     }
 401 
 402     // Create a symmetric (format/parse) converter with the default locale.
 403     private StringConverter<LocalDate> defaultConverter =
 404                 new LocalDateStringConverter(FormatStyle.SHORT, null, getChronology());
 405 
 406 
 407     // --- Editor
 408     /**
 409      * The editor for the DatePicker.
 410      *
 411      * @see javafx.scene.control.ComboBox#editorProperty
 412      */
 413     private ReadOnlyObjectWrapper<TextField> editor;
 414     public final TextField getEditor() {
 415         return editorProperty().get();
 416     }
 417     public final ReadOnlyObjectProperty<TextField> editorProperty() {
 418         if (editor == null) {
 419             editor = new ReadOnlyObjectWrapper<>(this, "editor");
 420             editor.set(new FakeFocusTextField());
 421         }
 422         return editor.getReadOnlyProperty();
 423     }
 424 
 425     /** {@inheritDoc} */
 426     @Override protected Skin<?> createDefaultSkin() {
 427         return new DatePickerSkin(this);
 428     }
 429 
 430 
 431     /***************************************************************************
 432      *                                                                         *
 433      * Stylesheet Handling                                                     *
 434      *                                                                         *
 435      **************************************************************************/
 436 
 437     private static final String DEFAULT_STYLE_CLASS = "date-picker";
 438 
 439      /**
 440       * @treatAsPrivate implementation detail