Skip to content

Commit

Permalink
Removed "dangerous" constructor for Segment.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed Apr 3, 2024
1 parent cef5506 commit 298145b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
3 changes: 2 additions & 1 deletion pickerfx/src/main/java/com/dlsc/pickerfx/DigitsSegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class DigitsSegment extends Segment<Integer, Integer> {
* @param picker the parent picker control
*/
public DigitsSegment(Picker<Integer> picker) {
super(picker, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
super(picker);
getItems().setAll(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
}
16 changes: 1 addition & 15 deletions pickerfx/src/main/java/com/dlsc/pickerfx/Segment.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,12 @@ public class Segment<T, S> extends Control {

private final Picker<T> picker;

/**
* Creates a new instance of a segment with no items and {@code null} value.
* @param picker The picker parent of this segment control.
*/
public Segment(Picker<T> picker) {
this(picker, (S) null);
}

/**
* Creates a new instance of a segment with the given list of items and {@code null} value.
*
* @param picker The picker parent of this segment control.
* @param items The default items in the segment.
*/
@SafeVarargs
public Segment(Picker<T> picker, S... items) {
public Segment(Picker<T> picker) {
this.picker = Objects.requireNonNull(picker);

getStyleClass().add("segment");
Expand All @@ -66,10 +56,6 @@ public Segment(Picker<T> picker, S... items) {
setCellFactory(p -> new SegmentCell<>());

readOnlyProperty().bind(picker.readOnlyProperty());

if (items != null) {
getItems().setAll(items);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ private Segment<Duration, Long> createSegment(ChronoUnit unit) {
return field;
}

private void addItems(Segment<Duration, Long> field, long maxValue) {
private void addItems(Segment<Duration, Long> fieldSegment, long maxValue) {
fieldSegment.getItems().clear();
for (long i = 0; i <= maxValue; i++) {
field.getItems().add(i);
fieldSegment.getItems().add(i);
}
}


private void updateSegmentValues() {
if (updatingValue) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public LocalDatePickerSkin(LocalDatePicker picker) {

InvalidationListener updateValueListener = it -> updateValue();

daySegment = new Segment<>(picker, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31);
daySegment = new Segment<>(picker);
daySegment.getItems().setAll(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31);
daySegment.getStyleClass().add("day");
daySegment.valueProperty().addListener(updateValueListener);
daySegment.cellFactoryProperty().bind(picker.dayCellFactoryProperty());
Expand Down

0 comments on commit 298145b

Please sign in to comment.