01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.plaf.css;
14:
15: import org.wings.*;
16: import org.wings.session.BrowserType;
17: import org.wings.io.Device;
18: import org.wings.plaf.LayoutCG;
19:
20: import java.io.IOException;
21:
22: public class CardLayoutCG implements LayoutCG {
23: private static final long serialVersionUID = 1L;
24:
25: /**
26: * @param d the device to write the code to
27: * @param l the layout manager
28: * @throws IOException
29: */
30: public void write(Device d, SLayoutManager l) throws IOException {
31: SCardLayout cardLayout = (SCardLayout) l;
32: SContainer container = l.getContainer();
33: SComponent c = cardLayout.getVisibleComponent();
34:
35: SDimension preferredSize = container.getPreferredSize();
36: String height = preferredSize != null ? preferredSize
37: .getHeight() : null;
38: boolean clientLayout = isMSIE(container) && height != null
39: && !"auto".equals(height);
40:
41: if (clientLayout)
42: d.print("<tr yweight=\"100\">");
43: else
44: openLayouterRow(d, "100%");
45:
46: openLayouterCell(d, c);
47: // Just present visible component
48: if (c != null) {
49: c.write(d);
50: }
51:
52: closeLayouterCell(d);
53: closeLayouterRow(d);
54: }
55:
56: public static void openLayouterRow(final Device d, String height)
57: throws IOException {
58: d.print("<tr");
59: Utils.optAttribute(d, "height", height);
60: d.print(">");
61: }
62:
63: public static void openLayouterCell(final Device d,
64: SComponent component) throws IOException {
65: d.print("<td");
66: Utils.printTableCellAlignment(d, component,
67: SConstants.CENTER_ALIGN, SConstants.CENTER_ALIGN);
68: d.print(">");
69: }
70:
71: public static void closeLayouterCell(final Device d)
72: throws IOException {
73: d.print("</td>");
74: }
75:
76: public static void closeLayouterRow(final Device d)
77: throws IOException {
78: d.print("</tr>");
79: }
80:
81: /**
82: * @return true if current browser is microsoft exploder
83: */
84: protected final boolean isMSIE(final SComponent component) {
85: return component.getSession().getUserAgent().getBrowserType() == BrowserType.IE;
86: }
87: }
|