Skip to content

Commit

Permalink
Merge pull request #205 from dlsc-software-consulting-gmbh/enhancemen…
Browse files Browse the repository at this point in the history
…t-add-pseudo-class-to-header

Add pseudo-classes to CalendarView header
  • Loading branch information
dlemmermann authored Sep 4, 2024
2 parents de801f0 + eaf96ca commit ad63587
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions gemsfx/src/main/java/com/dlsc/gemsfx/skins/CalendarViewSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.WeakChangeListener;
import javafx.css.PseudoClass;
import javafx.geometry.HPos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
Expand Down Expand Up @@ -79,6 +80,10 @@ public class CalendarViewSkin extends SkinBase<CalendarView> {
private static final String RANGE_DATE = "range-date";
private static final String DROPDOWN = "dropdown";

private static final PseudoClass HEADER_LEFT_PSEUDO_CLASS = PseudoClass.getPseudoClass("left");
private static final PseudoClass HEADER_CENTER_PSEUDO_CLASS = PseudoClass.getPseudoClass("center");
private static final PseudoClass HEADER_RIGHT_PSEUDO_CLASS = PseudoClass.getPseudoClass("right");

private final Label monthLabel;

private final Label yearLabel;
Expand Down Expand Up @@ -249,8 +254,7 @@ public CalendarViewSkin(CalendarView view) {
Spacer rightSpacer = new Spacer();
rightSpacer.getStyleClass().add("right");

updateHeader(header, previousArrowButton, leftSpacer, yearSpinnerBox, rightSpacer, nextMonthArrowButton);
view.headerLayoutProperty().addListener(it -> updateHeader(header, previousArrowButton, leftSpacer, yearSpinnerBox, rightSpacer, nextMonthArrowButton));
view.headerLayoutProperty().subscribe(headerLayout -> updateHeader(header, previousArrowButton, leftSpacer, yearSpinnerBox, rightSpacer, nextMonthArrowButton));

InvalidationListener updateViewListener = evt -> updateView();
view.yearMonthProperty().addListener(evt -> {
Expand Down Expand Up @@ -353,15 +357,22 @@ public CalendarViewSkin(CalendarView view) {
}

private void updateHeader(HBox header, StackPane previousArrowButton, Spacer leftSpacer, VBox yearSpinnerBox, Spacer rightSpacer, StackPane nextMonthArrowButton) {
header.pseudoClassStateChanged(HEADER_LEFT_PSEUDO_CLASS, false);
header.pseudoClassStateChanged(HEADER_CENTER_PSEUDO_CLASS, false);
header.pseudoClassStateChanged(HEADER_RIGHT_PSEUDO_CLASS, false);

switch (getSkinnable().getHeaderLayout()) {
case CENTER:
header.getChildren().setAll(previousArrowButton, leftSpacer, monthLabel, yearLabel, yearSpinnerBox, rightSpacer, nextMonthArrowButton);
header.pseudoClassStateChanged(HEADER_CENTER_PSEUDO_CLASS, true);
break;
case LEFT:
header.getChildren().setAll(monthLabel, yearLabel, yearSpinnerBox, rightSpacer, previousArrowButton, nextMonthArrowButton);
header.pseudoClassStateChanged(HEADER_LEFT_PSEUDO_CLASS, true);
break;
case RIGHT:
header.getChildren().setAll(previousArrowButton, nextMonthArrowButton, leftSpacer, monthLabel, yearLabel);
header.pseudoClassStateChanged(HEADER_RIGHT_PSEUDO_CLASS, true);
break;
}
}
Expand Down

0 comments on commit ad63587

Please sign in to comment.