1 21 24 package org.lobobrowser.html.domimpl; 25 26 import org.lobobrowser.html.style.*; 27 import org.w3c.dom.DOMException ; 28 import org.w3c.dom.Node ; 29 import org.w3c.dom.html2.HTMLCollection; 30 import org.w3c.dom.html2.HTMLElement; 31 import org.w3c.dom.html2.HTMLTableCaptionElement; 32 import org.w3c.dom.html2.HTMLTableElement; 33 import org.w3c.dom.html2.HTMLTableSectionElement; 34 import java.util.*; 35 36 public class HTMLTableElementImpl extends HTMLAbstractUIElement implements 37 HTMLTableElement { 38 39 public HTMLTableElementImpl() { 40 super("TABLE"); 41 } 42 43 public HTMLTableElementImpl(String name) { 44 super(name); 45 } 46 47 private HTMLTableCaptionElement caption; 48 49 public HTMLTableCaptionElement getCaption() { 50 return this.caption; 51 } 52 53 public void setCaption(HTMLTableCaptionElement caption) throws DOMException { 54 this.caption = caption; 55 } 56 57 private HTMLTableSectionElement thead; 58 59 public HTMLTableSectionElement getTHead() { 60 return this.thead; 61 } 62 63 public void setTHead(HTMLTableSectionElement tHead) throws DOMException { 64 this.thead = tHead; 65 } 66 67 private HTMLTableSectionElement tfoot; 68 69 public HTMLTableSectionElement getTFoot() { 70 return this.tfoot; 71 } 72 73 public void setTFoot(HTMLTableSectionElement tFoot) throws DOMException { 74 this.tfoot = tFoot; 75 } 76 77 public HTMLCollection getRows() { 78 return new DescendentHTMLCollection(this, new ElementFilter("TR")); 79 } 80 81 public HTMLCollection getTBodies() { 82 return new DescendentHTMLCollection(this, new ElementFilter("TBODY")); 83 } 84 85 public String getAlign() { 86 return this.getAttribute("align"); 87 } 88 89 public void setAlign(String align) { 90 this.setAttribute("align", align); 91 } 92 93 public String getBgColor() { 94 return this.getAttribute("bgcolor"); 95 } 96 97 public void setBgColor(String bgColor) { 98 this.setAttribute("bgcolor", bgColor); 99 } 100 101 public String getBorder() { 102 return this.getAttribute("border"); 103 } 104 105 public void setBorder(String border) { 106 this.setAttribute("border", border); 107 } 108 109 public String getCellPadding() { 110 return this.getAttribute("cellpadding"); 111 } 112 113 public void setCellPadding(String cellPadding) { 114 this.setAttribute("cellpadding", cellPadding); 115 } 116 117 public String getCellSpacing() { 118 return this.getAttribute("cellspacing"); 119 } 120 121 public void setCellSpacing(String cellSpacing) { 122 this.setAttribute("cellspacing", cellSpacing); 123 } 124 125 public String getFrame() { 126 return this.getAttribute("frame"); 127 } 128 129 public void setFrame(String frame) { 130 this.setAttribute("frame", frame); 131 } 132 133 public String getRules() { 134 return this.getAttribute("rules"); 135 } 136 137 public void setRules(String rules) { 138 this.setAttribute("rules", rules); 139 } 140 141 public String getSummary() { 142 return this.getAttribute("summary"); 143 } 144 145 public void setSummary(String summary) { 146 this.setAttribute("summary", summary); 147 } 148 149 public String getWidth() { 150 return this.getAttribute("width"); 151 } 152 153 public void setWidth(String width) { 154 this.setAttribute("width", width); 155 } 156 157 160 public HtmlLength getHeightLength(int availHeight) { 161 try { 162 CSS2PropertiesImpl props = this.getCurrentStyle(); 163 String heightText = props == null ? null : props.getHeight(); 164 if(heightText == null) { 165 return new HtmlLength(this.getAttribute("height")); 166 } 167 else { 168 return new HtmlLength(HtmlValues.getPixelSize(heightText, this.getRenderState(), 0, availHeight)); 169 } 170 } catch(Exception err) { 171 return null; 172 } 173 } 174 175 178 public HtmlLength getWidthLength(int availWidth) { 179 try { 180 CSS2PropertiesImpl props = this.getCurrentStyle(); 181 String widthText = props == null ? null : props.getWidth(); 182 if(widthText == null) { 183 return new HtmlLength(this.getAttribute("width")); 184 } 185 else { 186 return new HtmlLength(HtmlValues.getPixelSize(widthText, this.getRenderState(), 0, availWidth)); 187 } 188 } catch(Exception err) { 189 return null; 190 } 191 } 192 193 public HTMLElement createTHead() { 194 org.w3c.dom.Document doc = this.document; 195 return doc == null ? null : (HTMLElement) doc.createElement("thead"); 196 } 197 198 public void deleteTHead() { 199 this.removeChildren(new ElementFilter("THEAD")); 200 } 201 202 public HTMLElement createTFoot() { 203 org.w3c.dom.Document doc = this.document; 204 return doc == null ? null : (HTMLElement) doc.createElement("tfoot"); 205 } 206 207 public void deleteTFoot() { 208 this.removeChildren(new ElementFilter("TFOOT")); 209 } 210 211 public HTMLElement createCaption() { 212 org.w3c.dom.Document doc = this.document; 213 return doc == null ? null : (HTMLElement) doc.createElement("caption"); 214 } 215 216 public void deleteCaption() { 217 this.removeChildren(new ElementFilter("CAPTION")); 218 } 219 220 224 public HTMLElement insertRow(int index) throws DOMException { 225 org.w3c.dom.Document doc = this.document; 226 if(doc == null) { 227 throw new DOMException (DOMException.WRONG_DOCUMENT_ERR, "Orphan element"); 228 } 229 HTMLElement rowElement = (HTMLElement) doc.createElement("TR"); 230 synchronized(this.treeLock) { 231 if(index == -1) { 232 this.appendChild(rowElement); 233 return rowElement; 234 } 235 ArrayList nl = this.nodeList; 236 if(nl != null) { 237 int size = nl.size(); 238 int trcount = 0; 239 for(int i = 0; i < size; i++) { 240 Node node = (Node ) nl.get(i); 241 if("TR".equalsIgnoreCase(node.getNodeName())) { 242 if(trcount == index) { 243 this.insertAt(rowElement, i); 244 return rowElement; 245 } 246 trcount++; 247 } 248 } 249 } 250 else { 251 this.appendChild(rowElement); 252 return rowElement; 253 } 254 } 255 throw new DOMException (DOMException.INDEX_SIZE_ERR, "Index out of range"); 256 } 257 258 public void deleteRow(int index) throws DOMException { 259 synchronized(this.treeLock) { 260 ArrayList nl = this.nodeList; 261 if(nl != null) { 262 int size = nl.size(); 263 int trcount = 0; 264 for(int i = 0; i < size; i++) { 265 Node node = (Node ) nl.get(i); 266 if("TR".equalsIgnoreCase(node.getNodeName())) { 267 if(trcount == index) { 268 this.removeChildAt(i); 269 return; 270 } 271 trcount++; 272 } 273 } 274 } 275 } 276 throw new DOMException (DOMException.INDEX_SIZE_ERR, "Index out of range"); 277 } 278 279 protected RenderState createRenderState(RenderState prevRenderState) { 280 return new TableRenderState(prevRenderState, this); 281 } 282 } 283 | Popular Tags |