aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/ui/AbstractComponent.java
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2008-01-31 10:53:52 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2008-01-31 10:53:52 +0000
commit09837a9ad03cd073436c73359886e29176b805b9 (patch)
treefd7a317e1b3db81f3406f06bfea307881d82dc30 /src/com/itmill/toolkit/ui/AbstractComponent.java
parente6f54593975a695ae71090902df051771799e979 (diff)
downloadvaadin-framework-09837a9ad03cd073436c73359886e29176b805b9.tar.gz
vaadin-framework-09837a9ad03cd073436c73359886e29176b805b9.zip
setWidth(String) and setHeight(String) methods added to Sizeable
svn changeset:3680/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/ui/AbstractComponent.java')
-rw-r--r--src/com/itmill/toolkit/ui/AbstractComponent.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/com/itmill/toolkit/ui/AbstractComponent.java b/src/com/itmill/toolkit/ui/AbstractComponent.java
index 137e48a0c2..dc305af320 100644
--- a/src/com/itmill/toolkit/ui/AbstractComponent.java
+++ b/src/com/itmill/toolkit/ui/AbstractComponent.java
@@ -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