Skip to content

Commit

Permalink
1. Remove redundant properties from CalendarView for clarity.
Browse files Browse the repository at this point in the history
2. Simplify binding of yearSpinnerBox visibility in CalendarView.
3. Streamline mouse click handling in CalendarView dateLabel.
  • Loading branch information
leewyatt committed Apr 12, 2024
1 parent 93f9182 commit 687dbc6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ public void start(Stage stage) {
options2.getChildren().add(createOption("Disable next month", calendarView.disableNextMonthButtonProperty()));
options2.getChildren().add(createOption("Disable previous year", calendarView.disablePreviousYearButtonProperty()));
options2.getChildren().add(createOption("Disable next year", calendarView.disableNextYearButtonProperty()));
options2.getChildren().add(createOption("Disable month dropdown", calendarView.disableMonthDropdownButtonProperty()));
options2.getChildren().add(createOption("Disable year dropdown", calendarView.disableYearDropdownButtonProperty()));
options2.getChildren().add(new Separator(Orientation.HORIZONTAL));
options2.getChildren().add(createOption("Enable year selection view", calendarView.yearSelectionViewEnabledProperty()));
options2.getChildren().add(createOption("Enable month selection view", calendarView.monthSelectionViewEnabledProperty()));
Expand Down
38 changes: 0 additions & 38 deletions gemsfx/src/main/java/com/dlsc/gemsfx/CalendarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,44 +373,6 @@ public final void setDisablePreviousYearButton(boolean disablePreviousYearButton
this.disablePreviousYearButton.set(disablePreviousYearButton);
}

public final BooleanProperty disableMonthDropdownButton = new SimpleBooleanProperty(this, "disableMonthDropdownButton", false);

public final boolean isDisableMonthDropdownButton() {
return disableMonthDropdownButton.get();
}

/**
* A property to control whether the "show month view" button will be disabled or not.
*
* @return true if the button used for showing the month selection view should be disabled
*/
public final BooleanProperty disableMonthDropdownButtonProperty() {
return disableMonthDropdownButton;
}

public final void setDisableMonthDropdownButton(boolean disableMonthDropdownButton) {
this.disableMonthDropdownButton.set(disableMonthDropdownButton);
}

public final BooleanProperty disableYearDropdownButton = new SimpleBooleanProperty(this, "disableYearDropdownButton", false);

public final boolean isDisableYearDropdownButton() {
return disableYearDropdownButton.get();
}

/**
* A property to control whether the "show year view" button will be disabled or not.
*
* @return true if the button used for showing the year selection view should be disabled
*/
public final BooleanProperty disableYearDropdownButtonProperty() {
return disableYearDropdownButton;
}

public final void setDisableYearDropdownButton(boolean disableYearDropdownButton) {
this.disableYearDropdownButton.set(disableYearDropdownButton);
}

private final ObjectProperty<Callback<LocalDate, Boolean>> dateFilter = new SimpleObjectProperty<>(this, "dateFilter");

public final Callback<LocalDate, Boolean> getDateFilter() {
Expand Down
29 changes: 7 additions & 22 deletions gemsfx/src/main/java/com/dlsc/gemsfx/skins/CalendarViewSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public CalendarViewSkin(CalendarView view) {
VBox yearSpinnerBox = new VBox(incrementYearButton, decrementYearButton);
yearSpinnerBox.getStyleClass().add("year-spinner");
yearSpinnerBox.setMaxWidth(Region.USE_PREF_SIZE);
yearSpinnerBox.visibleProperty().bind(view.showYearProperty().and(view.showYearSpinnerProperty()).and(view.showYearDropdownProperty().not()));
yearSpinnerBox.visibleProperty().bind(view.showYearProperty().and(view.showYearSpinnerProperty()));
yearSpinnerBox.managedProperty().bind(yearSpinnerBox.visibleProperty());

HBox header = new HBox();
Expand Down Expand Up @@ -207,35 +207,20 @@ public CalendarViewSkin(CalendarView view) {

StackPane monthDropdownArrowButton = new StackPane(monthDropdownArrow);
monthDropdownArrowButton.getStyleClass().addAll("dropdown-button", "month-dropdown-button");
monthDropdownArrowButton.setOnMouseClicked(evt -> viewMode.set(ViewMode.MONTH));
monthDropdownArrowButton.visibleProperty().bind(view.monthSelectionViewEnabledProperty().and(view.showMonthDropdownProperty().and(view.showMonthProperty())));
monthDropdownArrowButton.visibleProperty().bind(view.showMonthDropdownProperty());
monthDropdownArrowButton.managedProperty().bind(monthDropdownArrowButton.visibleProperty());
monthDropdownArrowButton.disableProperty().bind(view.disableMonthDropdownButtonProperty());
monthLabel.graphicProperty().bind(Bindings.createObjectBinding(() -> {
if (view.isMonthSelectionViewEnabled() && view.isShowMonthDropdown()) {
return monthDropdownArrowButton;
}
return null;
},
view.showMonthDropdownProperty(), view.monthSelectionViewEnabledProperty()));
monthDropdownArrowButton.disableProperty().bind(view.monthSelectionViewEnabledProperty().not());
monthLabel.graphicProperty().bind(view.showMonthDropdownProperty().map(showMonthDropdown -> showMonthDropdown ? monthDropdownArrowButton : null));

StackPane yearDropdownArrow = new StackPane();
yearDropdownArrow.getStyleClass().add("arrow");

StackPane yearDropdownArrowButton = new StackPane(yearDropdownArrow);
yearDropdownArrowButton.getStyleClass().addAll("dropdown-button", "year-dropdown-button");
yearDropdownArrowButton.setOnMouseClicked(evt -> viewMode.set(ViewMode.YEAR));
yearDropdownArrowButton.visibleProperty().bind(view.yearSelectionViewEnabledProperty().and(view.showYearDropdownProperty().and(view.showYearProperty())));
yearDropdownArrowButton.visibleProperty().bind(view.showYearDropdownProperty());
yearDropdownArrowButton.managedProperty().bind(yearDropdownArrowButton.visibleProperty());
yearDropdownArrowButton.disableProperty().bind(view.disableYearDropdownButtonProperty());

yearLabel.graphicProperty().bind(Bindings.createObjectBinding(() -> {
if (view.isYearSelectionViewEnabled() && view.isShowYearDropdown()) {
return yearDropdownArrowButton;
}
return null;
},
view.showYearDropdownProperty(), view.yearSelectionViewEnabledProperty()));
yearDropdownArrowButton.disableProperty().bind(view.yearSelectionViewEnabledProperty().not());
yearLabel.graphicProperty().bind(view.showYearDropdownProperty().map(showYearDropdown -> showYearDropdown ? yearDropdownArrowButton : null));

Spacer leftSpacer = new Spacer();
leftSpacer.getStyleClass().add("left");
Expand Down
8 changes: 4 additions & 4 deletions gemsfx/src/main/resources/com/dlsc/gemsfx/calendar-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
-fx-background-radius: 2px;
}

.calendar-view > .stack-pane > .container > .header > .dropdown-button {
-fx-padding: 2px 2px 2px 5px;
}

.calendar-view > .stack-pane > .container > .header > .date-label > .dropdown-button > .arrow {
-fx-background-color: -fx-mark-color;
-fx-background-insets: 0;
Expand All @@ -70,6 +66,10 @@
-fx-scale-shape: false;
}

.calendar-view > .stack-pane > .container > .header > .date-label > .dropdown-button:disabled {
-fx-opacity: 0.4;
}

.calendar-view > .stack-pane > .container > .header > .year-spinner {
-fx-alignment: center;
-fx-spacing: 2px;
Expand Down

0 comments on commit 687dbc6

Please sign in to comment.