Skip to content

Commit

Permalink
Tweaking YearMonthView and YearView controls.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed Sep 21, 2023
1 parent 5ac2566 commit e58fdb9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
12 changes: 11 additions & 1 deletion gemsfx/src/main/java/com/dlsc/gemsfx/YearMonthPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Objects;

/**
* A control for quickly selecting the month of a year. The format used for the
Expand All @@ -27,6 +28,8 @@ public class YearMonthPicker extends ComboBoxBase<YearMonth> {

private final TextField editor = new TextField();

private YearMonthView yearMonthView;

/**
* Constructs a new picker.
*/
Expand Down Expand Up @@ -75,7 +78,14 @@ protected Skin<?> createDefaultSkin() {

@Override
public String getUserAgentStylesheet() {
return YearMonthView.class.getResource("year-month-picker.css").toExternalForm();
return Objects.requireNonNull(YearMonthView.class.getResource("year-month-picker.css")).toExternalForm();
}

public YearMonthView getYearMonthView() {
if (yearMonthView == null) {
yearMonthView = new YearMonthView();
}
return yearMonthView;
}

/*
Expand Down
15 changes: 15 additions & 0 deletions gemsfx/src/main/java/com/dlsc/gemsfx/YearPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class YearPicker extends ComboBoxBase<Year> {
private final TextField editor = new TextField();
private final NumberStringFilteredConverter converter = new NumberStringFilteredConverter();

private YearView yearView;

public YearPicker() {
getStyleClass().setAll("year-picker", "text-input");

Expand Down Expand Up @@ -73,6 +75,19 @@ protected Skin<?> createDefaultSkin() {
return new YearPickerSkin(this);
}

/**
* Returns the view that is being used by the picker to let the user chose
* a year.
*
* @return the view showing the years
*/
public YearView getYearView() {
if (yearView == null) {
yearView = new YearView();
}
return yearView;
}

@Override
public String getUserAgentStylesheet() {
return YearMonthView.class.getResource("year-picker.css").toExternalForm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public YearMonthPickerSkin(YearMonthPicker picker) {

protected Node getPopupContent() {
if (view == null) {
view = new YearMonthView();
view = getSkinnable().getYearMonthView();
view.valueProperty().bindBidirectional(getSkinnable().valueProperty());
view.valueProperty().addListener((obs, oldValue, newValue) -> {
if (!Objects.equals(oldValue, newValue)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public YearPickerSkin(YearPicker picker) {
@Override
protected Node getPopupContent() {
if (yearView == null) {
yearView = new YearView();
yearView = getSkinnable().getYearView();
yearView.valueProperty().bindBidirectional(getSkinnable().valueProperty());
yearView.valueProperty().addListener((obs, oldValue, newValue) -> {
if (!Objects.equals(oldValue, newValue)) {
Expand All @@ -50,5 +50,4 @@ protected Node getPopupContent() {
}
return yearView;
}

}

0 comments on commit e58fdb9

Please sign in to comment.