KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > plaf > css > ScrollPaneLayoutCG


1 /*
2  * Copyright (c) 2005 Your Corporation. All Rights Reserved.
3  */

4 package org.wings.plaf.css;
5
6 import org.wings.SComponent;
7 import org.wings.SContainer;
8 import org.wings.SLayoutManager;
9 import org.wings.SScrollPaneLayout;
10 import org.wings.io.Device;
11 import org.wings.plaf.LayoutCG;
12
13 import java.io.IOException JavaDoc;
14 import java.util.Map JavaDoc;
15
16 public class ScrollPaneLayoutCG extends AbstractLayoutCG {
17
18     public void write(Device d, SLayoutManager l)
19             throws IOException JavaDoc {
20         SScrollPaneLayout layout = (SScrollPaneLayout) l;
21
22         if (layout.isPaging())
23             writePaging(d, layout);
24         else
25             writeNonePaging(d, layout);
26     }
27
28     private void writeNonePaging(Device d, SScrollPaneLayout layout) throws IOException JavaDoc {
29         Map JavaDoc components = layout.getComponents();
30         SComponent center = (SComponent) components.get(SScrollPaneLayout.VIEWPORT);
31         writeComponent(d, center);
32     }
33
34     private void writePaging(Device d, SScrollPaneLayout layout) throws IOException JavaDoc {
35         SContainer container = layout.getContainer();
36
37         Map JavaDoc components = layout.getComponents();
38         SComponent north = (SComponent) components.get(SScrollPaneLayout.NORTH);
39         SComponent east = (SComponent) components.get(SScrollPaneLayout.EAST);
40         SComponent center = (SComponent) components.get(SScrollPaneLayout.VIEWPORT);
41         SComponent west = (SComponent) components.get(SScrollPaneLayout.WEST);
42         SComponent south = (SComponent) components.get(SScrollPaneLayout.SOUTH);
43
44         d.print("\n<table class=\"SScrollPaneLayout\"");
45         Utils.printCSSInlinePreferredSize(d, container.getPreferredSize());
46         d.print("><tbody>");
47
48         if (north != null) {
49             d.print("<tr height=\"0%\">");
50             if (west != null)
51                 d.print("<td width=\"0%\"></td>");
52
53             d.print("<td width=\"100%\">");
54             writeComponent(d, north);
55             d.print("</td>");
56
57             if (east != null)
58                 d.print("<td width=\"0%\"></td>");
59             d.print("</tr>\n");
60         }
61
62         d.print("<tr height=\"100%\">");
63         if (west != null) {
64             d.print("<td width=\"0%\">");
65             writeComponent(d, west);
66             d.print("</td>");
67         }
68         if (center != null) {
69             d.print("<td width=\"100%\">");
70             writeComponent(d, center);
71             d.print("</td>");
72         }
73         if (east != null) {
74             d.print("<td width=\"0%\">");
75             writeComponent(d, east);
76             d.print("</td>");
77         }
78         d.print("</tr>\n");
79
80         if (south != null) {
81             d.print("<tr height=\"0%\">");
82             if (west != null)
83                 d.print("<td width=\"0%\"></td>");
84
85             d.print("<td width=\"100%\">");
86             writeComponent(d, south);
87             d.print("</td>");
88
89             if (east != null)
90                 d.print("<td width=\"0%\"></td>");
91             d.print("</tr>\n");
92         }
93
94         d.print("</tbody></table>\n");
95     }
96
97     protected void writeComponent(Device d, SComponent c)
98             throws IOException JavaDoc {
99         c.write(d);
100     }
101 }
102
103
104
Popular Tags