1 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 ; 23 24 public class GridBagLayoutCG extends AbstractLayoutCG { 25 30 public void write(Device d, SLayoutManager l) 31 throws IOException { 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); 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 |