Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CalendarView properties #144

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
1. Remove redundant properties from CalendarView for clarity.
2. Simplify binding of yearSpinnerBox visibility in CalendarView.
3. Streamline mouse click handling in CalendarView dateLabel.
leewyatt committed Apr 12, 2024
commit 687dbc63d2bd1045f8631626cfe434df5f750245
Original file line number Diff line number Diff line change
@@ -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()));
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
@@ -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() {
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
@@ -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();
@@ -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");
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
@@ -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;
@@ -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;