]> source.dussan.org Git - vaadin-framework.git/commitdiff
extracted alignments and spacing to layouts subinterfaces
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 7 Feb 2008 08:14:16 +0000 (08:14 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 7 Feb 2008 08:14:16 +0000 (08:14 +0000)
svn changeset:3723/svn branch:trunk

src/com/itmill/toolkit/ui/GridLayout.java
src/com/itmill/toolkit/ui/Layout.java
src/com/itmill/toolkit/ui/OrderedLayout.java

index 9cbaa9b59fc4b36176fcebc99f6418d1d0211e70..01ac7f84f1512790d90afe64f1ed0f3c552dbb0e 100644 (file)
@@ -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;
 
 /**
  * <p>
@@ -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.
-     * 
-     * <p>
-     * <strong>NOTE:</strong> 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.
-     * </p>
+    /*
+     * (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;
+    }
+
 }
index 55430113c726ab9ba4b39f1e3d7b104dfabed345..d2bc21e85e063a7f6cb003f3d4c6cac5a09fcc7f 100644 (file)
@@ -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.
+         * 
+         * <p>
+         * <strong>NOTE:</strong> 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.
+         * </p>
+         * 
+         * @param enabled
+         */
+        public void setSpacing(boolean enabled);
+
+        /**
+         * 
+         * @return true if spacing, layout leaves space between components
+         */
+        public boolean isSpacingEnabled();
+    }
+
 }
index 6eefd72a464ad6c993d87f84f8903de0c2b204fc..97bceee1fab5de79ca41c366253ac4985312c1e4 100644 (file)
@@ -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.
-     * 
-     * <p>
-     * <strong>NOTE:</strong> 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.
-     * </p>
+    /*
+     * (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;