1 64 65 package com.jcorporate.expresso.services.html; 66 67 import com.jcorporate.expresso.core.misc.StringUtil; 68 69 import java.io.PrintWriter ; 70 import java.util.Enumeration ; 71 72 73 79 public class Cell 80 extends HtmlElement { 81 private String thisClass = (this.getClass().getName() + "."); 82 private String alignment = null; 83 private int cellspacing = 0; 84 private int border = 0; 85 private String verticalAlignment = null; 86 private boolean noWrap = true; 87 private int colSpan = 0; 88 private int rowSpan = 0; 89 private String width = null; 90 private boolean isHeaderCell = false; 91 private String bgColor = null; 92 private String fgColor = null; 93 94 99 public Cell() 100 throws HtmlException { 101 super(); 102 } 103 104 111 public Cell(HtmlElement newElement) 112 throws HtmlException { 113 super(newElement); 114 } 115 116 124 public Cell(String contentText) 125 throws HtmlException { 126 super(contentText); 127 } 128 129 137 protected synchronized void display(PrintWriter out, int depth) 138 throws HtmlException { 139 String myName = (thisClass + "display(PrintWriter)"); 140 141 if (contents.size() == 0) { 142 throw new HtmlException(myName + ":Cell '" + getName() + 143 "' has no contents"); 144 } 145 146 this.padWithTabs(out, depth); 147 148 if (isHeaderCell) { 149 out.print("<th"); 150 } else { 151 out.print("<td"); 152 } 153 if (cSSClass != null) { 154 out.print(" class=\"" + cSSClass + "\""); 155 } 156 if (cSSID != null) { 157 out.print(" ID=\"" + cSSID + "\""); 158 } 159 if (!StringUtil.notNull(fgColor).equals("")) { 160 out.print(" color=\"" + fgColor + "\""); 161 } 162 if (!StringUtil.notNull(bgColor).equals("")) { 163 out.print(" bgcolor=\"" + bgColor + "\""); 164 } 165 if (alignment != null) { 166 out.print(" align=\"" + alignment + "\""); 167 } 168 if (verticalAlignment != null) { 169 out.print(" valign=\"" + verticalAlignment + "\""); 170 } 171 if (colSpan > 0) { 172 out.print(" colspan=\"" + colSpan + "\""); 173 } 174 if (rowSpan > 0) { 175 out.print(" rowspan=\"" + rowSpan + "\""); 176 } 177 if (width != null) { 178 out.print(" width=\"" + width + "\""); 179 } 180 if (noWrap) { 181 out.print(" nowrap"); 182 } 183 184 out.println(">"); 185 186 HtmlElement oneElement = null; 187 188 for (Enumeration e = contents.elements(); e.hasMoreElements();) { 189 oneElement = (HtmlElement) e.nextElement(); 190 oneElement.display(out, depth + 1); 191 } 192 if (isHeaderCell) { 193 out.println(); 194 this.padWithTabs(out, depth); 195 out.println("</th>"); 196 } else { 197 out.println(); 198 this.padWithTabs(out, depth); 199 out.println("</td>"); 200 } 201 202 setDisplayed(); 203 } 204 205 206 213 public synchronized void setAlignment(String newAlignment) 214 throws HtmlException { 215 String myName = (thisClass + "setAlignment(String)"); 216 217 if (newAlignment.equalsIgnoreCase("left")) { 218 alignment = newAlignment; 219 } else if (newAlignment.equalsIgnoreCase("right")) { 220 alignment = newAlignment; 221 } else if (newAlignment.equalsIgnoreCase("center")) { 222 alignment = newAlignment; 223 } else { 224 throw new HtmlException(myName + 225 ":Alignment must be left, right, " + 226 "or center for '" + getName() + "'"); 227 } 228 } 229 230 231 237 public void setBGColor(String newColor) 238 throws HtmlException { 239 bgColor = newColor; 240 } 241 242 243 249 public synchronized void setBorder(int newBorder) 250 throws HtmlException { 251 border = newBorder; 252 } 253 254 255 261 public synchronized void setCellSpacing(int newSpacing) 262 throws HtmlException { 263 cellspacing = newSpacing; 264 } 265 266 267 273 public void setColSpan(int newSpan) 274 throws HtmlException { 275 colSpan = newSpan; 276 } 277 278 279 285 public void setFGColor(String newColor) 286 throws HtmlException { 287 fgColor = newColor; 288 } 289 290 291 296 public void setHeaderCell(boolean state) { 297 isHeaderCell = state; 298 } 299 300 306 public void setNoWrap(boolean newWrap) 307 throws HtmlException { 308 noWrap = newWrap; 309 } 310 311 312 318 public void setRowSpan(int newSpan) 319 throws HtmlException { 320 rowSpan = newSpan; 321 } 322 323 324 330 public synchronized void setVerticalAlignment(String newAlignment) 331 throws HtmlException { 332 String myName = (thisClass + "setVerticalAlignment(String)"); 333 334 if (newAlignment.equalsIgnoreCase("top")) { 335 verticalAlignment = newAlignment; 336 } else if (newAlignment.equalsIgnoreCase("bottom")) { 337 verticalAlignment = newAlignment; 338 } else if (newAlignment.equalsIgnoreCase("center")) { 339 verticalAlignment = newAlignment; 340 } else { 341 throw new HtmlException(myName + 342 ":Verical alignment must be top, " + 343 "bottom, or center for " + getName()); 344 } 345 } 346 347 348 351 public void setWidth(String newWidth) 352 throws HtmlException { 353 width = newWidth; 354 } 355 356 357 } 358 359 | Popular Tags |