/**
* FocusChangeListener is notified when the panel changes its _focused_
- * value. It can be set with
+ * value.
*/
public interface FocusChangeListener {
void focusChanged(Date focusedDate);
private static final String CN_SELECTED = "selected";
+ private static final String CN_OFFMONTH = "offmonth";
+
/**
* Represents a click handler for when a user selects a value by using the
* mouse
*/
public void onClick(ClickEvent event) {
Day day = (Day) event.getSource();
- focusDay(day.getDay());
+ focusDay(day.getDate());
selectFocused();
onSubmit();
}
private boolean showISOWeekNumbers;
+ private Date displayedMonth;
+
private Date focusedDate;
private Day selectedDay;
}
/**
- * Sets the focus to given day of current time. Used when moving in the
- * calender with the keyboard.
+ * Sets the focus to given date in the current view. Used when moving in the
+ * calendar with the keyboard.
*
- * @param day
- * The day number from by Date.getDate()
+ * @param date
+ * A Date representing the day of month to be focused. Must be
+ * one of the days currently visible.
*/
- private void focusDay(int day) {
+ private void focusDay(Date date) {
// Only used when calender body is present
if (resolution > VDateField.RESOLUTION_MONTH) {
if (focusedDay != null) {
focusedDay.removeStyleDependentName(CN_FOCUSED);
}
- if (day > 0 && focusedDate != null) {
- focusedDate.setDate(day);
+ if (date != null && focusedDate != null) {
+ focusedDate.setTime(date.getTime());
int rowCount = days.getRowCount();
for (int i = 0; i < rowCount; i++) {
int cellCount = days.getCellCount(i);
Widget widget = days.getWidget(i, j);
if (widget != null && widget instanceof Day) {
Day curday = (Day) widget;
- if (curday.getDay() == day) {
+ if (curday.getDate().equals(date)) {
curday.addStyleDependentName(CN_FOCUSED);
focusedDay = curday;
focusedRow = i;
}
/**
- * Sets the selection hightlight to a given date of current time
+ * Sets the selection highlight to a given day in the current view
+ *
+ * @param date
+ * A Date representing the day of month to be selected. Must be
+ * one of the days currently visible.
*
- * @param day
*/
- private void selectDate(int day) {
+ private void selectDate(Date date) {
if (selectedDay != null) {
selectedDay.removeStyleDependentName(CN_SELECTED);
}
Widget widget = days.getWidget(i, j);
if (widget != null && widget instanceof Day) {
Day curday = (Day) widget;
- if (curday.getDay() == day) {
+ if (curday.getDate().equals(date)) {
curday.addStyleDependentName(CN_SELECTED);
selectedDay = curday;
return;
// it was forced to 1 above.
value.setDate(focusedDate.getDate());
- selectDate(focusedDate.getDate());
+ selectDate(focusedDate);
} else {
VConsole.log("Trying to select a the focused date which is NULL!");
}
}
}
- // The day of month that is selected, -1 if no day of this month is
- // selected (i.e, showing another month/year than selected or nothing is
- // selected)
- int dayOfMonthSelected = -1;
- // The day of month that is today, -1 if no day of this month is today
- // (i.e., showing another month/year than current)
- int dayOfMonthToday = -1;
-
- boolean initiallyNull = value == null;
-
- if (!initiallyNull && value.getMonth() == focusedDate.getMonth()
- && value.getYear() == focusedDate.getYear()) {
- dayOfMonthSelected = value.getDate();
- }
- final Date today = new Date();
- if (today.getMonth() == focusedDate.getMonth()
- && today.getYear() == focusedDate.getYear()) {
- dayOfMonthToday = today.getDate();
- }
+ // today must have zeroed hours, minutes, seconds, and milliseconds
+ final Date tmp = new Date();
+ final Date today = new Date(tmp.getYear(), tmp.getMonth(),
+ tmp.getDate());
final int startWeekDay = getDateTimeService().getStartWeekDay(
focusedDate);
- final int daysInMonth = DateTimeService
- .getNumberOfDaysInMonth(focusedDate);
-
- int dayCount = 0;
- final Date curr = new Date(focusedDate.getTime());
+ final Date curr = (Date) focusedDate.clone();
+ // Start from the first day of the week that at least partially belongs
+ // to the current month
+ curr.setDate(-startWeekDay);
// No month has more than 6 weeks so 6 is a safe maximum for rows.
for (int weekOfMonth = 1; weekOfMonth < 7; weekOfMonth++) {
- boolean weekNumberProcessed[] = new boolean[] { false, false,
- false, false, false, false, false };
-
for (int dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) {
- if (!(weekOfMonth == 1 && dayOfWeek < startWeekDay)) {
-
- if (dayCount >= daysInMonth) {
- // All days printed and we are done
- break;
- }
-
- final int dayOfMonth = ++dayCount;
-
- curr.setDate(dayCount);
- // Actually write the day of month
- Day day = new Day(dayOfMonth);
+ // Actually write the day of month
+ Day day = new Day((Date) curr.clone());
- if (dayOfMonthSelected == dayOfMonth) {
- day.addStyleDependentName(CN_SELECTED);
- selectedDay = day;
+ if (curr.equals(value)) {
+ day.addStyleDependentName(CN_SELECTED);
+ selectedDay = day;
+ }
+ if (curr.equals(today)) {
+ day.addStyleDependentName(CN_TODAY);
+ }
+ if (curr.equals(focusedDate)) {
+ focusedDay = day;
+ focusedRow = weekOfMonth;
+ if (hasFocus) {
+ day.addStyleDependentName(CN_FOCUSED);
}
+ }
+ if (curr.getMonth() != focusedDate.getMonth()) {
+ day.addStyleDependentName(CN_OFFMONTH);
+ }
- if (dayOfMonthToday == dayOfMonth) {
- day.addStyleDependentName(CN_TODAY);
- }
+ days.setWidget(weekOfMonth, firstWeekdayColumn + dayOfWeek, day);
- if (dayOfMonth == focusedDate.getDate()) {
- focusedDay = day;
- focusedRow = weekOfMonth;
- if (hasFocus) {
- day.addStyleDependentName(CN_FOCUSED);
- }
- }
+ // ISO week numbers if requested
+ days.getCellFormatter().setVisible(weekOfMonth, weekColumn,
+ isShowISOWeekNumbers());
+ if (isShowISOWeekNumbers()) {
+ final String baseCssClass = VDateField.CLASSNAME
+ + "-calendarpanel-weeknumber";
+ String weekCssClass = baseCssClass;
- days.setWidget(weekOfMonth, firstWeekdayColumn + dayOfWeek,
- day);
-
- // ISO week numbers if requested
- if (!weekNumberProcessed[weekOfMonth]) {
- days.getCellFormatter().setVisible(weekOfMonth,
- weekColumn, isShowISOWeekNumbers());
- if (isShowISOWeekNumbers()) {
- final String baseCssClass = VDateField.CLASSNAME
- + "-calendarpanel-weeknumber";
- String weekCssClass = baseCssClass;
-
- int weekNumber = DateTimeService
- .getISOWeekNumber(curr);
-
- days.setHTML(weekOfMonth, 0, "<span class=\""
- + weekCssClass + "\"" + ">" + weekNumber
- + "</span>");
- weekNumberProcessed[weekOfMonth] = true;
- }
+ int weekNumber = DateTimeService.getISOWeekNumber(curr);
- }
+ days.setHTML(weekOfMonth, 0, "<span class=\""
+ + weekCssClass + "\"" + ">" + weekNumber
+ + "</span>");
}
+ curr.setDate(curr.getDate() + 1);
}
}
-
}
/**
while (focusedDate.getMonth() != requestedMonth) {
focusedDate.setDate(focusedDate.getDate() - 1);
}
+ displayedMonth.setMonth(displayedMonth.getMonth() + 1);
renderCalendar();
}
while (focusedDate.getMonth() == currentMonth) {
focusedDate.setDate(focusedDate.getDate() - 1);
}
+ displayedMonth.setMonth(displayedMonth.getMonth() - 1);
renderCalendar();
}
*/
private void focusPreviousYear(int years) {
focusedDate.setYear(focusedDate.getYear() - years);
+ displayedMonth.setYear(displayedMonth.getYear() - years);
renderCalendar();
}
*/
private void focusNextYear(int years) {
focusedDate.setYear(focusedDate.getYear() + years);
+ displayedMonth.setYear(displayedMonth.getYear() + years);
renderCalendar();
}
if (newCurrentDate.getMonth() == focusedDate.getMonth()) {
// Month did not change, only move the selection
- focusDay(focusedDate.getDate() + 1);
+ focusDay(newCurrentDate);
} else {
// If the month changed we need to re-render the calendar
focusedDate.setDate(focusedDate.getDate() + 1);
if (newCurrentDate.getMonth() == focusedDate.getMonth()) {
// Month did not change, only move the selection
- focusDay(focusedDate.getDate() - 1);
+ focusDay(newCurrentDate);
} else {
// If the month changed we need to re-render the calendar
focusedDate.setDate(focusedDate.getDate() - 1);
if (newCurrentDate.getMonth() == focusedDate.getMonth()
&& focusedRow > 1) {
// Month did not change, only move the selection
- focusDay(focusedDate.getDate() - 7);
+ focusDay(newCurrentDate);
} else {
// If the month changed we need to re-render the calendar
- focusedDate.setDate(focusedDate.getDate() - 7);
+ focusedDate = newCurrentDate;
renderCalendar();
}
if (newCurrentDate.getMonth() == focusedDate.getMonth()) {
// Month did not change, only move the selection
- focusDay(focusedDate.getDate() + 7);
+ focusDay(newCurrentDate);
} else {
// If the month changed we need to re-render the calendar
- focusedDate.setDate(focusedDate.getDate() + 7);
+ focusedDate = newCurrentDate;
renderCalendar();
}
return;
}
- Date oldFocusedValue = focusedDate;
+ Date oldDisplayedMonth = displayedMonth;
value = currentDate;
if (value == null) {
- focusedDate = null;
+ focusedDate = displayedMonth = null;
} else {
focusedDate = (Date) value.clone();
+ displayedMonth = (Date) value.clone();
}
// Re-render calendar if month or year of focused date has changed
- if (oldFocusedValue == null || value == null
- || oldFocusedValue.getYear() != value.getYear()
- || oldFocusedValue.getMonth() != value.getMonth()) {
+ if (oldDisplayedMonth == null || value == null
+ || oldDisplayedMonth.getYear() != value.getYear()
+ || oldDisplayedMonth.getMonth() != value.getMonth()) {
renderCalendar();
} else {
- focusDay(currentDate.getDate());
+ focusDay(currentDate);
selectFocused();
}
if (!hasFocus) {
- focusDay(-1);
+ focusDay((Date) null);
}
}
}
+ /**
+ * A widget representing a single day in the calendar panel.
+ */
private class Day extends InlineHTML {
private static final String BASECLASS = VDateField.CLASSNAME
+ "-calendarpanel-day";
- private final int day;
+ private final Date date;
- Day(int dayOfMonth) {
- super("" + dayOfMonth);
+ Day(Date date) {
+ super("" + date.getDate());
setStyleName(BASECLASS);
- day = dayOfMonth;
+ this.date = date;
addClickHandler(dayClickHandler);
}
- public int getDay() {
- return day;
+ public Date getDate() {
+ return date;
}
}
public void onBlur(final BlurEvent event) {
if (event.getSource() instanceof VCalendarPanel) {
hasFocus = false;
- focusDay(-1);
+ focusDay(null);
}
}
// Focuses the current day if the calendar shows the days
if (focusedDay != null) {
- focusDay(focusedDay.getDay());
+ focusDay(focusedDate);
}
}
}
// Day, find out which dayOfMonth and use that as the identifier
Day day = Util.findWidget(subElement, Day.class);
if (day != null) {
- return SUBPART_DAY + day.getDay();
+ Date date = day.getDate();
+ int id = date.getDate();
+ // Zero or negative ids map to days of the preceding month,
+ // past-the-end-of-month ids to days of the following month
+ if (date.getMonth() < displayedMonth.getMonth()) {
+ id -= DateTimeService.getNumberOfDaysInMonth(date);
+ } else if (date.getMonth() > displayedMonth.getMonth()) {
+ id += DateTimeService
+ .getNumberOfDaysInMonth(displayedMonth);
+ }
+ return SUBPART_DAY + id;
}
} else if (time != null) {
if (contains(time.hours, subElement)) {
return time.ampm.getElement();
}
if (subPart.startsWith(SUBPART_DAY)) {
+ // Zero or negative ids map to days in the preceding month,
+ // past-the-end-of-month ids to days in the following month
int dayOfMonth = Integer.parseInt(subPart.substring(SUBPART_DAY
.length()));
+ Date date = new Date(displayedMonth.getYear(),
+ displayedMonth.getMonth(), dayOfMonth);
Iterator<Widget> iter = days.iterator();
while (iter.hasNext()) {
Widget w = iter.next();
if (w instanceof Day) {
Day day = (Day) w;
- if (day.getDay() == dayOfMonth) {
+ if (day.getDate().equals(date)) {
return day.getElement();
}
}
setValueByEvent(event, true);
DOM.eventCancelBubble(event, true);
}
- } else if (DOM.eventGetType(event) == Event.ONMOUSEDOWN && dragging) {
- dragging = false;
- DOM.releaseCapture(getElement());
- setValueByEvent(event, true);
}
}
package com.vaadin.tests.server.component.abstractorderedlayout;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.fail;
-
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.junit.Test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import org.junit.Test;
-import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import com.vaadin.ui.Component;
-package com.vaadin.tests.server.componentcontainer;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import com.vaadin.ui.Component;\r
-import com.vaadin.ui.Label;\r
-import com.vaadin.ui.Layout;\r
-\r
-public abstract class AbstractIndexedLayoutTest extends TestCase {\r
-\r
- private Layout layout;\r
-\r
- protected abstract Layout createLayout();\r
-\r
- @Override\r
- protected void setUp() throws Exception {\r
- layout = createLayout();\r
- }\r
-\r
- public Layout getLayout() {\r
- return layout;\r
- }\r
-\r
- public void testAddRemoveComponent() {\r
- Label c1 = new Label();\r
- Label c2 = new Label();\r
-\r
- layout.addComponent(c1);\r
-\r
- assertEquals(c1, getComponent(0));\r
- assertEquals(1, getComponentCount());\r
- layout.addComponent(c2);\r
- assertEquals(c1, getComponent(0));\r
- assertEquals(c2, getComponent(1));\r
- assertEquals(2, getComponentCount());\r
- layout.removeComponent(c1);\r
- assertEquals(c2, getComponent(0));\r
- assertEquals(1, getComponentCount());\r
- layout.removeComponent(c2);\r
- assertEquals(0, getComponentCount());\r
- }\r
-\r
- protected abstract int getComponentCount();\r
-\r
- protected abstract Component getComponent(int index);\r
-\r
- protected abstract int getComponentIndex(Component c);\r
-\r
- public void testGetComponentIndex() {\r
- Label c1 = new Label();\r
- Label c2 = new Label();\r
-\r
- layout.addComponent(c1);\r
- assertEquals(0, getComponentIndex(c1));\r
- layout.addComponent(c2);\r
- assertEquals(0, getComponentIndex(c1));\r
- assertEquals(1, getComponentIndex(c2));\r
- layout.removeComponent(c1);\r
- assertEquals(0, getComponentIndex(c2));\r
- layout.removeComponent(c2);\r
- assertEquals(-1, getComponentIndex(c2));\r
- assertEquals(-1, getComponentIndex(c1));\r
- }\r
-\r
- public void testGetComponent() {\r
- Label c1 = new Label();\r
- Label c2 = new Label();\r
-\r
- layout.addComponent(c1);\r
- assertEquals(c1, getComponent(0));\r
- layout.addComponent(c2);\r
- assertEquals(c1, getComponent(0));\r
- assertEquals(c2, getComponent(1));\r
- layout.removeComponent(c1);\r
- assertEquals(c2, getComponent(0));\r
- layout.removeComponent(c2);\r
- try {\r
- getComponent(0);\r
- fail();\r
- } catch (IndexOutOfBoundsException e) {\r
- // Expected\r
- }\r
- }\r
-}\r
+package com.vaadin.tests.server.componentcontainer;
+
+import junit.framework.TestCase;
+
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Layout;
+
+public abstract class AbstractIndexedLayoutTest extends TestCase {
+
+ private Layout layout;
+
+ protected abstract Layout createLayout();
+
+ @Override
+ protected void setUp() throws Exception {
+ layout = createLayout();
+ }
+
+ public Layout getLayout() {
+ return layout;
+ }
+
+ public void testAddRemoveComponent() {
+ Label c1 = new Label();
+ Label c2 = new Label();
+
+ layout.addComponent(c1);
+
+ assertEquals(c1, getComponent(0));
+ assertEquals(1, getComponentCount());
+ layout.addComponent(c2);
+ assertEquals(c1, getComponent(0));
+ assertEquals(c2, getComponent(1));
+ assertEquals(2, getComponentCount());
+ layout.removeComponent(c1);
+ assertEquals(c2, getComponent(0));
+ assertEquals(1, getComponentCount());
+ layout.removeComponent(c2);
+ assertEquals(0, getComponentCount());
+ }
+
+ protected abstract int getComponentCount();
+
+ protected abstract Component getComponent(int index);
+
+ protected abstract int getComponentIndex(Component c);
+
+ public void testGetComponentIndex() {
+ Label c1 = new Label();
+ Label c2 = new Label();
+
+ layout.addComponent(c1);
+ assertEquals(0, getComponentIndex(c1));
+ layout.addComponent(c2);
+ assertEquals(0, getComponentIndex(c1));
+ assertEquals(1, getComponentIndex(c2));
+ layout.removeComponent(c1);
+ assertEquals(0, getComponentIndex(c2));
+ layout.removeComponent(c2);
+ assertEquals(-1, getComponentIndex(c2));
+ assertEquals(-1, getComponentIndex(c1));
+ }
+
+ public void testGetComponent() {
+ Label c1 = new Label();
+ Label c2 = new Label();
+
+ layout.addComponent(c1);
+ assertEquals(c1, getComponent(0));
+ layout.addComponent(c2);
+ assertEquals(c1, getComponent(0));
+ assertEquals(c2, getComponent(1));
+ layout.removeComponent(c1);
+ assertEquals(c2, getComponent(0));
+ layout.removeComponent(c2);
+ try {
+ getComponent(0);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+}
-package com.vaadin.tests.application;\r
-\r
-import com.vaadin.tests.components.TestBase;\r
-import com.vaadin.ui.Button;\r
-import com.vaadin.ui.Button.ClickEvent;\r
-import com.vaadin.ui.Label;\r
-\r
-public class WebBrowserSizeTest extends TestBase {\r
-\r
- @Override\r
- protected void setup() {\r
-\r
- final Label screenSizeLabel = new Label("n/a");\r
- screenSizeLabel.setCaption("Screen size");\r
-\r
- final Label browserSizeLabel = new Label("n/a");\r
- browserSizeLabel.setCaption("Client (browser window) size");\r
-\r
- final Button update = new Button("Refresh", new Button.ClickListener() {\r
-\r
- public void buttonClick(ClickEvent event) {\r
- screenSizeLabel.setValue(getBrowser().getScreenWidth() + " x "\r
- + getBrowser().getScreenHeight());\r
- browserSizeLabel.setValue(getBrowser().getClientWidth() + " x "\r
- + getBrowser().getClientHeight());\r
- }\r
- });\r
-\r
- addComponent(update);\r
- addComponent(screenSizeLabel);\r
- addComponent(browserSizeLabel);\r
-\r
- }\r
-\r
- @Override\r
- protected String getDescription() {\r
- return "Verifies that browser sizes are reported correctly. Note that client width differs depending on browser decorations.";\r
- }\r
-\r
- @Override\r
- protected Integer getTicketNumber() {\r
- return 5655;\r
- }\r
-\r
-}\r
+package com.vaadin.tests.application;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Label;
+
+public class WebBrowserSizeTest extends TestBase {
+
+ @Override
+ protected void setup() {
+
+ final Label screenSizeLabel = new Label("n/a");
+ screenSizeLabel.setCaption("Screen size");
+
+ final Label browserSizeLabel = new Label("n/a");
+ browserSizeLabel.setCaption("Client (browser window) size");
+
+ final Button update = new Button("Refresh", new Button.ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ screenSizeLabel.setValue(getBrowser().getScreenWidth() + " x "
+ + getBrowser().getScreenHeight());
+ browserSizeLabel.setValue(getBrowser().getClientWidth() + " x "
+ + getBrowser().getClientHeight());
+ }
+ });
+
+ addComponent(update);
+ addComponent(screenSizeLabel);
+ addComponent(browserSizeLabel);
+
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Verifies that browser sizes are reported correctly. Note that client width differs depending on browser decorations.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 5655;
+ }
+
+}
curDateLabel.setValue(getBrowser().getCurrentDate()
.toString());
+
}
});
addComponent(curDateLabel);
addComponent(diffLabel);
addComponent(containsLabel);
-
}
@Override
-package com.vaadin.tests.components.datefield;\r
-\r
-import java.util.Calendar;\r
-import java.util.Locale;\r
-\r
-import com.vaadin.tests.components.TestBase;\r
-import com.vaadin.ui.Button;\r
-import com.vaadin.ui.Button.ClickEvent;\r
-import com.vaadin.ui.Button.ClickListener;\r
-import com.vaadin.ui.DateField;\r
-import com.vaadin.ui.PopupDateField;\r
-\r
-@SuppressWarnings("serial")\r
-public class PopupDateFieldExtendedRange extends TestBase {\r
-\r
- private Calendar date = Calendar.getInstance();\r
-\r
- @Override\r
- protected void setup() {\r
- date.set(2011, 0, 1);\r
-\r
- getLayout().setSpacing(true);\r
-\r
- final PopupDateField[] fields = new PopupDateField[3];\r
-\r
- fields[0] = makeDateField();\r
- fields[0].setLocale(new Locale("fi", "FI"));\r
- fields[0].setCaption("Finnish locale");\r
-\r
- fields[1] = makeDateField();\r
- fields[1].setLocale(new Locale("en", "US"));\r
- fields[1].setCaption("US English locale");\r
-\r
- fields[2] = makeDateField();\r
- fields[2].setLocale(new Locale("fi", "FI"));\r
- fields[2].setShowISOWeekNumbers(true);\r
- fields[2].setCaption("Finnish locale with week numbers");\r
-\r
- for (PopupDateField f : fields) {\r
- addComponent(f);\r
- }\r
-\r
- addComponent(new Button("Change date", new ClickListener() {\r
- public void buttonClick(ClickEvent event) {\r
- date.set(2010, 1, 16);\r
- for (PopupDateField f : fields) {\r
- f.setValue(date.getTime());\r
- }\r
- }\r
- }));\r
- }\r
-\r
- @Override\r
- protected String getDescription() {\r
- return "Show a few days of the preceding and following months in the datefield popup";\r
- }\r
-\r
- @Override\r
- protected Integer getTicketNumber() {\r
- return 6718;\r
- }\r
-\r
- private PopupDateField makeDateField() {\r
- PopupDateField pdf = new PopupDateField();\r
- pdf.setResolution(DateField.RESOLUTION_DAY);\r
- pdf.setValue(date.getTime());\r
- return pdf;\r
- }\r
-}\r
+package com.vaadin.tests.components.datefield;
+
+import java.util.Calendar;
+import java.util.Locale;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.PopupDateField;
+
+@SuppressWarnings("serial")
+public class PopupDateFieldExtendedRange extends TestBase {
+
+ private Calendar date = Calendar.getInstance();
+
+ @Override
+ protected void setup() {
+ date.set(2011, 0, 1);
+
+ getLayout().setSpacing(true);
+
+ final PopupDateField[] fields = new PopupDateField[3];
+
+ fields[0] = makeDateField();
+ fields[0].setLocale(new Locale("fi", "FI"));
+ fields[0].setCaption("Finnish locale");
+
+ fields[1] = makeDateField();
+ fields[1].setLocale(new Locale("en", "US"));
+ fields[1].setCaption("US English locale");
+
+ fields[2] = makeDateField();
+ fields[2].setLocale(new Locale("fi", "FI"));
+ fields[2].setShowISOWeekNumbers(true);
+ fields[2].setCaption("Finnish locale with week numbers");
+
+ for (PopupDateField f : fields) {
+ addComponent(f);
+ }
+
+ addComponent(new Button("Change date", new ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ date.set(2010, 1, 16);
+ for (PopupDateField f : fields) {
+ f.setValue(date.getTime());
+ }
+ }
+ }));
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Show a few days of the preceding and following months in the datefield popup";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 6718;
+ }
+
+ private PopupDateField makeDateField() {
+ PopupDateField pdf = new PopupDateField();
+ pdf.setResolution(DateField.RESOLUTION_DAY);
+ pdf.setValue(date.getTime());
+ return pdf;
+ }
+}