From: Jouni Koivuviita Date: Thu, 27 Sep 2007 12:58:04 +0000 (+0000) Subject: ICalendarPopup popup position calculations refined (won't go over browser window... X-Git-Tag: 6.7.0.beta1~5947 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=495cb485219b51f07e6e971f98307baac24cf2c5;p=vaadin-framework.git ICalendarPopup popup position calculations refined (won't go over browser window anymore). ITextualDate textfield size now accommodates less space if it only shows date, not date+time. svn changeset:2389/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupCalendar.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupCalendar.java index 07b87a80e9..62885d6578 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupCalendar.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupCalendar.java @@ -1,5 +1,6 @@ package com.itmill.toolkit.terminal.gwt.client.ui; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.ClickListener; import com.google.gwt.user.client.ui.PopupListener; import com.google.gwt.user.client.ui.PopupPanel; @@ -41,10 +42,18 @@ public class IPopupCalendar extends ITextualDate implements Paintable, ClickList public void onClick(Widget sender) { if(sender == calendarToggle) { calendar.updateCalendar(); - popup.setPopupPosition(calendarToggle.getAbsoluteLeft(), calendarToggle.getAbsoluteTop() + calendarToggle.getOffsetHeight() + 2); popup.show(); - popup.setWidth(calendar.getOffsetWidth() + "px"); - popup.setHeight(calendar.getOffsetHeight() + "px"); + int w = calendar.getOffsetWidth(); + int h = calendar.getOffsetHeight(); + int t = calendarToggle.getAbsoluteTop(); + int l = calendarToggle.getAbsoluteLeft(); + if(l+w > Window.getClientWidth()) + l = Window.getClientWidth() - w; + if(t+h > Window.getClientHeight()) + t = Window.getClientHeight() - h - calendarToggle.getOffsetHeight() - 2; + popup.setPopupPosition(l, t + calendarToggle.getOffsetHeight() + 2); + popup.setWidth(w + "px"); + popup.setHeight(h + "px"); } } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java index 8eb768b980..7fe11c2cec 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java @@ -39,10 +39,15 @@ public class ITextualDate extends IDateField implements Paintable, ChangeListene DateLocale.SUPPORTED_DF_TOKENS = DateLocale.TOKENS_RESOLUTION_MONTH; else if(currentResolution >= IDateField.RESOLUTION_DAY) DateLocale.SUPPORTED_DF_TOKENS = DateLocale.TOKENS_RESOLUTION_DAY; - - format = new SimpleDateFormat(verifyFormat(dts.getDateFormat())); + + format = new SimpleDateFormat(cleanFormat(dts.getDateFormat())); format.setLocale(dl); + // Size the textfield a bit smaller if no clock time is needed + if(currentResolution <= IDateField.RESOLUTION_DAY) + text.setColumns(12); + + // Create the initial text for the textfield String dateText = ""; if(date != null) { dateText = format.format(date); @@ -90,7 +95,7 @@ public class ITextualDate extends IDateField implements Paintable, ChangeListene else if(currentResolution == IDateField.RESOLUTION_DAY) DateLocale.SUPPORTED_DF_TOKENS = DateLocale.TOKENS_RESOLUTION_DAY; - String f = verifyFormat(dts.getDateFormat()); + String f = cleanFormat(dts.getDateFormat()); if(currentResolution >= IDateField.RESOLUTION_HOUR) f += " " + (dts.isTwelveHourClock()? @@ -127,7 +132,7 @@ public class ITextualDate extends IDateField implements Paintable, ChangeListene // Update variables // (only the smallest defining resolution needs to be immediate) - client.updateVariable(id, "year", date!=null?date.getYear()+1900:-1, currentResolution==IDateField.RESOLUTION_YEAR); + client.updateVariable(id, "year", date!=null?date.getYear()+1900:-1, currentResolution==IDateField.RESOLUTION_YEAR&&immediate); if(currentResolution >= IDateField.RESOLUTION_MONTH) client.updateVariable(id, "month", date!=null?date.getMonth()+1:-1, currentResolution==IDateField.RESOLUTION_MONTH&&immediate); if(currentResolution >= IDateField.RESOLUTION_DAY) @@ -145,7 +150,7 @@ public class ITextualDate extends IDateField implements Paintable, ChangeListene } } - private String verifyFormat(String format) { + private String cleanFormat(String format) { // Remove unnecessary d & M if resolution is too low if(currentResolution < IDateField.RESOLUTION_DAY) format = format.replaceAll("d", "");