]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #2432, AlignmentHandler methods now symmetric + saner usage overall
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 9 Jan 2009 09:07:13 +0000 (09:07 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 9 Jan 2009 09:07:13 +0000 (09:07 +0000)
svn changeset:6473/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/AlignmentInfo.java
src/com/itmill/toolkit/terminal/gwt/client/ui/layout/ChildComponentContainer.java
src/com/itmill/toolkit/tests/tickets/Ticket2279.java
src/com/itmill/toolkit/tests/tickets/Ticket2432.java [new file with mode: 0644]
src/com/itmill/toolkit/ui/AbstractOrderedLayout.java
src/com/itmill/toolkit/ui/Alignment.java [new file with mode: 0644]
src/com/itmill/toolkit/ui/AlignmentUtils.java
src/com/itmill/toolkit/ui/GridLayout.java
src/com/itmill/toolkit/ui/Layout.java

index 68024d849a74751a7ff0dd0c3204df01f6d5a17e..cf4afb44dda9dea2e2256cdc33ca2790c0e93078 100644 (file)
@@ -4,27 +4,40 @@
 
 package com.itmill.toolkit.terminal.gwt.client.ui;
 
-public class AlignmentInfo {
-
-    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 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;
+    }
 
-    private int bitMask;
+    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(int horizontal, int vertical) {
-        setAlignment(horizontal, vertical);
-    }
-
-    public void setAlignment(int horiz, int vert) {
-        bitMask = horiz + vert;
+    public AlignmentInfo(AlignmentInfo horizontal, AlignmentInfo vertical) {
+        this(horizontal.getBitMask() + vertical.getBitMask());
     }
 
     public int getBitMask() {
@@ -32,27 +45,27 @@ public class AlignmentInfo {
     }
 
     public boolean isTop() {
-        return (bitMask & ALIGNMENT_TOP) == ALIGNMENT_TOP;
+        return (bitMask & Bits.ALIGNMENT_TOP) == Bits.ALIGNMENT_TOP;
     }
 
     public boolean isBottom() {
-        return (bitMask & ALIGNMENT_BOTTOM) == ALIGNMENT_BOTTOM;
+        return (bitMask & Bits.ALIGNMENT_BOTTOM) == Bits.ALIGNMENT_BOTTOM;
     }
 
     public boolean isLeft() {
-        return (bitMask & ALIGNMENT_LEFT) == ALIGNMENT_LEFT;
+        return (bitMask & Bits.ALIGNMENT_LEFT) == Bits.ALIGNMENT_LEFT;
     }
 
     public boolean isRight() {
-        return (bitMask & ALIGNMENT_RIGHT) == ALIGNMENT_RIGHT;
+        return (bitMask & Bits.ALIGNMENT_RIGHT) == Bits.ALIGNMENT_RIGHT;
     }
 
     public boolean isVerticalCenter() {
-        return (bitMask & ALIGNMENT_VERTICAL_CENTER) == ALIGNMENT_VERTICAL_CENTER;
+        return (bitMask & Bits.ALIGNMENT_VERTICAL_CENTER) == Bits.ALIGNMENT_VERTICAL_CENTER;
     }
 
     public boolean isHorizontalCenter() {
-        return (bitMask & ALIGNMENT_HORIZONTAL_CENTER) == ALIGNMENT_HORIZONTAL_CENTER;
+        return (bitMask & Bits.ALIGNMENT_HORIZONTAL_CENTER) == Bits.ALIGNMENT_HORIZONTAL_CENTER;
     }
 
     public String getVerticalAlignment() {
index 6836c592707842c123876d6963f0f78bbf478d73..6367c03a3e7133a13ddca0071381c0a0d35c87e0 100644 (file)
@@ -46,8 +46,8 @@ public class ChildComponentContainer extends Panel {
     private int containerMarginLeft = 0;
     private int containerMarginTop = 0;
 
-    AlignmentInfo alignment = new AlignmentInfo(AlignmentInfo.ALIGNMENT_LEFT,
-            AlignmentInfo.ALIGNMENT_TOP);
+    AlignmentInfo alignment = AlignmentInfo.TOP_LEFT;
+
     private int alignmentLeftOffsetForWidget = 0;
     private int alignmentLeftOffsetForCaption = 0;
     /**
index 530ee035d07ceeffae0f3a705e537bdae24d7971..f7889c599fb2b714eecca1c565425b18915b391f 100644 (file)
@@ -27,19 +27,19 @@ public class Ticket2279 extends Application {
     private static Set<String> shortVerticalAlignments = new HashSet<String>();
 
     static {
-        expected.put("r", AlignmentInfo.ALIGNMENT_RIGHT);
-        expected.put("l", AlignmentInfo.ALIGNMENT_LEFT);
-        expected.put("c", AlignmentInfo.ALIGNMENT_HORIZONTAL_CENTER);
-        expected.put("t", AlignmentInfo.ALIGNMENT_TOP);
-        expected.put("b", AlignmentInfo.ALIGNMENT_BOTTOM);
-        expected.put("m", AlignmentInfo.ALIGNMENT_VERTICAL_CENTER);
-
-        expected.put("right", AlignmentInfo.ALIGNMENT_RIGHT);
-        expected.put("left", AlignmentInfo.ALIGNMENT_LEFT);
-        expected.put("center", AlignmentInfo.ALIGNMENT_HORIZONTAL_CENTER);
-        expected.put("top", AlignmentInfo.ALIGNMENT_TOP);
-        expected.put("bottom", AlignmentInfo.ALIGNMENT_BOTTOM);
-        expected.put("middle", AlignmentInfo.ALIGNMENT_VERTICAL_CENTER);
+        expected.put("r", AlignmentInfo.Bits.ALIGNMENT_RIGHT);
+        expected.put("l", AlignmentInfo.Bits.ALIGNMENT_LEFT);
+        expected.put("c", AlignmentInfo.Bits.ALIGNMENT_HORIZONTAL_CENTER);
+        expected.put("t", AlignmentInfo.Bits.ALIGNMENT_TOP);
+        expected.put("b", AlignmentInfo.Bits.ALIGNMENT_BOTTOM);
+        expected.put("m", AlignmentInfo.Bits.ALIGNMENT_VERTICAL_CENTER);
+
+        expected.put("right", AlignmentInfo.Bits.ALIGNMENT_RIGHT);
+        expected.put("left", AlignmentInfo.Bits.ALIGNMENT_LEFT);
+        expected.put("center", AlignmentInfo.Bits.ALIGNMENT_HORIZONTAL_CENTER);
+        expected.put("top", AlignmentInfo.Bits.ALIGNMENT_TOP);
+        expected.put("bottom", AlignmentInfo.Bits.ALIGNMENT_BOTTOM);
+        expected.put("middle", AlignmentInfo.Bits.ALIGNMENT_VERTICAL_CENTER);
 
         shortHorizontalAlignments.add("r");
         shortHorizontalAlignments.add("l");
@@ -178,8 +178,8 @@ public class Ticket2279 extends Application {
 
     private void checkAlignment(AlignmentHandler layout,
             String alignmentString, int expected) {
-        layout.setComponentAlignment(label, AlignmentInfo.ALIGNMENT_TOP,
-                AlignmentInfo.ALIGNMENT_LEFT);
+        layout.setComponentAlignment(label, AlignmentInfo.Bits.ALIGNMENT_TOP,
+                AlignmentInfo.Bits.ALIGNMENT_LEFT);
         if (layout instanceof AbstractOrderedLayout) {
             ((AbstractOrderedLayout) layout).setComponentAlignment(label,
                     alignmentString);
@@ -187,7 +187,7 @@ public class Ticket2279 extends Application {
             ((GridLayout) layout).setComponentAlignment(label, alignmentString);
         }
 
-        int actual = layout.getComponentAlignment(label);
+        int actual = layout.getComponentAlignment(label).getBitMask();
         if (actual != expected) {
             String error = "Error " + alignmentString
                     + " did not produce expected results";
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket2432.java b/src/com/itmill/toolkit/tests/tickets/Ticket2432.java
new file mode 100644 (file)
index 0000000..8897f0c
--- /dev/null
@@ -0,0 +1,51 @@
+package com.itmill.toolkit.tests.tickets;
+
+import com.itmill.toolkit.Application;
+import com.itmill.toolkit.ui.Alignment;
+import com.itmill.toolkit.ui.GridLayout;
+import com.itmill.toolkit.ui.HorizontalLayout;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.Layout;
+import com.itmill.toolkit.ui.Window;
+import com.itmill.toolkit.ui.Layout.AlignmentHandler;
+import com.itmill.toolkit.ui.Layout.SpacingHandler;
+
+public class Ticket2432 extends Application {
+
+    @Override
+    public void init() {
+
+        Window w = new Window();
+        setMainWindow(w);
+        w.getLayout().setSizeFull();
+        ((SpacingHandler) w.getLayout()).setSpacing(true);
+
+        Layout layout = new GridLayout(3, 3);
+        populateLayout(layout);
+        w.addComponent(layout);
+        layout = new HorizontalLayout();
+        populateLayout(layout);
+        w.addComponent(layout);
+
+    }
+
+    private static Alignment[] alignments = new Alignment[] {
+            Alignment.TOP_LEFT, Alignment.TOP_CENTER, Alignment.TOP_RIGHT,
+            Alignment.MIDDLE_LEFT, Alignment.MIDDLE_CENTER,
+            Alignment.MIDDLE_RIGHT, Alignment.BOTTOM_LEFT,
+            Alignment.BOTTOM_CENTER, Alignment.BOTTOM_RIGHT };
+
+    private void populateLayout(Layout layout) {
+        layout.setSizeFull();
+        for (int i = 0; i < 9; i++) {
+            Label l = new Label("M");
+            Alignment a = alignments[i];
+            l.setCaption(a.getHorizontalAlignment() + " "
+                    + a.getVerticalAlignment() + " " + a.getBitMask());
+            layout.addComponent(l);
+            ((AlignmentHandler) layout).setComponentAlignment(l, a);
+        }
+
+    }
+
+}
index 5fe3d616d919ba0edb7b48a800e7a69fb4741d58..6e430c98f28f5e7ab41668eb84ae35f87d7b323c 100644 (file)
@@ -17,19 +17,19 @@ import com.itmill.toolkit.terminal.Sizeable;
 public abstract class AbstractOrderedLayout extends AbstractLayout implements
         Layout.AlignmentHandler, Layout.SpacingHandler {
 
-    private static final int ALIGNMENT_DEFAULT = ALIGNMENT_TOP + ALIGNMENT_LEFT;
+    private static final Alignment ALIGNMENT_DEFAULT = Alignment.TOP_LEFT;
 
     /**
      * Custom layout slots containing the components.
      */
-    protected LinkedList components = new LinkedList();
+    protected LinkedList<Component> components = new LinkedList<Component>();
 
     /* Child component alignments */
 
     /**
      * Mapping from components to alignments (horizontal + vertical).
      */
-    private final Map componentToAlignment = new HashMap();
+    private final Map<Component, Alignment> componentToAlignment = new HashMap<Component, Alignment>();
 
     private final Map<Component, Float> componentToExpandRatio = new HashMap<Component, Float>();
 
@@ -157,7 +157,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
                 // Paint child component UIDL
                 c.paint(target);
                 alignmentsArray[index] = String
-                        .valueOf(getComponentAlignment(c));
+                        .valueOf(getComponentAlignment(c).getBitMask());
                 if (!equallyDivided) {
                     int myRatio = Math.round((getExpandRatio(c) / sum) * 1000);
                     expandRatioArray[index] = myRatio;
@@ -240,7 +240,8 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
     public void setComponentAlignment(Component childComponent,
             int horizontalAlignment, int verticalAlignment) {
         if (components.contains(childComponent)) {
-            componentToAlignment.put(childComponent, new Integer(
+            // Alignments are bit masks
+            componentToAlignment.put(childComponent, new Alignment(
                     horizontalAlignment + verticalAlignment));
             requestRepaint();
         } else {
@@ -249,6 +250,18 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
         }
     }
 
+    public void setComponentAlignment(Component childComponent,
+            Alignment alignment) {
+        if (components.contains(childComponent)) {
+            componentToAlignment.put(childComponent, alignment);
+            requestRepaint();
+        } else {
+            throw new IllegalArgumentException(
+                    "Component must be added to layout before using setComponentAlignment()");
+        }
+
+    }
+
     /*
      * (non-Javadoc)
      * 
@@ -256,13 +269,12 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
      * com.itmill.toolkit.ui.Layout.AlignmentHandler#getComponentAlignment(com
      * .itmill.toolkit.ui.Component)
      */
-    public int getComponentAlignment(Component childComponent) {
-        final Integer bitMask = (Integer) componentToAlignment
-                .get(childComponent);
-        if (bitMask != null) {
-            return bitMask.intValue();
-        } else {
+    public Alignment getComponentAlignment(Component childComponent) {
+        Alignment alignment = componentToAlignment.get(childComponent);
+        if (alignment == null) {
             return ALIGNMENT_DEFAULT;
+        } else {
+            return alignment;
         }
     }
 
diff --git a/src/com/itmill/toolkit/ui/Alignment.java b/src/com/itmill/toolkit/ui/Alignment.java
new file mode 100644 (file)
index 0000000..6d7ad9a
--- /dev/null
@@ -0,0 +1,152 @@
+package com.itmill.toolkit.ui;
+
+import com.itmill.toolkit.terminal.gwt.client.ui.AlignmentInfo.Bits;
+
+/**
+ * Class containing information about alignment of a component. Use the
+ * pre-instantiated classes.
+ */
+public final class Alignment {
+
+    public static final Alignment TOP_RIGHT = new Alignment(Bits.ALIGNMENT_TOP
+            + Bits.ALIGNMENT_RIGHT);
+    public static final Alignment TOP_LEFT = new Alignment(Bits.ALIGNMENT_TOP
+            + Bits.ALIGNMENT_LEFT);
+    public static final Alignment TOP_CENTER = new Alignment(Bits.ALIGNMENT_TOP
+            + Bits.ALIGNMENT_HORIZONTAL_CENTER);
+    public static final Alignment MIDDLE_RIGHT = new Alignment(
+            Bits.ALIGNMENT_VERTICAL_CENTER + Bits.ALIGNMENT_RIGHT);
+    public static final Alignment MIDDLE_LEFT = new Alignment(
+            Bits.ALIGNMENT_VERTICAL_CENTER + Bits.ALIGNMENT_LEFT);
+    public static final Alignment MIDDLE_CENTER = new Alignment(
+            Bits.ALIGNMENT_VERTICAL_CENTER + Bits.ALIGNMENT_HORIZONTAL_CENTER);
+    public static final Alignment BOTTOM_RIGHT = new Alignment(
+            Bits.ALIGNMENT_BOTTOM + Bits.ALIGNMENT_RIGHT);
+    public static final Alignment BOTTOM_LEFT = new Alignment(
+            Bits.ALIGNMENT_BOTTOM + Bits.ALIGNMENT_LEFT);
+    public static final Alignment BOTTOM_CENTER = new Alignment(
+            Bits.ALIGNMENT_BOTTOM + Bits.ALIGNMENT_HORIZONTAL_CENTER);
+
+    private final int bitMask;
+
+    public Alignment(int bitMask) {
+        this.bitMask = bitMask;
+    }
+
+    /**
+     * Returns a bitmask representation of the alignment value. Used internally
+     * by terminal.
+     * 
+     * @return the bitmask representation of the alignment value
+     */
+    public int getBitMask() {
+        return bitMask;
+    }
+
+    /**
+     * Checks if component is aligned to the top of the available space.
+     * 
+     * @return true if aligned top
+     */
+    public boolean isTop() {
+        return (bitMask & Bits.ALIGNMENT_TOP) == Bits.ALIGNMENT_TOP;
+    }
+
+    /**
+     * Checks if component is aligned to the bottom of the available space.
+     * 
+     * @return true if aligned bottom
+     */
+    public boolean isBottom() {
+        return (bitMask & Bits.ALIGNMENT_BOTTOM) == Bits.ALIGNMENT_BOTTOM;
+    }
+
+    /**
+     * Checks if component is aligned to the left of the available space.
+     * 
+     * @return true if aligned left
+     */
+    public boolean isLeft() {
+        return (bitMask & Bits.ALIGNMENT_LEFT) == Bits.ALIGNMENT_LEFT;
+    }
+
+    /**
+     * Checks if component is aligned to the right of the available space.
+     * 
+     * @return true if aligned right
+     */
+    public boolean isRight() {
+        return (bitMask & Bits.ALIGNMENT_RIGHT) == Bits.ALIGNMENT_RIGHT;
+    }
+
+    /**
+     * Checks if component is aligned middle (vertically center) of the
+     * available space.
+     * 
+     * @return true if aligned bottom
+     */
+    public boolean isMiddle() {
+        return (bitMask & Bits.ALIGNMENT_VERTICAL_CENTER) == Bits.ALIGNMENT_VERTICAL_CENTER;
+    }
+
+    /**
+     * Checks if component is aligned center (horizontally) of the available
+     * space.
+     * 
+     * @return true if aligned center
+     */
+    public boolean isCenter() {
+        return (bitMask & Bits.ALIGNMENT_HORIZONTAL_CENTER) == Bits.ALIGNMENT_HORIZONTAL_CENTER;
+    }
+
+    /**
+     * Returns string representation of vertical alignment.
+     * 
+     * @return vertical alignment as CSS value
+     */
+    public String getVerticalAlignment() {
+        if (isBottom()) {
+            return "bottom";
+        } else if (isMiddle()) {
+            return "middle";
+        }
+        return "top";
+    }
+
+    /**
+     * Returns string representation of horizontal alignment.
+     * 
+     * @return horizontal alignment as CSS value
+     */
+    public String getHorizontalAlignment() {
+        if (isRight()) {
+            return "right";
+        } else if (isCenter()) {
+            return "center";
+        }
+        return "left";
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if ((obj == null) || (obj.getClass() != this.getClass())) {
+            return false;
+        }
+        Alignment a = (Alignment) obj;
+        return bitMask == a.bitMask;
+    }
+
+    @Override
+    public int hashCode() {
+        return bitMask;
+    }
+
+    @Override
+    public String toString() {
+        return String.valueOf(bitMask);
+    }
+
+}
index 76ba3d5dc9d096a4fef4a51c727e8d7c15dbdd13..6a3c556241b24293c5a5a673dd807bc9d87272a8 100644 (file)
@@ -73,7 +73,8 @@ public class AlignmentUtils {
                     "alignment for setComponentAlignment() cannot be null or empty");
         }
 
-        Integer currentAlignment = parent.getComponentAlignment(component);
+        Integer currentAlignment = parent.getComponentAlignment(component)
+                .getBitMask();
 
         if (alignment.length() == 1) {
             // Use short form "t","l",...
@@ -100,8 +101,8 @@ public class AlignmentUtils {
 
         int horizontalAlignment = currentAlignment & horizontalMask;
         int verticalAlignment = currentAlignment & verticalMask;
-        parent.setComponentAlignment(component, horizontalAlignment,
-                verticalAlignment);
+        parent.setComponentAlignment(component, new Alignment(
+                horizontalAlignment + verticalAlignment));
     }
 
     /**
index c2c732a0c0a52d9997082bdab3369a42fdf4c8e0..49618620e304902c02fff33ad6f92ece3d1635ff 100644 (file)
@@ -73,14 +73,14 @@ public class GridLayout extends AbstractLayout implements
     /**
      * Mapping from components to alignments (horizontal + vertical).
      */
-    private Map componentToAlignment = new HashMap();
+    private Map<Component, Alignment> componentToAlignment = new HashMap<Component, Alignment>();
 
     /**
      * Is spacing between contained components enabled. Defaults to false.
      */
     private boolean spacing = false;
 
-    private static final int ALIGNMENT_DEFAULT = ALIGNMENT_TOP + ALIGNMENT_LEFT;
+    private static final Alignment ALIGNMENT_DEFAULT = Alignment.TOP_LEFT;
 
     /**
      * Has there been rows inserted or deleted in the middle of the layout since
@@ -504,7 +504,8 @@ public class GridLayout extends AbstractLayout implements
                     area.getComponent().paint(target);
 
                     alignmentsArray[index++] = String
-                            .valueOf(getComponentAlignment(area.getComponent()));
+                            .valueOf(getComponentAlignment(area.getComponent())
+                                    .getBitMask());
 
                     target.endTag("gc");
 
@@ -625,13 +626,12 @@ public class GridLayout extends AbstractLayout implements
      * com.itmill.toolkit.ui.Layout.AlignmentHandler#getComponentAlignment(com
      * .itmill.toolkit.ui.Component)
      */
-    public int getComponentAlignment(Component childComponent) {
-        final Integer bitMask = (Integer) componentToAlignment
-                .get(childComponent);
-        if (bitMask != null) {
-            return bitMask.intValue();
-        } else {
+    public Alignment getComponentAlignment(Component childComponent) {
+        Alignment alignment = componentToAlignment.get(childComponent);
+        if (alignment == null) {
             return ALIGNMENT_DEFAULT;
+        } else {
+            return alignment;
         }
     }
 
@@ -1091,11 +1091,17 @@ public class GridLayout extends AbstractLayout implements
      */
     public void setComponentAlignment(Component childComponent,
             int horizontalAlignment, int verticalAlignment) {
-        componentToAlignment.put(childComponent, new Integer(
+        componentToAlignment.put(childComponent, new Alignment(
                 horizontalAlignment + verticalAlignment));
         requestRepaint();
     }
 
+    public void setComponentAlignment(Component childComponent,
+            Alignment alignment) {
+        componentToAlignment.put(childComponent, alignment);
+        requestRepaint();
+    }
+
     /*
      * (non-Javadoc)
      * 
index bd26e6822e386bf3595367cf3ee6739a5430d90f..06d9b2b3bf57213b94d2658fdb02c2575bc65002 100644 (file)
@@ -4,8 +4,8 @@
 
 package com.itmill.toolkit.ui;
 
-import com.itmill.toolkit.terminal.gwt.client.ui.AlignmentInfo;
 import com.itmill.toolkit.terminal.gwt.client.ui.IMarginInfo;
+import com.itmill.toolkit.terminal.gwt.client.ui.AlignmentInfo.Bits;
 
 /**
  * Extension to the {@link ComponentContainer} interface which adds the
@@ -45,44 +45,66 @@ public interface Layout extends ComponentContainer {
             boolean left);
 
     /**
-     * TODO make javadocs, remove from implementing classes
+     * AlignmentHandler is most commonly an advanced {@link Layout} that can
+     * align its components.
      */
     public interface AlignmentHandler {
 
         /**
          * Contained component should be aligned horizontally to the left.
+         * 
+         * @deprecated Use of {@link Alignment} class and its constants
          */
-        public static final int ALIGNMENT_LEFT = AlignmentInfo.ALIGNMENT_LEFT;
+        @Deprecated
+        public static final int ALIGNMENT_LEFT = Bits.ALIGNMENT_LEFT;
 
         /**
          * Contained component should be aligned horizontally to the right.
+         * 
+         * @deprecated Use of {@link Alignment} class and its constants
          */
-        public static final int ALIGNMENT_RIGHT = AlignmentInfo.ALIGNMENT_RIGHT;
+        @Deprecated
+        public static final int ALIGNMENT_RIGHT = Bits.ALIGNMENT_RIGHT;
 
         /**
          * Contained component should be aligned vertically to the top.
+         * 
+         * @deprecated Use of {@link Alignment} class and its constants
          */
-        public static final int ALIGNMENT_TOP = AlignmentInfo.ALIGNMENT_TOP;
+        @Deprecated
+        public static final int ALIGNMENT_TOP = Bits.ALIGNMENT_TOP;
 
         /**
          * Contained component should be aligned vertically to the bottom.
+         * 
+         * @deprecated Use of {@link Alignment} class and its constants
          */
-        public static final int ALIGNMENT_BOTTOM = AlignmentInfo.ALIGNMENT_BOTTOM;
+        @Deprecated
+        public static final int ALIGNMENT_BOTTOM = Bits.ALIGNMENT_BOTTOM;
 
         /**
          * Contained component should be horizontally aligned to center.
+         * 
+         * @deprecated Use of {@link Alignment} class and its constants
          */
-        public static final int ALIGNMENT_HORIZONTAL_CENTER = AlignmentInfo.ALIGNMENT_HORIZONTAL_CENTER;
+        @Deprecated
+        public static final int ALIGNMENT_HORIZONTAL_CENTER = Bits.ALIGNMENT_HORIZONTAL_CENTER;
 
         /**
          * Contained component should be vertically aligned to center.
+         * 
+         * @deprecated Use of {@link Alignment} class and its constants
          */
-        public static final int ALIGNMENT_VERTICAL_CENTER = AlignmentInfo.ALIGNMENT_VERTICAL_CENTER;
+        @Deprecated
+        public static final int ALIGNMENT_VERTICAL_CENTER = Bits.ALIGNMENT_VERTICAL_CENTER;
 
         /**
          * Set alignment for one contained component in this layout. Alignment
          * is calculated as a bit mask of the two passed values.
          * 
+         * @deprecated Use {@link #setComponentAlignment(Component, Alignment)}
+         *             instead
+         * 
          * @param childComponent
          *            the component to align within it's layout cell.
          * @param horizontalAlignment
@@ -92,15 +114,33 @@ public interface Layout extends ComponentContainer {
          *            the vertical alignment for the child component (top,
          *            center, bottom). Use ALIGNMENT constants.
          */
+        @Deprecated
         public void setComponentAlignment(Component childComponent,
                 int horizontalAlignment, int verticalAlignment);
 
         /**
+         * Set alignment for one contained component in this layout. Use
+         * predefined alignments from Alignment class.
+         * 
+         * Example: <code>
+         *      layout.setComponentAlignment(myComponent, Alignment.TOP_RIGHT);
+         * </code>
          * 
          * @param childComponent
-         * @return
+         *            the component to align within it's layout cell.
+         * @param alignment
+         *            the Alignment value to be set
          */
-        public int getComponentAlignment(Component childComponent);
+        public void setComponentAlignment(Component childComponent,
+                Alignment alignment);
+
+        /**
+         * Returns the current Alignment of given component.
+         * 
+         * @param childComponent
+         * @return the {@link Alignment}
+         */
+        public Alignment getComponentAlignment(Component childComponent);
 
     }
 
@@ -133,8 +173,6 @@ public interface Layout extends ComponentContainer {
 
     /**
      * This type of layout can enable margins.
-     * 
-     * TODO refine javadocs
      */
     public interface MarginHandler {
         /**