aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/ui/AbstractLayout.java
diff options
context:
space:
mode:
authorJouni Koivuviita <jouni.koivuviita@itmill.com>2007-11-15 13:38:58 +0000
committerJouni Koivuviita <jouni.koivuviita@itmill.com>2007-11-15 13:38:58 +0000
commit61e5a7ae2ccd332b08d6509dd1769befd6b7f9b6 (patch)
tree61abc59b9bb319ab886ede9c5e1155e1165c4184 /src/com/itmill/toolkit/ui/AbstractLayout.java
parentc353f4494eac14591b8bd6234200442b8e1f851e (diff)
downloadvaadin-framework-61e5a7ae2ccd332b08d6509dd1769befd6b7f9b6.tar.gz
vaadin-framework-61e5a7ae2ccd332b08d6509dd1769befd6b7f9b6.zip
MAJOR UPDATE:
-Layout API changes: Layout extends Sizeable, Layout has two methods setMargin. -OrderedLayout and GridLayout got two new mehtods: setSpacing and setComponentAlignment. -Client-side layout implementations now mainly done using TABLE elements (changes to IOrderedLayout and IExpandLayout). -IScrollTable initial height calculation modified (small fix, clientHeight -> offsetHeight). -Some test modified to conform to new layout API. -Small typo fixes in comments. -OrderedLayout fix when changing orientation on the fly. -Panel and TabSheet are no longer Layouts, only ComponentContainers. -Refactored layout margins to use MarginInfo class, more readable, self-documenting code now. svn changeset:2827/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/ui/AbstractLayout.java')
-rw-r--r--src/com/itmill/toolkit/ui/AbstractLayout.java157
1 files changed, 140 insertions, 17 deletions
diff --git a/src/com/itmill/toolkit/ui/AbstractLayout.java b/src/com/itmill/toolkit/ui/AbstractLayout.java
index 10dc8694ba..6e7049bacc 100644
--- a/src/com/itmill/toolkit/ui/AbstractLayout.java
+++ b/src/com/itmill/toolkit/ui/AbstractLayout.java
@@ -2,6 +2,8 @@ package com.itmill.toolkit.ui;
import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget;
+import com.itmill.toolkit.terminal.Sizeable;
+import com.itmill.toolkit.terminal.gwt.client.ui.MarginInfo;
/**
* An abstract class that defines default implementation for the {@link Layout}
@@ -15,12 +17,31 @@ import com.itmill.toolkit.terminal.PaintTarget;
public abstract class AbstractLayout extends AbstractComponentContainer
implements Layout {
+ protected MarginInfo margins = new MarginInfo(false,false,false,false);
+
/**
- * Layout edge margins, clockwise from top: top, right, bottom, left. Each
- * is set to true, if the client-side implementation should leave extra
- * space at that edge.
+ * Height of the layout. Set to -1 for undefined height.
*/
- protected boolean[] margins;
+ private int height = -1;
+
+ /**
+ * Height unit.
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
+ */
+ private int heightUnit = UNITS_PIXELS;
+
+ /**
+ * Width of the layout. Set to -1 for undefined width.
+ */
+ private int width = -1;
+
+ /**
+ * Width unit.
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
+ */
+ private int widthUnit = UNITS_PIXELS;
/*
* (non-Javadoc)
@@ -35,7 +56,8 @@ public abstract class AbstractLayout extends AbstractComponentContainer
* @see com.itmill.toolkit.ui.Layout#setMargin(boolean)
*/
public void setMargin(boolean enabled) {
- margins = new boolean[] { enabled, enabled, enabled, enabled };
+ margins.setMargins(enabled);
+ requestRepaint();
}
/*
@@ -46,8 +68,110 @@ public abstract class AbstractLayout extends AbstractComponentContainer
*/
public void setMargin(boolean topEnabled, boolean rightEnabled,
boolean bottomEnabled, boolean leftEnabled) {
- margins = new boolean[] { topEnabled, rightEnabled, bottomEnabled,
- leftEnabled };
+ margins.setMargins(topEnabled, rightEnabled, bottomEnabled, leftEnabled);
+ requestRepaint();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable#getHeight()
+ */
+ public int getHeight() {
+ return height;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits()
+ */
+ public int getHeightUnits() {
+ return heightUnit;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable#getWidth()
+ */
+ public int getWidth() {
+ return width;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits()
+ */
+ public int getWidthUnits() {
+ return widthUnit;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable#setHeight(int)
+ */
+ public void setHeight(int height) {
+ this.height = height;
+ requestRepaint();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int)
+ */
+ public void setHeightUnits(int units) {
+ this.heightUnit = units;
+ requestRepaint();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable#setSizeFull()
+ */
+ public void setSizeFull() {
+ height = 100;
+ width = 100;
+ heightUnit = UNITS_PERCENTAGE;
+ widthUnit = UNITS_PERCENTAGE;
+ requestRepaint();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable#setSizeUndefined()
+ */
+ public void setSizeUndefined() {
+ height = -1;
+ width = -1;
+ heightUnit = UNITS_PIXELS;
+ widthUnit = UNITS_PIXELS;
+ requestRepaint();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable#setWidth(int)
+ */
+ public void setWidth(int width) {
+ this.width = width;
+ requestRepaint();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.itmill.toolkit.terminal.Sizeable#setWidthUnits(int)
+ */
+ public void setWidthUnits(int units) {
+ this.widthUnit = units;
+ requestRepaint();
}
/*
@@ -58,16 +182,15 @@ public abstract class AbstractLayout extends AbstractComponentContainer
public void paintContent(PaintTarget target) throws PaintException {
// Add margin info. Defaults to false.
- if (margins == null)
- setMargin(false);
- if (margins[0])
- target.addAttribute("marginTop", margins[0]);
- if (margins[1])
- target.addAttribute("marginRight", margins[1]);
- if (margins[2])
- target.addAttribute("marginBottom", margins[2]);
- if (margins[3])
- target.addAttribute("marginLeft", margins[3]);
+ target.addAttribute("margins", margins.getBitMask());
+
+ // Size
+ if (getHeight() >= 0)
+ target.addAttribute("height", "" + getHeight()
+ + Sizeable.UNIT_SYMBOLS[getHeightUnits()]);
+ if (getWidth() >= 0)
+ target.addAttribute("width", "" + getWidth()
+ + Sizeable.UNIT_SYMBOLS[getWidthUnits()]);
}
}