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;
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");
}
}
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);
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.
// Add component with area
addComponent(child, j, i, j + colspan, i + rowspan);
+ setComponentAlignment(child, alignments.get(child));
}
}
// Set cursor position explicitly
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) {
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
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);
+ }
+ }
+
}
@Test
public void testOneBigComponentGridLayout() {
- Button b1 = new Button("Button 0,0 -> 1,1");
+ Button b1 = new Button("Button 0,0 -> 1,1");
b1.setCaptionAsHtml(true);
String design = "<vaadin-grid-layout><row>" //
+ "<column colspan=2 rowspan=2>" + writeChild(b1) + "</column>" //
@Test
public void testMultipleSpannedComponentsGridLayout() {
GridLayout gl = new GridLayout(5, 5);
- Button b1 = new Button("Button 0,0 -> 0,2");
+ Button b1 = new Button("Button 0,0 -> 0,2");
b1.setCaptionAsHtml(true);
gl.addComponent(b1, 0, 0, 2, 0);
- Button b2 = new Button("Button 0,3 -> 3,3");
+ Button b2 = new Button("Button 0,3 -> 3,3");
b2.setCaptionAsHtml(true);
gl.addComponent(b2, 3, 0, 3, 3);
- Button b3 = new Button("Button 0,4 -> 1,4");
+ Button b3 = new Button("Button 0,4 -> 1,4");
b3.setCaptionAsHtml(true);
gl.addComponent(b3, 4, 0, 4, 1);
- Button b4 = new Button("Button 1,0 -> 3,1");
+ Button b4 = new Button("Button 1,0 -> 3,1");
b4.setCaptionAsHtml(true);
gl.addComponent(b4, 0, 1, 1, 3);
b5.setCaptionAsHtml(true);
gl.addComponent(b5, 2, 2);
- Button b6 = new Button("Button 3,4 -> 4,4");
+ Button b6 = new Button("Button 3,4 -> 4,4");
b6.setCaptionAsHtml(true);
gl.addComponent(b6, 4, 3, 4, 4);
- Button b7 = new Button("Button 4,1 -> 4,2");
+ Button b7 = new Button("Button 4,1 -> 4,2");
b7.setCaptionAsHtml(true);
gl.addComponent(b7, 2, 4, 3, 4);
@Test
public void testManyExtraGridLayoutSlots() {
GridLayout gl = new GridLayout(5, 5);
- Button b1 = new Button("Button 0,4 -> 4,4");
+ Button b1 = new Button("Button 0,4 -> 4,4");
b1.setCaptionAsHtml(true);
gl.addComponent(b1, 4, 0, 4, 4);
gl.setColumnExpandRatio(2, 2.0f);
@Test
public void testManyEmptyColumnsWithOneExpand() {
GridLayout gl = new GridLayout(5, 5);
- Button b1 = new Button("Button 0,4 -> 4,4");
+ Button b1 = new Button("Button 0,4 -> 4,4");
b1.setCaptionAsHtml(true);
gl.addComponent(b1, 0, 0, 0, 4);
gl.setColumnExpandRatio(4, 2.0f);
GridLayout result = super.testRead(design, expected);
for (int row = 0; row < expected.getRows(); ++row) {
- Assert.assertTrue(Math.abs(expected.getRowExpandRatio(row)
- - result.getRowExpandRatio(row)) < 0.00001);
+ Assert.assertEquals(expected.getRowExpandRatio(row),
+ result.getRowExpandRatio(row), 0.00001);
}
for (int col = 0; col < expected.getColumns(); ++col) {
- Assert.assertTrue(Math.abs(expected.getColumnExpandRatio(col)
- - result.getColumnExpandRatio(col)) < 0.00001);
+ Assert.assertEquals(expected.getColumnExpandRatio(col),
+ result.getColumnExpandRatio(col), 0.00001);
}
+ for (int row = 0; row < expected.getRows(); ++row) {
+ for (int col = 0; col < expected.getColumns(); ++col) {
+ Component eC = expected.getComponent(col, row);
+ Component rC = result.getComponent(col, row);
+
+ assertEquals(eC, rC);
+ if (eC == null) {
+ continue;
+ }
+
+ Assert.assertEquals(expected.getComponentAlignment(eC),
+ result.getComponentAlignment(rC));
+
+ }
+ }
+
return result;
}