aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
diff options
context:
space:
mode:
authorelmot <elmot@vaadin.com>2016-04-13 15:01:50 +0300
committerelmot <elmot@vaadin.com>2016-04-13 15:32:47 +0300
commit980f879176696906c25e985e4f7c8e3bdc04258d (patch)
treed781a70e24eef0994ba5d371280e1cf837f94825 /server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
parentf7f5ba596dbba0c2374a6d8ac10e89362cbbaeb5 (diff)
parent9b46608f6c645c4289b854e2949bae3b1a2f5147 (diff)
downloadvaadin-framework-980f879176696906c25e985e4f7c8e3bdc04258d.tar.gz
vaadin-framework-980f879176696906c25e985e4f7c8e3bdc04258d.zip
Merge branch 'master' into feature/mavenize
Change-Id: Id7db526d07a14ac259cbb50415bbafd2a7c2ab94
Diffstat (limited to 'server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java')
-rw-r--r--server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java b/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
index cee2ebe381..bbfd90b2cc 100644
--- a/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
+++ b/server/src/main/java/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 7.6.4
+ * @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 7.6.4
+ * @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);
+ }
+ }
+
}