summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJens Jansson <peppe@vaadin.com>2011-12-21 18:22:58 +0200
committerJens Jansson <peppe@vaadin.com>2011-12-22 12:26:15 +0200
commita327be687e901dec4108da4d3e747ebf8cf833c7 (patch)
tree0cf3bc9a0ae1628ce90917c0d562c2cde02eb1d0 /src
parentd9f5e4c8054fa3d99f30640c9ac44eb8e850fe50 (diff)
downloadvaadin-framework-a327be687e901dec4108da4d3e747ebf8cf833c7.tar.gz
vaadin-framework-a327be687e901dec4108da4d3e747ebf8cf833c7.zip
#8019 Fixed Sizable UNITS to use an Enum Unit instead of constants
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/Sizeable.java150
-rw-r--r--src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java10
-rw-r--r--src/com/vaadin/ui/AbsoluteLayout.java76
-rw-r--r--src/com/vaadin/ui/AbstractComponent.java106
-rw-r--r--src/com/vaadin/ui/AbstractComponentContainer.java16
-rw-r--r--src/com/vaadin/ui/AbstractSplitPanel.java14
-rw-r--r--src/com/vaadin/ui/CustomField.java6
-rw-r--r--src/com/vaadin/ui/LoginForm.java4
8 files changed, 206 insertions, 176 deletions
diff --git a/src/com/vaadin/terminal/Sizeable.java b/src/com/vaadin/terminal/Sizeable.java
index 74fb8eefbb..055c74f20f 100644
--- a/src/com/vaadin/terminal/Sizeable.java
+++ b/src/com/vaadin/terminal/Sizeable.java
@@ -18,71 +18,127 @@ import java.io.Serializable;
public interface Sizeable extends Serializable {
/**
- * Unit code representing pixels.
+ * @deprecated from 7.0, use {@link Unit#PIXELS} instead    
*/
- public static final int UNITS_PIXELS = 0;
+ @Deprecated
+ public static final Unit UNITS_PIXELS = Unit.PIXELS;
/**
- * Unit code representing points (1/72nd of an inch).
+ * @deprecated from 7.0, use {@link Unit#POINTS} instead    
*/
- public static final int UNITS_POINTS = 1;
+ @Deprecated
+ public static final Unit UNITS_POINTS = Unit.POINTS;
/**
- * Unit code representing picas (12 points).
+ * @deprecated from 7.0, use {@link Unit#PICAS} instead    
*/
- public static final int UNITS_PICAS = 2;
+ @Deprecated
+ public static final Unit UNITS_PICAS = Unit.PICAS;
/**
- * Unit code representing the font-size of the relevant font.
+ * @deprecated from 7.0, use {@link Unit#EM} instead    
*/
- public static final int UNITS_EM = 3;
+ @Deprecated
+ public static final Unit UNITS_EM = Unit.EM;
/**
- * Unit code representing the x-height of the relevant font.
+ * @deprecated from 7.0, use {@link Unit#EX} instead    
*/
- public static final int UNITS_EX = 4;
+ @Deprecated
+ public static final Unit UNITS_EX = Unit.EX;
/**
- * Unit code representing millimeters.
+ * @deprecated from 7.0, use {@link Unit#MM} instead    
*/
- public static final int UNITS_MM = 5;
+ @Deprecated
+ public static final Unit UNITS_MM = Unit.MM;
/**
- * Unit code representing centimeters.
+ * @deprecated from 7.0, use {@link Unit#CM} instead    
*/
- public static final int UNITS_CM = 6;
+ @Deprecated
+ public static final Unit UNITS_CM = Unit.CM;
/**
- * Unit code representing inches.
+ * @deprecated from 7.0, use {@link Unit#INCH} instead    
*/
- public static final int UNITS_INCH = 7;
+ @Deprecated
+ public static final Unit UNITS_INCH = Unit.INCH;
/**
- * Unit code representing in percentage of the containing element defined by
- * terminal.
+ * @deprecated from 7.0, use {@link Unit#PERCENTAGE} instead    
*/
- public static final int UNITS_PERCENTAGE = 8;
+ @Deprecated
+ public static final Unit UNITS_PERCENTAGE = Unit.PERCENTAGE;
public static final float SIZE_UNDEFINED = -1;
- /**
- * Textual representations of units symbols. Supported units and their
- * symbols are:
- * <ul>
- * <li>{@link #UNITS_PIXELS}: "px"</li>
- * <li>{@link #UNITS_POINTS}: "pt"</li>
- * <li>{@link #UNITS_PICAS}: "pc"</li>
- * <li>{@link #UNITS_EM}: "em"</li>
- * <li>{@link #UNITS_EX}: "ex"</li>
- * <li>{@link #UNITS_MM}: "mm"</li>
- * <li>{@link #UNITS_CM}. "cm"</li>
- * <li>{@link #UNITS_INCH}: "in"</li>
- * <li>{@link #UNITS_PERCENTAGE}: "%"</li>
- * </ul>
- * These can be used like <code>Sizeable.UNIT_SYMBOLS[UNITS_PIXELS]</code>.
- */
- public static final String[] UNIT_SYMBOLS = { "px", "pt", "pc", "em", "ex",
- "mm", "cm", "in", "%" };
+ public enum Unit {
+ /**
+ * Unit code representing pixels.
+ */
+ PIXELS("px"),
+ /**
+ * Unit code representing points (1/72nd of an inch).
+ */
+ POINTS("pt"),
+ /**
+ * Unit code representing picas (12 points).
+ */
+ PICAS("pc"),
+ /**
+ * Unit code representing the font-size of the relevant font.
+ */
+ EM("em"),
+ /**
+ * Unit code representing the x-height of the relevant font.
+ */
+ EX("ex"),
+ /**
+ * Unit code representing millimeters.
+ */
+ MM("mm"),
+ /**
+ * Unit code representing centimeters.
+ */
+ CM("cm"),
+ /**
+ * Unit code representing inches.
+ */
+ INCH("in"),
+ /**
+ * Unit code representing in percentage of the containing element
+ * defined by terminal.
+ */
+ PERCENTAGE("%");
+
+ private String symbol;
+
+ private Unit(String symbol) {
+ this.symbol = symbol;
+ }
+
+ public String getSymbol() {
+ return symbol;
+ }
+
+ @Override
+ public String toString() {
+ return symbol;
+ }
+
+ public static Unit getUnitFromSymbol(String symbol) {
+ if (symbol == null) {
+ return null;
+ }
+ for (Unit unit : Unit.values()) {
+ if (symbol.equals(unit.getSymbol())) {
+ return unit;
+ }
+ }
+ return null;
+ }
+ }
/**
* Gets the width of the object. Negative number implies unspecified size
@@ -105,14 +161,14 @@ public interface Sizeable extends Serializable {
*
* @return units used in width property.
*/
- public int getWidthUnits();
+ public Unit getWidthUnits();
/**
* Gets the height property units.
*
* @return units used in height property.
*/
- public int getHeightUnits();
+ public Unit getHeightUnits();
/**
* Sets the height of the component using String presentation.
@@ -139,13 +195,9 @@ public interface Sizeable extends Serializable {
* @param width
* the width of the object.
* @param unit
- * the unit used for the width. Possible values include
- * {@link #UNITS_PIXELS}, {@link #UNITS_POINTS},
- * {@link #UNITS_PICAS}, {@link #UNITS_EM}, {@link #UNITS_EX},
- * {@link #UNITS_MM}, {@link #UNITS_CM}, {@link #UNITS_INCH},
- * {@link #UNITS_PERCENTAGE}.
+ * the unit used for the width.
*/
- public void setWidth(float width, int unit);
+ public void setWidth(float width, Unit unit);
/**
* Sets the height of the object. Negative number implies unspecified size
@@ -154,13 +206,9 @@ public interface Sizeable extends Serializable {
* @param height
* the height of the object.
* @param unit
- * the unit used for the width. Possible values include
- * {@link #UNITS_PIXELS}, {@link #UNITS_POINTS},
- * {@link #UNITS_PICAS}, {@link #UNITS_EM}, {@link #UNITS_EX},
- * {@link #UNITS_MM}, {@link #UNITS_CM}, {@link #UNITS_INCH},
- * {@link #UNITS_PERCENTAGE}.
+ * the unit used for the width.
*/
- public void setHeight(float height, int unit);
+ public void setHeight(float height, Unit unit);
/**
* Sets the width of the component using String presentation.
diff --git a/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java b/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java
index 97ae19a8dd..fad5220eb7 100644
--- a/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java
+++ b/src/com/vaadin/terminal/gwt/server/ComponentSizeValidator.java
@@ -16,7 +16,7 @@ import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
-import com.vaadin.terminal.Sizeable;
+import com.vaadin.terminal.Sizeable.Unit;
import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
@@ -314,7 +314,7 @@ public class ComponentSizeValidator implements Serializable {
width += "MAIN WINDOW";
} else if (component.getWidth() >= 0) {
width += "ABSOLUTE, " + component.getWidth() + " "
- + Sizeable.UNIT_SYMBOLS[component.getWidthUnits()];
+ + component.getWidthUnits().getSymbol();
} else {
width += "UNDEFINED";
}
@@ -330,7 +330,7 @@ public class ComponentSizeValidator implements Serializable {
height += "MAIN WINDOW";
} else if (component.getHeight() > 0) {
height += "ABSOLUTE, " + component.getHeight() + " "
- + Sizeable.UNIT_SYMBOLS[component.getHeightUnits()];
+ + component.getHeightUnits().getSymbol();
} else {
height += "UNDEFINED";
}
@@ -477,7 +477,7 @@ public class ComponentSizeValidator implements Serializable {
}
private static boolean hasRelativeHeight(Component component) {
- return (component.getHeightUnits() == Sizeable.UNITS_PERCENTAGE && component
+ return (component.getHeightUnits() == Unit.PERCENTAGE && component
.getHeight() > 0);
}
@@ -493,7 +493,7 @@ public class ComponentSizeValidator implements Serializable {
private static boolean hasRelativeWidth(Component paintable) {
return paintable.getWidth() > 0
- && paintable.getWidthUnits() == Sizeable.UNITS_PERCENTAGE;
+ && paintable.getWidthUnits() == Unit.PERCENTAGE;
}
public static boolean parentCanDefineWidth(Component component) {
diff --git a/src/com/vaadin/ui/AbsoluteLayout.java b/src/com/vaadin/ui/AbsoluteLayout.java
index 7872e05774..3bea3b0847 100644
--- a/src/com/vaadin/ui/AbsoluteLayout.java
+++ b/src/com/vaadin/ui/AbsoluteLayout.java
@@ -176,10 +176,10 @@ public class AbsoluteLayout extends AbstractLayout implements
private Float bottomValue = null;
private Float leftValue = null;
- private int topUnits;
- private int rightUnits;
- private int bottomUnits;
- private int leftUnits;
+ private Unit topUnits;
+ private Unit rightUnits;
+ private Unit bottomUnits;
+ private Unit leftUnits;
/**
* Sets the position attributes using CSS syntax. Attributes not
@@ -193,7 +193,7 @@ public class AbsoluteLayout extends AbstractLayout implements
*/
public void setCSSString(String css) {
topValue = rightValue = bottomValue = leftValue = null;
- topUnits = rightUnits = bottomUnits = leftUnits = 0;
+ topUnits = rightUnits = bottomUnits = leftUnits = null;
zIndex = -1;
if (css == null) {
return;
@@ -215,24 +215,25 @@ public class AbsoluteLayout extends AbstractLayout implements
} else {
value = "";
}
- String unit = value.replaceAll("[0-9\\.\\-]+", "");
- if (!unit.equals("")) {
- value = value.substring(0, value.indexOf(unit)).trim();
+ String symbol = value.replaceAll("[0-9\\.\\-]+", "");
+ if (!symbol.equals("")) {
+ value = value.substring(0, value.indexOf(symbol))
+ .trim();
}
float v = Float.parseFloat(value);
- int unitInt = parseCssUnit(unit);
+ Unit unit = Unit.getUnitFromSymbol(symbol);
if (key.equals("top")) {
topValue = v;
- topUnits = unitInt;
+ topUnits = unit;
} else if (key.equals("right")) {
rightValue = v;
- rightUnits = unitInt;
+ rightUnits = unit;
} else if (key.equals("bottom")) {
bottomValue = v;
- bottomUnits = unitInt;
+ bottomUnits = unit;
} else if (key.equals("left")) {
leftValue = v;
- leftUnits = unitInt;
+ leftUnits = unit;
}
}
}
@@ -240,23 +241,6 @@ public class AbsoluteLayout extends AbstractLayout implements
}
/**
- * Parses a string and checks if a unit is found. If a unit is not found
- * from the string the unit pixels is used.
- *
- * @param string
- * The string to parse the unit from
- * @return The found unit
- */
- private int parseCssUnit(String string) {
- for (int i = 0; i < UNIT_SYMBOLS.length; i++) {
- if (UNIT_SYMBOLS[i].equals(string)) {
- return i;
- }
- }
- return 0; // defaults to px (eg. top:0;)
- }
-
- /**
* Converts the internal values into a valid CSS string.
*
* @return A valid CSS string
@@ -264,16 +248,16 @@ public class AbsoluteLayout extends AbstractLayout implements
public String getCSSString() {
String s = "";
if (topValue != null) {
- s += "top:" + topValue + UNIT_SYMBOLS[topUnits] + ";";
+ s += "top:" + topValue + topUnits.getSymbol() + ";";
}
if (rightValue != null) {
- s += "right:" + rightValue + UNIT_SYMBOLS[rightUnits] + ";";
+ s += "right:" + rightValue + rightUnits.getSymbol() + ";";
}
if (bottomValue != null) {
- s += "bottom:" + bottomValue + UNIT_SYMBOLS[bottomUnits] + ";";
+ s += "bottom:" + bottomValue + bottomUnits.getSymbol() + ";";
}
if (leftValue != null) {
- s += "left:" + leftValue + UNIT_SYMBOLS[leftUnits] + ";";
+ s += "left:" + leftValue + leftUnits.getSymbol() + ";";
}
if (zIndex >= 0) {
s += "z-index:" + zIndex + ";";
@@ -291,7 +275,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* The unit of the 'top' attribute. See UNIT_SYMBOLS for a
* description of the available units.
*/
- public void setTop(Float topValue, int topUnits) {
+ public void setTop(Float topValue, Unit topUnits) {
this.topValue = topValue;
this.topUnits = topUnits;
requestRepaint();
@@ -307,7 +291,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* The unit of the 'right' attribute. See UNIT_SYMBOLS for a
* description of the available units.
*/
- public void setRight(Float rightValue, int rightUnits) {
+ public void setRight(Float rightValue, Unit rightUnits) {
this.rightValue = rightValue;
this.rightUnits = rightUnits;
requestRepaint();
@@ -323,7 +307,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* The unit of the 'bottom' attribute. See UNIT_SYMBOLS for a
* description of the available units.
*/
- public void setBottom(Float bottomValue, int bottomUnits) {
+ public void setBottom(Float bottomValue, Unit bottomUnits) {
this.bottomValue = bottomValue;
this.bottomUnits = bottomUnits;
requestRepaint();
@@ -339,7 +323,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* The unit of the 'left' attribute. See UNIT_SYMBOLS for a
* description of the available units.
*/
- public void setLeft(Float leftValue, int leftUnits) {
+ public void setLeft(Float leftValue, Unit leftUnits) {
this.leftValue = leftValue;
this.leftUnits = leftUnits;
requestRepaint();
@@ -456,7 +440,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* @return See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public int getTopUnits() {
+ public Unit getTopUnits() {
return topUnits;
}
@@ -467,7 +451,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public void setTopUnits(int topUnits) {
+ public void setTopUnits(Unit topUnits) {
this.topUnits = topUnits;
requestRepaint();
}
@@ -478,7 +462,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* @return See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public int getRightUnits() {
+ public Unit getRightUnits() {
return rightUnits;
}
@@ -489,7 +473,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public void setRightUnits(int rightUnits) {
+ public void setRightUnits(Unit rightUnits) {
this.rightUnits = rightUnits;
requestRepaint();
}
@@ -500,7 +484,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* @return See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public int getBottomUnits() {
+ public Unit getBottomUnits() {
return bottomUnits;
}
@@ -511,7 +495,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public void setBottomUnits(int bottomUnits) {
+ public void setBottomUnits(Unit bottomUnits) {
this.bottomUnits = bottomUnits;
requestRepaint();
}
@@ -522,7 +506,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* @return See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public int getLeftUnits() {
+ public Unit getLeftUnits() {
return leftUnits;
}
@@ -533,7 +517,7 @@ public class AbsoluteLayout extends AbstractLayout implements
* See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public void setLeftUnits(int leftUnits) {
+ public void setLeftUnits(Unit leftUnits) {
this.leftUnits = leftUnits;
requestRepaint();
}
diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java
index 70d7fe32a9..7462aab3a5 100644
--- a/src/com/vaadin/ui/AbstractComponent.java
+++ b/src/com/vaadin/ui/AbstractComponent.java
@@ -140,8 +140,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource
private float width = SIZE_UNDEFINED;
private float height = SIZE_UNDEFINED;
- private int widthUnit = UNITS_PIXELS;
- private int heightUnit = UNITS_PIXELS;
+ private Unit widthUnit = Unit.PIXELS;
+ private Unit heightUnit = Unit.PIXELS;
private static final Pattern sizePattern = Pattern
.compile("^(-?\\d+(\\.\\d+)?)(%|px|em|ex|in|cm|mm|pt|pc)?$");
@@ -743,13 +743,13 @@ public abstract class AbstractComponent implements Component, MethodEventSource
// Only paint content of visible components.
if (isVisible()) {
if (getHeight() >= 0
- && (getHeightUnits() != UNITS_PERCENTAGE || ComponentSizeValidator
+ && (getHeightUnits() != Unit.PERCENTAGE || ComponentSizeValidator
.parentCanDefineHeight(this))) {
target.addAttribute("height", "" + getCSSHeight());
}
if (getWidth() >= 0
- && (getWidthUnits() != UNITS_PERCENTAGE || ComponentSizeValidator
+ && (getWidthUnits() != Unit.PERCENTAGE || ComponentSizeValidator
.parentCanDefineWidth(this))) {
target.addAttribute("width", "" + getCSSWidth());
}
@@ -807,10 +807,10 @@ public abstract class AbstractComponent implements Component, MethodEventSource
* @return CSS height
*/
private String getCSSHeight() {
- if (getHeightUnits() == UNITS_PIXELS) {
- return ((int) getHeight()) + UNIT_SYMBOLS[getHeightUnits()];
+ if (getHeightUnits() == Unit.PIXELS) {
+ return ((int) getHeight()) + getHeightUnits().getSymbol();
} else {
- return getHeight() + UNIT_SYMBOLS[getHeightUnits()];
+ return getHeight() + getHeightUnits().getSymbol();
}
}
@@ -820,10 +820,10 @@ public abstract class AbstractComponent implements Component, MethodEventSource
* @return CSS width
*/
private String getCSSWidth() {
- if (getWidthUnits() == UNITS_PIXELS) {
- return ((int) getWidth()) + UNIT_SYMBOLS[getWidthUnits()];
+ if (getWidthUnits() == Unit.PIXELS) {
+ return ((int) getWidth()) + getWidthUnits().getSymbol();
} else {
- return getWidth() + UNIT_SYMBOLS[getWidthUnits()];
+ return getWidth() + getWidthUnits().getSymbol();
}
}
@@ -1299,7 +1299,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
*
* @see com.vaadin.terminal.Sizeable#getHeightUnits()
*/
- public int getHeightUnits() {
+ public Unit getHeightUnits() {
return heightUnit;
}
@@ -1317,7 +1317,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
*
* @see com.vaadin.terminal.Sizeable#getWidthUnits()
*/
- public int getWidthUnits() {
+ public Unit getWidthUnits() {
return widthUnit;
}
@@ -1326,7 +1326,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
*
* @see com.vaadin.terminal.Sizeable#setHeight(float, int)
*/
- public void setHeight(float height, int unit) {
+ public void setHeight(float height, Unit unit) {
this.height = height;
heightUnit = unit;
requestRepaint();
@@ -1339,8 +1339,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource
* @see com.vaadin.terminal.Sizeable#setSizeFull()
*/
public void setSizeFull() {
- setWidth(100, UNITS_PERCENTAGE);
- setHeight(100, UNITS_PERCENTAGE);
+ setWidth(100, Unit.PERCENTAGE);
+ setHeight(100, Unit.PERCENTAGE);
}
/*
@@ -1349,8 +1349,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource
* @see com.vaadin.terminal.Sizeable#setSizeUndefined()
*/
public void setSizeUndefined() {
- setWidth(-1, UNITS_PIXELS);
- setHeight(-1, UNITS_PIXELS);
+ setWidth(-1, Unit.PIXELS);
+ setHeight(-1, Unit.PIXELS);
}
/*
@@ -1358,7 +1358,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
*
* @see com.vaadin.terminal.Sizeable#setWidth(float, int)
*/
- public void setWidth(float width, int unit) {
+ public void setWidth(float width, Unit unit) {
this.width = width;
widthUnit = unit;
requestRepaint();
@@ -1371,8 +1371,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource
* @see com.vaadin.terminal.Sizeable#setWidth(java.lang.String)
*/
public void setWidth(String width) {
- float[] p = parseStringSize(width);
- setWidth(p[0], (int) p[1]);
+ Size size = parseStringSize(width);
+ setWidth(size.getSize(), size.getUnit());
}
/*
@@ -1381,58 +1381,56 @@ public abstract class AbstractComponent implements Component, MethodEventSource
* @see com.vaadin.terminal.Sizeable#setHeight(java.lang.String)
*/
public void setHeight(String height) {
- float[] p = parseStringSize(height);
- setHeight(p[0], (int) p[1]);
+ Size size = parseStringSize(height);
+ setHeight(size.getSize(), size.getUnit());
}
/*
* Returns array with size in index 0 unit in index 1. Null or empty string
- * will produce {-1,UNITS_PIXELS}
+ * will produce {-1,Unit#PIXELS}
*/
- private static float[] parseStringSize(String s) {
- float[] values = { -1, UNITS_PIXELS };
+ private static Size parseStringSize(String s) {
if (s == null) {
- return values;
+ return null;
}
s = s.trim();
if ("".equals(s)) {
- return values;
+ return null;
}
-
+ float size = 0;
+ Unit unit = null;
Matcher matcher = sizePattern.matcher(s);
if (matcher.find()) {
- values[0] = Float.parseFloat(matcher.group(1));
- if (values[0] < 0) {
- values[0] = -1;
+ size = Float.parseFloat(matcher.group(1));
+ if (size < 0) {
+ size = -1;
} else {
- String unit = matcher.group(3);
- if (unit == null) {
- values[1] = UNITS_PIXELS;
- } else if (unit.equals("px")) {
- values[1] = UNITS_PIXELS;
- } else if (unit.equals("%")) {
- values[1] = UNITS_PERCENTAGE;
- } else if (unit.equals("em")) {
- values[1] = UNITS_EM;
- } else if (unit.equals("ex")) {
- values[1] = UNITS_EX;
- } else if (unit.equals("in")) {
- values[1] = UNITS_INCH;
- } else if (unit.equals("cm")) {
- values[1] = UNITS_CM;
- } else if (unit.equals("mm")) {
- values[1] = UNITS_MM;
- } else if (unit.equals("pt")) {
- values[1] = UNITS_POINTS;
- } else if (unit.equals("pc")) {
- values[1] = UNITS_PICAS;
- }
+ String symbol = matcher.group(3);
+ unit = Unit.getUnitFromSymbol(symbol);
}
} else {
throw new IllegalArgumentException("Invalid size argument: \"" + s
+ "\" (should match " + sizePattern.pattern() + ")");
}
- return values;
+ return new Size(size, unit);
+ }
+
+ private static class Size {
+ float size;
+ Unit unit;
+
+ public Size(float size, Unit unit) {
+ this.size = size;
+ this.unit = unit;
+ }
+
+ public float getSize() {
+ return size;
+ }
+
+ public Unit getUnit() {
+ return unit;
+ }
}
public interface ComponentErrorEvent extends Terminal.ErrorEvent {
diff --git a/src/com/vaadin/ui/AbstractComponentContainer.java b/src/com/vaadin/ui/AbstractComponentContainer.java
index 5d5218307a..bbe2c20ea5 100644
--- a/src/com/vaadin/ui/AbstractComponentContainer.java
+++ b/src/com/vaadin/ui/AbstractComponentContainer.java
@@ -226,7 +226,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent
}
@Override
- public void setWidth(float width, int unit) {
+ public void setWidth(float width, Unit unit) {
/*
* child tree repaints may be needed, due to our fall back support for
* invalid relative sizes
@@ -237,9 +237,9 @@ public abstract class AbstractComponentContainer extends AbstractComponent
// children currently in invalid state may need repaint
dirtyChildren = getInvalidSizedChildren(false);
} else if ((width == SIZE_UNDEFINED && getWidth() != SIZE_UNDEFINED)
- || (unit == UNITS_PERCENTAGE
- && getWidthUnits() != UNITS_PERCENTAGE && !ComponentSizeValidator
- .parentCanDefineWidth(this))) {
+ || (unit == Unit.PERCENTAGE
+ && getWidthUnits() != Unit.PERCENTAGE && !ComponentSizeValidator
+ .parentCanDefineWidth(this))) {
/*
* relative width children may get to invalid state if width becomes
* invalid. Width may also become invalid if units become percentage
@@ -326,7 +326,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent
}
@Override
- public void setHeight(float height, int unit) {
+ public void setHeight(float height, Unit unit) {
/*
* child tree repaints may be needed, due to our fall back support for
* invalid relative sizes
@@ -337,9 +337,9 @@ public abstract class AbstractComponentContainer extends AbstractComponent
// children currently in invalid state may need repaint
dirtyChildren = getInvalidSizedChildren(true);
} else if ((height == SIZE_UNDEFINED && getHeight() != SIZE_UNDEFINED)
- || (unit == UNITS_PERCENTAGE
- && getHeightUnits() != UNITS_PERCENTAGE && !ComponentSizeValidator
- .parentCanDefineHeight(this))) {
+ || (unit == Unit.PERCENTAGE
+ && getHeightUnits() != Unit.PERCENTAGE && !ComponentSizeValidator
+ .parentCanDefineHeight(this))) {
/*
* relative height children may get to invalid state if height
* becomes invalid. Height may also become invalid if units become
diff --git a/src/com/vaadin/ui/AbstractSplitPanel.java b/src/com/vaadin/ui/AbstractSplitPanel.java
index adb84f9d9d..e0a2d24aaa 100644
--- a/src/com/vaadin/ui/AbstractSplitPanel.java
+++ b/src/com/vaadin/ui/AbstractSplitPanel.java
@@ -37,7 +37,7 @@ public abstract class AbstractSplitPanel extends AbstractLayout {
private int pos = 50;
- private int posUnit = UNITS_PERCENTAGE;
+ private Unit posUnit = Unit.PERCENTAGE;
private boolean posReversed = false;
@@ -209,7 +209,7 @@ public abstract class AbstractSplitPanel extends AbstractLayout {
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
- final String position = pos + UNIT_SYMBOLS[posUnit];
+ final String position = pos + posUnit.getSymbol();
target.addAttribute("position", position);
@@ -278,7 +278,7 @@ public abstract class AbstractSplitPanel extends AbstractLayout {
* @param unit
* the unit (from {@link Sizeable}) in which the size is given.
*/
- public void setSplitPosition(int pos, int unit) {
+ public void setSplitPosition(int pos, Unit unit) {
setSplitPosition(pos, unit, true, false);
}
@@ -294,7 +294,7 @@ public abstract class AbstractSplitPanel extends AbstractLayout {
* second region else it is measured by the first region
*
*/
- public void setSplitPosition(int pos, int unit, boolean reverse) {
+ public void setSplitPosition(int pos, Unit unit, boolean reverse) {
setSplitPosition(pos, unit, true, reverse);
}
@@ -313,7 +313,7 @@ public abstract class AbstractSplitPanel extends AbstractLayout {
*
* @return unit of position of the splitter
*/
- public int getSplitPositionUnit() {
+ public Unit getSplitPositionUnit() {
return posUnit;
}
@@ -329,9 +329,9 @@ public abstract class AbstractSplitPanel extends AbstractLayout {
* position info has come from the client side, thus it already
* knows the position.
*/
- private void setSplitPosition(int pos, int unit, boolean repaintNeeded,
+ private void setSplitPosition(int pos, Unit unit, boolean repaintNeeded,
boolean reverse) {
- if (unit != UNITS_PERCENTAGE && unit != UNITS_PIXELS) {
+ if (unit != Unit.PERCENTAGE && unit != Unit.PIXELS) {
throw new IllegalArgumentException(
"Only percentage and pixel units are allowed");
}
diff --git a/src/com/vaadin/ui/CustomField.java b/src/com/vaadin/ui/CustomField.java
index bb5f154f22..72f863ca8b 100644
--- a/src/com/vaadin/ui/CustomField.java
+++ b/src/com/vaadin/ui/CustomField.java
@@ -55,7 +55,7 @@ public abstract class CustomField<T> extends AbstractField<T> implements
*/
public CustomField() {
// expand horizontally by default
- setWidth(100, UNITS_PERCENTAGE);
+ setWidth(100, Unit.PERCENTAGE);
}
/**
@@ -138,13 +138,13 @@ public abstract class CustomField<T> extends AbstractField<T> implements
// AbstractComponentContainer
@Override
- public void setHeight(float height, int unit) {
+ public void setHeight(float height, Unit unit) {
super.setHeight(height, unit);
requestContentRepaint();
}
@Override
- public void setWidth(float height, int unit) {
+ public void setWidth(float height, Unit unit) {
super.setWidth(height, unit);
requestContentRepaint();
}
diff --git a/src/com/vaadin/ui/LoginForm.java b/src/com/vaadin/ui/LoginForm.java
index 369bc45fe4..7eaeb824c9 100644
--- a/src/com/vaadin/ui/LoginForm.java
+++ b/src/com/vaadin/ui/LoginForm.java
@@ -263,7 +263,7 @@ public class LoginForm extends CustomComponent {
}
@Override
- public void setWidth(float width, int unit) {
+ public void setWidth(float width, Unit unit) {
super.setWidth(width, unit);
if (iframe != null) {
if (width < 0) {
@@ -275,7 +275,7 @@ public class LoginForm extends CustomComponent {
}
@Override
- public void setHeight(float height, int unit) {
+ public void setHeight(float height, Unit unit) {
super.setHeight(height, unit);
if (iframe != null) {
if (height < 0) {