use of org.apache.pivot.wtk.Calendar in project pivot by apache.
the class CalendarSkin method install.
@Override
public void install(Component component) {
super.install(component);
Calendar calendar = (Calendar) component;
calendar.getCalendarListeners().add(this);
calendar.getCalendarSelectionListeners().add(this);
}
use of org.apache.pivot.wtk.Calendar in project pivot by apache.
the class TerraCalendarSkin method install.
@Override
public void install(Component component) {
super.install(component);
Calendar calendar = (Calendar) component;
calendar.add(calendarTablePane);
yearSpinner.setSelectedItem(Integer.valueOf(calendar.getYear()));
monthSpinner.setSelectedIndex(calendar.getMonth());
updateLabels();
updateCalendar();
}
use of org.apache.pivot.wtk.Calendar in project pivot by apache.
the class TerraCalendarSkin method updateCalendar.
private void updateCalendar() {
Calendar calendar = (Calendar) getComponent();
int month = calendar.getMonth();
int year = calendar.getYear();
Filter<CalendarDate> disabledDateFilter = calendar.getDisabledDateFilter();
monthSpinner.setSelectedIndex(month);
yearSpinner.setSelectedItem(Integer.valueOf(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 = (7 + gregorianCalendar.get(java.util.Calendar.DAY_OF_WEEK) - gregorianCalendar.getFirstDayOfWeek()) % 7;
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
CalendarDate lastWeekStartDate = (CalendarDate) dateButtons[5][0].getButtonData();
boolean visible = (lastWeekStartDate.month == calendar.getMonth());
for (Component component : calendarTablePane.getRows().get(7)) {
component.setVisible(visible);
}
today = new CalendarDate();
updateSelection(calendar.getSelectedDate());
}
use of org.apache.pivot.wtk.Calendar in project pivot by apache.
the class TerraCalendarSkin method updateLabels.
private void updateLabels() {
TablePane.Row row = calendarTablePane.getRows().get(1);
Calendar calendar = (Calendar) getComponent();
Locale locale = calendar.getLocale();
GregorianCalendar gregorianCalendar = new GregorianCalendar(locale);
SimpleDateFormat monthFormat = new SimpleDateFormat("E", locale);
int firstDayOfWeek = gregorianCalendar.getFirstDayOfWeek();
for (int i = 0; i < 7; i++) {
Label label = (Label) row.get(i);
gregorianCalendar.set(java.util.Calendar.DAY_OF_WEEK, firstDayOfWeek + i);
String text = monthFormat.format(gregorianCalendar.getTime());
text = Character.toString(text.charAt(weekdayCharacterIndex));
label.setText(text);
}
}
use of org.apache.pivot.wtk.Calendar in project pivot by apache.
the class TerraCalendarSkin method updateSelection.
private void updateSelection(CalendarDate selectedDate) {
Calendar calendar = (Calendar) getComponent();
Button selection = dateButtonGroup.getSelection();
if (selectedDate == null) {
if (selection != null) {
selection.setSelected(false);
}
} else {
int year = selectedDate.year;
int month = selectedDate.month;
if (year == calendar.getYear() && month == calendar.getMonth()) {
int day = selectedDate.day;
// Update the button group
int cellIndex = getCellIndex(year, month, day, calendar.getLocale());
int rowIndex = cellIndex / 7;
int columnIndex = cellIndex % 7;
TablePane.Row row = calendarTablePane.getRows().get(rowIndex + 2);
DateButton dateButton = (DateButton) row.get(columnIndex);
dateButton.setSelected(true);
} else {
if (selection != null) {
selection.setSelected(false);
}
}
}
}
Aggregations