001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.plaf.css;
014:
015: import org.wings.*;
016: import org.wings.plaf.css.PaddingVoodoo;
017: import org.wings.io.Device;
018:
019: import java.io.IOException;
020: import java.awt.*;
021:
022: public class BorderLayoutCG extends AbstractLayoutCG {
023:
024: private static final long serialVersionUID = 1L;
025:
026: public void write(Device d, SLayoutManager l) throws IOException {
027: final SBorderLayout layout = (SBorderLayout) l;
028: SContainer container = l.getContainer();
029:
030: final SComponent north = (SComponent) layout.getComponents()
031: .get(SBorderLayout.NORTH);
032: final SComponent east = (SComponent) layout.getComponents()
033: .get(SBorderLayout.EAST);
034: final SComponent center = (SComponent) layout.getComponents()
035: .get(SBorderLayout.CENTER);
036: final SComponent west = (SComponent) layout.getComponents()
037: .get(SBorderLayout.WEST);
038: final SComponent south = (SComponent) layout.getComponents()
039: .get(SBorderLayout.SOUTH);
040:
041: final TableCellStyle cellStyle = cellLayoutStyle(layout);
042: final TableCellStyle origCellStyle = cellStyle.makeACopy();
043:
044: SDimension preferredSize = container.getPreferredSize();
045: String height = preferredSize != null ? preferredSize
046: .getHeight() : null;
047: boolean clientLayout = isMSIE(container) && height != null
048: && !"auto".equals(height);
049: int oversize = layoutOversize(l);
050:
051: int cols = 1;
052: if (west != null) {
053: cols++;
054: }
055: if (east != null) {
056: cols++;
057: }
058:
059: openLayouterBody(d, layout);
060:
061: if (north != null) {
062: cellStyle.defaultLayoutCellHAlignment = SConstants.LEFT;
063: cellStyle.defaultLayoutCellVAlignment = SConstants.TOP;
064: cellStyle.width = null;
065: cellStyle.colspan = cols;
066: cellStyle.rowspan = -1;
067:
068: if (clientLayout) {
069: d.print("<tr");
070: Utils.optAttribute(d, "oversize", oversize);
071: d.print(">");
072: } else
073: openLayouterRow(d, "0%");
074: Utils.printNewline(d, north);
075:
076: if (PaddingVoodoo.hasPaddingInsets(container)) {
077: final Insets patchedInsets = (Insets) origCellStyle
078: .getInsets().clone();
079: final boolean isFirstRow = true;
080: final boolean isLastRow = west == null
081: && center == null && east == null
082: && south == null;
083: final boolean isFirstCol = true;
084: final boolean isLastCol = true;
085: PaddingVoodoo.doBorderPaddingsWorkaround(container
086: .getBorder(), patchedInsets, isFirstRow,
087: isFirstCol, isLastCol, isLastRow);
088: cellStyle.setInsets(patchedInsets);
089: }
090:
091: openLayouterCell(d, north, cellStyle);
092: north.write(d);
093: closeLayouterCell(d, north, false);
094: Utils.printNewline(d, layout.getContainer());
095: closeLayouterRow(d);
096: Utils.printNewline(d, layout.getContainer());
097: }
098:
099: if (clientLayout) {
100: d.print("<tr yweight=\"100\"");
101: Utils.optAttribute(d, "oversize", oversize);
102: d.print(">");
103: } else
104: openLayouterRow(d, "100%");
105:
106: if (west != null) {
107: cellStyle.defaultLayoutCellHAlignment = SConstants.LEFT;
108: cellStyle.defaultLayoutCellVAlignment = SConstants.CENTER;
109: cellStyle.width = "0%";
110: cellStyle.colspan = -1;
111: cellStyle.rowspan = -1;
112:
113: if (PaddingVoodoo.hasPaddingInsets(container)) {
114: final Insets patchedInsets = (Insets) origCellStyle
115: .getInsets().clone();
116: final boolean isFirstRow = north == null;
117: final boolean isLastRow = south == null;
118: final boolean isFirstCol = true;
119: final boolean isLastCol = center == null
120: && east == null;
121: PaddingVoodoo.doBorderPaddingsWorkaround(container
122: .getBorder(), patchedInsets, isFirstRow,
123: isFirstCol, isLastCol, isLastRow);
124: cellStyle.setInsets(patchedInsets);
125: }
126:
127: Utils.printNewline(d, west);
128: openLayouterCell(d, west, cellStyle);
129: west.write(d);
130: closeLayouterCell(d, west, false);
131: }
132:
133: if (center != null) {
134: cellStyle.defaultLayoutCellHAlignment = SConstants.LEFT;
135: cellStyle.defaultLayoutCellVAlignment = SConstants.CENTER;
136: cellStyle.width = "100%";
137: cellStyle.colspan = -1;
138: cellStyle.rowspan = -1;
139:
140: if (PaddingVoodoo.hasPaddingInsets(container)) {
141: final Insets patchedInsets = (Insets) origCellStyle
142: .getInsets().clone();
143: final boolean isFirstRow = north == null;
144: final boolean isLastRow = south == null;
145: final boolean isFirstCol = west == null;
146: final boolean isLastCol = east == null;
147: PaddingVoodoo.doBorderPaddingsWorkaround(container
148: .getBorder(), patchedInsets, isFirstRow,
149: isFirstCol, isLastCol, isLastRow);
150: cellStyle.setInsets(patchedInsets);
151: }
152:
153: Utils.printNewline(d, center);
154: openLayouterCell(d, center, cellStyle);
155: center.write(d);
156: closeLayouterCell(d, center, false);
157: } else {
158: d.print("<td width=\"100%\"></td>");
159: }
160:
161: if (east != null) {
162: cellStyle.defaultLayoutCellHAlignment = SConstants.RIGHT;
163: cellStyle.defaultLayoutCellVAlignment = SConstants.CENTER;
164: cellStyle.width = "0%";
165: cellStyle.colspan = -1;
166: cellStyle.rowspan = -1;
167:
168: if (PaddingVoodoo.hasPaddingInsets(container)) {
169: final Insets patchedInsets = (Insets) origCellStyle
170: .getInsets().clone();
171: final boolean isFirstRow = north == null;
172: final boolean isLastRow = south == null;
173: final boolean isFirstCol = west == null
174: && center == null;
175: final boolean isLastCol = true;
176: PaddingVoodoo.doBorderPaddingsWorkaround(container
177: .getBorder(), patchedInsets, isFirstRow,
178: isFirstCol, isLastCol, isLastRow);
179: cellStyle.setInsets(patchedInsets);
180: }
181:
182: Utils.printNewline(d, east);
183: openLayouterCell(d, east, cellStyle);
184: east.write(d);
185: closeLayouterCell(d, east, false);
186: }
187:
188: Utils.printNewline(d, layout.getContainer());
189: closeLayouterRow(d);
190:
191: if (south != null) {
192: cellStyle.defaultLayoutCellHAlignment = SConstants.LEFT;
193: cellStyle.defaultLayoutCellVAlignment = SConstants.BOTTOM;
194: cellStyle.width = "0%";
195: cellStyle.colspan = cols;
196: cellStyle.rowspan = -1;
197:
198: if (PaddingVoodoo.hasPaddingInsets(container)) {
199: final Insets patchedInsets = (Insets) origCellStyle
200: .getInsets().clone();
201: final boolean isFirstRow = north == null
202: && west == null && center == null
203: && east == null;
204: final boolean isLastRow = true;
205: final boolean isFirstCol = true;
206: final boolean isLastCol = true;
207: PaddingVoodoo.doBorderPaddingsWorkaround(container
208: .getBorder(), patchedInsets, isFirstRow,
209: isFirstCol, isLastCol, isLastRow);
210: cellStyle.setInsets(patchedInsets);
211: }
212:
213: Utils.printNewline(d, layout.getContainer());
214: if (clientLayout) {
215: d.print("<tr");
216: Utils.optAttribute(d, "oversize", oversize);
217: d.print(">");
218: } else
219: openLayouterRow(d, "0%");
220: Utils.printNewline(d, south);
221: openLayouterCell(d, south, cellStyle);
222: south.write(d);
223: closeLayouterCell(d, south, false);
224: Utils.printNewline(d, layout.getContainer());
225: closeLayouterRow(d);
226: Utils.printNewline(d, layout.getContainer());
227: }
228:
229: closeLayouterBody(d, layout);
230: }
231:
232: protected int layoutOversize(SLayoutManager layout) {
233: SBorderLayout borderLayout = (SBorderLayout) layout;
234: return borderLayout.getVgap() + borderLayout.getBorder();
235: }
236:
237: protected int getLayoutHGap(SLayoutManager layout) {
238: SBorderLayout borderLayout = (SBorderLayout) layout;
239: return borderLayout.getHgap();
240: }
241:
242: protected int getLayoutVGap(SLayoutManager layout) {
243: SBorderLayout borderLayout = (SBorderLayout) layout;
244: return borderLayout.getVgap();
245: }
246:
247: protected int getLayoutBorder(SLayoutManager layout) {
248: SBorderLayout borderLayout = (SBorderLayout) layout;
249: return borderLayout.getBorder();
250: }
251:
252: public int getDefaultLayoutCellHAlignment() {
253: return SConstants.NO_ALIGN; // Don't knoff.
254: }
255:
256: public int getDefaultLayoutCellVAlignment() {
257: return SConstants.NO_ALIGN; // Don't knoff.
258: }
259:
260: }
|