From 0c9e98e2256cfb23b4079ba0a1daa2af77560cbb Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 7 Feb 2008 08:14:16 +0000 Subject: [PATCH] extracted alignments and spacing to layouts subinterfaces svn changeset:3723/svn branch:trunk --- src/com/itmill/toolkit/ui/GridLayout.java | 79 ++++++------------ src/com/itmill/toolkit/ui/Layout.java | 88 ++++++++++++++++++++ src/com/itmill/toolkit/ui/OrderedLayout.java | 76 +++++------------ 3 files changed, 132 insertions(+), 111 deletions(-) diff --git a/src/com/itmill/toolkit/ui/GridLayout.java b/src/com/itmill/toolkit/ui/GridLayout.java index 9cbaa9b59f..01ac7f84f1 100644 --- a/src/com/itmill/toolkit/ui/GridLayout.java +++ b/src/com/itmill/toolkit/ui/GridLayout.java @@ -12,7 +12,6 @@ import java.util.Map; import com.itmill.toolkit.terminal.PaintException; import com.itmill.toolkit.terminal.PaintTarget; -import com.itmill.toolkit.terminal.gwt.client.ui.AlignmentInfo; /** *

@@ -34,7 +33,8 @@ import com.itmill.toolkit.terminal.gwt.client.ui.AlignmentInfo; * @VERSION@ * @since 3.0 */ -public class GridLayout extends AbstractLayout { +public class GridLayout extends AbstractLayout implements + Layout.AlignmentHandler, Layout.SpacingHandler { /** * Initial grid columns. @@ -74,43 +74,13 @@ public class GridLayout extends AbstractLayout { */ private Map componentToAlignment = new HashMap(); - /** - * Contained component should be aligned horizontally to the left. - */ - public static final int ALIGNMENT_LEFT = AlignmentInfo.ALIGNMENT_LEFT; - - /** - * Contained component should be aligned horizontally to the right. - */ - public static final int ALIGNMENT_RIGHT = AlignmentInfo.ALIGNMENT_RIGHT; - - /** - * Contained component should be aligned vertically to the top. - */ - public static final int ALIGNMENT_TOP = AlignmentInfo.ALIGNMENT_TOP; - - /** - * Contained component should be aligned vertically to the bottom. - */ - public static final int ALIGNMENT_BOTTOM = AlignmentInfo.ALIGNMENT_BOTTOM; - - /** - * Contained component should be horizontally aligned to center. - */ - public static final int ALIGNMENT_HORIZONTAL_CENTER = AlignmentInfo.ALIGNMENT_HORIZONTAL_CENTER; - - /** - * Contained component should be vertically aligned to center. - */ - public static final int ALIGNMENT_VERTICAL_CENTER = AlignmentInfo.ALIGNMENT_VERTICAL_CENTER; - - private static final int ALIGNMENT_DEFAULT = ALIGNMENT_TOP + ALIGNMENT_LEFT; - /** * Is spacing between contained components enabled. Defaults to false. */ private boolean spacing = false; + private static final int ALIGNMENT_DEFAULT = ALIGNMENT_TOP + ALIGNMENT_LEFT; + /** * Constructor for grid of given size (number of cells). Note that grid's * final size depends on the items that are added into the grid. Grid grows @@ -546,6 +516,11 @@ public class GridLayout extends AbstractLayout { } + /* + * (non-Javadoc) + * + * @see com.itmill.toolkit.ui.Layout.AlignmentHandler#getComponentAlignment(com.itmill.toolkit.ui.Component) + */ public int getComponentAlignment(Component childComponent) { final Integer bitMask = (Integer) componentToAlignment .get(childComponent); @@ -977,17 +952,11 @@ public class GridLayout extends AbstractLayout { cursorY = 0; } - /** - * Set alignment for one contained component in this layout. + /* + * (non-Javadoc) * - * @param childComponent - * the component to align within it's layout cell. - * @param horizontalAlignment - * the horizontal alignment for the child component (left, - * center, right). - * @param verticalAlignment - * the vertical alignment for the child component (top, - * center, bottom). + * @see com.itmill.toolkit.ui.Layout.AlignmentHandler#setComponentAlignment(com.itmill.toolkit.ui.Component, + * int, int) */ public void setComponentAlignment(Component childComponent, int horizontalAlignment, int verticalAlignment) { @@ -995,20 +964,22 @@ public class GridLayout extends AbstractLayout { horizontalAlignment + verticalAlignment)); } - /** - * Enable spacing between child components within this layout. - * - *

- * NOTE: This will only affect spaces between components, - * not also all around spacing of the layout (i.e. do not mix this with HTML - * Table elements cellspacing-attribute). Use {@link #setMargin(boolean)} to - * add extra space around the layout. - *

+ /* + * (non-Javadoc) * - * @param enabled + * @see com.itmill.toolkit.ui.Layout.SpacingHandler#setSpacing(boolean) */ public void setSpacing(boolean enabled) { spacing = enabled; } + /* + * (non-Javadoc) + * + * @see com.itmill.toolkit.ui.Layout.SpacingHandler#isSpacingEnabled() + */ + public boolean isSpacingEnabled() { + return spacing; + } + } diff --git a/src/com/itmill/toolkit/ui/Layout.java b/src/com/itmill/toolkit/ui/Layout.java index 55430113c7..d2bc21e85e 100644 --- a/src/com/itmill/toolkit/ui/Layout.java +++ b/src/com/itmill/toolkit/ui/Layout.java @@ -4,6 +4,7 @@ package com.itmill.toolkit.ui; +import com.itmill.toolkit.terminal.gwt.client.ui.AlignmentInfo; /** * Extension to the {@link ComponentContainer} interface which adds the @@ -42,4 +43,91 @@ public interface Layout extends ComponentContainer { public void setMargin(boolean top, boolean right, boolean bottom, boolean left); + /** + * TODO make javadocs, remove from implementing classes + */ + public interface AlignmentHandler extends Layout { + + /** + * Contained component should be aligned horizontally to the left. + */ + public static final int ALIGNMENT_LEFT = AlignmentInfo.ALIGNMENT_LEFT; + + /** + * Contained component should be aligned horizontally to the right. + */ + public static final int ALIGNMENT_RIGHT = AlignmentInfo.ALIGNMENT_RIGHT; + + /** + * Contained component should be aligned vertically to the top. + */ + public static final int ALIGNMENT_TOP = AlignmentInfo.ALIGNMENT_TOP; + + /** + * Contained component should be aligned vertically to the bottom. + */ + public static final int ALIGNMENT_BOTTOM = AlignmentInfo.ALIGNMENT_BOTTOM; + + /** + * Contained component should be horizontally aligned to center. + */ + public static final int ALIGNMENT_HORIZONTAL_CENTER = AlignmentInfo.ALIGNMENT_HORIZONTAL_CENTER; + + /** + * Contained component should be vertically aligned to center. + */ + public static final int ALIGNMENT_VERTICAL_CENTER = AlignmentInfo.ALIGNMENT_VERTICAL_CENTER; + + /** + * Set alignment for one contained component in this layout. Alignment + * is calculated as a bit mask of the two passed values. + * + * @param childComponent + * the component to align within it's layout cell. + * @param horizontalAlignment + * the horizontal alignment for the child component + * (left, center, right). Use ALIGNMENT constants. + * @param verticalAlignment + * the vertical alignment for the child component (top, + * center, bottom). Use ALIGNMENT constants. + */ + public void setComponentAlignment(Component childComponent, + int horizontalAlignment, int verticalAlignment); + + /** + * + * @param childComponent + * @return + */ + public int getComponentAlignment(Component childComponent); + + } + + /** + * This type of layout can set spacing between its components on of off. + * + * TODO refine javadocs + */ + public interface SpacingHandler extends Layout { + /** + * Enable spacing between child components within this layout. + * + *

+ * NOTE: This will only affect spaces between + * components, not also all around spacing of the layout (i.e. do not + * mix this with HTML Table elements cellspacing-attribute). Use + * {@link #setMargin(boolean)} to add extra space around the layout. + *

+ * + * @param enabled + */ + public void setSpacing(boolean enabled); + + /** + * + * @return true if spacing, layout leaves space between components + */ + public boolean isSpacingEnabled(); + } + } diff --git a/src/com/itmill/toolkit/ui/OrderedLayout.java b/src/com/itmill/toolkit/ui/OrderedLayout.java index 6eefd72a46..97bceee1fa 100644 --- a/src/com/itmill/toolkit/ui/OrderedLayout.java +++ b/src/com/itmill/toolkit/ui/OrderedLayout.java @@ -11,7 +11,6 @@ import java.util.Map; import com.itmill.toolkit.terminal.PaintException; import com.itmill.toolkit.terminal.PaintTarget; -import com.itmill.toolkit.terminal.gwt.client.ui.AlignmentInfo; /** * Ordered layout. @@ -24,7 +23,8 @@ import com.itmill.toolkit.terminal.gwt.client.ui.AlignmentInfo; * @VERSION@ * @since 3.0 */ -public class OrderedLayout extends AbstractLayout { +public class OrderedLayout extends AbstractLayout implements + Layout.AlignmentHandler, Layout.SpacingHandler { /* Predefined orientations ***************************************** */ @@ -38,6 +38,8 @@ public class OrderedLayout extends AbstractLayout { */ public static int ORIENTATION_HORIZONTAL = 1; + private static final int ALIGNMENT_DEFAULT = ALIGNMENT_TOP + ALIGNMENT_LEFT; + /** * Custom layout slots containing the components. */ @@ -50,38 +52,6 @@ public class OrderedLayout extends AbstractLayout { */ private final Map componentToAlignment = new HashMap(); - /** - * Contained component should be aligned horizontally to the left. - */ - public static final int ALIGNMENT_LEFT = AlignmentInfo.ALIGNMENT_LEFT; - - /** - * Contained component should be aligned horizontally to the right. - */ - public static final int ALIGNMENT_RIGHT = AlignmentInfo.ALIGNMENT_RIGHT; - - /** - * Contained component should be aligned vertically to the top. - */ - public static final int ALIGNMENT_TOP = AlignmentInfo.ALIGNMENT_TOP; - - /** - * Contained component should be aligned vertically to the bottom. - */ - public static final int ALIGNMENT_BOTTOM = AlignmentInfo.ALIGNMENT_BOTTOM; - - /** - * Contained component should be horizontally aligned to center. - */ - public static final int ALIGNMENT_HORIZONTAL_CENTER = AlignmentInfo.ALIGNMENT_HORIZONTAL_CENTER; - - /** - * Contained component should be vertically aligned to center. - */ - public static final int ALIGNMENT_VERTICAL_CENTER = AlignmentInfo.ALIGNMENT_VERTICAL_CENTER; - - private static final int ALIGNMENT_DEFAULT = ALIGNMENT_TOP + ALIGNMENT_LEFT; - /** * Orientation of the layout. */ @@ -303,18 +273,11 @@ public class OrderedLayout extends AbstractLayout { } } - /** - * Set alignment for one contained component in this layout. Alignment is - * calculated as a bit mask of the two passed values. + /* + * (non-Javadoc) * - * @param childComponent - * the component to align within it's layout cell. - * @param horizontalAlignment - * the horizontal alignment for the child component (left, - * center, right). - * @param verticalAlignment - * the vertical alignment for the child component (top, - * center, bottom). + * @see com.itmill.toolkit.ui.Layout.AlignmentHandler#setComponentAlignment(com.itmill.toolkit.ui.Component, + * int, int) */ public void setComponentAlignment(Component childComponent, int horizontalAlignment, int verticalAlignment) { @@ -323,6 +286,11 @@ public class OrderedLayout extends AbstractLayout { requestRepaint(); } + /* + * (non-Javadoc) + * + * @see com.itmill.toolkit.ui.Layout.AlignmentHandler#getComponentAlignment(com.itmill.toolkit.ui.Component) + */ public int getComponentAlignment(Component childComponent) { final Integer bitMask = (Integer) componentToAlignment .get(childComponent); @@ -333,26 +301,20 @@ public class OrderedLayout extends AbstractLayout { } } - /** - * Enable spacing between child components within this layout. - * - *

- * NOTE: This will only affect spaces between components, - * not also all around spacing of the layout (i.e. do not mix this with HTML - * Table elements cellspacing-attribute). Use {@link #setMargin(boolean)} to - * add extra space around the layout. - *

+ /* + * (non-Javadoc) * - * @param enabled + * @see com.itmill.toolkit.ui.Layout.SpacingHandler#setSpacing(boolean) */ public void setSpacing(boolean enabled) { spacing = enabled; requestRepaint(); } - /** + /* + * (non-Javadoc) * - * @return true if spacing, layout leaves space between components + * @see com.itmill.toolkit.ui.Layout.SpacingHandler#isSpacingEnabled() */ public boolean isSpacingEnabled() { return spacing; -- 2.39.5