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
*
* @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.
* @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
* @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.
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;
width += "MAIN WINDOW";
} else if (component.getWidth() >= 0) {
width += "ABSOLUTE, " + component.getWidth() + " "
- + Sizeable.UNIT_SYMBOLS[component.getWidthUnits()];
+ + component.getWidthUnits().getSymbol();
} else {
width += "UNDEFINED";
}
height += "MAIN WINDOW";
} else if (component.getHeight() > 0) {
height += "ABSOLUTE, " + component.getHeight() + " "
- + Sizeable.UNIT_SYMBOLS[component.getHeightUnits()];
+ + component.getHeightUnits().getSymbol();
} else {
height += "UNDEFINED";
}
}
private static boolean hasRelativeHeight(Component component) {
- return (component.getHeightUnits() == Sizeable.UNITS_PERCENTAGE && component
+ return (component.getHeightUnits() == Unit.PERCENTAGE && component
.getHeight() > 0);
}
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) {
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
*/
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;
} 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;
}
}
}
requestRepaint();
}
- /**
- * 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.
*
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 + ";";
* 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();
* 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();
* 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();
* 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();
* @return See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public int getTopUnits() {
+ public Unit getTopUnits() {
return topUnits;
}
* 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();
}
* @return See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public int getRightUnits() {
+ public Unit getRightUnits() {
return rightUnits;
}
* 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();
}
* @return See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public int getBottomUnits() {
+ public Unit getBottomUnits() {
return bottomUnits;
}
* 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();
}
* @return See {@link Sizeable} UNIT_SYMBOLS for a description of the
* available units.
*/
- public int getLeftUnits() {
+ public Unit getLeftUnits() {
return leftUnits;
}
* 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();
}
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)?$");
// 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());
}
* @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();
}
}
* @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();
}
}
*
* @see com.vaadin.terminal.Sizeable#getHeightUnits()
*/
- public int getHeightUnits() {
+ public Unit getHeightUnits() {
return heightUnit;
}
*
* @see com.vaadin.terminal.Sizeable#getWidthUnits()
*/
- public int getWidthUnits() {
+ public Unit getWidthUnits() {
return widthUnit;
}
*
* @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();
* @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);
}
/*
* @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);
}
/*
*
* @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();
* @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());
}
/*
* @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 {
}
@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
// 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
}
@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
// 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
private int pos = 50;
- private int posUnit = UNITS_PERCENTAGE;
+ private Unit posUnit = Unit.PERCENTAGE;
private boolean posReversed = false;
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);
* @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);
}
* 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);
}
*
* @return unit of position of the splitter
*/
- public int getSplitPositionUnit() {
+ public Unit getSplitPositionUnit() {
return posUnit;
}
* 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");
}
*/
public CustomField() {
// expand horizontally by default
- setWidth(100, UNITS_PERCENTAGE);
+ setWidth(100, Unit.PERCENTAGE);
}
/**
// 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();
}
}
@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) {
}
@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) {
import junit.framework.TestCase;\r
\r
import com.vaadin.terminal.Sizeable;\r
+import com.vaadin.terminal.Sizeable.Unit;\r
import com.vaadin.ui.AbsoluteLayout;\r
import com.vaadin.ui.Button;\r
\r
private static final String PARTIAL_CSS = "top:7.0px;left:7.0em;";\r
private static final Float CSS_VALUE = Float.valueOf(7);\r
\r
- private static final int UNIT_UNSET = Sizeable.UNITS_PIXELS;\r
+ private static final Unit UNIT_UNSET = Sizeable.Unit.PIXELS;\r
\r
/**\r
* Add component w/o giving positions, assert that everything is unset\r
assertEquals(CSS_VALUE, layout.getPosition(b).getLeftValue());\r
assertEquals(CSS_VALUE, layout.getPosition(b).getRightValue());\r
\r
- assertEquals(Sizeable.UNITS_PIXELS, layout.getPosition(b).getTopUnits());\r
- assertEquals(Sizeable.UNITS_PICAS, layout.getPosition(b)\r
+ assertEquals(Sizeable.Unit.PIXELS, layout.getPosition(b).getTopUnits());\r
+ assertEquals(Sizeable.Unit.PICAS, layout.getPosition(b)\r
.getBottomUnits());\r
- assertEquals(Sizeable.UNITS_EM, layout.getPosition(b).getLeftUnits());\r
- assertEquals(Sizeable.UNITS_PERCENTAGE, layout.getPosition(b)\r
+ assertEquals(Sizeable.Unit.EM, layout.getPosition(b).getLeftUnits());\r
+ assertEquals(Sizeable.Unit.PERCENTAGE, layout.getPosition(b)\r
.getRightUnits());\r
\r
assertEquals(7, layout.getPosition(b).getZIndex());\r
assertEquals(CSS_VALUE, layout.getPosition(b).getLeftValue());\r
assertNull(layout.getPosition(b).getRightValue());\r
\r
- assertEquals(Sizeable.UNITS_PIXELS, layout.getPosition(b).getTopUnits());\r
+ assertEquals(Sizeable.Unit.PIXELS, layout.getPosition(b).getTopUnits());\r
assertEquals(UNIT_UNSET, layout.getPosition(b).getBottomUnits());\r
- assertEquals(Sizeable.UNITS_EM, layout.getPosition(b).getLeftUnits());\r
+ assertEquals(Sizeable.Unit.EM, layout.getPosition(b).getLeftUnits());\r
assertEquals(UNIT_UNSET, layout.getPosition(b).getRightUnits());\r
\r
assertEquals(-1, layout.getPosition(b).getZIndex());\r
assertEquals(CSS_VALUE, layout.getPosition(b).getLeftValue());\r
assertNull(layout.getPosition(b).getRightValue());\r
\r
- assertEquals(Sizeable.UNITS_PIXELS, layout.getPosition(b).getTopUnits());\r
+ assertEquals(Sizeable.Unit.PIXELS, layout.getPosition(b).getTopUnits());\r
assertEquals(UNIT_UNSET, layout.getPosition(b).getBottomUnits());\r
- assertEquals(Sizeable.UNITS_EM, layout.getPosition(b).getLeftUnits());\r
+ assertEquals(Sizeable.Unit.EM, layout.getPosition(b).getLeftUnits());\r
assertEquals(UNIT_UNSET, layout.getPosition(b).getRightUnits());\r
\r
assertEquals(-1, layout.getPosition(b).getZIndex());\r
layout.getPosition(b).setBottomValue(SIZE);\r
layout.getPosition(b).setLeftValue(SIZE);\r
\r
- layout.getPosition(b).setTopUnits(Sizeable.UNITS_CM);\r
- layout.getPosition(b).setRightUnits(Sizeable.UNITS_EX);\r
- layout.getPosition(b).setBottomUnits(Sizeable.UNITS_INCH);\r
- layout.getPosition(b).setLeftUnits(Sizeable.UNITS_MM);\r
+ layout.getPosition(b).setTopUnits(Sizeable.Unit.CM);\r
+ layout.getPosition(b).setRightUnits(Sizeable.Unit.EX);\r
+ layout.getPosition(b).setBottomUnits(Sizeable.Unit.INCH);\r
+ layout.getPosition(b).setLeftUnits(Sizeable.Unit.MM);\r
\r
assertEquals(SIZE, layout.getPosition(b).getTopValue());\r
assertEquals(SIZE, layout.getPosition(b).getRightValue());\r
assertEquals(SIZE, layout.getPosition(b).getBottomValue());\r
assertEquals(SIZE, layout.getPosition(b).getLeftValue());\r
\r
- assertEquals(Sizeable.UNITS_CM, layout.getPosition(b).getTopUnits());\r
- assertEquals(Sizeable.UNITS_EX, layout.getPosition(b).getRightUnits());\r
- assertEquals(Sizeable.UNITS_INCH, layout.getPosition(b)\r
- .getBottomUnits());\r
- assertEquals(Sizeable.UNITS_MM, layout.getPosition(b).getLeftUnits());\r
+ assertEquals(Sizeable.Unit.CM, layout.getPosition(b).getTopUnits());\r
+ assertEquals(Sizeable.Unit.EX, layout.getPosition(b).getRightUnits());\r
+ assertEquals(Sizeable.Unit.INCH, layout.getPosition(b).getBottomUnits());\r
+ assertEquals(Sizeable.Unit.MM, layout.getPosition(b).getLeftUnits());\r
\r
}\r
\r
Button b = new Button();\r
layout.addComponent(b);\r
\r
- layout.getPosition(b).setTop(SIZE, Sizeable.UNITS_CM);\r
- layout.getPosition(b).setRight(SIZE, Sizeable.UNITS_EX);\r
- layout.getPosition(b).setBottom(SIZE, Sizeable.UNITS_INCH);\r
- layout.getPosition(b).setLeft(SIZE, Sizeable.UNITS_MM);\r
+ layout.getPosition(b).setTop(SIZE, Sizeable.Unit.CM);\r
+ layout.getPosition(b).setRight(SIZE, Sizeable.Unit.EX);\r
+ layout.getPosition(b).setBottom(SIZE, Sizeable.Unit.INCH);\r
+ layout.getPosition(b).setLeft(SIZE, Sizeable.Unit.MM);\r
\r
assertEquals(SIZE, layout.getPosition(b).getTopValue());\r
assertEquals(SIZE, layout.getPosition(b).getRightValue());\r
assertEquals(SIZE, layout.getPosition(b).getBottomValue());\r
assertEquals(SIZE, layout.getPosition(b).getLeftValue());\r
\r
- assertEquals(Sizeable.UNITS_CM, layout.getPosition(b).getTopUnits());\r
- assertEquals(Sizeable.UNITS_EX, layout.getPosition(b).getRightUnits());\r
- assertEquals(Sizeable.UNITS_INCH, layout.getPosition(b)\r
- .getBottomUnits());\r
- assertEquals(Sizeable.UNITS_MM, layout.getPosition(b).getLeftUnits());\r
+ assertEquals(Sizeable.Unit.CM, layout.getPosition(b).getTopUnits());\r
+ assertEquals(Sizeable.Unit.EX, layout.getPosition(b).getRightUnits());\r
+ assertEquals(Sizeable.Unit.INCH, layout.getPosition(b).getBottomUnits());\r
+ assertEquals(Sizeable.Unit.MM, layout.getPosition(b).getLeftUnits());\r
\r
}\r
\r
package com.vaadin.tests.components.splitpanel;\r
\r
import com.vaadin.terminal.Sizeable;\r
+import com.vaadin.terminal.Sizeable.Unit;\r
import com.vaadin.tests.components.AbstractLayoutTest;\r
import com.vaadin.ui.AbstractSplitPanel;\r
import com.vaadin.ui.AbstractSplitPanel.SplitterClickEvent;\r
\r
private boolean reverse = false;\r
private int position;\r
- private int unit;\r
+ private Unit unit;\r
private String posString;\r
\r
public SplitPosition(String pos) {\r
\r
if (pos.endsWith("px")) {\r
position = Integer.parseInt(pos.substring(0, pos.length() - 2));\r
- unit = Sizeable.UNITS_PIXELS;\r
+ unit = Sizeable.Unit.PIXELS;\r
} else if (pos.endsWith("%")) {\r
position = Integer.parseInt(pos.substring(0, pos.length() - 1));\r
- unit = Sizeable.UNITS_PERCENTAGE;\r
+ unit = Sizeable.Unit.PERCENTAGE;\r
} else {\r
throw new RuntimeException("Could not parse " + pos);\r
}\r
package com.vaadin.tests.components.table;
import com.vaadin.data.util.MethodProperty;
-import com.vaadin.terminal.Sizeable;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
}
public String getTableHeight() {
- return "" + (int) table.getHeight()
- + Sizeable.UNIT_SYMBOLS[table.getHeightUnits()];
+ return "" + (int) table.getHeight() + table.getHeightUnits().getSymbol();
}
public void setTableHeight(String height) {
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
-import com.vaadin.terminal.Sizeable;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
}
public void updateLabel() {
- sizeLabel
- .setValue(getWidth() + Sizeable.UNIT_SYMBOLS[getWidthUnits()]
- + " x " + getHeight()
- + Sizeable.UNIT_SYMBOLS[getHeightUnits()]);
+ sizeLabel.setValue(getWidth() + getWidthUnits().getSymbol() + " x "
+ + getHeight() + getHeightUnits().getSymbol());
}
}
s.addContainerProperty("caption", String.class, "");\r
s.setItemCaptionPropertyId("caption");\r
s.setNullSelectionAllowed(false);\r
- for (int i = 0; i < Layout.UNIT_SYMBOLS.length; i++) {\r
+ for (int i = 0; i < Layout.Unit.values().length; i++) {\r
Item unitItem = s.addItem(i);\r
unitItem.getItemProperty("caption").setValue(\r
- Layout.UNIT_SYMBOLS[i]);\r
+ Layout.Unit.values()[i]);\r
}\r
return s;\r
}\r
// Last known height before the panel was collapsed
private float lastHeight = -1;
- private int lastHeightUnit = -1;
+ private Unit lastHeightUnit = null;
public ButtonPanel(String labelString) {
setCompositionRoot(root);
root.setExpandRatio(container, 1);
}
- public void setHeight(int height, int unit) {
+ public void setHeight(int height, Unit unit) {
root.setHeight(height, unit);
lastHeight = height;
lastHeightUnit = unit;
root.setWidth(width);
}
- public void setWidth(int width, int unit) {
+ public void setWidth(int width, Unit unit) {
root.setWidth(width, unit);
}
import com.vaadin.Application;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
-import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.UserError;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
private void updateLabel() {
label.setValue("width: " + target.getWidth()
- + Sizeable.UNIT_SYMBOLS[target.getWidthUnits()] + ", height: "
- + target.getHeight()
- + Sizeable.UNIT_SYMBOLS[target.getHeightUnits()]);
+ + target.getWidthUnits().getSymbol() + ", height: "
+ + target.getHeight() + target.getHeightUnits().getSymbol());
}
}