summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2009-01-09 09:07:13 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2009-01-09 09:07:13 +0000
commit55b3412fbae777d96d8c85cd36505e8ac18f79b9 (patch)
tree13a3944c555d02736eebfde49d81c610eb051df7 /src
parent9b5131c8fcb74823908d6757998bbb77d787a3b7 (diff)
downloadvaadin-framework-55b3412fbae777d96d8c85cd36505e8ac18f79b9.tar.gz
vaadin-framework-55b3412fbae777d96d8c85cd36505e8ac18f79b9.zip
fixes #2432, AlignmentHandler methods now symmetric + saner usage overall
svn changeset:6473/svn branch:trunk
Diffstat (limited to 'src')
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/AlignmentInfo.java55
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/layout/ChildComponentContainer.java4
-rw-r--r--src/com/itmill/toolkit/tests/tickets/Ticket2279.java32
-rw-r--r--src/com/itmill/toolkit/tests/tickets/Ticket2432.java51
-rw-r--r--src/com/itmill/toolkit/ui/AbstractOrderedLayout.java34
-rw-r--r--src/com/itmill/toolkit/ui/Alignment.java152
-rw-r--r--src/com/itmill/toolkit/ui/AlignmentUtils.java7
-rw-r--r--src/com/itmill/toolkit/ui/GridLayout.java26
-rw-r--r--src/com/itmill/toolkit/ui/Layout.java62
9 files changed, 348 insertions, 75 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/AlignmentInfo.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/AlignmentInfo.java
index 68024d849a..cf4afb44dd 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/AlignmentInfo.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/AlignmentInfo.java
@@ -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() {
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/ChildComponentContainer.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/ChildComponentContainer.java
index 6836c59270..6367c03a3e 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/ChildComponentContainer.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/ChildComponentContainer.java
@@ -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;
/**
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket2279.java b/src/com/itmill/toolkit/tests/tickets/Ticket2279.java
index 530ee035d0..f7889c599f 100644
--- a/src/com/itmill/toolkit/tests/tickets/Ticket2279.java
+++ b/src/com/itmill/toolkit/tests/tickets/Ticket2279.java
@@ -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
index 0000000000..8897f0ccec
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/tickets/Ticket2432.java
@@ -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);
+ }
+
+ }
+
+}
diff --git a/src/com/itmill/toolkit/ui/AbstractOrderedLayout.java b/src/com/itmill/toolkit/ui/AbstractOrderedLayout.java
index 5fe3d616d9..6e430c98f2 100644
--- a/src/com/itmill/toolkit/ui/AbstractOrderedLayout.java
+++ b/src/com/itmill/toolkit/ui/AbstractOrderedLayout.java
@@ -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
index 0000000000..6d7ad9accf
--- /dev/null
+++ b/src/com/itmill/toolkit/ui/Alignment.java
@@ -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);
+ }
+
+}
diff --git a/src/com/itmill/toolkit/ui/AlignmentUtils.java b/src/com/itmill/toolkit/ui/AlignmentUtils.java
index 76ba3d5dc9..6a3c556241 100644
--- a/src/com/itmill/toolkit/ui/AlignmentUtils.java
+++ b/src/com/itmill/toolkit/ui/AlignmentUtils.java
@@ -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));
}
/**
diff --git a/src/com/itmill/toolkit/ui/GridLayout.java b/src/com/itmill/toolkit/ui/GridLayout.java
index c2c732a0c0..49618620e3 100644
--- a/src/com/itmill/toolkit/ui/GridLayout.java
+++ b/src/com/itmill/toolkit/ui/GridLayout.java
@@ -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)
*
diff --git a/src/com/itmill/toolkit/ui/Layout.java b/src/com/itmill/toolkit/ui/Layout.java
index bd26e6822e..06d9b2b3bf 100644
--- a/src/com/itmill/toolkit/ui/Layout.java
+++ b/src/com/itmill/toolkit/ui/Layout.java
@@ -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 {
/**