diff --git a/modules/controls/src/main/java/javafx/scene/control/Spinner.java b/modules/controls/src/main/java/javafx/scene/control/Spinner.java --- a/modules/controls/src/main/java/javafx/scene/control/Spinner.java +++ b/modules/controls/src/main/java/javafx/scene/control/Spinner.java @@ -118,6 +118,164 @@ /*************************************************************************** * * + * Static convenience methods * + * * + **************************************************************************/ + + /** + * Creates a Spinner instance with the + * {@link #valueFactoryProperty() value factory} set to be an instance + * of {@link SpinnerValueFactory.IntegerSpinnerValueFactory}. + * + * @param min The minimum allowed integer value for the Spinner. + * @param max The maximum allowed integer value for the Spinner. + * @param initialValue The value of the Spinner when first instantiated, must + * be within the bounds of the min and max arguments, or + * else the min value will be used. + * @since 9 + */ + public static Spinner createIntegerSpinner(int min, int max, int initialValue) { + return new Spinner<>(new SpinnerValueFactory.IntegerSpinnerValueFactory(min, max, initialValue)); + } + + /** + * Creates a Spinner instance with the + * {@link #valueFactoryProperty() value factory} set to be an instance + * of {@link SpinnerValueFactory.IntegerSpinnerValueFactory}. + * + * @param min The minimum allowed integer value for the Spinner. + * @param max The maximum allowed integer value for the Spinner. + * @param initialValue The value of the Spinner when first instantiated, must + * be within the bounds of the min and max arguments, or + * else the min value will be used. + * @param amountToStepBy The amount to increment or decrement by, per step. + * @since 9 + */ + public static Spinner createIntegerSpinner(int min, int max, int initialValue, int amountToStepBy) { + return new Spinner<>(new SpinnerValueFactory.IntegerSpinnerValueFactory(min, max, initialValue, amountToStepBy)); + } + + /** + * Creates a Spinner instance with the + * {@link #valueFactoryProperty() value factory} set to be an instance + * of {@link SpinnerValueFactory.DoubleSpinnerValueFactory}. + * + * @param min The minimum allowed double value for the Spinner. + * @param max The maximum allowed double value for the Spinner. + * @param initialValue The value of the Spinner when first instantiated, must + * be within the bounds of the min and max arguments, or + * else the min value will be used. + * @since 9 + */ + public static Spinner createDoubleSpinner(double min, double max, double initialValue) { + return new Spinner<>(new SpinnerValueFactory.DoubleSpinnerValueFactory(min, max, initialValue)); + } + + /** + * Creates a Spinner instance with the + * {@link #valueFactoryProperty() value factory} set to be an instance + * of {@link SpinnerValueFactory.DoubleSpinnerValueFactory}. + * + * @param min The minimum allowed double value for the Spinner. + * @param max The maximum allowed double value for the Spinner. + * @param initialValue The value of the Spinner when first instantiated, must + * be within the bounds of the min and max arguments, or + * else the min value will be used. + * @param amountToStepBy The amount to increment or decrement by, per step. + * @since 9 + */ + public static Spinner createDoubleSpinner(double min, double max, double initialValue, double amountToStepBy) { + return new Spinner<>(new SpinnerValueFactory.DoubleSpinnerValueFactory(min, max, initialValue, amountToStepBy)); + } + + /** + * Creates a Spinner instance with the + * {@link #valueFactoryProperty() value factory} set to be an instance + * of {@link SpinnerValueFactory.LocalDateSpinnerValueFactory}. + * + * @param min The minimum allowed LocalDate value for the Spinner. + * @param max The maximum allowed LocalDate value for the Spinner. + * @param initialValue The value of the Spinner when first instantiated, must + * be within the bounds of the min and max arguments, or + * else the min value will be used. + * @since 9 + */ + public static Spinner createLocalDateSpinner(LocalDate min, LocalDate max, LocalDate initialValue) { + return new Spinner<>(new SpinnerValueFactory.LocalDateSpinnerValueFactory(min, max, initialValue)); + } + + /** + * Creates a Spinner instance with the + * {@link #valueFactoryProperty() value factory} set to be an instance + * of {@link SpinnerValueFactory.LocalDateSpinnerValueFactory}. + * + * @param min The minimum allowed LocalDate value for the Spinner. + * @param max The maximum allowed LocalDate value for the Spinner. + * @param initialValue The value of the Spinner when first instantiated, must + * be within the bounds of the min and max arguments, or + * else the min value will be used. + * @param amountToStepBy The amount to increment or decrement by, per step. + * @param temporalUnit The size of each step (e.g. day, week, month, year, etc). + * @since 9 + */ + public static Spinner createLocalDateSpinner(LocalDate min, LocalDate max, LocalDate initialValue, + long amountToStepBy, TemporalUnit temporalUnit) { + return new Spinner<>(new SpinnerValueFactory.LocalDateSpinnerValueFactory(min, max, initialValue, amountToStepBy, temporalUnit)); + } + + /** + * Creates a Spinner instance with the + * {@link #valueFactoryProperty() value factory} set to be an instance + * of {@link SpinnerValueFactory.LocalTimeSpinnerValueFactory}. + * + * @param min The minimum allowed LocalTime value for the Spinner. + * @param max The maximum allowed LocalTime value for the Spinner. + * @param initialValue The value of the Spinner when first instantiated, must + * be within the bounds of the min and max arguments, or + * else the min value will be used. + * @since 9 + */ + public static Spinner createLocalTimeSpinner(LocalTime min, LocalTime max, LocalTime initialValue) { + return new Spinner<>(new SpinnerValueFactory.LocalTimeSpinnerValueFactory(min, max, initialValue))); + } + + /** + * Creates a Spinner instance with the + * {@link #valueFactoryProperty() value factory} set to be an instance + * of {@link SpinnerValueFactory.LocalTimeSpinnerValueFactory}. + * + * @param min The minimum allowed LocalTime value for the Spinner. + * @param max The maximum allowed LocalTime value for the Spinner. + * @param initialValue The value of the Spinner when first instantiated, must + * be within the bounds of the min and max arguments, or + * else the min value will be used. + * @param amountToStepBy The amount to increment or decrement by, per step. + * @param temporalUnit The size of each step (e.g. hour, minute, second, etc). + * @since 9 + */ + public static Spinner createLocalTimeSpinner(LocalTime min, LocalTime max, LocalTime initialValue, + long amountToStepBy, TemporalUnit temporalUnit) { + return new Spinner<>(new SpinnerValueFactory.LocalTimeSpinnerValueFactory(min, max, initialValue, amountToStepBy, temporalUnit))); + } + + /** + * Creates a Spinner instance with the + * {@link #valueFactoryProperty() value factory} set to be an instance + * of {@link SpinnerValueFactory.ListSpinnerValueFactory}. The + * Spinner {@link #valueProperty() value property} will be set to the first + * element of the list, if an element exists, or null otherwise. + * + * @param items A list of items that will be stepped through in the Spinner. + * @since 9 + */ + public static Spinner createListSpinner(ObservableList items) { + return new Spinner<>(new SpinnerValueFactory.ListSpinnerValueFactory(items)); + } + + + + /*************************************************************************** + * * * Constructors * * * **************************************************************************/ @@ -170,7 +328,9 @@ * @param initialValue The value of the Spinner when first instantiated, must * be within the bounds of the min and max arguments, or * else the min value will be used. + * @deprecated Use {@link #createIntegerSpinner(int, int, int)} instead. */ + @Deprecated public Spinner(@NamedArg("min") int min, @NamedArg("max") int max, @NamedArg("initialValue") int initialValue) { @@ -191,7 +351,9 @@ * be within the bounds of the min and max arguments, or * else the min value will be used. * @param amountToStepBy The amount to increment or decrement by, per step. + * @deprecated Use {@link #createIntegerSpinner(int, int, int, int)} instead. */ + @Deprecated public Spinner(@NamedArg("min") int min, @NamedArg("max") int max, @NamedArg("initialValue") int initialValue, @@ -212,7 +374,9 @@ * @param initialValue The value of the Spinner when first instantiated, must * be within the bounds of the min and max arguments, or * else the min value will be used. + * @deprecated Use {@link #createDoubleSpinner(double, double, double)} instead. */ + @Deprecated public Spinner(@NamedArg("min") double min, @NamedArg("max") double max, @NamedArg("initialValue") double initialValue) { @@ -233,7 +397,9 @@ * be within the bounds of the min and max arguments, or * else the min value will be used. * @param amountToStepBy The amount to increment or decrement by, per step. + * @deprecated Use {@link #createDoubleSpinner(double, double, double, double)} instead. */ + @Deprecated public Spinner(@NamedArg("min") double min, @NamedArg("max") double max, @NamedArg("initialValue") double initialValue, @@ -254,7 +420,9 @@ * @param initialValue The value of the Spinner when first instantiated, must * be within the bounds of the min and max arguments, or * else the min value will be used. + * @deprecated Use {@link #createLocalDateSpinner(LocalDate, LocalDate, LocalDate)} instead. */ + @Deprecated Spinner(@NamedArg("min") LocalDate min, @NamedArg("max") LocalDate max, @NamedArg("initialValue") LocalDate initialValue) { @@ -276,7 +444,9 @@ * else the min value will be used. * @param amountToStepBy The amount to increment or decrement by, per step. * @param temporalUnit The size of each step (e.g. day, week, month, year, etc). + * @deprecated Use {@link #createLocalDateSpinner(LocalDate, LocalDate, LocalDate, long, TemporalUnit)} instead. */ + @Deprecated Spinner(@NamedArg("min") LocalDate min, @NamedArg("max") LocalDate max, @NamedArg("initialValue") LocalDate initialValue, @@ -298,7 +468,9 @@ * @param initialValue The value of the Spinner when first instantiated, must * be within the bounds of the min and max arguments, or * else the min value will be used. + * @deprecated Use {@link #createLocalTimeSpinner(LocalTime, LocalTime, LocalTime)} instead. */ + @Deprecated Spinner(@NamedArg("min") LocalTime min, @NamedArg("max") LocalTime max, @NamedArg("initialValue") LocalTime initialValue) { @@ -320,7 +492,9 @@ * else the min value will be used. * @param amountToStepBy The amount to increment or decrement by, per step. * @param temporalUnit The size of each step (e.g. hour, minute, second, etc). + * @deprecated Use {@link #createLocalTimeSpinner(LocalTime, LocalTime, LocalTime, long, TemporalUnit)} instead. */ + @Deprecated Spinner(@NamedArg("min") LocalTime min, @NamedArg("max") LocalTime max, @NamedArg("initialValue") LocalTime initialValue, @@ -338,7 +512,9 @@ * element of the list, if an element exists, or null otherwise. * * @param items A list of items that will be stepped through in the Spinner. + * @deprecated Use {@link #createListSpinner(ObservableList)} instead. */ + @Deprecated public Spinner(@NamedArg("items") ObservableList items) { this(new SpinnerValueFactory.ListSpinnerValueFactory(items)); }