]> source.dussan.org Git - vaadin-framework.git/commitdiff
ICalendarPopup popup position calculations refined (won't go over browser window...
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Thu, 27 Sep 2007 12:58:04 +0000 (12:58 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Thu, 27 Sep 2007 12:58:04 +0000 (12:58 +0000)
ITextualDate textfield size now accommodates less space if it only shows date, not date+time.

svn changeset:2389/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupCalendar.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java

index 07b87a80e965d6a67d4b27a08bc8c85c1234b812..62885d657861f0b3646caaaba00fd23da87424fb 100644 (file)
@@ -1,5 +1,6 @@
 package com.itmill.toolkit.terminal.gwt.client.ui;\r
 \r
+import com.google.gwt.user.client.Window;\r
 import com.google.gwt.user.client.ui.ClickListener;\r
 import com.google.gwt.user.client.ui.PopupListener;\r
 import com.google.gwt.user.client.ui.PopupPanel;\r
@@ -41,10 +42,18 @@ public class IPopupCalendar extends ITextualDate implements Paintable, ClickList
        public void onClick(Widget sender) {\r
                if(sender == calendarToggle) {\r
                                calendar.updateCalendar();\r
-                               popup.setPopupPosition(calendarToggle.getAbsoluteLeft(), calendarToggle.getAbsoluteTop() + calendarToggle.getOffsetHeight() + 2);\r
                                popup.show();\r
-                               popup.setWidth(calendar.getOffsetWidth() + "px");\r
-                               popup.setHeight(calendar.getOffsetHeight() + "px");\r
+                               int w = calendar.getOffsetWidth();\r
+                               int h = calendar.getOffsetHeight();\r
+                               int t = calendarToggle.getAbsoluteTop();\r
+                               int l = calendarToggle.getAbsoluteLeft();\r
+                               if(l+w > Window.getClientWidth())\r
+                                       l = Window.getClientWidth() - w;\r
+                               if(t+h > Window.getClientHeight())\r
+                                       t = Window.getClientHeight() - h - calendarToggle.getOffsetHeight() - 2;\r
+                               popup.setPopupPosition(l, t + calendarToggle.getOffsetHeight() + 2);\r
+                               popup.setWidth(w + "px");\r
+                               popup.setHeight(h + "px");\r
                }\r
        }\r
 \r
index 8eb768b980ba1dd936141ce92a67d8f4c69c683e..7fe11c2cecc89c12394c3aea782b4346e57eafc8 100644 (file)
@@ -39,10 +39,15 @@ public class ITextualDate extends IDateField implements Paintable, ChangeListene
                        DateLocale.SUPPORTED_DF_TOKENS = DateLocale.TOKENS_RESOLUTION_MONTH;\r
                else if(currentResolution >= IDateField.RESOLUTION_DAY)\r
                        DateLocale.SUPPORTED_DF_TOKENS = DateLocale.TOKENS_RESOLUTION_DAY;\r
-                       \r
-               format = new SimpleDateFormat(verifyFormat(dts.getDateFormat()));\r
+               \r
+               format = new SimpleDateFormat(cleanFormat(dts.getDateFormat()));\r
                format.setLocale(dl);\r
                \r
+               // Size the textfield a bit smaller if no clock time is needed\r
+               if(currentResolution <= IDateField.RESOLUTION_DAY)\r
+                       text.setColumns(12);\r
+               \r
+               // Create the initial text for the textfield\r
                String dateText = "";\r
                if(date != null) {\r
                        dateText = format.format(date);\r
@@ -90,7 +95,7 @@ public class ITextualDate extends IDateField implements Paintable, ChangeListene
                                else if(currentResolution == IDateField.RESOLUTION_DAY)\r
                                        DateLocale.SUPPORTED_DF_TOKENS = DateLocale.TOKENS_RESOLUTION_DAY;\r
                                \r
-                               String f = verifyFormat(dts.getDateFormat());\r
+                               String f = cleanFormat(dts.getDateFormat());\r
                                \r
                                if(currentResolution >= IDateField.RESOLUTION_HOUR)\r
                                        f += " " + (dts.isTwelveHourClock()?\r
@@ -127,7 +132,7 @@ public class ITextualDate extends IDateField implements Paintable, ChangeListene
                        \r
                        // Update variables\r
                        // (only the smallest defining resolution needs to be immediate)\r
-                       client.updateVariable(id, "year", date!=null?date.getYear()+1900:-1, currentResolution==IDateField.RESOLUTION_YEAR);\r
+                       client.updateVariable(id, "year", date!=null?date.getYear()+1900:-1, currentResolution==IDateField.RESOLUTION_YEAR&&immediate);\r
                        if(currentResolution >= IDateField.RESOLUTION_MONTH)\r
                                client.updateVariable(id, "month", date!=null?date.getMonth()+1:-1, currentResolution==IDateField.RESOLUTION_MONTH&&immediate);\r
                        if(currentResolution >= IDateField.RESOLUTION_DAY)\r
@@ -145,7 +150,7 @@ public class ITextualDate extends IDateField implements Paintable, ChangeListene
                }\r
        }\r
        \r
-       private String verifyFormat(String format) {\r
+       private String cleanFormat(String format) {\r
                // Remove unnecessary d & M if resolution is too low\r
                if(currentResolution < IDateField.RESOLUTION_DAY)\r
                        format = format.replaceAll("d", "");\r