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