label.setText(text);
}
}
private void updateCalendar() {
Calendar calendar = (Calendar)getComponent();
int month = calendar.getMonth();
int year = calendar.getYear();
Filter<CalendarDate> disabledDateFilter = calendar.getDisabledDateFilter();
monthSpinner.setSelectedIndex(month);
yearSpinner.setSelectedIndex(year);
// Determine the first and last days of the month
Locale locale = calendar.getLocale();
GregorianCalendar gregorianCalendar = new GregorianCalendar(locale);
gregorianCalendar.set(year, month, 1);
int firstIndex = gregorianCalendar.get(java.util.Calendar.DAY_OF_WEEK)
- gregorianCalendar.getFirstDayOfWeek();
int lastIndex = firstIndex + gregorianCalendar.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
// Determine the last day of last month
gregorianCalendar.add(java.util.Calendar.MONTH, -1);
int daysLastMonth = gregorianCalendar.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
for (int j = 0; j < 6; j++) {
for (int i = 0; i < 7; i++) {
month = calendar.getMonth();
year = calendar.getYear();
int k = j * 7 + i;
DateButton dateButton = dateButtons[j][i];
int day;
boolean enabled = false;
if (k < firstIndex) {
month--;
if (month < 0) {
month = 11;
year--;
}
day = daysLastMonth - (firstIndex - k);
} else if (k >= lastIndex) {
month++;
if (month > 11) {
month = 0;
year++;
}
day = k - lastIndex;
} else {
day = k - firstIndex;
enabled = true;
}
CalendarDate buttonData = new CalendarDate(year, month, day);
dateButton.setButtonData(buttonData);
dateButton.setEnabled(enabled
&& (disabledDateFilter == null
|| disabledDateFilter.include(buttonData)));
}
}
// Show/hide last row
calendarTablePane.getRows().get(7).setVisible(dateButtons[5][0].isEnabled());
today = new CalendarDate();
updateSelection(calendar.getSelectedDate());
}