1 14 package org.wings.plaf.css; 15 16 import org.wings.SComponent; 17 import org.wings.SLayoutManager; 18 import org.wings.io.Device; 19 import org.wings.plaf.LayoutCG; 20 21 import java.io.IOException ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 30 public abstract class AbstractLayoutCG implements LayoutCG { 31 32 35 protected void printLayouterTableHeader(Device d, String styleClass, int hgap, int vgap, 36 int border, SLayoutManager layout) 37 throws IOException { 38 Utils.printDebugNewline(d, layout.getContainer()); 39 Utils.printDebug(d, "<!-- START LAYOUT: ").print(styleClass).print(" -->"); 40 41 StringBuffer styleString = Utils.generateCSSInlinePreferredSize(layout.getContainer().getPreferredSize()); 45 styleString.append(Utils.generateCSSInlineBorder(border)); 46 styleString.append(createInlineStylesForGaps(hgap, vgap)); 47 48 Utils.printNewline(d, layout.getContainer()); 49 d.print("<table "); 50 53 Utils.optAttribute(d, "class", styleClass != null ? styleClass + " SLayout" : "SLayout"); 54 Utils.optAttribute(d, "style", styleString.toString()); 55 d.print("><tbody>"); 56 Utils.printNewline(d, layout.getContainer()); 57 } 58 59 62 protected void printLayouterTableFooter(Device d, String styleClass, SLayoutManager layout) throws IOException { 63 Utils.printNewline(d, layout.getContainer()); 64 d.print("</tbody></table>"); 65 66 Utils.printDebugNewline(d, layout.getContainer()); 67 Utils.printDebug(d, "<!-- END LAYOUT: ").print(styleClass).print(" -->"); 68 } 69 70 83 protected void printLayouterTableBody(Device d, int cols, final boolean renderFirstLineAsHeader, 84 int hgap, int vgap, int border, final List components) 85 throws IOException { 86 boolean firstRow = true; 87 int col = 0; 88 for (Iterator iter = components.iterator(); iter.hasNext();) { 89 final SComponent c = (SComponent) iter.next(); 90 91 if (col == 0) { 92 d.print("<tr>"); 93 } else if (col % cols == 0) { 94 d.print("</tr>"); 95 Utils.printNewline(d, c.getParent()); 96 d.print("<tr>"); 97 firstRow = false; 98 } 99 100 openLayouterCell(d, firstRow && renderFirstLineAsHeader, hgap, vgap, border, c); 101 d.print(">"); 102 103 Utils.printNewline(d, c); 104 c.write(d); 106 closeLayouterCell(d, firstRow && renderFirstLineAsHeader); 107 108 col++; 109 110 if (!iter.hasNext()) { 111 d.print("</tr>"); 112 Utils.printNewline(d, c.getParent()); 113 } 114 } 115 } 116 117 123 protected static StringBuffer createInlineStylesForGaps(int hgap, int vgap) { 124 StringBuffer inlineStyle = new StringBuffer (); 125 if (hgap > 0 || vgap > 0) { 126 int hPaddingTop = (int) Math.round((vgap < 0 ? 0 : vgap) / 2.0); 127 int hPaddingBottom = (int) Math.round((vgap < 0 ? 0 : vgap) / 2.0 + 0.1); int vPaddingLeft = (int) Math.round((hgap < 0 ? 0 : hgap) / 2.0); 129 int vPaddingRight = (int) Math.round((hgap < 0 ? 0 : hgap) / 2.0 + 0.1); if (hPaddingBottom == hPaddingTop && hPaddingTop == vPaddingRight && vPaddingRight == vPaddingLeft) { 131 inlineStyle.append("padding:").append(hPaddingTop).append("px;"); 132 } else { 133 inlineStyle.append("padding:").append(hPaddingTop).append("px ").append(vPaddingRight).append("px ") 134 .append(hPaddingBottom).append("px ").append(vPaddingLeft).append("px;"); 135 } 136 } 137 return inlineStyle; 138 } 139 140 146 public static void openLayouterCell(Device d, boolean renderAsHeader, int hgap, int vgap, int border, 147 SComponent containedComponent) throws IOException { 148 if (renderAsHeader) { 149 d.print("<th"); 150 } else { 151 d.print("<td"); 152 } 153 154 d.print(" class=\"SLayout\""); 155 Utils.printTableCellAlignment(d, containedComponent); 156 157 StringBuffer inlineAttributes = Utils.generateCSSInlineBorder(border); 159 inlineAttributes.append(createInlineStylesForGaps(hgap, vgap)); 160 Utils.optAttribute(d, "style", inlineAttributes.toString()); 161 } 162 163 168 public static void closeLayouterCell(Device d, boolean renderAsHeader) throws IOException { 169 d.print(renderAsHeader ? "</th>" : "</td>"); 170 } 171 } 172 | Popular Tags |