1 21 24 package org.lobobrowser.html.domimpl; 25 26 import java.util.ArrayList ; 27 28 import org.w3c.dom.DOMException ; 29 import org.w3c.dom.Node ; 30 import org.w3c.dom.html2.HTMLCollection; 31 import org.w3c.dom.html2.HTMLElement; 32 import org.w3c.dom.html2.HTMLTableRowElement; 33 34 public class HTMLTableRowElementImpl extends HTMLElementImpl implements 35 HTMLTableRowElement { 36 public HTMLTableRowElementImpl(String name) { 37 super(name, true); 38 } 39 40 public HTMLTableRowElementImpl() { 41 super("TR", true); 42 } 43 44 public int getRowIndex() { 45 NodeImpl parent = (NodeImpl) this.getParentNode(); 46 if(parent == null) { 47 return -1; 48 } 49 try { 50 parent.visit(new NodeVisitor() { 51 private int count = 0; 52 53 public void visit(Node node) { 54 if(node instanceof HTMLTableRowElementImpl) { 55 if(HTMLTableRowElementImpl.this == node) { 56 throw new StopVisitorException(new Integer (this.count)); 57 } 58 this.count++; 59 } 60 } 61 }); 62 } catch(StopVisitorException sve) { 63 return ((Integer ) sve.getTag()).intValue(); 64 } 65 return -1; 66 } 67 68 public int getSectionRowIndex() { 69 return 0; 71 } 72 73 public HTMLCollection getCells() { 74 NodeFilter filter = new NodeFilter() { 75 public boolean accept(Node node) { 76 return node instanceof HTMLTableCellElementImpl; 77 } 78 }; 79 return new DescendentHTMLCollection(this, filter); 80 } 81 82 public String getAlign() { 83 return this.getAttribute("align"); 84 } 85 86 public void setAlign(String align) { 87 this.setAttribute("align", align); 88 } 89 90 public String getBgColor() { 91 return this.getAttribute("bgcolor"); 92 } 93 94 public void setBgColor(String bgColor) { 95 this.setAttribute("bgcolor", bgColor); 96 } 97 98 public String getCh() { 99 return this.getAttribute("ch"); 100 } 101 102 public void setCh(String ch) { 103 this.setAttribute("ch", ch); 104 } 105 106 public String getChOff() { 107 return this.getAttribute("choff"); 108 } 109 110 public void setChOff(String chOff) { 111 this.setAttribute("choff", chOff); 112 } 113 114 public String getVAlign() { 115 return this.getAttribute("valign"); 116 } 117 118 public void setVAlign(String vAlign) { 119 this.setAttribute("valign", vAlign); 120 } 121 122 public HTMLElement insertCell(int index) throws DOMException { 123 org.w3c.dom.Document doc = this.document; 124 if(doc == null) { 125 throw new DOMException (DOMException.WRONG_DOCUMENT_ERR, "Orphan element"); 126 } 127 HTMLElement cellElement = (HTMLElement) doc.createElement("TD"); 128 synchronized(this.treeLock) { 129 if(index == -1) { 130 this.appendChild(cellElement); 131 return cellElement; 132 } 133 ArrayList nl = this.nodeList; 134 if(nl != null) { 135 int size = nl.size(); 136 int trcount = 0; 137 for(int i = 0; i < size; i++) { 138 Node node = (Node ) nl.get(i); 139 if(node instanceof org.w3c.dom.html2.HTMLTableCellElement) { 140 if(trcount == index) { 141 this.insertAt(cellElement, i); 142 return cellElement; 143 } 144 trcount++; 145 } 146 } 147 } 148 else { 149 this.appendChild(cellElement); 150 return cellElement; 151 } 152 } 153 throw new DOMException (DOMException.INDEX_SIZE_ERR, "Index out of range"); 154 } 155 156 public void deleteCell(int index) throws DOMException { 157 synchronized(this.treeLock) { 158 ArrayList nl = this.nodeList; 159 if(nl != null) { 160 int size = nl.size(); 161 int trcount = 0; 162 for(int i = 0; i < size; i++) { 163 Node node = (Node ) nl.get(i); 164 if(node instanceof org.w3c.dom.html2.HTMLTableCellElement) { 165 if(trcount == index) { 166 this.removeChildAt(index); 167 } 168 trcount++; 169 } 170 } 171 } 172 } 173 throw new DOMException (DOMException.INDEX_SIZE_ERR, "Index out of range"); 174 } 175 } 176 | Popular Tags |