Search in sources :

Example 1 with CalendarDate

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

the class ComponentInspectorSkin method updateCalendarDateControl.

private void updateCalendarDateControl(Dictionary<String, Object> dictionary, String key) {
    CalendarButton calendarButton = (CalendarButton) controls.get(key);
    if (calendarButton != null) {
        CalendarDate value = (CalendarDate) dictionary.get(key);
        calendarButton.setSelectedDate(value);
    }
}
Also used : CalendarDate(org.apache.pivot.util.CalendarDate) CalendarButton(org.apache.pivot.wtk.CalendarButton)

Example 2 with CalendarDate

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

the class ComponentInspectorSkin method addCalendarDateControl.

private static Component addCalendarDateControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    CalendarDate calendarDate = (CalendarDate) dictionary.get(key);
    CalendarButton calendarButton = new CalendarButton();
    calendarButton.setMinimumWidth(75);
    calendarButton.setSelectedDate(calendarDate);
    section.add(calendarButton);
    Form.setLabel(calendarButton, key);
    calendarButton.getCalendarButtonSelectionListeners().add(new CalendarButtonSelectionListener() {

        @Override
        public void selectedDateChanged(CalendarButton calendarButtonArgument, CalendarDate previousSelectedDate) {
            try {
                dictionary.put(key, calendarButtonArgument.getSelectedDate());
            } catch (Exception exception) {
                displayErrorMessage(exception, calendarButtonArgument.getWindow());
                dictionary.put(key, previousSelectedDate);
            }
        }
    });
    return calendarButton;
}
Also used : CalendarDate(org.apache.pivot.util.CalendarDate) CalendarButton(org.apache.pivot.wtk.CalendarButton) CalendarButtonSelectionListener(org.apache.pivot.wtk.CalendarButtonSelectionListener)

Example 3 with CalendarDate

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

the class CalendarButtonDataRenderer method render.

@Override
public void render(final Object data, final Button button, boolean highlight) {
    Object dataMutable = data;
    CalendarButton calendarButton = (CalendarButton) button;
    Locale locale = calendarButton.getLocale();
    if (dataMutable == null) {
        dataMutable = "";
    } else {
        if (dataMutable instanceof CalendarDate) {
            CalendarDate date = (CalendarDate) dataMutable;
            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
            dataMutable = dateFormat.format(date.toCalendar().getTime());
        }
    }
    super.render(dataMutable, button, highlight);
}
Also used : Locale(java.util.Locale) CalendarDate(org.apache.pivot.util.CalendarDate) CalendarButton(org.apache.pivot.wtk.CalendarButton) DateFormat(java.text.DateFormat)

Example 4 with CalendarDate

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

the class CalendarButtonSkin method selectedDateChanged.

// Calendar button selection events
@Override
public void selectedDateChanged(CalendarButton calendarButton, CalendarDate previousSelectedDate) {
    // Set the selected date as the button data
    CalendarDate date = calendarButton.getSelectedDate();
    calendarButton.setButtonData(date);
    calendar.setSelectedDate(date);
    if (date != null) {
        calendar.setYear(date.year);
        calendar.setMonth(date.month);
    }
}
Also used : CalendarDate(org.apache.pivot.util.CalendarDate)

Example 5 with CalendarDate

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

the class CalendarDateTest method test1.

@Test
public void test1() {
    CalendarDate.Range r1 = new CalendarDate.Range(d1);
    CalendarDate.Range r1a = new CalendarDate.Range(d1, d1);
    CalendarDate.Range r2 = new CalendarDate.Range(d2, d3);
    CalendarDate.Range r3 = CalendarDate.Range.decode("{ \"start\" : \"1929-10-29\", \"end\" : \"2008-09-29\"}");
    CalendarDate.Range r3a = CalendarDate.Range.decode("[ \"1929-10-29\", \"2008-09-29\" ]");
    CalendarDate.Range r3b = CalendarDate.Range.decode("1929-10-29, 2008-09-29");
    CalendarDate cd1 = CalendarDate.decode(d1);
    CalendarDate cd2 = CalendarDate.decode(d2);
    CalendarDate cd3 = CalendarDate.decode(d3);
    assertTrue(r2.contains(r1));
    assertEquals(r1, r1a);
    assertEquals(r1.getLength(), 1);
    assertTrue(r2.normalize().equals(r2));
    // TODO: more tests of range methods: intersects, etc.
    assertEquals(r3, r3a);
    assertEquals(r3, r3b);
    assertEquals(r3a, r3b);
    assertEquals(cd1.year, 1941);
    assertEquals(cd1.month, 11);
    assertEquals(cd1.day, 6);
    assertEquals(cd1.toString(), d1);
}
Also used : CalendarDate(org.apache.pivot.util.CalendarDate) Test(org.junit.Test)

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