Skip to content

Commit

Permalink
Hide the popup when the value changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
leewyatt committed Mar 8, 2024
1 parent 3436ce4 commit 13d9e8e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
12 changes: 9 additions & 3 deletions gemsfx/src/main/java/com/dlsc/gemsfx/CalendarPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public CalendarPicker() {

setFocusTraversable(false);

valueProperty().addListener(it -> updateText());
valueProperty().addListener(it -> updateTextAndHidePopup());

editor.promptTextProperty().bindBidirectional(promptTextProperty());
editor.editableProperty().bind(editableProperty());
Expand Down Expand Up @@ -83,7 +83,7 @@ public CalendarPicker() {
});

setMaxWidth(Region.USE_PREF_SIZE);
updateText();
updateTextAndHidePopup();
}

private void placeCaretAtEnd() {
Expand Down Expand Up @@ -134,15 +134,21 @@ private void commitValue() {

/*
* Updates the text of the text field based on the current value / month.
* Hide the popup.
*/
private void updateText() {
private void updateTextAndHidePopup() {
LocalDate value = getValue();
if (value != null && getConverter() != null) {
editor.setText(getConverter().toString(value));
} else {
editor.setText("");
}
editor.positionCaret(editor.getText().length());

CalendarPickerSkin skin = (CalendarPickerSkin) getSkin();
if (skin != null) {
skin.hide();
}
}

/**
Expand Down
10 changes: 8 additions & 2 deletions gemsfx/src/main/java/com/dlsc/gemsfx/YearMonthPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public YearMonthPicker() {
setFocusTraversable(false);
setOnTouchPressed(evt -> commitValueAndShow());

valueProperty().addListener(it -> updateText());
valueProperty().addListener(it -> updateTextAndHidedPopup());

editor.setPromptText("Example: March 2023");
editor.editableProperty().bind(editableProperty());
Expand Down Expand Up @@ -114,15 +114,21 @@ public void commit() {

/*
* Updates the text of the text field based on the current value / month.
* Hide the popup.
*/
private void updateText() {
private void updateTextAndHidedPopup() {
YearMonth value = getValue();
if (value != null && getConverter() != null) {
editor.setText(getConverter().toString(value));
} else {
editor.setText("");
}
editor.positionCaret(editor.getText().length());

YearMonthPickerSkin skin = (YearMonthPickerSkin) getSkin();
if (skin != null) {
skin.hide();
}
}

/**
Expand Down
9 changes: 7 additions & 2 deletions gemsfx/src/main/java/com/dlsc/gemsfx/YearPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public YearPicker() {
setOnTouchPressed(evt -> commitValueAndShow());

valueProperty().addListener((obs, oldV, newV) -> {
updateText(newV);
updateTextAndHidePopup(newV);
year.set(newV == null ? null : newV.getValue());
});

Expand Down Expand Up @@ -142,13 +142,18 @@ private void commit() {
}
}

private void updateText(Year value) {
private void updateTextAndHidePopup(Year value) {
if (value != null) {
editor.setText(String.valueOf(value.getValue()));
} else {
editor.setText("");
}
editor.positionCaret(editor.getText().length());

YearPickerSkin skin = (YearPickerSkin) getSkin();
if (skin != null) {
skin.hide();
}
}

static class NumberStringFilteredConverter extends NumberStringConverter {
Expand Down

0 comments on commit 13d9e8e

Please sign in to comment.