001: /* Borderlayout.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Aug 27, 2007 3:34:53 PM , Created by jumperchen
010: }}IS_NOTE
011:
012: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.zkex.zul;
020:
021: import org.zkoss.zk.ui.Component;
022: import org.zkoss.zk.ui.HtmlBasedComponent;
023: import org.zkoss.zk.ui.UiException;
024: import org.zkoss.zk.ui.ext.render.ChildChangedAware;
025: import org.zkoss.zul.impl.XulElement;
026:
027: /**
028: * A border layout lays out a container, arranging and resizing its components
029: * to fit in five regions: north, south, east, west, and center. Each region may
030: * contain no more than one component, and is identified by a corresponding
031: * constant: <code>NORTH</code>, <code>SOUTH</code>, <code>EAST</code>,
032: * <code>WEST</code>, and <code>CENTER</code>. When adding a component to
033: * a container with a border layout, use one of these five constants, for
034: * example:
035: *
036: * <pre>
037: * <borderlayout>
038: * <north margins="1,5,1,1" size="20%" splittable="true" collapsible="true" minsize="100" maxsize="400">
039: * <div>
040: * North
041: * </div>
042: * </north>
043: * <west size="25%" splittable="true" autoscroll="true">
044: * <div>
045: * West
046: * </div>
047: * </west>
048: * <center flex="true">
049: * <div>
050: * Center
051: * </div>
052: * </center>
053: * <east size="25%" collapsible="true" onOpen='alert(self.id + " is open :" +event.open)'>
054: * <div>
055: * East
056: * </div>
057: * </east>
058: * <south size="50%" splittable="true">
059: * <div>
060: * south
061: * </div>
062: * </south>
063: * </borderlayout>
064: *
065: * </pre>
066: *
067: * The default class of CSS is specified "layout-container".
068: *
069: * @author jumperchen
070: * @since 3.0.0
071: */
072: public class Borderlayout extends HtmlBasedComponent {
073:
074: /**
075: * The north layout constraint (top of container).
076: */
077: public static final String NORTH = "north";
078:
079: /**
080: * The south layout constraint (bottom of container).
081: */
082: public static final String SOUTH = "south";
083:
084: /**
085: * The east layout constraint (right side of container).
086: */
087: public static final String EAST = "east";
088:
089: /**
090: * The west layout constraint (left side of container).
091: */
092: public static final String WEST = "west";
093:
094: /**
095: * The center layout constraint (middle of container).
096: */
097: public static final String CENTER = "center";
098:
099: private North _north;
100:
101: private South _south;
102:
103: private West _west;
104:
105: private East _east;
106:
107: private Center _center;
108:
109: public Borderlayout() {
110: setClass("layout-container");
111: }
112:
113: public North getNorth() {
114: return _north;
115: }
116:
117: public South getSouth() {
118: return _south;
119: }
120:
121: public West getWest() {
122: return _west;
123: }
124:
125: public East getEast() {
126: return _east;
127: }
128:
129: public Center getCenter() {
130: return _center;
131: }
132:
133: /**
134: * Re-size this layout component.
135: */
136: public void resize() {
137: smartUpdate("z.resize", "");
138: }
139:
140: public boolean insertBefore(Component child, Component insertBefore) {
141: if (!(child instanceof LayoutRegion))
142: throw new UiException(
143: "Unsupported child for Borderlayout: " + child);
144: if (child instanceof North) {
145: if (_north != null && child != _north)
146: throw new UiException(
147: "Only one north child is allowed: " + this );
148: _north = (North) child;
149: } else if (child instanceof South) {
150: if (_south != null && child != _south)
151: throw new UiException(
152: "Only one south child is allowed: " + this );
153: _south = (South) child;
154: } else if (child instanceof West) {
155: if (_west != null && child != _west)
156: throw new UiException(
157: "Only one west child is allowed: " + this );
158: _west = (West) child;
159: } else if (child instanceof East) {
160: if (_east != null && child != _east)
161: throw new UiException(
162: "Only one east child is allowed: " + this );
163: _east = (East) child;
164: } else if (child instanceof Center) {
165: if (_center != null && child != _center)
166: throw new UiException(
167: "Only one center child is allowed: " + this );
168: _center = (Center) child;
169: }
170: return super .insertBefore(child, insertBefore);
171: }
172:
173: // -- ComponentCtrl --//
174: protected Object newExtraCtrl() {
175: return new ExtraCtrl();
176: }
177:
178: /**
179: * A utility class to implement {@link #getExtraCtrl}. It is used only by
180: * component developers.
181: */
182: protected class ExtraCtrl extends XulElement.ExtraCtrl implements
183: ChildChangedAware {
184:
185: public boolean isChildChangedAware() {
186: return true;
187: }
188: }
189: }
|