KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: GridBagLayoutCG.java,v 1.6 2005/06/03 13:16:16 blueshift 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.SComponent;
17 import org.wings.SGridBagLayout;
18 import org.wings.SLayoutManager;
19 import org.wings.io.Device;
20
21 import java.awt.*;
22 import java.io.IOException JavaDoc;
23
24 public class GridBagLayoutCG 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)
31             throws IOException JavaDoc {
32         final SGridBagLayout layout = (SGridBagLayout) l;
33         final boolean header = layout.getHeader();
34         final int border = layout.getBorder() >= 0 ? layout.getBorder() : 0;
35         final SGridBagLayout.Grid grid = layout.getGrid();
36
37         if (grid.cols == 0)
38             return;
39
40         printLayouterTableHeader(d, "SGridBagLayout", layout.getHgap(), layout.getVgap(), border, layout);
41
42         for (int row = grid.firstRow; row < grid.rows; row++) {
43             Utils.printNewline(d, layout.getContainer());
44             d.print("<tr>");
45             for (int col = grid.firstCol; col < grid.cols; col++) {
46                 SComponent comp = grid.grid[col][row];
47                 Utils.printNewline(d, layout.getContainer());
48                 final boolean headerCell = row == grid.firstRow && header;
49                 if (comp == null) {
50                     openLayouterCell(d, headerCell, layout.getHgap(), layout.getVgap(),border, comp);
51                     d.print(">");
52                     closeLayouterCell(d, headerCell);
53                 } else {
54                     GridBagConstraints c = layout.getConstraints(comp);
55                     if ((c.gridx == SGridBagLayout.LAST_CELL || c.gridx == col) &&
56                             (c.gridy == SGridBagLayout.LAST_CELL || c.gridy == row)) {
57
58                         openLayouterCell(d, headerCell, layout.getHgap(), layout.getVgap(),border, comp);
59
60                         int gridwidth = c.gridwidth;
61                         if (gridwidth == GridBagConstraints.RELATIVE) {
62                             gridwidth = grid.cols - col - 1;
63                         } else if (gridwidth == GridBagConstraints.REMAINDER) {
64                             gridwidth = grid.cols - col;
65                         }
66                         if (gridwidth > 1) {
67                             d.print(" colspan=" + gridwidth);
68                         }
69
70                         int gridheight = c.gridheight;
71                         if (gridheight == GridBagConstraints.RELATIVE) {
72                             gridheight = grid.rows - row - 1;
73                         } else if (gridheight == GridBagConstraints.REMAINDER) {
74                             gridheight = grid.rows - row;
75                         }
76                         if (gridheight > 1) {
77                             d.print(" rowspan=" + gridheight);
78                         }
79                         if (c.weightx > 0 && grid.colweight[row] > 0) {
80                             d.print(" width=\"" +
81                                     (int) (100 * c.weightx / grid.colweight[row]) +
82                                     "%\"");
83                         }
84                         if (c.weighty > 0 && grid.rowweight[col] > 0) {
85                             d.print(" height=\"" +
86                                     (int) (100 * c.weighty / grid.rowweight[col]) +
87                                     "%\"");
88                         }
89
90                         d.print(">");
91
92                         Utils.printNewline(d, comp);
93                         comp.write(d); // Render component
94

95                         closeLayouterCell(d, headerCell);
96                     }
97                 }
98             }
99             Utils.printNewline(d, layout.getContainer());
100             d.print("</tr>");
101         }
102         printLayouterTableFooter(d, "SGridBagLayout", layout);
103     }
104
105
106
107 }
108
109
110
Popular Tags