diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-05-21 12:06:51 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-05-21 12:06:51 +0000 |
commit | 69c2c0d7ce71e857997cd82d3050fce52559fcb3 (patch) | |
tree | be401899f605eda39c3a6dc1ab20a47e954dd550 /src/com/vaadin/ui | |
parent | eeb590805ab8875752282ad0810c679db50c8d4f (diff) | |
parent | 211358bd93db47a63b74cab37e16e557ff363270 (diff) | |
download | vaadin-framework-69c2c0d7ce71e857997cd82d3050fce52559fcb3.tar.gz vaadin-framework-69c2c0d7ce71e857997cd82d3050fce52559fcb3.zip |
merged bug fixes from 6.3 to 6.4
svn changeset:13304/svn branch:6.4
Diffstat (limited to 'src/com/vaadin/ui')
-rw-r--r-- | src/com/vaadin/ui/AbsoluteLayout.java | 244 | ||||
-rw-r--r-- | src/com/vaadin/ui/GridLayout.java | 19 |
2 files changed, 232 insertions, 31 deletions
diff --git a/src/com/vaadin/ui/AbsoluteLayout.java b/src/com/vaadin/ui/AbsoluteLayout.java index b2f0f5539f..56c3474091 100644 --- a/src/com/vaadin/ui/AbsoluteLayout.java +++ b/src/com/vaadin/ui/AbsoluteLayout.java @@ -28,17 +28,31 @@ public class AbsoluteLayout extends AbstractLayout { private static final String CLICK_EVENT = VAbsoluteLayout.CLICK_EVENT_IDENTIFIER; + // The components in the layout private Collection<Component> components = new LinkedHashSet<Component>(); + + // Maps each component to a position private Map<Component, ComponentPosition> componentToCoordinates = new HashMap<Component, ComponentPosition>(); + /** + * Creates an AbsoluteLayout with full size. + */ public AbsoluteLayout() { setSizeFull(); } + /** + * Gets an iterator for going through all components enclosed in the + * absolute layout. + */ public Iterator<Component> getComponentIterator() { return components.iterator(); } + /** + * Replaces one component with another one. The new component inherits the + * old components position. + */ public void replaceComponent(Component oldComponent, Component newComponent) { ComponentPosition position = getPosition(oldComponent); removeComponent(oldComponent); @@ -46,6 +60,13 @@ public class AbsoluteLayout extends AbstractLayout { componentToCoordinates.put(newComponent, position); } + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractComponentContainer#addComponent(com.vaadin.ui.Component + * ) + */ @Override public void addComponent(Component c) { components.add(c); @@ -53,6 +74,13 @@ public class AbsoluteLayout extends AbstractLayout { requestRepaint(); } + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractComponentContainer#removeComponent(com.vaadin.ui + * .Component) + */ @Override public void removeComponent(Component c) { components.remove(c); @@ -60,11 +88,35 @@ public class AbsoluteLayout extends AbstractLayout { requestRepaint(); } + /** + * Adds a component to the layout. The component can be positioned by + * providing a string formatted in CSS-format. + * <p> + * For example the string "top:10px;left:10px" will position the component + * 10 pixels from the left and 10 pixels from the top. The identifiers: + * "top","left","right" and "bottom" can be used to specify the position. + * </p> + * + * @param c + * The component to add to the layout + * @param cssPosition + * The css position string + */ public void addComponent(Component c, String cssPosition) { addComponent(c); getPosition(c).setCSSString(cssPosition); } + /** + * Gets the position of a component in the layout. Returns null if component + * is not attached to the layout. + * + * @param component + * The component which position is needed + * @return An instance of ComponentPosition containing the position of the + * component, or null if the component is not enclosed in the + * layout. + */ public ComponentPosition getPosition(Component component) { if (componentToCoordinates.containsKey(component)) { return componentToCoordinates.get(component); @@ -76,6 +128,10 @@ public class AbsoluteLayout extends AbstractLayout { } /** + * The CompontPosition class represents a components position within the + * absolute layout. It contains the CSS attributes for left, right, top and + * bottom and the units used to specify them. * + * * TODO symmetric getters and setters for fields to make this simpler to use * in generic java tools * @@ -83,10 +139,10 @@ public class AbsoluteLayout extends AbstractLayout { public class ComponentPosition implements Serializable { private int zIndex = -1; - private float topValue = -1; - private float rightValue = -1; - private float bottomValue = -1; - private float leftValue = -1; + private Float topValue = null; + private Float rightValue = null; + private Float bottomValue = null; + private Float leftValue = null; private int topUnits; private int rightUnits; @@ -103,6 +159,10 @@ public class AbsoluteLayout extends AbstractLayout { * @param css */ public void setCSSString(String css) { + if (css == null) { + return; + } + String[] cssProperties = css.split(";"); for (int i = 0; i < cssProperties.length; i++) { String[] keyValuePair = cssProperties[i].split(":"); @@ -119,7 +179,7 @@ public class AbsoluteLayout extends AbstractLayout { } else { value = ""; } - String unit = value.replaceAll("[0-9\\.]+", ""); + String unit = value.replaceAll("[0-9\\.\\-]+", ""); if (!unit.equals("")) { value = value.substring(0, value.indexOf(unit)).trim(); } @@ -143,6 +203,14 @@ public class AbsoluteLayout extends AbstractLayout { 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)) { @@ -152,18 +220,23 @@ public class AbsoluteLayout extends AbstractLayout { return 0; // defaults to px (eg. top:0;) } + /** + * Converts the internal values into a valid CSS string. + * + * @return A valid CSS string + */ public String getCSSString() { String s = ""; - if (topValue >= 0) { + if (topValue != null) { s += "top:" + topValue + UNIT_SYMBOLS[topUnits] + ";"; } - if (rightValue >= 0) { + if (rightValue != null) { s += "right:" + rightValue + UNIT_SYMBOLS[rightUnits] + ";"; } - if (bottomValue >= 0) { + if (bottomValue != null) { s += "bottom:" + bottomValue + UNIT_SYMBOLS[bottomUnits] + ";"; } - if (leftValue >= 0) { + if (leftValue != null) { s += "left:" + leftValue + UNIT_SYMBOLS[leftUnits] + ";"; } if (zIndex >= 0) { @@ -172,6 +245,15 @@ public class AbsoluteLayout extends AbstractLayout { return s; } + /** + * Sets the 'top' CSS-attribute + * + * @param topValue + * The value of the 'top' attribute + * @param topUnits + * The unit of the 'top' attribute. See UNIT_SYMBOLS for a + * description of the available units. + */ public void setTop(float topValue, int topUnits) { validateLength(topValue, topUnits); this.topValue = topValue; @@ -179,6 +261,15 @@ public class AbsoluteLayout extends AbstractLayout { requestRepaint(); } + /** + * Sets the 'right' CSS-attribute + * + * @param rightValue + * The value of the 'right' attribute + * @param rightUnits + * The unit of the 'right' attribute. See UNIT_SYMBOLS for a + * description of the available units. + */ public void setRight(float rightValue, int rightUnits) { validateLength(rightValue, rightUnits); this.rightValue = rightValue; @@ -186,6 +277,15 @@ public class AbsoluteLayout extends AbstractLayout { requestRepaint(); } + /** + * Sets the 'bottom' CSS-attribute + * + * @param bottomValue + * The value of the 'bottom' attribute + * @param units + * The unit of the 'bottom' attribute. See UNIT_SYMBOLS for a + * description of the available units. + */ public void setBottom(float bottomValue, int units) { validateLength(bottomValue, units); this.bottomValue = bottomValue; @@ -193,6 +293,15 @@ public class AbsoluteLayout extends AbstractLayout { requestRepaint(); } + /** + * Sets the 'left' CSS-attribute + * + * @param leftValue + * The value of the 'left' attribute + * @param units + * The unit of the 'left' attribute. See UNIT_SYMBOLS for a + * description of the available units. + */ public void setLeft(float leftValue, int units) { validateLength(leftValue, units); this.leftValue = leftValue; @@ -200,31 +309,52 @@ public class AbsoluteLayout extends AbstractLayout { requestRepaint(); } + /** + * Sets the 'z-index' CSS-attribute + * + * @param zIndex + * The z-index for the component. + */ public void setZIndex(int zIndex) { this.zIndex = zIndex; requestRepaint(); } + /** + * Sets the value of the 'top' CSS-attribute + * + * @param topValue + * The value of the 'left' attribute + */ public void setTopValue(float topValue) { validateLength(topValue, topUnits); this.topValue = topValue; requestRepaint(); } + /** + * Gets the 'top' CSS-attributes value in specified units. + * + * @return The value of the 'top' CSS-attribute + */ public float getTopValue() { - return topValue; + return topValue == null ? 0 : rightValue.floatValue(); } /** - * @return the rightValue + * Gets the 'right' CSS-attributes value in specified units. + * + * @return The value of the 'right' CSS-attribute */ public float getRightValue() { - return rightValue; + return rightValue == null ? 0 : rightValue.floatValue(); } /** + * Sets the 'right' CSS-attributes value in specified units. + * * @param rightValue - * the rightValue to set + * The value of the 'right' CSS-attribute */ public void setRightValue(float rightValue) { validateLength(rightValue, rightUnits); @@ -233,15 +363,19 @@ public class AbsoluteLayout extends AbstractLayout { } /** - * @return the bottomValue + * Gets the 'bottom' CSS-attributes value in specified units. + * + * @return The value of the 'bottom' CSS-attribute */ public float getBottomValue() { - return bottomValue; + return bottomValue == null ? 0 : bottomValue.floatValue(); } /** + * Sets the 'bottom' CSS-attributes value in specified units. + * * @param bottomValue - * the bottomValue to set + * The value of the 'bottom' CSS-attribute */ public void setBottomValue(float bottomValue) { validateLength(bottomValue, bottomUnits); @@ -250,15 +384,19 @@ public class AbsoluteLayout extends AbstractLayout { } /** - * @return the leftValue + * Gets the 'left' CSS-attributes value in specified units. + * + * @return The value of the 'left' CSS-attribute */ public float getLeftValue() { - return leftValue; + return leftValue == null ? 0 : leftValue.floatValue(); } /** + * Sets the 'left' CSS-attributes value in specified units. + * * @param leftValue - * the leftValue to set + * The value of the 'left' CSS-attribute */ public void setLeftValue(float leftValue) { validateLength(leftValue, leftUnits); @@ -267,15 +405,19 @@ public class AbsoluteLayout extends AbstractLayout { } /** - * @return the topUnits + * Gets the unit for the 'top' CSS-attribute + * + * @return See UNIT_SYMBOLS for a description of the available units. */ public int getTopUnits() { return topUnits; } /** + * Sets the unit for the 'top' CSS-attribute + * * @param topUnits - * the topUnits to set + * See UNIT_SYMBOLS for a description of the available units. */ public void setTopUnits(int topUnits) { validateLength(topValue, topUnits); @@ -284,15 +426,19 @@ public class AbsoluteLayout extends AbstractLayout { } /** - * @return the rightUnits + * Gets the unit for the 'right' CSS-attribute + * + * @return See UNIT_SYMBOLS for a description of the available units. */ public int getRightUnits() { return rightUnits; } /** + * Sets the unit for the 'right' CSS-attribute + * * @param rightUnits - * the rightUnits to set + * See UNIT_SYMBOLS for a description of the available units. */ public void setRightUnits(int rightUnits) { validateLength(rightValue, rightUnits); @@ -301,15 +447,19 @@ public class AbsoluteLayout extends AbstractLayout { } /** - * @return the bottomUnits + * Gets the unit for the 'bottom' CSS-attribute + * + * @return See UNIT_SYMBOLS for a description of the available units. */ public int getBottomUnits() { return bottomUnits; } /** + * Sets the unit for the 'bottom' CSS-attribute + * * @param bottomUnits - * the bottomUnits to set + * See UNIT_SYMBOLS for a description of the available units. */ public void setBottomUnits(int bottomUnits) { validateLength(bottomValue, bottomUnits); @@ -318,15 +468,19 @@ public class AbsoluteLayout extends AbstractLayout { } /** - * @return the leftUnits + * Gets the unit for the 'left' CSS-attribute + * + * @return See UNIT_SYMBOLS for a description of the available units. */ public int getLeftUnits() { return leftUnits; } /** + * Sets the unit for the 'left' CSS-attribute + * * @param leftUnits - * the leftUnits to set + * See UNIT_SYMBOLS for a description of the available units. */ public void setLeftUnits(int leftUnits) { validateLength(leftValue, leftUnits); @@ -335,12 +489,19 @@ public class AbsoluteLayout extends AbstractLayout { } /** - * @return the zIndex + * Gets the 'z-index' CSS-attribute. + * + * @return the zIndex The z-index attribute */ public int getZIndex() { return zIndex; } + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ @Override public String toString() { return getCSSString(); @@ -348,6 +509,13 @@ public class AbsoluteLayout extends AbstractLayout { } + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractLayout#paintContent(com.vaadin.terminal.PaintTarget + * ) + */ @Override public void paintContent(PaintTarget target) throws PaintException { super.paintContent(target); @@ -359,11 +527,25 @@ public class AbsoluteLayout extends AbstractLayout { } } + /** + * Validates a value with the unit + * + * @param topValue + * The value to validate + * @param topUnits2 + * The unit to validate + */ private static void validateLength(float topValue, int topUnits2) { // TODO throw on invalid value } + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.AbstractComponent#changeVariables(java.lang.Object, + * java.util.Map) + */ @Override public void changeVariables(Object source, Map variables) { super.changeVariables(source, variables); @@ -373,6 +555,12 @@ public class AbsoluteLayout extends AbstractLayout { } + /** + * Fires a click event when the layout is clicked + * + * @param parameters + * The parameters recieved from the client side implementation + */ private void fireClick(Map<String, Object> parameters) { MouseEventDetails mouseDetails = MouseEventDetails .deSerialize((String) parameters.get("mouseDetails")); diff --git a/src/com/vaadin/ui/GridLayout.java b/src/com/vaadin/ui/GridLayout.java index 19abe8d142..1e31eb9b65 100644 --- a/src/com/vaadin/ui/GridLayout.java +++ b/src/com/vaadin/ui/GridLayout.java @@ -1183,6 +1183,10 @@ public class GridLayout extends AbstractLayout implements * Removes row and all components in the row. Components which span over * several rows are removed if the selected row is the component's first * row. + * <p> + * If the last row is removed then all remaining components will be removed + * and the grid will be reduced to one row and one column. + * </p> * * @param row * The row number to remove @@ -1210,9 +1214,18 @@ public class GridLayout extends AbstractLayout implements } } - setRows(rows - 1); - if (cursorY > row) { - cursorY--; + if (rows == 1) { + /* + * Removing the last row means that the dimensions of the Grid + * layout will be truncated to 1x1 and all components removed. + */ + setColumns(1); + cursorY = 0; + } else { + setRows(rows - 1); + if (cursorY > row) { + cursorY--; + } } structuralChange = true; |