/** * Create a new date picker. */ public DatePicker() { this(new DefaultMonthSelector(), new DefaultCalendarView(), new CalendarModel()); }
private void setDate(Date date) { if (getDatePicker().isYearAndMonthDropdownVisible()) { // setup months dropdown int month = date.getMonth(); monthSelect.setSelectedIndex(month); // setup years dropdown yearSelect.clear(); int year = date.getYear(); int startYear = year - getNoOfYearsToDisplayBefore(); int endYear = year + getNoOfYearsToDisplayAfter(); Date newDate = new Date(); for (int i = startYear; i <= endYear; i++) { newDate.setYear(i); yearSelect.addItem(getModel().getYearFormatter().format(newDate)); } yearSelect.setSelectedIndex(year - startYear); } else { grid.setText(0, monthColumn, getModel().formatCurrentMonthAndYear()); } }
private ListBox createMonthSelect() { final ListBox monthListBox = new ListBox(); for (int i = 0; i < CalendarModel.MONTHS_IN_YEAR; i++) { monthListBox.addItem(getModel().formatMonth(i)); } monthListBox.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { int previousMonth = getModel().getCurrentMonth().getMonth(); int newMonth = monthListBox.getSelectedIndex(); int delta = newMonth - previousMonth; addMonths(delta); } }); return monthListBox; }
/** * Format the current month and year in the current locale. For example, "Jan 2013" in English. * * @return the formatted month and year */ public String formatCurrentMonthAndYear() { return getMonthAndYearFormatter().format(getCurrentMonth()); }
/** * Formats the current specified month. For example "September" in English. * * @return the formatted month */ public String formatCurrentMonth() { return getMonthFormatter().format(getCurrentMonth()); }
/** * Formats the current specified year. For example "2012". * * @return the formatted year */ public String formatCurrentYear() { return getYearFormatter().format(getCurrentMonth()); }
/** * Constructor. */ public CalendarModel() { currentMonth = new Date(); CalendarUtil.setToFirstDayOfMonth(currentMonth); // Finding day of week names Date date = new Date(); for (int i = 1; i <= DAYS_IN_WEEK; i++) { date.setDate(i); int dayOfWeek = date.getDay(); dayOfWeekNames[dayOfWeek] = getDayOfWeekFormatter().format(date); } // Finding day of month names date.setMonth(0); for (int i = 1; i < MAX_DAYS_IN_MONTH; ++i) { date.setDate(i); dayOfMonthNames[i] = getDayOfMonthFormatter().format(date); } // finding month names date.setDate(1); for (int i = 0; i < MONTHS_IN_YEAR; ++i) { date.setMonth(i); monthOfYearNames[i] = getMonthFormatter().format(date); } }
/** * Gets the current month the date picker is showing. * * <p> * A datepicker <b> may </b> show days not in the current month. It * <b>must</b> show all days in the current month. * </p> * * @return the current month * */ public Date getCurrentMonth() { return getModel().getCurrentMonth(); }
/*************************************** * @see MonthSelector#refresh() */ @Override protected void refresh() { if (rDatePicker != null) { aMonthLabel.setText(getModel().formatCurrentMonthAndYear()); } }
/** * Returns {@code true} if the month is before year in the date formatter in current locale. */ protected boolean isMonthBeforeYear() { String monthAndYearPattern = getMonthAndYearFormatter().getPattern(); for (int i = 0; i < monthAndYearPattern.length(); ++i) { switch (monthAndYearPattern.charAt(i)) { case 'y': return false; case 'M': case 'L': return true; } } return true; }
@Override public void refresh() { firstDisplayed = getModel().getCurrentFirstDayOfFirstWeek(); if (firstDisplayed.getDate() == 1) { // show one empty week if date is Monday is the first in month. addDays(firstDisplayed, -7); } lastDisplayed.setTime(firstDisplayed.getTime()); for (int i = 0; i < grid.getNumCells(); i++) { if (i != 0) { addDays(lastDisplayed, 1); } DateCell cell = (DateCell) grid.getCell(i); cell.update(lastDisplayed); } setAriaSelectedCell(null); }
void update(Date current) { setEnabled(true); getValue().setTime(current.getTime()); String value = getModel().formatDayOfMonth(getValue()); setText(value); dateStyle = cellStyle; if (isFiller()) { getElement().setTabIndex(-1); dateStyle += " " + css().dayIsFiller(); } else { getElement().setTabIndex(0); String extraStyle = getDatePicker().getStyleOfDate(current); if (extraStyle != null) { dateStyle += " " + extraStyle; } } // We want to certify that all date styles have " " before and after // them for ease of adding to and replacing them. dateStyle += " "; updateStyle(); }
int dayIdx = i + shift < CalendarModel.DAYS_IN_WEEK ? i + shift : i + shift - CalendarModel.DAYS_IN_WEEK; grid.setText(0, i, getModel().formatDayOfWeek(dayIdx));
/** * Constructor. */ public CalendarModel() { currentMonth = new Date(); CalendarUtil.setToFirstDayOfMonth(currentMonth); // Finding day of week names Date date = new Date(); for (int i = 1; i <= DAYS_IN_WEEK; i++) { date.setDate(i); int dayOfWeek = date.getDay(); dayOfWeekNames[dayOfWeek] = getDayOfWeekFormatter().format(date); } // Finding day of month names date.setMonth(0); for (int i = 1; i < MAX_DAYS_IN_MONTH; ++i) { date.setDate(i); dayOfMonthNames[i] = getDayOfMonthFormatter().format(date); } // finding month names date.setDate(1); for (int i = 0; i < MONTHS_IN_YEAR; ++i) { date.setMonth(i); monthOfYearNames[i] = getMonthFormatter().format(date); } }
/** * Format the current month and year in the current locale. For example, "Jan 2013" in English. * * @return the formatted month and year */ public String formatCurrentMonthAndYear() { return getMonthAndYearFormatter().format(getCurrentMonth()); }
/** * Formats the current specified month. For example "September" in English. * * @return the formatted month */ public String formatCurrentMonth() { return getMonthFormatter().format(getCurrentMonth()); }
/** * Formats the current specified year. For example "2012". * * @return the formatted year */ public String formatCurrentYear() { return getYearFormatter().format(getCurrentMonth()); }
@Override public void onChange(ChangeEvent event) { int previousMonth = getModel().getCurrentMonth().getMonth(); int newMonth = monthListBox.getSelectedIndex(); int delta = newMonth - previousMonth; addMonths(delta); } });
/** * Returns {@code true} if the month is before year in the date formatter in current locale. */ protected boolean isMonthBeforeYear() { String monthAndYearPattern = getMonthAndYearFormatter().getPattern(); for (int i = 0; i < monthAndYearPattern.length(); ++i) { switch (monthAndYearPattern.charAt(i)) { case 'y': return false; case 'M': case 'L': return true; } } return true; }
@Override public void refresh() { firstDisplayed = getModel().getCurrentFirstDayOfFirstWeek(); if (firstDisplayed.getDate() == 1) { // show one empty week if date is Monday is the first in month. addDays(firstDisplayed, -7); } lastDisplayed.setTime(firstDisplayed.getTime()); for (int i = 0; i < grid.getNumCells(); i++) { if (i != 0) { addDays(lastDisplayed, 1); } DateCell cell = (DateCell) grid.getCell(i); cell.update(lastDisplayed); } setAriaSelectedCell(null); }