items = getItems();
return items == null ? null : (index >= 0 && index < items.size()) ? items.get(index) : null;
}
}
/**
* A {@link javafx.scene.control.SpinnerValueFactory} implementation designed to iterate through
* integer values.
*
* Note that the default {@link #converterProperty() converter} is implemented
* as an {@link javafx.util.converter.IntegerStringConverter} instance.
*
* @since JavaFX 8u40
*/
public static class IntegerSpinnerValueFactory extends SpinnerValueFactory {
/***********************************************************************
* *
* Constructors *
* *
**********************************************************************/
/**
* Constructs a new IntegerSpinnerValueFactory that sets the initial value
* to be equal to the min value, and a default {@code amountToStepBy} of one.
*
* @param min The minimum allowed integer value for the Spinner.
* @param max The maximum allowed integer value for the Spinner.
*/
public IntegerSpinnerValueFactory(@NamedArg("min") int min,
@NamedArg("max") int max) {
this(min, max, min);
}
/**
* Constructs a new IntegerSpinnerValueFactory with a default
* {@code amountToStepBy} of one.
*
* @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.
*/
public IntegerSpinnerValueFactory(@NamedArg("min") int min,
@NamedArg("max") int max,
@NamedArg("initialValue") int initialValue) {
this(min, max, initialValue, 1);
}
/**
* Constructs a new 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.
*/
public IntegerSpinnerValueFactory(@NamedArg("min") int min,
@NamedArg("max") int max,
@NamedArg("initialValue") int initialValue,
@NamedArg("amountToStepBy") int amountToStepBy) {
setMin(min);
setMax(max);
setAmountToStepBy(amountToStepBy);
setConverter(new IntegerStringConverter());
valueProperty().addListener((o, oldValue, newValue) -> {
// when the value is set, we need to react to ensure it is a
// valid value (and if not, blow up appropriately)
if (newValue < getMin()) {
setValue(getMin());
} else if (newValue > getMax()) {
setValue(getMax());
}
});
setValue(initialValue >= min && initialValue <= max ? initialValue : min);
}
/***********************************************************************
* *
* Properties *
* *
**********************************************************************/
// --- min
private IntegerProperty min = new SimpleIntegerProperty(this, "min") {
@Override protected void invalidated() {
Integer currentValue = IntegerSpinnerValueFactory.this.getValue();
if (currentValue == null) {
return;
}
int newMin = get();
if (newMin > getMax()) {
setMin(getMax());
return;
}
if (currentValue < newMin) {
IntegerSpinnerValueFactory.this.setValue(newMin);
}
}
};
public final void setMin(int value) {
min.set(value);
}
public final int getMin() {
return min.get();
}
/**
* Sets the minimum allowable value for this value factory
*/
public final IntegerProperty minProperty() {
return min;
}
// --- max
private IntegerProperty max = new SimpleIntegerProperty(this, "max") {
@Override protected void invalidated() {
Integer currentValue = IntegerSpinnerValueFactory.this.getValue();
if (currentValue == null) {
return;
}
int newMax = get();
if (newMax < getMin()) {
setMax(getMin());
return;
}
if (currentValue > newMax) {
IntegerSpinnerValueFactory.this.setValue(newMax);
}
}
};
public final void setMax(int value) {
max.set(value);
}
public final int getMax() {
return max.get();
}
/**
* Sets the maximum allowable value for this value factory
*/
public final IntegerProperty maxProperty() {
return max;
}
// --- amountToStepBy
private IntegerProperty amountToStepBy = new SimpleIntegerProperty(this, "amountToStepBy");
public final void setAmountToStepBy(int value) {
amountToStepBy.set(value);
}
public final int getAmountToStepBy() {
return amountToStepBy.get();
}
/**
* Sets the amount to increment or decrement by, per step.
*/
public final IntegerProperty amountToStepByProperty() {
return amountToStepBy;
}
/***********************************************************************
* *
* Overridden methods *
* *
**********************************************************************/
/** {@inheritDoc} */
@Override public void decrement(int steps) {
final int min = getMin();
final int max = getMax();
final int newIndex = getValue() - steps * getAmountToStepBy();
setValue(newIndex >= min ? newIndex : (isWrapAround() ? Spinner.wrapValue(newIndex, min, max) + 1 : min));
}
/** {@inheritDoc} */
@Override public void increment(int steps) {
final int min = getMin();
final int max = getMax();
final int currentValue = getValue();
final int newIndex = currentValue + steps * getAmountToStepBy();
setValue(newIndex <= max ? newIndex : (isWrapAround() ? Spinner.wrapValue(newIndex, min, max) - 1 : max));
}
}
/**
* A {@link javafx.scene.control.SpinnerValueFactory} implementation designed to iterate through
* double values.
*
* Note that the default {@link #converterProperty() converter} is implemented
* simply as shown below, which may be adequate in many cases, but it is important
* for users to ensure that this suits their needs (and adjust when necessary). The
* main point to note is that this {@link javafx.util.StringConverter} embeds
* within it a {@link java.text.DecimalFormat} instance that shows the Double
* to two decimal places. This is used for both the toString and fromString
* methods:
*
*
* setConverter(new StringConverter<Double>() {
* private final DecimalFormat df = new DecimalFormat("#.##");
*
* @Override public String toString(Double value) {
* // If the specified value is null, return a zero-length String
* if (value == null) {
* return "";
* }
*
* return df.format(value);
* }
*
* @Override public Double fromString(String value) {
* try {
* // If the specified value is null or zero-length, return null
* if (value == null) {
* return null;
* }
*
* value = value.trim();
*
* if (value.length() < 1) {
* return null;
* }
*
* // Perform the requested parsing
* return df.parse(value).doubleValue();
* } catch (ParseException ex) {
* throw new RuntimeException(ex);
* }
* }
* });
*
* @since JavaFX 8u40
*/
public static class DoubleSpinnerValueFactory extends SpinnerValueFactory {
/**
* Constructs a new DoubleSpinnerValueFactory that sets the initial value
* to be equal to the min value, and a default {@code amountToStepBy} of
* one.
*
* @param min The minimum allowed double value for the Spinner.
* @param max The maximum allowed double value for the Spinner.
*/
public DoubleSpinnerValueFactory(@NamedArg("min") double min,
@NamedArg("max") double max) {
this(min, max, min);
}
/**
* Constructs a new DoubleSpinnerValueFactory with a default
* {@code amountToStepBy} of one.
*
* @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.
*/
public DoubleSpinnerValueFactory(@NamedArg("min") double min,
@NamedArg("max") double max,
@NamedArg("initialValue") double initialValue) {
this(min, max, initialValue, 1);
}
/**
* Constructs a new 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.
*/
public DoubleSpinnerValueFactory(@NamedArg("min") double min,
@NamedArg("max") double max,
@NamedArg("initialValue") double initialValue,
@NamedArg("amountToStepBy") double amountToStepBy) {
setMin(min);
setMax(max);
setAmountToStepBy(amountToStepBy);
setConverter(new StringConverter() {
private final DecimalFormat df = new DecimalFormat("#.##");
@Override public String toString(Double value) {
// If the specified value is null, return a zero-length String
if (value == null) {
return "";
}
return df.format(value);
}
@Override public Double fromString(String value) {
try {
// If the specified value is null or zero-length, return null
if (value == null) {
return null;
}
value = value.trim();
if (value.length() < 1) {
return null;
}
// Perform the requested parsing
return df.parse(value).doubleValue();
} catch (ParseException ex) {
throw new RuntimeException(ex);
}
}
});
valueProperty().addListener((o, oldValue, newValue) -> {
// when the value is set, we need to react to ensure it is a
// valid value (and if not, blow up appropriately)
if (newValue < getMin()) {
setValue(getMin());
} else if (newValue > getMax()) {
setValue(getMax());
}
});
setValue(initialValue >= min && initialValue <= max ? initialValue : min);
}
/***********************************************************************
* *
* Properties *
* *
**********************************************************************/
// --- min
private DoubleProperty min = new SimpleDoubleProperty(this, "min") {
@Override protected void invalidated() {
Double currentValue = DoubleSpinnerValueFactory.this.getValue();
if (currentValue == null) {
return;
}
final double newMin = get();
if (newMin > getMax()) {
setMin(getMax());
return;
}
if (currentValue < newMin) {
DoubleSpinnerValueFactory.this.setValue(newMin);
}
}
};
public final void setMin(double value) {
min.set(value);
}
public final double getMin() {
return min.get();
}
/**
* Sets the minimum allowable value for this value factory
*/
public final DoubleProperty minProperty() {
return min;
}
// --- max
private DoubleProperty max = new SimpleDoubleProperty(this, "max") {
@Override protected void invalidated() {
Double currentValue = DoubleSpinnerValueFactory.this.getValue();
if (currentValue == null) {
return;
}
final double newMax = get();
if (newMax < getMin()) {
setMax(getMin());
return;
}
if (currentValue > newMax) {
DoubleSpinnerValueFactory.this.setValue(newMax);
}
}
};
public final void setMax(double value) {
max.set(value);
}
public final double getMax() {
return max.get();
}
/**
* Sets the maximum allowable value for this value factory
*/
public final DoubleProperty maxProperty() {
return max;
}
// --- amountToStepBy
private DoubleProperty amountToStepBy = new SimpleDoubleProperty(this, "amountToStepBy");
public final void setAmountToStepBy(double value) {
amountToStepBy.set(value);
}
public final double getAmountToStepBy() {
return amountToStepBy.get();
}
/**
* Sets the amount to increment or decrement by, per step.
*/
public final DoubleProperty amountToStepByProperty() {
return amountToStepBy;
}
/** {@inheritDoc} */
@Override public void decrement(int steps) {
final BigDecimal currentValue = BigDecimal.valueOf(getValue());
final BigDecimal minBigDecimal = BigDecimal.valueOf(getMin());
final BigDecimal maxBigDecimal = BigDecimal.valueOf(getMax());
final BigDecimal amountToStepByBigDecimal = BigDecimal.valueOf(getAmountToStepBy());
BigDecimal newValue = currentValue.subtract(amountToStepByBigDecimal.multiply(BigDecimal.valueOf(steps)));
setValue(newValue.compareTo(minBigDecimal) >= 0 ? newValue.doubleValue() :
(isWrapAround() ? Spinner.wrapValue(newValue, minBigDecimal, maxBigDecimal).doubleValue() : getMin()));
}
/** {@inheritDoc} */
@Override public void increment(int steps) {
final BigDecimal currentValue = BigDecimal.valueOf(getValue());
final BigDecimal minBigDecimal = BigDecimal.valueOf(getMin());
final BigDecimal maxBigDecimal = BigDecimal.valueOf(getMax());
final BigDecimal amountToStepByBigDecimal = BigDecimal.valueOf(getAmountToStepBy());
BigDecimal newValue = currentValue.add(amountToStepByBigDecimal.multiply(BigDecimal.valueOf(steps)));
setValue(newValue.compareTo(maxBigDecimal) <= 0 ? newValue.doubleValue() :
(isWrapAround() ? Spinner.wrapValue(newValue, minBigDecimal, maxBigDecimal).doubleValue() : getMax()));
}
}
/**
* A {@link javafx.scene.control.SpinnerValueFactory} implementation designed to iterate through
* {@link java.time.LocalDate} values.
*
* Note that the default {@link #converterProperty() converter} is implemented
* simply as shown below, which may be adequate in many cases, but it is important
* for users to ensure that this suits their needs (and adjust when necessary):
*
*
* setConverter(new StringConverter<LocalDate>() {
* @Override public String toString(LocalDate object) {
* if (object == null) {
* return "";
* }
* return object.toString();
* }
*
* @Override public LocalDate fromString(String string) {
* return LocalDate.parse(string);
* }
* });
*/
static class LocalDateSpinnerValueFactory extends SpinnerValueFactory {
/**
* Creates a new instance of the LocalDateSpinnerValueFactory, using the
* value returned by calling {@code LocalDate#now()} as the initial value,
* and using a stepping amount of one day.
*/
public LocalDateSpinnerValueFactory() {
this(LocalDate.now());
}
/**
* Creates a new instance of the LocalDateSpinnerValueFactory, using the
* provided initial value, and a stepping amount of one day.
*
* @param initialValue The value of the Spinner when first instantiated.
*/
public LocalDateSpinnerValueFactory(@NamedArg("initialValue") LocalDate initialValue) {
this(LocalDate.MIN, LocalDate.MAX, initialValue);
}
/**
* Creates a new instance of the LocalDateSpinnerValueFactory, using the
* provided initial value, and a stepping amount of one day.
*
* @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.
*/
public LocalDateSpinnerValueFactory(@NamedArg("min") LocalDate min,
@NamedArg("min") LocalDate max,
@NamedArg("initialValue") LocalDate initialValue) {
this(min, max, initialValue, 1, ChronoUnit.DAYS);
}
/**
* Creates a new instance of the LocalDateSpinnerValueFactory, using the
* provided min, max, and initial values, as well as the amount to step
* by and {@link java.time.temporal.TemporalUnit}.
*
* To better understand, here are a few examples:
*
*
* - To step by one day from today: {@code new LocalDateSpinnerValueFactory(LocalDate.MIN, LocalDate.MAX, LocalDate.now(), 1, ChronoUnit.DAYS)}
* - To step by one month from today: {@code new LocalDateSpinnerValueFactory(LocalDate.MIN, LocalDate.MAX, LocalDate.now(), 1, ChronoUnit.MONTHS)}
* - To step by one year from today: {@code new LocalDateSpinnerValueFactory(LocalDate.MIN, LocalDate.MAX, LocalDate.now(), 1, ChronoUnit.YEARS)}
*
*
* @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.
* @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)
*/
public LocalDateSpinnerValueFactory(@NamedArg("min") LocalDate min,
@NamedArg("min") LocalDate max,
@NamedArg("initialValue") LocalDate initialValue,
@NamedArg("amountToStepBy") long amountToStepBy,
@NamedArg("temporalUnit") TemporalUnit temporalUnit) {
setMin(min);
setMax(max);
setAmountToStepBy(amountToStepBy);
setTemporalUnit(temporalUnit);
setConverter(new StringConverter() {
@Override public String toString(LocalDate object) {
if (object == null) {
return "";
}
return object.toString();
}
@Override public LocalDate fromString(String string) {
return LocalDate.parse(string);
}
});
valueProperty().addListener((o, oldValue, newValue) -> {
// when the value is set, we need to react to ensure it is a
// valid value (and if not, blow up appropriately)
if (getMin() != null && newValue.isBefore(getMin())) {
setValue(getMin());
} else if (getMax() != null && newValue.isAfter(getMax())) {
setValue(getMax());
}
});
setValue(initialValue != null ? initialValue : LocalDate.now());
}
/***********************************************************************
* *
* Properties *
* *
**********************************************************************/
// --- min
private ObjectProperty min = new SimpleObjectProperty(this, "min") {
@Override protected void invalidated() {
LocalDate currentValue = LocalDateSpinnerValueFactory.this.getValue();
if (currentValue == null) {
return;
}
final LocalDate newMin = get();
if (newMin.isAfter(getMax())) {
setMin(getMax());
return;
}
if (currentValue.isBefore(newMin)) {
LocalDateSpinnerValueFactory.this.setValue(newMin);
}
}
};
public final void setMin(LocalDate value) {
min.set(value);
}
public final LocalDate getMin() {
return min.get();
}
/**
* Sets the minimum allowable value for this value factory
*/
public final ObjectProperty minProperty() {
return min;
}
// --- max
private ObjectProperty max = new SimpleObjectProperty(this, "max") {
@Override protected void invalidated() {
LocalDate currentValue = LocalDateSpinnerValueFactory.this.getValue();
if (currentValue == null) {
return;
}
final LocalDate newMax = get();
if (newMax.isBefore(getMin())) {
setMax(getMin());
return;
}
if (currentValue.isAfter(newMax)) {
LocalDateSpinnerValueFactory.this.setValue(newMax);
}
}
};
public final void setMax(LocalDate value) {
max.set(value);
}
public final LocalDate getMax() {
return max.get();
}
/**
* Sets the maximum allowable value for this value factory
*/
public final ObjectProperty maxProperty() {
return max;
}
// --- temporalUnit
private ObjectProperty temporalUnit = new SimpleObjectProperty<>(this, "temporalUnit");
public final void setTemporalUnit(TemporalUnit value) {
temporalUnit.set(value);
}
public final TemporalUnit getTemporalUnit() {
return temporalUnit.get();
}
/**
* The size of each step (e.g. day, week, month, year, etc).
*/
public final ObjectProperty temporalUnitProperty() {
return temporalUnit;
}
// --- amountToStepBy
private LongProperty amountToStepBy = new SimpleLongProperty(this, "amountToStepBy");
public final void setAmountToStepBy(long value) {
amountToStepBy.set(value);
}
public final long getAmountToStepBy() {
return amountToStepBy.get();
}
/**
* Sets the amount to increment or decrement by, per step.
*/
public final LongProperty amountToStepByProperty() {
return amountToStepBy;
}
/***********************************************************************
* *
* Overridden methods *
* *
**********************************************************************/
/** {@inheritDoc} */
@Override public void decrement(int steps) {
final LocalDate currentValue = getValue();
final LocalDate min = getMin();
LocalDate newValue = currentValue.minus(getAmountToStepBy() * steps, getTemporalUnit());
if (min != null && isWrapAround() && newValue.isBefore(min)) {
// we need to wrap around
newValue = getMax();
}
setValue(newValue);
}
/** {@inheritDoc} */
@Override public void increment(int steps) {
final LocalDate currentValue = getValue();
final LocalDate max = getMax();
LocalDate newValue = currentValue.plus(getAmountToStepBy() * steps, getTemporalUnit());
if (max != null && isWrapAround() && newValue.isAfter(max)) {
// we need to wrap around
newValue = getMin();
}
setValue(newValue);
}
}
/**
* A {@link javafx.scene.control.SpinnerValueFactory} implementation designed to iterate through
* {@link java.time.LocalTime} values.
*
* Note that the default {@link #converterProperty() converter} is implemented
* simply as shown below, which may be adequate in many cases, but it is important
* for users to ensure that this suits their needs (and adjust when necessary):
*
*
* setConverter(new StringConverter<LocalTime>() {
* @Override public String toString(LocalTime object) {
* if (object == null) {
* return "";
* }
* return object.toString();
* }
*
* @Override public LocalTime fromString(String string) {
* return LocalTime.parse(string);
* }
* });
*/
static class LocalTimeSpinnerValueFactory extends SpinnerValueFactory {
/**
* Creates a new instance of the LocalTimepinnerValueFactory, using the
* value returned by calling {@code LocalTime#now()} as the initial value,
* and using a stepping amount of one day.
*/
public LocalTimeSpinnerValueFactory() {
this(LocalTime.now());
}
/**
* Creates a new instance of the LocalTimeSpinnerValueFactory, using the
* provided initial value, and a stepping amount of one hour.
*
* @param initialValue The value of the Spinner when first instantiated.
*/
public LocalTimeSpinnerValueFactory(@NamedArg("initialValue") LocalTime initialValue) {
this(LocalTime.MIN, LocalTime.MAX, initialValue);
}
/**
* Creates a new instance of the LocalTimeSpinnerValueFactory, using the
* provided initial value, and a stepping amount of one hour.
*
* @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.
*/
public LocalTimeSpinnerValueFactory(@NamedArg("min") LocalTime min,
@NamedArg("min") LocalTime max,
@NamedArg("initialValue") LocalTime initialValue) {
this(min, max, initialValue, 1, ChronoUnit.HOURS);
}
/**
* Creates a new instance of the LocalTimeSpinnerValueFactory, using the
* provided min, max, and initial values, as well as the amount to step
* by and {@link java.time.temporal.TemporalUnit}.
*
* To better understand, here are a few examples:
*
*
* - To step by one hour from the current time: {@code new LocalTimeSpinnerValueFactory(LocalTime.MIN, LocalTime.MAX, LocalTime.now(), 1, ChronoUnit.HOURS)}
* - To step by one minute from the current time: {@code new LocalTimeSpinnerValueFactory(LocalTime.MIN, LocalTime.MAX, LocalTime.now(), 1, ChronoUnit.MINUTES)}
*
*
* @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.
* @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)
*/
public LocalTimeSpinnerValueFactory(@NamedArg("min") LocalTime min,
@NamedArg("min") LocalTime max,
@NamedArg("initialValue") LocalTime initialValue,
@NamedArg("amountToStepBy") long amountToStepBy,
@NamedArg("temporalUnit") TemporalUnit temporalUnit) {
setMin(min);
setMax(max);
setAmountToStepBy(amountToStepBy);
setTemporalUnit(temporalUnit);
setConverter(new StringConverter() {
private DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
@Override public String toString(LocalTime localTime) {
if (localTime == null) {
return "";
}
return localTime.format(dtf);
}
@Override public LocalTime fromString(String string) {
return LocalTime.parse(string);
}
});
valueProperty().addListener((o, oldValue, newValue) -> {
// when the value is set, we need to react to ensure it is a
// valid value (and if not, blow up appropriately)
if (getMin() != null && newValue.isBefore(getMin())) {
setValue(getMin());
} else if (getMax() != null && newValue.isAfter(getMax())) {
setValue(getMax());
}
});
setValue(initialValue != null ? initialValue : LocalTime.now());
}
/***********************************************************************
* *
* Properties *
* *
**********************************************************************/
// --- min
private ObjectProperty min = new SimpleObjectProperty(this, "min") {
@Override protected void invalidated() {
LocalTime currentValue = LocalTimeSpinnerValueFactory.this.getValue();
if (currentValue == null) {
return;
}
final LocalTime newMin = get();
if (newMin.isAfter(getMax())) {
setMin(getMax());
return;
}
if (currentValue.isBefore(newMin)) {
LocalTimeSpinnerValueFactory.this.setValue(newMin);
}
}
};
public final void setMin(LocalTime value) {
min.set(value);
}
public final LocalTime getMin() {
return min.get();
}
/**
* Sets the minimum allowable value for this value factory
*/
public final ObjectProperty minProperty() {
return min;
}
// --- max
private ObjectProperty max = new SimpleObjectProperty(this, "max") {
@Override protected void invalidated() {
LocalTime currentValue = LocalTimeSpinnerValueFactory.this.getValue();
if (currentValue == null) {
return;
}
final LocalTime newMax = get();
if (newMax.isBefore(getMin())) {
setMax(getMin());
return;
}
if (currentValue.isAfter(newMax)) {
LocalTimeSpinnerValueFactory.this.setValue(newMax);
}
}
};
public final void setMax(LocalTime value) {
max.set(value);
}
public final LocalTime getMax() {
return max.get();
}
/**
* Sets the maximum allowable value for this value factory
*/
public final ObjectProperty maxProperty() {
return max;
}
// --- temporalUnit
private ObjectProperty temporalUnit = new SimpleObjectProperty<>(this, "temporalUnit");
public final void setTemporalUnit(TemporalUnit value) {
temporalUnit.set(value);
}
public final TemporalUnit getTemporalUnit() {
return temporalUnit.get();
}
/**
* The size of each step (e.g. day, week, month, year, etc).
*/
public final ObjectProperty temporalUnitProperty() {
return temporalUnit;
}
// --- amountToStepBy
private LongProperty amountToStepBy = new SimpleLongProperty(this, "amountToStepBy");
public final void setAmountToStepBy(long value) {
amountToStepBy.set(value);
}
public final long getAmountToStepBy() {
return amountToStepBy.get();
}
/**
* Sets the amount to increment or decrement by, per step.
*/
public final LongProperty amountToStepByProperty() {
return amountToStepBy;
}
/***********************************************************************
* *
* Overridden methods *
* *
**********************************************************************/
/** {@inheritDoc} */
@Override public void decrement(int steps) {
final LocalTime currentValue = getValue();
final LocalTime min = getMin();
final Duration duration = Duration.of(getAmountToStepBy() * steps, getTemporalUnit());
final long durationInSeconds = duration.toMinutes() * 60;
final long currentValueInSeconds = currentValue.toSecondOfDay();
if (! isWrapAround() && durationInSeconds > currentValueInSeconds) {
setValue(min == null ? LocalTime.MIN : min);
} else {
setValue(currentValue.minus(duration));
}
}
/** {@inheritDoc} */
@Override public void increment(int steps) {
final LocalTime currentValue = getValue();
final LocalTime max = getMax();
final Duration duration = Duration.of(getAmountToStepBy() * steps, getTemporalUnit());
final long durationInSeconds = duration.toMinutes() * 60;
final long currentValueInSeconds = currentValue.toSecondOfDay();
if (! isWrapAround() && durationInSeconds > (LocalTime.MAX.toSecondOfDay() - currentValueInSeconds)) {
setValue(max == null ? LocalTime.MAX : max);
} else {
setValue(currentValue.plus(duration));
}
}
}
}