1 2 24 25 26 27 28 29 package com.lutris.html; 30 31 import java.util.Enumeration ; 32 import java.util.Vector ; 33 34 44 public class HtmlTable { 45 46 private String caption = null; 47 private int percentWidth = 0; 48 private int borderWidth = -1; 49 private int cellPadding = -1; 50 private int cellSpacing = -1; 51 private String bgColor = null; 52 private String rules = null; 53 private String frame = null; 54 private Vector rows = new Vector (); 55 private Object thead = null; 56 57 public HtmlTable() 58 { 59 this.caption = null; 60 } 61 62 public HtmlTable(String caption) 63 { 64 this.caption = caption; 65 } 66 67 public void setBorderWidth(int pixels) 68 { 69 this.borderWidth = pixels; 70 } 71 72 public void addRow(HtmlTableRow row) 73 { 74 rows.addElement(row); 75 } 76 77 public void addRow(String row) 78 { 79 rows.addElement(row); 80 } 81 82 public void setHeader(Object row) 83 { 84 thead = row; 85 } 86 87 public void setPercentWidth(int percent) 88 { 89 if (percent > 0 && percent <= 100) 90 this.percentWidth = percent; 91 } 92 93 public void setCaption(String caption) 94 { 95 this.caption = caption; 96 } 97 98 public void setCellSpacing(int size) 99 { 100 if (size >= 0) 101 cellSpacing = size; 102 } 103 104 public void setCellPadding(int size) 105 { 106 if (size >= 0) 107 cellPadding = size; 108 } 109 110 public void setBackgroundColor(String bgColor) 111 { 112 this.bgColor = bgColor; 113 } 114 115 public void setFrame(String frame) 116 { 117 this.frame = frame; 118 } 119 120 public void setRules(String rules) 121 { 122 this.rules = rules; 123 } 124 125 public String toString() 126 { 127 StringBuffer html = new StringBuffer (); 128 129 html.append("<TABLE"); 130 if (borderWidth >= 0) 131 html.append(" BORDER=" + borderWidth); 132 if (percentWidth > 0) 133 html.append(" WIDTH=" + percentWidth + "%"); 134 if (cellPadding >= 0) 135 html.append(" CELLPADDING=" + cellPadding); 136 if (cellSpacing >= 0) 137 html.append(" CELLSPACING=" + cellSpacing); 138 if (bgColor != null) 139 html.append(" BGCOLOR=" + bgColor); 140 if (rules != null) 141 html.append(" RULES=" + rules); 142 if (frame != null) 143 html.append(" FRAME=" + frame); 144 html.append(">\n"); 145 146 if (caption != null) { 147 html.append("<CAPTION>"); 148 html.append(caption); 149 html.append("</CAPTION>\n"); 150 } 151 152 if (thead != null) { 153 html.append("<THEAD>"); 154 html.append(thead.toString()); 155 html.append("</THEAD>\n"); 156 } 157 158 Enumeration e = rows.elements(); 159 while (e.hasMoreElements()) { 160 html.append(e.nextElement().toString()); 161 } 162 html.append("</TABLE>\n"); 163 164 return html.toString(); 165 } 166 } 167 | Popular Tags |