summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Dahlström <johannes.dahlstrom@vaadin.com>2012-02-06 09:45:33 +0000
committerJohannes Dahlström <johannes.dahlstrom@vaadin.com>2012-02-06 09:45:33 +0000
commit95d7ee20a33f17759fd6eec74ad8a44b5ac72947 (patch)
tree146b9709583a66591703fcd5db18a74da2556d6c
parentee2c73f6d374ba5a275365319fdf9de215371984 (diff)
downloadvaadin-framework-95d7ee20a33f17759fd6eec74ad8a44b5ac72947.tar.gz
vaadin-framework-95d7ee20a33f17759fd6eec74ad8a44b5ac72947.zip
#6718 Fixed more regressions, refactored a bit
svn changeset:22917/svn branch:6.8
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java106
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 513c94ef98..867e49c181 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java
@@ -475,11 +475,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();
@@ -494,7 +498,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;
}
@@ -577,7 +581,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);
}
/**
@@ -893,80 +920,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;
/*
@@ -976,6 +951,7 @@ public class VCalendarPanel extends FocusableFlexTable implements
selectFocused();
onSubmit(); // submit
return true;
+
} else if (keycode == getCloseKey()) {
onCancel();
// TODO close event
@@ -1015,7 +991,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;
}
@@ -1223,7 +1201,7 @@ public class VCalendarPanel extends FocusableFlexTable implements
|| oldDisplayedMonth.getMonth() != value.getMonth()) {
renderCalendar();
} else {
- focusDay(currentDate);
+ focusDay(focusedDate);
selectFocused();
}