Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DatePicker:

- Simplified DefaultCalendarView changes
- Added to the showcase
  • Loading branch information...
commit bdaedfffbe3d7782c8d788a8e8db7ada79fd8999 1 parent 028c521
@ctasada authored
View
55 gwt-eureka/src/main/java/com/blogspot/ctasada/gwt/eureka/client/ui/ExtendedDatePicker.java
@@ -12,11 +12,12 @@
import com.google.gwt.user.datepicker.client.MonthSelector;
/**
- * This extended DatePicker uses a modified DatePicker source code. In this way we can add some extra features.
+ * This extended DatePicker uses a modified DatePicker source code. In this way
+ * we can add some extra features.
*
- * <li> Indicate the first day of the week, independently of the i18 format
- * <li> Indicate a minimum valid date for the calendar
- * <li> Indicate a maximum valid date for the calendar
+ * <li>Indicate the first day of the week, independently of the i18 format <li>
+ * Indicate a minimum valid date for the calendar <li>Indicate a maximum valid
+ * date for the calendar
*
* @author Carlos Tasada
*/
@@ -37,14 +38,54 @@ public ExtendedDatePicker() {
public ExtendedDatePicker(int firstDayOfWeek) {
this(firstDayOfWeek, null, null);
}
-
+
+ /**
+ * Constructor.
+ *
+ * @param firstDayofWeek
+ * First Day of the Week (0 - Sunday, 1 - Monday, ...).
+ *
+ * @param minDate
+ * Minimum allowed date.
+ * @param maxDate
+ * Maximum allowed date.
+ */
public ExtendedDatePicker(int firstDayOfWeek, Date minDate, Date maxDate) {
- super(new DefaultMonthSelector(), new DefaultCalendarView(
- firstDayOfWeek, minDate, maxDate), new CalendarModel());
+ super(new DefaultMonthSelector(), new DefaultCalendarView(minDate,
+ maxDate), new ExtendedCalendarModel(firstDayOfWeek));
}
public ExtendedDatePicker(MonthSelector monthSelector, CalendarView view,
CalendarModel model) {
super(monthSelector, view, model);
}
+
+ public static class ExtendedCalendarModel extends CalendarModel {
+ public static final int MILLIS_IN_A_SECOND = 1000;
+ public static final long MILLIS_IN_A_DAY = MILLIS_IN_A_SECOND * 60 * 60 * 24;
+
+ private int firstDayofWeek = 1;
+
+ public ExtendedCalendarModel() {
+ super();
+ }
+
+ /**
+ *
+ * @param firstDayofWeek
+ * First Day of the Week (0 - Sunday, 1 - Monday, ...).
+ */
+ public ExtendedCalendarModel(int firstDayofWeek) {
+ this.firstDayofWeek = firstDayofWeek;
+ }
+
+ @Override
+ public Date getCurrentFirstDayOfFirstWeek() {
+ Date firstDisplayed = super.getCurrentFirstDayOfFirstWeek();
+ Date d = new Date(firstDisplayed.getTime()
+ + (firstDayofWeek * MILLIS_IN_A_DAY));
+
+ return d;
+ }
+ }
}
View
45 gwt-eureka/src/main/java/com/google/gwt/user/datepicker/client/DefaultCalendarView.java
@@ -15,26 +15,23 @@
*/
package com.google.gwt.user.datepicker.client;
+import java.util.Date;
+
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
import com.google.gwt.user.datepicker.client.DefaultCalendarView.CellGrid.DateCell;
-import java.util.Date;
-
/**
* Simple calendar view. Not extensible as we wish to evolve it freely over
* time.
*
- * TODO: Needs to be kept in sync with original Google class. FIXME: Overload
- * Constructor and whole class just to configure the first day of the week :(
+ * TODO: Needs to be kept in sync with original Google class.
+ * FIXME: Overload Constructor and whole class just to configure the days should be disabled :(
*/
@SuppressWarnings(/* Date manipulation required */{"deprecation"})
public final class DefaultCalendarView extends CalendarView {
-
- public static final int MILLIS_IN_A_SECOND = 1000;
- public static final long MILLIS_IN_A_DAY = MILLIS_IN_A_SECOND * 60 * 60 * 24;
/**
* Cell grid.
@@ -92,8 +89,8 @@ public void removeStyleName(String styleName) {
}
public void update(Date current) {
- // * Another Tweak *//
- setEnabled(getDatePicker().isDateEnabled(current));
+ // * Another Tweak *//
+ setEnabled(getDatePicker().isDateEnabled(current));
getValue().setTime(current.getTime());
String value = getModel().formatDayOfMonth(getValue());
setText(value);
@@ -149,7 +146,6 @@ protected void onSelected(Cell lastSelected, Cell cell) {
private Date lastDisplayed = new Date();
- private int firstDayofWeek = 1;
private Date minDate = null;
private Date maxDate = null;
@@ -159,20 +155,16 @@ protected void onSelected(Cell lastSelected, Cell cell) {
public DefaultCalendarView() {
}
- // FIXME: Overload Constructor and whole class just to configure the first
- // day of the week :(
+ // FIXME: Overload Constructor and whole class just to configure the days should be disabled :(
/**
* Constructor.
*
- * @param firstDayofWeek
- * First Day of the Week (0 - Sunday, 1 - Monday, ...).
* @param minDate
* Minimum allowed date.
* @param maxDate
* Maximum allowed date.
*/
- public DefaultCalendarView(int firstDayofWeek, Date minDate, Date maxDate) {
- this.firstDayofWeek = firstDayofWeek;
+ public DefaultCalendarView(Date minDate, Date maxDate) {
this.minDate = minDate;
this.maxDate = maxDate;
}
@@ -206,11 +198,6 @@ public boolean isDateEnabled(Date d) {
@Override
public void refresh() {
firstDisplayed = getModel().getCurrentFirstDayOfFirstWeek();
- // //* Here is my change *////
- if (firstDisplayed.getDay() != firstDayofWeek) {
- firstDisplayed = new Date(firstDisplayed.getTime()
- + (firstDayofWeek * MILLIS_IN_A_DAY));
- }
if ((firstDisplayed.getDate() > 1) && (firstDisplayed.getDate() < 7)) {
// show one empty week if date is Monday is the first in month.
@@ -245,16 +232,12 @@ public void setup() {
int weekendStartColumn = -1;
int weekendEndColumn = -1;
- // Set up the day labels.
- for (int i = 0; i < CalendarModel.DAYS_IN_WEEK; i++) {
- int shift = CalendarUtil.getStartingDayOfWeek();
- // //* Here is my change *////
- shift += firstDayofWeek;
- int dayIdx = i + shift;
- if (i + shift >= CalendarModel.DAYS_IN_WEEK) {
- dayIdx = i + shift - CalendarModel.DAYS_IN_WEEK;
- }
- grid.setText(0, i, getModel().formatDayOfWeek(dayIdx));
+ // Set up the day labels.
+ for (int i = 0; i < CalendarModel.DAYS_IN_WEEK; i++) {
+ int shift = CalendarUtil.getStartingDayOfWeek();
+ int dayIdx = i + shift < CalendarModel.DAYS_IN_WEEK ? i + shift : i
+ + shift - CalendarModel.DAYS_IN_WEEK;
+ grid.setText(0, i, getModel().formatDayOfWeek(dayIdx));
if (CalendarUtil.isWeekend(dayIdx)) {
formatter.setStyleName(0, i, css().weekendLabel());
View
100 showcase/src/main/java/com/blogspot/ctasada/gwt/eureka/demo/client/Eureka.java
@@ -2,12 +2,16 @@
import java.util.Date;
+import com.blogspot.ctasada.gwt.eureka.client.ui.ExtendedDatePicker;
import com.blogspot.ctasada.gwt.eureka.client.ui.IOSButton;
import com.blogspot.ctasada.gwt.eureka.client.ui.SmallTimeBox;
import com.blogspot.ctasada.gwt.eureka.client.ui.TimeBox;
import com.blogspot.ctasada.gwt.eureka.demo.client.resources.Resources;
import com.google.gwt.core.client.EntryPoint;
-import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.event.logical.shared.ValueChangeEvent;
+import com.google.gwt.event.logical.shared.ValueChangeHandler;
+import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.i18n.shared.DateTimeFormat.PredefinedFormat;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
@@ -16,8 +20,8 @@
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
-import com.google.gwt.user.client.ui.StackLayoutPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.user.datepicker.client.DatePicker;
/**
* Entry point classes define <code>onModuleLoad()</code>.
@@ -33,48 +37,49 @@ public void onModuleLoad() {
dock.setHeight("300px");
dock.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
dock.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
-
+
dock.add(createHeader(), DockPanel.NORTH);
-
- //StackLayoutPanel stackPanel = new StackLayoutPanel(Unit.EM);
-
+
// Time Picker Examples
dock.add(createTimePicker(), DockPanel.WEST);
// Time Picker Small Examples
dock.add(createSmallTimePicker(), DockPanel.WEST);
// iOSButton Examples
dock.add(createIOSButton(), DockPanel.WEST);
-
+ // DatePicker Examples
+ dock.add(createDatePicker(), DockPanel.WEST);
+
RootPanel.get().add(dock);
}
-
+
private HorizontalPanel createHeader() {
HorizontalPanel hPanel = new HorizontalPanel();
hPanel.setWidth("100%");
hPanel.setHeight("80px");
hPanel.setStyleName("headerBackground");
-
+
Label title = new Label("GWT-Eureka Library");
title.setStyleName("headerFont");
Label subtitle = new Label("Widgets Demo");
subtitle.setStyleName("subheaderFont");
-
+
VerticalPanel vPanel = new VerticalPanel();
vPanel.add(title);
vPanel.add(subtitle);
-
- Anchor link = new Anchor("GWT-Eureka Homepage", "https://github.com/ctasada/GWT-Eureka");
-
+
+ Anchor link = new Anchor("GWT-Eureka Homepage",
+ "https://github.com/ctasada/GWT-Eureka");
+
hPanel.add(vPanel);
hPanel.add(link);
hPanel.setSpacing(20);
-
+
return hPanel;
}
-
+
private VerticalPanel getNewVerticalPanel(String label) {
VerticalPanel vPanel = new VerticalPanel();
- //vPanel.addStyleName("mainBackground");
+ // vPanel.addStyleName("mainBackground");
vPanel.setWidth("100%");
vPanel.setHeight("100%");
vPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
@@ -85,64 +90,93 @@ private VerticalPanel getNewVerticalPanel(String label) {
return vPanel;
}
-
+
@SuppressWarnings("deprecation")
private VerticalPanel createTimePicker() {
VerticalPanel vPanel = getNewVerticalPanel("TimePicker Examples");
-
+
Date now = new Date();
now.setHours(12);
now.setMinutes(0);
-
+
TimeBox timePicker = new TimeBox(now);
vPanel.add(timePicker);
-
+
TimeBox timePicker_readonly = new TimeBox(now);
timePicker_readonly.setReadOnly(true);
vPanel.add(timePicker_readonly);
-
+
TimeBox timePicker_ampm = new TimeBox(now, true);
vPanel.add(timePicker_ampm);
TimeBox timePicker_ampm_readonly = new TimeBox(now, true);
- //timePicker_ampm_readonly.setReadOnly(true);
+ timePicker_ampm_readonly.setReadOnly(true);
vPanel.add(timePicker_ampm_readonly);
-
+
return vPanel;
}
-
+
@SuppressWarnings("deprecation")
private VerticalPanel createSmallTimePicker() {
VerticalPanel vPanel = getNewVerticalPanel("Small TimePicker Examples");
-
+
Date now = new Date();
now.setHours(12);
now.setMinutes(0);
-
+
SmallTimeBox smallTimePicker = new SmallTimeBox(now);
vPanel.add(smallTimePicker);
-
+
SmallTimeBox smallTimePicker_readonly = new SmallTimeBox(now);
smallTimePicker_readonly.setReadOnly(true);
vPanel.add(smallTimePicker_readonly);
-
+
SmallTimeBox smallTimePicker_ampm = new SmallTimeBox(now, true);
vPanel.add(smallTimePicker_ampm);
SmallTimeBox smallTimePicker_ampm_readonly = new SmallTimeBox(now, true);
smallTimePicker_ampm_readonly.setReadOnly(true);
vPanel.add(smallTimePicker_ampm_readonly);
-
+
return vPanel;
}
-
+
private VerticalPanel createIOSButton() {
VerticalPanel vPanel = getNewVerticalPanel("iOSButton Examples");
-
- IOSButton button = new IOSButton(new Image(Resources.INSTANCE.gwtLogo()));
+
+ IOSButton button = new IOSButton(
+ new Image(Resources.INSTANCE.gwtLogo()));
button.setBadge(11);
vPanel.add(button);
+
+ return vPanel;
+ }
+
+ private VerticalPanel createDatePicker() {
+ VerticalPanel vPanel = getNewVerticalPanel("DatePicker Examples");
+ final Label text = new Label();
+
+ Date today = new Date();
+ Date nextWeek = new Date();
+ nextWeek.setDate(today.getDate() + 7);
+
+ ExtendedDatePicker datePicker = new ExtendedDatePicker(0, today,
+ nextWeek);
+ datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
+ @Override
+ public void onValueChange(ValueChangeEvent<Date> event) {
+ Date date = event.getValue();
+ String dateString = DateTimeFormat.getFormat(PredefinedFormat.DATE_MEDIUM).format(date);
+ text.setText(dateString);
+ }
+
+ });
+ vPanel.add(datePicker);
+ vPanel.add(text);
+
+ datePicker.setValue(new Date());
return vPanel;
- }
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.