year = today.get(Calendar.YEAR);
dateProperty = new SimpleObjectProperty<Date>((new GregorianCalendar()).getTime());
// First block of the picker pane, which is constructed to show month and year and to change them by decreasing and increasing.
HBox monthYearRow = new HBox();
final Label monthYear = new Label(getMonthYear((new GregorianCalendar()).getTime()));
monthYear.setMinHeight(CELL_HEIGHT * 1.5);
monthYear.setMinWidth(CELL_WIDTH * 6.0);
monthYear.setAlignment(Pos.CENTER);
monthYearRow.getStyleClass().add(DATEPICKER_MONTHYEAR);
Path decrementArrow = new Path();
decrementArrow.setId(DATEPICKER_ARROW);
decrementArrow.getElements().addAll(new MoveTo(0, ARROW_SIZE), new LineTo(0, -ARROW_SIZE),
new LineTo(-ARROW_SIZE, 0), new LineTo(0, ARROW_SIZE));
decrementArrow.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent me) {
month--;
if(month < 0) {
month = Calendar.DECEMBER;
year--;
}
monthYear.setText(getMonthYear((new GregorianCalendar(year, month, 1)).getTime()));
setDayCells();
me.consume();
}
});
Path inreamentArrow = new Path();
inreamentArrow.setId(DATEPICKER_ARROW);
inreamentArrow.getElements().addAll(new MoveTo(0, ARROW_SIZE), new LineTo(0, -ARROW_SIZE),
new LineTo(ARROW_SIZE, 0), new LineTo(0, ARROW_SIZE));
inreamentArrow.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent me) {
month++;
if(month > Calendar.DECEMBER) {
month = Calendar.JANUARY;
year++;
}
monthYear.setText(getMonthYear((new GregorianCalendar(year, month, 1)).getTime()));
setDayCells();
me.consume();
}
});
monthYearRow.getChildren().addAll(decrementArrow, monthYear, inreamentArrow);
monthYearRow.setAlignment(Pos.CENTER);
// Second block of the picker pane, which is constructed to show the first letter of names of days in the week.
HBox firstLetterOfDayRow = new HBox();
firstLetterOfDayRow.getStyleClass().add(DATEPICKER_WEEKDAY);
String[] weekDays = getFirstLettersOfDays();
for (int i = 0; i < weekDays.length; i++) {
Label cell = new Label(weekDays[i]);
cell.setMinHeight(CELL_HEIGHT);
cell.setMinWidth(CELL_WIDTH);
cell.setAlignment(Pos.CENTER);
firstLetterOfDayRow.getChildren().add(cell);
}
pickerBox.getChildren().addAll(monthYearRow, firstLetterOfDayRow);
// Third block of the picker pane, which is constructed to show the days in a ROW_NUMBER by COLUMN_NUMBER matrix.
// The matrix constitutes of DayCell class which extends Label class and holds date information.
dayCells = new DayCell[COLUMN_NUMBER * ROW_NUMBER];
int index = 0;
for (int i = 0; i < ROW_NUMBER; i++) {
HBox row = new HBox();
for (int j = 0; j < COLUMN_NUMBER; j++) {
DayCell cell = createCell(0, 0, 0);
row.getChildren().add(cell);
cell.setId(DATEPICKER_DAYCELL);
dayCells[index++] = cell;
}
pickerBox.getChildren().add(row);
}