diff options
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r-- | server/src/com/vaadin/ui/AbstractOrderedLayout.java | 19 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/GridLayout.java | 20 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java | 53 |
3 files changed, 63 insertions, 29 deletions
diff --git a/server/src/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/com/vaadin/ui/AbstractOrderedLayout.java index e0dbcb004b..f517ab0af5 100644 --- a/server/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/server/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -31,7 +31,6 @@ import com.vaadin.server.Sizeable; import com.vaadin.shared.Connector; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; -import com.vaadin.shared.ui.AlignmentInfo; import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutServerRpc; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState; @@ -486,22 +485,8 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements Component newChild = designContext.readDesign(childComponent); addComponent(newChild); // handle alignment - int bitMask = 0; - if (attr.hasKey(":middle")) { - bitMask += AlignmentInfo.Bits.ALIGNMENT_VERTICAL_CENTER; - } else if (attr.hasKey(":bottom")) { - bitMask += AlignmentInfo.Bits.ALIGNMENT_BOTTOM; - } else { - bitMask += AlignmentInfo.Bits.ALIGNMENT_TOP; - } - if (attr.hasKey(":center")) { - bitMask += AlignmentInfo.Bits.ALIGNMENT_HORIZONTAL_CENTER; - } else if (attr.hasKey(":right")) { - bitMask += AlignmentInfo.Bits.ALIGNMENT_RIGHT; - } else { - bitMask += AlignmentInfo.Bits.ALIGNMENT_LEFT; - } - setComponentAlignment(newChild, new Alignment(bitMask)); + setComponentAlignment(newChild, + DesignAttributeHandler.readAlignment(attr)); // handle expand ratio if (attr.hasKey(":expand")) { String value = attr.get(":expand"); diff --git a/server/src/com/vaadin/ui/GridLayout.java b/server/src/com/vaadin/ui/GridLayout.java index 8517962e91..148fd85fff 100644 --- a/server/src/com/vaadin/ui/GridLayout.java +++ b/server/src/com/vaadin/ui/GridLayout.java @@ -1330,7 +1330,7 @@ public class GridLayout extends AbstractLayout implements } } setRows(Math.max(rows.size(), 1)); - + Map<Component, Alignment> alignments = new HashMap<Component, Alignment>(); List<Integer> columnExpandRatios = new ArrayList<Integer>(); for (int row = 0; row < rowElements.size(); ++row) { Element rowElement = rowElements.get(row); @@ -1357,7 +1357,10 @@ public class GridLayout extends AbstractLayout implements Component child = null; if (col.children().size() > 0) { - child = designContext.readDesign(col.child(0)); + Element childElement = col.child(0); + child = designContext.readDesign(childElement); + alignments.put(child, DesignAttributeHandler + .readAlignment(childElement.attributes())); // TODO: Currently ignoring any extra children. // Needs Error handling? } // Else: Empty placeholder. No child component. @@ -1441,6 +1444,7 @@ public class GridLayout extends AbstractLayout implements // Add component with area addComponent(child, j, i, j + colspan, i + rowspan); + setComponentAlignment(child, alignments.get(child)); } } // Set cursor position explicitly @@ -1511,16 +1515,8 @@ public class GridLayout extends AbstractLayout implements ChildComponentData coords = childData.get(child); Alignment alignment = getComponentAlignment(child); - if (alignment.isMiddle()) { - childElement.attr(":middle", true); - } else if (alignment.isBottom()) { - childElement.attr(":bottom", true); - } - if (alignment.isCenter()) { - childElement.attr(":center", true); - } else if (alignment.isRight()) { - childElement.attr(":right", true); - } + DesignAttributeHandler.writeAlignment(childElement, + alignment); col.appendChild(childElement); if (coords.row1 != coords.row2) { diff --git a/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java b/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java index cee2ebe381..4e9617c018 100644 --- a/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java +++ b/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java @@ -37,7 +37,9 @@ import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; import com.vaadin.data.util.converter.Converter; +import com.vaadin.shared.ui.AlignmentInfo; import com.vaadin.shared.util.SharedUtil; +import com.vaadin.ui.Alignment; /** * Default attribute handler implementation used when parsing designs to @@ -452,4 +454,55 @@ public class DesignAttributeHandler implements Serializable { return (methods != null && methods.length > 1) ? methods[1] : null; } } + + /** + * Read the alignment from the given child component attributes. + * + * @since + * @param attr + * the child component attributes + * @return the component alignment + */ + public static Alignment readAlignment(Attributes attr) { + int bitMask = 0; + if (attr.hasKey(":middle")) { + bitMask += AlignmentInfo.Bits.ALIGNMENT_VERTICAL_CENTER; + } else if (attr.hasKey(":bottom")) { + bitMask += AlignmentInfo.Bits.ALIGNMENT_BOTTOM; + } else { + bitMask += AlignmentInfo.Bits.ALIGNMENT_TOP; + } + if (attr.hasKey(":center")) { + bitMask += AlignmentInfo.Bits.ALIGNMENT_HORIZONTAL_CENTER; + } else if (attr.hasKey(":right")) { + bitMask += AlignmentInfo.Bits.ALIGNMENT_RIGHT; + } else { + bitMask += AlignmentInfo.Bits.ALIGNMENT_LEFT; + } + + return new Alignment(bitMask); + } + + /** + * Writes the alignment to the given child element attributes. + * + * @since + * @param childElement + * the child element + * @param alignment + * the component alignment + */ + public static void writeAlignment(Element childElement, Alignment alignment) { + if (alignment.isMiddle()) { + childElement.attr(":middle", true); + } else if (alignment.isBottom()) { + childElement.attr(":bottom", true); + } + if (alignment.isCenter()) { + childElement.attr(":center", true); + } else if (alignment.isRight()) { + childElement.attr(":right", true); + } + } + } |