diff options
Diffstat (limited to 'src/com/vaadin/terminal/gwt/client')
4 files changed, 172 insertions, 114 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java index cb9ffd2c67..85c4124dd4 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java @@ -41,6 +41,8 @@ public class VCalendarPanel extends FlexTable implements MouseListener { private CalendarEntrySource entrySource;
+ private FlexTable days = new FlexTable();
+
/* Needed to identify resolution changes */
private int resolution = VDateField.RESOLUTION_YEAR;
@@ -51,14 +53,13 @@ public class VCalendarPanel extends FlexTable implements MouseListener { datefield = parent;
setStyleName(VDateField.CLASSNAME + "-calendarpanel");
// buildCalendar(true);
- addTableListener(new DateClickListener(this));
+ days.addTableListener(new DateClickListener(this));
}
public VCalendarPanel(VDateField parent, Date min, Date max) {
datefield = parent;
setStyleName(VDateField.CLASSNAME + "-calendarpanel");
- // buildCalendar(true);
- addTableListener(new DateClickListener(this));
+ days.addTableListener(new DateClickListener(this));
}
@@ -82,21 +83,34 @@ public class VCalendarPanel extends FlexTable implements MouseListener { private void clearCalendarBody(boolean remove) {
if (!remove) {
- for (int row = 2; row < 8; row++) {
+ for (int row = 1; row < 7; row++) {
for (int col = 0; col < 7; col++) {
- setHTML(row, col, " ");
+ days.setHTML(row, col, " ");
}
}
- } else if (getRowCount() > 2) {
- while (getRowCount() > 2) {
- removeRow(2);
- }
+ } else if (getRowCount() > 1) {
+ removeRow(1);
+ days.clear();
+
}
}
private void buildCalendarHeader(boolean forceRedraw, boolean needsMonth) {
if (forceRedraw) {
- if (prevMonth == null) { // Only do once
+ if (prevMonth == null) {
+
+ getFlexCellFormatter().setStyleName(0, 0,
+ VDateField.CLASSNAME + "-calendarpanel-prevyear");
+ getFlexCellFormatter().setStyleName(0, 4,
+ VDateField.CLASSNAME + "-calendarpanel-nextyear");
+ getFlexCellFormatter().setStyleName(0, 3,
+ VDateField.CLASSNAME + "-calendarpanel-nextmonth");
+ getFlexCellFormatter().setStyleName(0, 1,
+ VDateField.CLASSNAME + "-calendarpanel-prevmonth");
+
+ getRowFormatter().addStyleName(0,
+ VDateField.CLASSNAME + "-calendarpanel-header");
+
prevYear = new VEventButton();
prevYear.setHTML("«");
prevYear.setStyleName("v-button-prevyear");
@@ -120,10 +134,6 @@ public class VCalendarPanel extends FlexTable implements MouseListener { setWidget(0, 3, nextMonth);
setWidget(0, 1, prevMonth);
}
-
- getFlexCellFormatter().setColSpan(0, 2, 3);
- getRowFormatter().addStyleName(0,
- VDateField.CLASSNAME + "-calendarpanel-header");
} else if (!needsMonth) {
// Remove month traverse buttons
prevMonth.removeMouseListener(this);
@@ -133,34 +143,48 @@ public class VCalendarPanel extends FlexTable implements MouseListener { prevMonth = null;
nextMonth = null;
}
-
- // Print weekday names
- final int firstDay = datefield.getDateTimeService()
- .getFirstDayOfWeek();
- for (int i = 0; i < 7; i++) {
- int day = i + firstDay;
- if (day > 6) {
- day = 0;
- }
- if (datefield.getCurrentResolution() > VDateField.RESOLUTION_MONTH) {
- setHTML(1, i, "<strong>"
- + datefield.getDateTimeService().getShortDay(day)
- + "</strong>");
- } else {
- setHTML(1, i, "");
- }
- }
}
final String monthName = needsMonth ? datefield.getDateTimeService()
.getMonth(datefield.getShowingDate().getMonth()) : "";
final int year = datefield.getShowingDate().getYear() + 1900;
+ getFlexCellFormatter().setStyleName(0, 2,
+ VDateField.CLASSNAME + "-calendarpanel-month");
setHTML(0, 2, "<span class=\"" + VDateField.CLASSNAME
+ "-calendarpanel-month\">" + monthName + " " + year
+ "</span>");
}
private void buildCalendarBody() {
+
+ setWidget(1, 0, days);
+ setCellPadding(0);
+ setCellSpacing(0);
+ getFlexCellFormatter().setColSpan(1, 0, 5);
+ getFlexCellFormatter().setStyleName(1, 0,
+ VDateField.CLASSNAME + "-calendarpanel-body");
+
+ days.getFlexCellFormatter().setStyleName(0, 0, "v-first");
+ days.getFlexCellFormatter().setStyleName(0, 6, "v-last");
+ days.getRowFormatter().setStyleName(0,
+ VDateField.CLASSNAME + "-calendarpanel-weekdays");
+
+ // Print weekday names
+ final int firstDay = datefield.getDateTimeService().getFirstDayOfWeek();
+ for (int i = 0; i < 7; i++) {
+ int day = i + firstDay;
+ if (day > 6) {
+ day = 0;
+ }
+ if (datefield.getCurrentResolution() > VDateField.RESOLUTION_MONTH) {
+ days.setHTML(0, i, "<strong>"
+ + datefield.getDateTimeService().getShortDay(day)
+ + "</strong>");
+ } else {
+ days.setHTML(0, i, "");
+ }
+ }
+
// date actually selected?
Date currentDate = datefield.getCurrentDate();
Date showing = datefield.getShowingDate();
@@ -175,9 +199,9 @@ public class VCalendarPanel extends FlexTable implements MouseListener { int dayCount = 0;
final Date today = new Date();
final Date curr = new Date(datefield.getShowingDate().getTime());
- for (int row = 2; row < 8; row++) {
+ for (int row = 1; row < 7; row++) {
for (int col = 0; col < 7; col++) {
- if (!(row == 2 && col < startWeekDay)) {
+ if (!(row == 1 && col < startWeekDay)) {
if (dayCount < numDays) {
final int selectedDate = ++dayCount;
String title = "";
@@ -215,7 +239,7 @@ public class VCalendarPanel extends FlexTable implements MouseListener { if (title.length() > 0) {
cssClass += " " + baseclass + "-entry";
}
- setHTML(row, col, "<span title=\"" + title
+ days.setHTML(row, col, "<span title=\"" + title
+ "\" class=\"" + cssClass + "\">"
+ selectedDate + "</span>");
} else {
@@ -230,9 +254,10 @@ public class VCalendarPanel extends FlexTable implements MouseListener { private void buildTime(boolean forceRedraw) {
if (time == null) {
time = new VTime(datefield);
- setText(8, 0, ""); // Add new row
- getFlexCellFormatter().setColSpan(8, 0, 7);
- setWidget(8, 0, time);
+ setWidget(2, 0, time);
+ getFlexCellFormatter().setColSpan(2, 0, 5);
+ getFlexCellFormatter().setStyleName(2, 0,
+ VDateField.CLASSNAME + "-calendarpanel-time");
}
time.updateTime(forceRedraw);
}
@@ -418,12 +443,12 @@ public class VCalendarPanel extends FlexTable implements MouseListener { }
public void onCellClicked(SourcesTableEvents sender, int row, int col) {
- if (sender != cal || row < 2 || row > 7
+ if (sender != cal.days || row < 1 || row > 6
|| !cal.datefield.isEnabled() || cal.datefield.isReadonly()) {
return;
}
- final String text = cal.getText(row, col);
+ final String text = cal.days.getText(row, col);
if (text.equals(" ")) {
return;
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDateField.java b/src/com/vaadin/terminal/gwt/client/ui/VDateField.java index fd9e252fb7..07fd9e33cb 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VDateField.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VDateField.java @@ -34,6 +34,19 @@ public class VDateField extends FlowPanel implements Paintable, Field { public static final int RESOLUTION_SEC = 5;
public static final int RESOLUTION_MSEC = 6;
+ static String resolutionToString(int res) {
+ if (res > RESOLUTION_DAY) {
+ return "full";
+ }
+ if (res == RESOLUTION_DAY) {
+ return "day";
+ }
+ if (res == RESOLUTION_MONTH) {
+ return "month";
+ }
+ return "year";
+ }
+
protected int currentResolution = RESOLUTION_YEAR;
protected String currentLocale;
@@ -109,6 +122,10 @@ public class VDateField extends FlowPanel implements Paintable, Field { currentResolution = newResolution;
+ // Add stylename that indicates current resolution
+ setStyleName(CLASSNAME + " " + CLASSNAME + "-"
+ + resolutionToString(currentResolution));
+
final int year = uidl.getIntVariable("year");
final int month = (currentResolution >= RESOLUTION_MONTH) ? uidl
.getIntVariable("month") : -1;
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java index 31004be71d..983b1fb71e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java @@ -50,6 +50,10 @@ public class VPopupCalendar extends VTextualDate implements Paintable, Field, @Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
super.updateFromUIDL(uidl, client);
+ addStyleName(CLASSNAME + "-popupcalendar");
+ popup.setStyleName(VDateField.CLASSNAME + "-popup "
+ + VDateField.CLASSNAME + "-"
+ + resolutionToString(currentResolution));
if (date != null) {
calendar.updateCalendar();
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java index 05128c943b..e8e5fe255a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java @@ -6,11 +6,15 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.Date;
+import com.google.gwt.event.dom.client.BlurEvent;
+import com.google.gwt.event.dom.client.BlurHandler;
+import com.google.gwt.event.dom.client.ChangeEvent;
+import com.google.gwt.event.dom.client.ChangeHandler;
+import com.google.gwt.event.dom.client.FocusEvent;
+import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.TextBox;
-import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.ClientExceptionHandler;
@@ -22,7 +26,7 @@ import com.vaadin.terminal.gwt.client.Paintable; import com.vaadin.terminal.gwt.client.UIDL;
public class VTextualDate extends VDateField implements Paintable, Field,
- ChangeListener, ContainerResizedListener, Focusable {
+ ChangeHandler, ContainerResizedListener, Focusable {
private static final String PARSE_ERROR_CLASSNAME = CLASSNAME
+ "-parseerror";
@@ -44,7 +48,19 @@ public class VTextualDate extends VDateField implements Paintable, Field, text.setStyleName(VTextField.CLASSNAME);
// add datefield spesific style name also
text.addStyleName(CLASSNAME + "-textfield");
- text.addChangeListener(this);
+ text.addChangeHandler(this);
+ text.addFocusHandler(new FocusHandler() {
+ public void onFocus(FocusEvent event) {
+ text.addStyleName(VTextField.CLASSNAME + "-"
+ + VTextField.CLASSNAME_FOCUS);
+ }
+ });
+ text.addBlurHandler(new BlurHandler() {
+ public void onBlur(BlurEvent event) {
+ text.removeStyleName(VTextField.CLASSNAME + "-"
+ + VTextField.CLASSNAME_FOCUS);
+ }
+ });
add(text);
}
@@ -135,85 +151,81 @@ public class VTextualDate extends VDateField implements Paintable, Field, }
- public void onChange(Widget sender) {
- if (sender == text) {
- if (!text.getText().equals("")) {
- try {
- DateTimeFormat format = DateTimeFormat
- .getFormat(getFormatString());
- date = format.parse(text.getText());
- long stamp = date.getTime();
- if (stamp == 0) {
- // If date parsing fails in firefox the stamp will be 0
- date = null;
- addStyleName(PARSE_ERROR_CLASSNAME);
- } else {
- // remove possibly added invalid value indication
- removeStyleName(PARSE_ERROR_CLASSNAME);
- }
- } catch (final Exception e) {
- ClientExceptionHandler.displayError(e.getMessage());
-
- addStyleName(PARSE_ERROR_CLASSNAME);
- // this is a hack that may eventually be removed
- client.updateVariable(id, "lastInvalidDateString", text
- .getText(), false);
+ public void onChange(ChangeEvent event) {
+ if (!text.getText().equals("")) {
+ try {
+ DateTimeFormat format = DateTimeFormat
+ .getFormat(getFormatString());
+ date = format.parse(text.getText());
+ long stamp = date.getTime();
+ if (stamp == 0) {
+ // If date parsing fails in firefox the stamp will be 0
date = null;
+ addStyleName(PARSE_ERROR_CLASSNAME);
+ } else {
+ // remove possibly added invalid value indication
+ removeStyleName(PARSE_ERROR_CLASSNAME);
}
- } else {
+ } catch (final Exception e) {
+ ClientExceptionHandler.displayError(e.getMessage());
+
+ addStyleName(PARSE_ERROR_CLASSNAME);
+ // this is a hack that may eventually be removed
+ client.updateVariable(id, "lastInvalidDateString", text
+ .getText(), false);
date = null;
- // remove possibly added invalid value indication
- removeStyleName(PARSE_ERROR_CLASSNAME);
}
- // always send the date string
- client.updateVariable(id, "dateString", text.getText(), false);
+ } else {
+ date = null;
+ // remove possibly added invalid value indication
+ removeStyleName(PARSE_ERROR_CLASSNAME);
+ }
+ // always send the date string
+ client.updateVariable(id, "dateString", text.getText(), false);
- if (date != null) {
- showingDate = new Date(date.getTime());
- }
+ if (date != null) {
+ showingDate = new Date(date.getTime());
+ }
- // Update variables
- // (only the smallest defining resolution needs to be
- // immediate)
- client.updateVariable(id, "year",
- date != null ? date.getYear() + 1900 : -1,
- currentResolution == VDateField.RESOLUTION_YEAR
+ // Update variables
+ // (only the smallest defining resolution needs to be
+ // immediate)
+ client.updateVariable(id, "year", date != null ? date.getYear() + 1900
+ : -1, currentResolution == VDateField.RESOLUTION_YEAR
+ && immediate);
+ if (currentResolution >= VDateField.RESOLUTION_MONTH) {
+ client.updateVariable(id, "month",
+ date != null ? date.getMonth() + 1 : -1,
+ currentResolution == VDateField.RESOLUTION_MONTH
&& immediate);
- if (currentResolution >= VDateField.RESOLUTION_MONTH) {
- client.updateVariable(id, "month", date != null ? date
- .getMonth() + 1 : -1,
- currentResolution == VDateField.RESOLUTION_MONTH
- && immediate);
- }
- if (currentResolution >= VDateField.RESOLUTION_DAY) {
- client.updateVariable(id, "day", date != null ? date.getDate()
- : -1, currentResolution == VDateField.RESOLUTION_DAY
- && immediate);
- }
- if (currentResolution >= VDateField.RESOLUTION_HOUR) {
- client.updateVariable(id, "hour", date != null ? date
- .getHours() : -1,
- currentResolution == VDateField.RESOLUTION_HOUR
- && immediate);
- }
- if (currentResolution >= VDateField.RESOLUTION_MIN) {
- client.updateVariable(id, "min", date != null ? date
- .getMinutes() : -1,
- currentResolution == VDateField.RESOLUTION_MIN
- && immediate);
- }
- if (currentResolution >= VDateField.RESOLUTION_SEC) {
- client.updateVariable(id, "sec", date != null ? date
- .getSeconds() : -1,
- currentResolution == VDateField.RESOLUTION_SEC
- && immediate);
- }
- if (currentResolution == VDateField.RESOLUTION_MSEC) {
- client.updateVariable(id, "msec",
- date != null ? getMilliseconds() : -1, immediate);
- }
-
}
+ if (currentResolution >= VDateField.RESOLUTION_DAY) {
+ client
+ .updateVariable(id, "day", date != null ? date.getDate()
+ : -1,
+ currentResolution == VDateField.RESOLUTION_DAY
+ && immediate);
+ }
+ if (currentResolution >= VDateField.RESOLUTION_HOUR) {
+ client.updateVariable(id, "hour", date != null ? date.getHours()
+ : -1, currentResolution == VDateField.RESOLUTION_HOUR
+ && immediate);
+ }
+ if (currentResolution >= VDateField.RESOLUTION_MIN) {
+ client.updateVariable(id, "min", date != null ? date.getMinutes()
+ : -1, currentResolution == VDateField.RESOLUTION_MIN
+ && immediate);
+ }
+ if (currentResolution >= VDateField.RESOLUTION_SEC) {
+ client.updateVariable(id, "sec", date != null ? date.getSeconds()
+ : -1, currentResolution == VDateField.RESOLUTION_SEC
+ && immediate);
+ }
+ if (currentResolution == VDateField.RESOLUTION_MSEC) {
+ client.updateVariable(id, "msec", date != null ? getMilliseconds()
+ : -1, immediate);
+ }
+
}
private String cleanFormat(String format) {
|