diff options
author | Artur Signell <artur@vaadin.com> | 2012-02-06 12:36:48 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2012-02-06 12:36:48 +0200 |
commit | e145df6622c4ac1aa499ace426602cea8da91b21 (patch) | |
tree | b5233d72f786a5787c7f84a6d5573c6974d3a57a | |
parent | e5a3755a3b0377e0f133fe2f130f0692198e6bd3 (diff) | |
parent | 95d7ee20a33f17759fd6eec74ad8a44b5ac72947 (diff) | |
download | vaadin-framework-e145df6622c4ac1aa499ace426602cea8da91b21.tar.gz vaadin-framework-e145df6622c4ac1aa499ace426602cea8da91b21.zip |
Merge remote-tracking branch 'origin/6.8'
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java | 106 |
1 files changed, 42 insertions, 64 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java index 96be51dab0..2968e132c6 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java @@ -476,11 +476,15 @@ public class VCalendarPanel extends FocusableFlexTable implements } } - // today must have zeroed hours, minutes, seconds, and milliseconds + // Zero out hours, minutes, seconds, and milliseconds to compare dates + // without time part final Date tmp = new Date(); final Date today = new Date(tmp.getYear(), tmp.getMonth(), tmp.getDate()); + final Date selectedDate = value == null ? null : new Date( + value.getYear(), value.getMonth(), value.getDate()); + final int startWeekDay = getDateTimeService().getStartWeekDay( displayedMonth); final Date curr = (Date) displayedMonth.clone(); @@ -495,7 +499,7 @@ public class VCalendarPanel extends FocusableFlexTable implements // Actually write the day of month Day day = new Day((Date) curr.clone()); - if (curr.equals(value)) { + if (curr.equals(selectedDate)) { day.addStyleDependentName(CN_SELECTED); selectedDay = day; } @@ -578,7 +582,30 @@ public class VCalendarPanel extends FocusableFlexTable implements } else if (time != null) { remove(time); } + } + + /** + * Moves the focus forward the given number of days. + */ + private void focusNextDay(int days) { + int oldMonth = focusedDate.getMonth(); + focusedDate.setDate(focusedDate.getDate() + days); + + if (focusedDate.getMonth() == oldMonth) { + // Month did not change, only move the selection + focusDay(focusedDate); + } else { + // If the month changed we need to re-render the calendar + displayedMonth.setMonth(focusedDate.getMonth()); + renderCalendar(); + } + } + /** + * Moves the focus backward the given number of days. + */ + private void focusPreviousDay(int days) { + focusNextDay(-days); } /** @@ -894,80 +921,28 @@ public class VCalendarPanel extends FocusableFlexTable implements * Jumps to the next day. */ if (keycode == getForwardKey() && !shift) { - // Calculate new showing value - - Date newCurrentDate = (Date) focusedDate.clone(); - - newCurrentDate.setDate(newCurrentDate.getDate() + 1); - - if (newCurrentDate.getMonth() == focusedDate.getMonth()) { - // Month did not change, only move the selection - focusDay(newCurrentDate); - } else { - // If the month changed we need to re-render the calendar - focusedDate.setDate(focusedDate.getDate() + 1); - renderCalendar(); - } - + focusNextDay(1); return true; /* * Jumps to the previous day */ } else if (keycode == getBackwardKey() && !shift) { - // Calculate new showing value - Date newCurrentDate = (Date) focusedDate.clone(); - newCurrentDate.setDate(newCurrentDate.getDate() - 1); - - if (newCurrentDate.getMonth() == focusedDate.getMonth()) { - // Month did not change, only move the selection - focusDay(newCurrentDate); - } else { - // If the month changed we need to re-render the calendar - focusedDate.setDate(focusedDate.getDate() - 1); - renderCalendar(); - } - + focusPreviousDay(1); return true; /* - * Jumps one week back in the calendar + * Jumps one week forward in the calendar */ - } else if (keycode == getPreviousKey() && !shift) { - // Calculate new showing value - Date newCurrentDate = (Date) focusedDate.clone(); - newCurrentDate.setDate(newCurrentDate.getDate() - 7); - - if (newCurrentDate.getMonth() == focusedDate.getMonth() - && focusedRow > 1) { - // Month did not change, only move the selection - focusDay(newCurrentDate); - } else { - // If the month changed we need to re-render the calendar - focusedDate = newCurrentDate; - renderCalendar(); - } - + } else if (keycode == getNextKey() && !shift) { + focusNextDay(7); return true; /* - * Jumps one week forward in the calendar + * Jumps one week back in the calendar */ - } else if (keycode == getNextKey() && !ctrl && !shift) { - // Calculate new showing value - Date newCurrentDate = (Date) focusedDate.clone(); - newCurrentDate.setDate(newCurrentDate.getDate() + 7); - - if (newCurrentDate.getMonth() == focusedDate.getMonth()) { - // Month did not change, only move the selection - focusDay(newCurrentDate); - } else { - // If the month changed we need to re-render the calendar - focusedDate = newCurrentDate; - renderCalendar(); - - } - + } else if (keycode == getPreviousKey() && !shift) { + focusPreviousDay(7); return true; /* @@ -977,6 +952,7 @@ public class VCalendarPanel extends FocusableFlexTable implements selectFocused(); onSubmit(); // submit return true; + } else if (keycode == getCloseKey()) { onCancel(); // TODO close event @@ -1016,7 +992,9 @@ public class VCalendarPanel extends FocusableFlexTable implements */ } else if (keycode == getResetKey() && !shift) { // Restore showing value the selected value - focusedDate.setTime(value.getTime()); + focusedDate = new Date(value.getYear(), value.getMonth(), + value.getDate()); + displayedMonth = new Date(value.getYear(), value.getMonth(), 1); renderCalendar(); return true; } @@ -1224,7 +1202,7 @@ public class VCalendarPanel extends FocusableFlexTable implements || oldDisplayedMonth.getMonth() != value.getMonth()) { renderCalendar(); } else { - focusDay(currentDate); + focusDay(focusedDate); selectFocused(); } |