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);
}
}
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;
}
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);
}
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);
}
}
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);
}
Aggregations