aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/shared/ui/AlignmentInfo.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/vaadin/shared/ui/AlignmentInfo.java')
-rw-r--r--src/com/vaadin/shared/ui/AlignmentInfo.java89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/com/vaadin/shared/ui/AlignmentInfo.java b/src/com/vaadin/shared/ui/AlignmentInfo.java
new file mode 100644
index 0000000000..ff800de646
--- /dev/null
+++ b/src/com/vaadin/shared/ui/AlignmentInfo.java
@@ -0,0 +1,89 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.shared.ui;
+
+public final class AlignmentInfo {
+ /** Bitmask values for client server communication */
+ public static class Bits {
+ public static final int ALIGNMENT_LEFT = 1;
+ public static final int ALIGNMENT_RIGHT = 2;
+ public static final int ALIGNMENT_TOP = 4;
+ public static final int ALIGNMENT_BOTTOM = 8;
+ public static final int ALIGNMENT_HORIZONTAL_CENTER = 16;
+ public static final int ALIGNMENT_VERTICAL_CENTER = 32;
+ }
+
+ public static final AlignmentInfo LEFT = new AlignmentInfo(
+ Bits.ALIGNMENT_LEFT);
+ public static final AlignmentInfo RIGHT = new AlignmentInfo(
+ Bits.ALIGNMENT_RIGHT);
+ public static final AlignmentInfo TOP = new AlignmentInfo(
+ Bits.ALIGNMENT_TOP);
+ public static final AlignmentInfo BOTTOM = new AlignmentInfo(
+ Bits.ALIGNMENT_BOTTOM);
+ public static final AlignmentInfo CENTER = new AlignmentInfo(
+ Bits.ALIGNMENT_HORIZONTAL_CENTER);
+ public static final AlignmentInfo MIDDLE = new AlignmentInfo(
+ Bits.ALIGNMENT_VERTICAL_CENTER);
+ public static final AlignmentInfo TOP_LEFT = new AlignmentInfo(
+ Bits.ALIGNMENT_TOP + Bits.ALIGNMENT_LEFT);
+
+ private final int bitMask;
+
+ public AlignmentInfo(int bitMask) {
+ this.bitMask = bitMask;
+ }
+
+ public AlignmentInfo(AlignmentInfo horizontal, AlignmentInfo vertical) {
+ this(horizontal.getBitMask() + vertical.getBitMask());
+ }
+
+ public int getBitMask() {
+ return bitMask;
+ }
+
+ public boolean isTop() {
+ return (bitMask & Bits.ALIGNMENT_TOP) == Bits.ALIGNMENT_TOP;
+ }
+
+ public boolean isBottom() {
+ return (bitMask & Bits.ALIGNMENT_BOTTOM) == Bits.ALIGNMENT_BOTTOM;
+ }
+
+ public boolean isLeft() {
+ return (bitMask & Bits.ALIGNMENT_LEFT) == Bits.ALIGNMENT_LEFT;
+ }
+
+ public boolean isRight() {
+ return (bitMask & Bits.ALIGNMENT_RIGHT) == Bits.ALIGNMENT_RIGHT;
+ }
+
+ public boolean isVerticalCenter() {
+ return (bitMask & Bits.ALIGNMENT_VERTICAL_CENTER) == Bits.ALIGNMENT_VERTICAL_CENTER;
+ }
+
+ public boolean isHorizontalCenter() {
+ return (bitMask & Bits.ALIGNMENT_HORIZONTAL_CENTER) == Bits.ALIGNMENT_HORIZONTAL_CENTER;
+ }
+
+ public String getVerticalAlignment() {
+ if (isBottom()) {
+ return "bottom";
+ } else if (isVerticalCenter()) {
+ return "middle";
+ }
+ return "top";
+ }
+
+ public String getHorizontalAlignment() {
+ if (isRight()) {
+ return "right";
+ } else if (isHorizontalCenter()) {
+ return "center";
+ }
+ return "left";
+ }
+
+}