1 64 65 package com.jcorporate.expresso.services.html; 66 67 72 73 import java.io.PrintWriter ; 74 import java.util.Enumeration ; 75 import java.util.StringTokenizer ; 76 77 78 82 public class Row 83 extends HtmlElement { 84 private String thisClass = (this.getClass().getName() + "."); 85 private String alignment = null; 86 private int cellspacing = 0; 87 private int border = 0; 88 private String titleString = null; 89 private boolean captionRow = false; 90 91 94 public Row() 95 throws HtmlException { 96 super(); 97 } 98 99 104 public Row(HtmlElement newElement) 105 throws HtmlException { 106 super(newElement); 107 } 108 109 114 public Row(String newName) 115 throws HtmlException { 116 super(newName); 117 } 118 119 125 public synchronized void add(HtmlElement newElement) 126 throws HtmlException { 127 if (newElement instanceof Cell) { 128 super.add(newElement); 129 } else { 130 Cell newCell = new Cell(); 131 newCell.add(newElement); 132 add(newCell); 133 } 134 } 135 136 137 140 public synchronized void addCell(String cellContents) 141 throws HtmlException { 142 Cell oneCell = new Cell(cellContents); 143 add(oneCell); 144 } 145 146 147 151 protected synchronized void display(PrintWriter out, int depth) 152 throws HtmlException { 153 String myName = (thisClass + "display(PrintWriter)"); 154 155 if (contents.size() == 0 && captionRow == false && 156 titleString == null) { 157 throw new HtmlException(myName + ":Row '" + getName() + 158 "' has no contents"); 159 } 160 if (captionRow) { 161 this.padWithTabs(out, depth); 162 out.print("<caption class=\"jc-caption\">"); 163 out.print(titleString); 164 out.println("</caption>"); 165 } else { 166 if (titleString != null) { 167 StringTokenizer stk = new StringTokenizer (titleString, "|"); 168 this.padWithTabs(out, depth); 169 out.println("<tr class=\"jc-tabletitlerow\">"); 170 171 while (stk.hasMoreTokens()) { 172 this.padWithTabs(out, depth + 1); 173 out.print("<th class=\"jc-tabletitle\">"); 174 out.print(stk.nextToken()); 175 out.println("</th>"); 176 } 177 178 this.padWithTabs(out, depth); 179 out.println("</tr>"); 180 } 181 if (contents.size() != 0) { 182 this.padWithTabs(out, depth); 183 out.print("<tr"); 184 185 if (cSSClass != null) { 186 out.print(" class=\"" + cSSClass + "\""); 187 } 188 if (cSSID != null) { 189 out.print(" id=\"" + cSSID + "\""); 190 } 191 192 out.println(">"); 193 194 HtmlElement oneElement = null; 195 196 for (Enumeration e = contents.elements(); e.hasMoreElements();) { 197 oneElement = (HtmlElement) e.nextElement(); 198 oneElement.display(out, depth + 1); 199 } 200 201 this.padWithTabs(out, depth); 202 out.println("</tr>"); 203 } 204 } 205 206 setDisplayed(); 207 } 208 209 210 public synchronized boolean isCaptionRow() { 211 return captionRow; 212 } 213 214 217 public synchronized void setAlignment(String newAlignment) 218 throws HtmlException { 219 String myName = (thisClass + "setAlignment(String)"); 220 221 if (newAlignment.equalsIgnoreCase("left")) { 222 alignment = newAlignment; 223 } else if (newAlignment.equalsIgnoreCase("right")) { 224 alignment = newAlignment; 225 } else if (newAlignment.equalsIgnoreCase("center")) { 226 alignment = newAlignment; 227 } else { 228 throw new HtmlException(myName + 229 ":Alignment must be left, right, or center for " + 230 getName()); 231 } 232 } 233 234 235 238 public synchronized void setBorder(int newBorder) 239 throws HtmlException { 240 border = newBorder; 241 } 242 243 244 247 public void setCaptionRow(boolean state) { 248 captionRow = state; 249 } 250 251 254 public synchronized void setCellSpacing(int newSpacing) 255 throws HtmlException { 256 cellspacing = newSpacing; 257 } 258 259 260 263 public synchronized void setTitle(String newTitleString) 264 throws HtmlException { 265 titleString = newTitleString; 266 } 267 268 269 } 270 | Popular Tags |