Search in sources :

Example 6 with CalendarDate

use of org.apache.pivot.util.CalendarDate in project pivot by apache.

the class CalendarDateTest method test2.

@Test
public void test2() {
    // PIVOT-1010: test interaction with LocalDate, etc. (new Java 8 classes)
    LocalDate ld1 = LocalDate.of(1941, 12, 7);
    CalendarDate cd1 = new CalendarDate(ld1);
    CalendarDate cd1a = CalendarDate.decode(d1);
    LocalDate ld1a = cd1a.toLocalDate();
    assertEquals(cd1, cd1a);
    assertEquals(ld1, ld1a);
    Time t1 = Time.decode("07:48:00");
    LocalDateTime dt1 = LocalDateTime.of(1941, 12, 7, 7, 48, 0);
    LocalDateTime dt1a = cd1.toLocalDateTime(t1);
    assertEquals(dt1, dt1a);
}
Also used : LocalDateTime(java.time.LocalDateTime) CalendarDate(org.apache.pivot.util.CalendarDate) Time(org.apache.pivot.util.Time) LocalDateTime(java.time.LocalDateTime) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 7 with CalendarDate

use of org.apache.pivot.util.CalendarDate in project pivot by apache.

the class CalendarTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(CalendarTest.class, "calendar_test.bxml");
    bxmlSerializer.bind(this, CalendarTest.class);
    Filter<CalendarDate> todayFilter = new Filter<CalendarDate>() {

        @Override
        public boolean include(CalendarDate date) {
            CalendarDate today = new CalendarDate();
            return (!date.equals(today));
        }
    };
    calendar.setDisabledDateFilter(todayFilter);
    calendarButton.getCalendarButtonListeners().add(new CalendarButtonListener() {

        @Override
        public void yearChanged(CalendarButton calendarButtonArgument, int previousYear) {
            disable();
        }

        @Override
        public void monthChanged(CalendarButton calendarButtonArgument, int previousMonth) {
            disable();
        }

        private void disable() {
            calendarButton.setDisabledDateFilter(new Filter<CalendarDate>() {

                @Override
                public boolean include(CalendarDate date) {
                    return true;
                }
            });
            Task<Void> task = new Task<Void>() {

                @Override
                public Void execute() {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException exception) {
                    // ignore exception
                    }
                    return null;
                }
            };
            System.out.println("STARTING TASK");
            task.execute(new TaskAdapter<>(new TaskListener<Void>() {

                @Override
                public void taskExecuted(Task<Void> taskArgument) {
                    System.out.println("EXECUTED");
                    calendarButton.setDisabledDateFilter(null);
                }

                @Override
                public void executeFailed(Task<Void> taskArgument) {
                    System.out.println("FAILED");
                    calendarButton.setDisabledDateFilter(null);
                }
            }));
        }
    });
    window.open(display);
}
Also used : Task(org.apache.pivot.util.concurrent.Task) CalendarDate(org.apache.pivot.util.CalendarDate) Filter(org.apache.pivot.util.Filter) TaskAdapter(org.apache.pivot.wtk.TaskAdapter) CalendarButton(org.apache.pivot.wtk.CalendarButton) CalendarButtonListener(org.apache.pivot.wtk.CalendarButtonListener) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 8 with CalendarDate

use of org.apache.pivot.util.CalendarDate in project pivot by apache.

the class Calendar method setSelectedDate.

/**
 * Sets the currently selected date.
 *
 * @param selectedDate The selected date, or <tt>null</tt> to specify no
 * selection
 */
public void setSelectedDate(CalendarDate selectedDate) {
    CalendarDate previousSelectedDate = this.selectedDate;
    if (previousSelectedDate != selectedDate) {
        this.selectedDate = selectedDate;
        calendarSelectionListeners.selectedDateChanged(this, previousSelectedDate);
    }
}
Also used : CalendarDate(org.apache.pivot.util.CalendarDate)

Example 9 with CalendarDate

use of org.apache.pivot.util.CalendarDate in project pivot by apache.

the class CalendarButton method load.

@Override
public void load(Object context) {
    if (selectedDateKey != null && JSON.containsKey(context, selectedDateKey) && selectedDateBindType != BindType.STORE) {
        Object value = JSON.get(context, selectedDateKey);
        CalendarDate selectedDateLocal = null;
        if (value instanceof CalendarDate) {
            selectedDateLocal = (CalendarDate) value;
        } else if (selectedDateBindMapping == null) {
            if (value != null) {
                selectedDateLocal = CalendarDate.decode(value.toString());
            }
        } else {
            selectedDateLocal = selectedDateBindMapping.toDate(value);
        }
        setSelectedDate(selectedDateLocal);
    }
}
Also used : CalendarDate(org.apache.pivot.util.CalendarDate)

Example 10 with CalendarDate

use of org.apache.pivot.util.CalendarDate 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)

Aggregations

CalendarDate (org.apache.pivot.util.CalendarDate)15 CalendarButton (org.apache.pivot.wtk.CalendarButton)5 Locale (java.util.Locale)2 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 CalendarButtonSelectionListener (org.apache.pivot.wtk.CalendarButtonSelectionListener)2 Test (org.junit.Test)2 GradientPaint (java.awt.GradientPaint)1 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 ArrayList (org.apache.pivot.collections.ArrayList)1 SerializationException (org.apache.pivot.serialization.SerializationException)1 Filter (org.apache.pivot.util.Filter)1 Time (org.apache.pivot.util.Time)1 Task (org.apache.pivot.util.concurrent.Task)1 Calendar (org.apache.pivot.wtk.Calendar)1