Search in sources :

Example 1 with Calendar

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);
}
Also used : Calendar(org.apache.pivot.wtk.Calendar)

Example 2 with Calendar

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();
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(org.apache.pivot.wtk.Calendar)

Example 3 with Calendar

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());
}
Also used : Locale(java.util.Locale) CalendarDate(org.apache.pivot.util.CalendarDate) GregorianCalendar(java.util.GregorianCalendar) Calendar(org.apache.pivot.wtk.Calendar) GregorianCalendar(java.util.GregorianCalendar) Component(org.apache.pivot.wtk.Component) GradientPaint(java.awt.GradientPaint)

Example 4 with Calendar

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);
    }
}
Also used : Locale(java.util.Locale) GregorianCalendar(java.util.GregorianCalendar) Calendar(org.apache.pivot.wtk.Calendar) GregorianCalendar(java.util.GregorianCalendar) Label(org.apache.pivot.wtk.Label) SimpleDateFormat(java.text.SimpleDateFormat) GradientPaint(java.awt.GradientPaint) TablePane(org.apache.pivot.wtk.TablePane)

Example 5 with Calendar

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);
            }
        }
    }
}
Also used : Button(org.apache.pivot.wtk.Button) GregorianCalendar(java.util.GregorianCalendar) Calendar(org.apache.pivot.wtk.Calendar) GradientPaint(java.awt.GradientPaint) TablePane(org.apache.pivot.wtk.TablePane)

Aggregations

Calendar (org.apache.pivot.wtk.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)4 GradientPaint (java.awt.GradientPaint)3 Locale (java.util.Locale)2 TablePane (org.apache.pivot.wtk.TablePane)2 SimpleDateFormat (java.text.SimpleDateFormat)1 CalendarDate (org.apache.pivot.util.CalendarDate)1 Button (org.apache.pivot.wtk.Button)1 Component (org.apache.pivot.wtk.Component)1 Label (org.apache.pivot.wtk.Label)1