KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: FlowLayoutCG.java,v 1.9 2005/05/26 14:29:41 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.plaf.css;
15
16 import org.wings.*;
17 import org.wings.io.Device;
18 import org.wings.plaf.LayoutCG;
19
20 import java.io.IOException JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 public class FlowLayoutCG extends AbstractLayoutCG {
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 JavaDoc {
31         final SFlowLayout layout = (SFlowLayout) l;
32         final List JavaDoc components = layout.getComponents();
33         final int alignment = layout.getAlignment();
34         final int orientation = layout.getOrientation();
35         final SContainer container = layout.getContainer();
36
37         Utils.printNewline(d, container);
38         d.print("<div");
39         Utils.printDivHorizontalAlignment(d, alignment);
40         if (alignment == SConstants.CENTER)
41             // Cheat -- margin left/right to simulate center float. Will not wrap
42
d.print(" style=\"display:table; margin-left:auto; margin-right:auto;\"");
43         else
44             d.print(" style=\"display:table; width:100%;\""); // gecko bug workaround: inherit surrounding panel bg color.
45
d.print(" class=\"SFlowLayout\">");
46
47         final String JavaDoc alignmentStyle;
48         if (orientation == SConstants.HORIZONTAL) {
49             if (alignment == SConstants.LEFT)
50                 alignmentStyle = "float:left;";
51             else if (alignment == SConstants.RIGHT)
52                 alignmentStyle = "float:right;";
53             else if (alignment == SConstants.CENTER)
54                 alignmentStyle = "float:left; "; // Floating does not work with center :-(
55
else
56                 alignmentStyle = "";
57         } else {
58             alignmentStyle = "display:block;"; // Vertical align does not support floating!
59
}
60
61         if (components.size() > 0) {
62             /* We need two spacer divs (end/beginning) so that the sourrounding flow layout takes up
63                the whole space instead of 0px heigth. See http://www.alistapart.com/articles/practicalcss/ */

64             d.print("<div class=\"spacer\">&nbsp;</div>");
65
66             for (Iterator JavaDoc componentIterator = components.iterator(); componentIterator.hasNext();) {
67                 SComponent component = (SComponent) componentIterator.next();
68                 if (component.isVisible()) {
69                     Utils.printNewline(d, component);
70                     d.print("<div style=\"");
71                     d.print(alignmentStyle);
72                     d.print("\">");
73                     component.write(d); // Render contained component
74
Utils.printNewline(d, component);
75                     d.print("</div>");
76                 }
77             }
78
79             /* Second spacer. See upper. */
80             d.print("<div class=\"spacer\">&nbsp;</div>");
81         }
82         Utils.printNewline(d, container);
83         d.print("</div>");
84     }
85 }
86
87
88
Popular Tags