Skip to content

Commit

Permalink
Refactor month box addition to grid pane.
Browse files Browse the repository at this point in the history
Extracted repetitive code into the `addMonthBoxToGridPane` method. This improves the maintainability and readability of the `YearMonthViewSkin` class.
  • Loading branch information
leewyatt committed Sep 5, 2024
1 parent 14001f1 commit 292faed
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions gemsfx/src/main/java/com/dlsc/gemsfx/skins/YearMonthViewSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,7 @@ public YearMonthViewSkin(YearMonthView control) {

GridPane gridPane = new GridPane();
gridPane.getStyleClass().add("grid-pane");
gridPane.add(new MonthBox(Month.JANUARY, control), 0, 0);
gridPane.add(new MonthBox(Month.FEBRUARY, control), 2, 0);
gridPane.add(new MonthBox(Month.MARCH, control), 0, 1);
gridPane.add(new MonthBox(Month.APRIL, control), 2, 1);
gridPane.add(new MonthBox(Month.MAY, control), 0, 2);
gridPane.add(new MonthBox(Month.JUNE, control), 2, 2);
gridPane.add(new MonthBox(Month.JULY, control), 0, 3);
gridPane.add(new MonthBox(Month.AUGUST, control), 2, 3);
gridPane.add(new MonthBox(Month.SEPTEMBER, control), 0, 4);
gridPane.add(new MonthBox(Month.OCTOBER, control), 2, 4);
gridPane.add(new MonthBox(Month.NOVEMBER, control), 0, 5);
gridPane.add(new MonthBox(Month.DECEMBER, control), 2, 5);
addMonthBoxToGridPane(gridPane, control);

Region divider = new Region();
divider.getStyleClass().add("divider");
Expand Down Expand Up @@ -131,6 +120,14 @@ public YearMonthViewSkin(YearMonthView control) {
});
}

private void addMonthBoxToGridPane(GridPane gridPane, YearMonthView control) {
for (Month month : Month.values()) {
int columnIndex = (month.getValue() % 2 == 0) ? 2 : 0;
int rowIndex = (month.getValue() - 1) / 2;
gridPane.add(new MonthBox(month, control), columnIndex, rowIndex);
}
}

/**
* Updates the pseudo-class state of the MonthBoxes.
*/
Expand Down

0 comments on commit 292faed

Please sign in to comment.