]> source.dussan.org Git - vaadin-framework.git/commitdiff
setWidth(String) and setHeight(String) methods added to Sizeable
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 31 Jan 2008 10:53:52 +0000 (10:53 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 31 Jan 2008 10:53:52 +0000 (10:53 +0000)
svn changeset:3680/svn branch:trunk

src/com/itmill/toolkit/terminal/Sizeable.java
src/com/itmill/toolkit/ui/AbstractComponent.java
src/com/itmill/toolkit/ui/CustomComponent.java

index c5cb14acd216eb59a4d309075bc1391228d9b917..b6dbb187adec115db86a26f49a581785c97e0d2f 100644 (file)
@@ -41,12 +41,12 @@ public interface Sizeable {
     public static final int UNITS_EX = 4;
 
     /**
-     * Unit code representing millimetres.
+     * Unit code representing millimeters.
      */
     public static final int UNITS_MM = 5;
 
     /**
-     * Unit code representing centimetres.
+     * Unit code representing centimeters.
      */
     public static final int UNITS_CM = 6;
 
@@ -156,6 +156,22 @@ public interface Sizeable {
      */
     public void setHeightUnits(int units);
 
+    /**
+     * TODO
+     * 
+     * @param height
+     *                in CSS style string representation
+     */
+    public void setHeight(String height);
+
+    /**
+     * TODO
+     * 
+     * @param width
+     *                in CSS style string representation
+     */
+    public void setWidth(String width);
+
     /**
      * Sets the size to 100% x 100%.
      */
index 137e48a0c2be0c44690abba5f87917dcb5596d17..dc305af320ed4d2868e9bafaa0e506546a6c9421 100644 (file)
@@ -1109,4 +1109,49 @@ public abstract class AbstractComponent implements Component, MethodEventSource
         setWidth(width);
         setWidthUnits(unit);
     }
+
+    public void setWidth(String width) {
+        int[] p = parseStringSize(width);
+        setWidth(p[0]);
+        setWidthUnits(p[1]);
+    }
+
+    public void setHeight(String width) {
+        int[] p = parseStringSize(width);
+        setHeight(p[0]);
+        setHeightUnits(p[1]);
+    }
+
+    /*
+     * returns array with size in index 0 unit in index 1
+     */
+    private static int[] parseStringSize(String s) {
+        int[] values = new int[2];
+        s = s.trim();
+        if (s.contains("%")) {
+            values[1] = UNITS_PERCENTAGE;
+            values[0] = (int) Float.parseFloat(s.substring(0, s.indexOf("%")));
+        } else {
+            values[0] = (int) Float.parseFloat(s.substring(0, s.length() - 2));
+            if (s.endsWith("px")) {
+                values[1] = UNITS_PIXELS;
+            } else if (s.endsWith("em")) {
+                values[1] = UNITS_EM;
+            } else if (s.endsWith("ex")) {
+                values[1] = UNITS_EX;
+            } else if (s.endsWith("in")) {
+                values[1] = UNITS_INCH;
+            } else if (s.endsWith("cm")) {
+                values[1] = UNITS_CM;
+            } else if (s.endsWith("mm")) {
+                values[1] = UNITS_MM;
+            } else if (s.endsWith("pt")) {
+                values[1] = UNITS_POINTS;
+            } else if (s.endsWith("pc")) {
+                values[1] = UNITS_PICAS;
+            }
+        }
+        return values;
+    }
+
 }
\ No newline at end of file
index 27c99f2f5c204b3a07eb47ee9e2cc1f7605dd2b0..ef531aa12f33076f4f62757890455aeb43ba0504 100644 (file)
@@ -559,4 +559,14 @@ public class CustomComponent implements Component {
 
     }
 
+    public void setHeight(String height) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setWidth(String width) {
+        // TODO Auto-generated method stub
+
+    }
+
 }