]> source.dussan.org Git - vaadin-framework.git/commitdiff
support for non-pixel sizes for window. Fixes #1619
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 9 May 2008 17:52:40 +0000 (17:52 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 9 May 2008 17:52:40 +0000 (17:52 +0000)
svn changeset:4415/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java
src/com/itmill/toolkit/ui/Window.java

index d846960b4d918315e8d35911de5c65719ba74cdb..17f19af5e2619877ebb729a2f7d2b472369fd8ac 100644 (file)
@@ -203,14 +203,16 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener {
             setModal(!modal);
         }
 
-        // Initialize the width from UIDL
+        // Initialize the size from UIDL
+        // FIXME relational size is for outer size, others are applied for
+        // content
         if (uidl.hasVariable("width")) {
             final String width = uidl.getStringVariable("width");
-            setWidth(width);
-        }
-        if (uidl.hasVariable("height")) {
-            final String height = uidl.getStringVariable("height");
-            setHeight(height);
+            if (width.indexOf("px") < 0) {
+                DOM.setStyleAttribute(getElement(), "width", width);
+            } else {
+                setWidth(width);
+            }
         }
 
         // Initialize the position form UIDL
@@ -229,6 +231,26 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener {
             show();
         }
 
+        // Height set after show so we can detect space used by decorations
+        if (uidl.hasVariable("height")) {
+            final String height = uidl.getStringVariable("height");
+            if (height.indexOf("%") > 0) {
+                int winHeight = Window.getClientHeight();
+                float percent = Float.parseFloat(height.substring(0, height
+                        .indexOf("%"))) / 100.0f;
+                int contentPixels = (int) (winHeight * percent);
+                contentPixels -= (DOM.getElementPropertyInt(getElement(),
+                        "offsetHeight") - DOM.getElementPropertyInt(contents,
+                        "offsetHeight"));
+                // FIXME hardcoded contents elements border size
+                contentPixels -= 2;
+
+                setHeight(contentPixels + "px");
+            } else {
+                setHeight(height);
+            }
+        }
+
         if (uidl.hasAttribute("caption")) {
             setCaption(uidl.getStringAttribute("caption"));
         }
index 2c87eab866d2eb7243435226ee60d837d3bafefe..f8d8322d7c420980857eef8d04576956b9ea64eb 100644 (file)
@@ -20,7 +20,6 @@ import com.itmill.toolkit.terminal.PaintException;
 import com.itmill.toolkit.terminal.PaintTarget;
 import com.itmill.toolkit.terminal.ParameterHandler;
 import com.itmill.toolkit.terminal.Resource;
-import com.itmill.toolkit.terminal.Sizeable;
 import com.itmill.toolkit.terminal.Terminal;
 import com.itmill.toolkit.terminal.URIHandler;
 
@@ -723,28 +722,6 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
         terminal = type;
     }
 
-    /**
-     * Window only supports pixels as unit.
-     * 
-     * @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits()
-     */
-    public void setHeightUnits(int units) {
-        if (units != Sizeable.UNITS_PIXELS) {
-            throw new IllegalArgumentException("Only pixels are supported");
-        }
-    }
-
-    /**
-     * Window only supports pixels as unit.
-     * 
-     * @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits()
-     */
-    public void setWidthUnits(int units) {
-        if (units != Sizeable.UNITS_PIXELS) {
-            throw new IllegalArgumentException("Only pixels are supported");
-        }
-    }
-
     /**
      * Private data structure for storing opening window properties.
      */