1 57 package org.enhydra.xml.lazydom.html; 58 import org.enhydra.xml.lazydom.LazyElement; 59 import org.enhydra.xml.lazydom.LazyElementNoNS; 60 import org.w3c.dom.Node ; 61 import org.w3c.dom.NodeList ; 62 import org.w3c.dom.html.HTMLCollection; 63 import org.w3c.dom.html.HTMLElement; 64 import org.w3c.dom.html.HTMLTableCellElement; 65 import org.w3c.dom.html.HTMLTableElement; 66 import org.w3c.dom.html.HTMLTableRowElement; 67 import org.w3c.dom.html.HTMLTableSectionElement; 68 69 70 76 public class HTMLTableRowElementImpl 77 extends LazyHTMLElement 78 implements HTMLTableRowElement 79 { 80 81 82 public int getRowIndex() 83 { 84 Node parent; 85 86 parent = getParentNode(); 87 if ( parent instanceof HTMLTableSectionElement ) 88 parent = parent.getParentNode(); 89 if ( parent instanceof HTMLTableElement ) 90 return getRowIndex( parent );; 91 return -1; 92 } 93 94 95 public void setRowIndex( int rowIndex ) 96 { 97 Node parent; 98 99 parent = getParentNode(); 100 if ( parent instanceof HTMLTableSectionElement ) 101 parent = parent.getParentNode(); 102 if ( parent instanceof HTMLTableElement ) 103 ( (HTMLTableElementImpl) parent ).insertRowX( rowIndex, this ); 104 } 105 106 107 public int getSectionRowIndex() 108 { 109 Node parent; 110 111 parent = getParentNode(); 112 if ( parent instanceof HTMLTableSectionElement ) 113 return getRowIndex( parent ); 114 else 115 return -1; 116 } 117 118 119 public void setSectionRowIndex( int sectionRowIndex ) 120 { 121 Node parent; 122 123 parent = getParentNode(); 124 if ( parent instanceof HTMLTableSectionElement ) 125 ( (HTMLTableSectionElementImpl) parent ).insertRowX( sectionRowIndex, this ); 126 } 127 128 129 int getRowIndex( Node parent ) 130 { 131 NodeList rows; 132 int i; 133 134 rows = ( (HTMLElement) parent ).getElementsByTagName( "TR" ); 138 for ( i = 0 ; i < rows.getLength() ; ++i ) 139 if ( rows.item( i ) == this ) 140 return i; 141 return -1; 142 } 143 144 145 public HTMLCollection getCells() 146 { 147 if ( _cells == null ) 148 _cells = new HTMLCollectionImpl( this, HTMLCollectionImpl.CELL ); 149 return _cells; 150 } 151 152 153 public void setCells( HTMLCollection cells ) 154 { 155 Node child; 156 int i; 157 158 child = getFirstChild(); 159 while ( child != null ) 160 { 161 removeChild( child ); 162 child = child.getNextSibling(); 163 } 164 i = 0; 165 child = cells.item( i ); 166 while ( child != null ) 167 { 168 appendChild ( child ); 169 ++i; 170 child = cells.item( i ); 171 } 172 } 173 174 175 public HTMLElement insertCell( int index ) 176 { 177 Node child; 178 HTMLElement newCell; 179 180 newCell = new HTMLTableCellElementImpl( (LazyHTMLDocument) getOwnerDocument(), null, "TD" ); 181 child = getFirstChild(); 182 while ( child != null ) 183 { 184 if ( child instanceof HTMLTableCellElement ) 185 { 186 if ( index == 0 ) 187 { 188 insertBefore( newCell, child ); 189 return newCell; 190 } 191 --index; 192 } 193 child = child.getNextSibling(); 194 } 195 appendChild( newCell ); 196 return newCell; 197 } 198 199 200 public void deleteCell( int index ) 201 { 202 Node child; 203 204 child = getFirstChild(); 205 while ( child != null ) 206 { 207 if ( child instanceof HTMLTableCellElement ) 208 { 209 if ( index == 0 ) 210 { 211 removeChild ( child ); 212 return; 213 } 214 --index; 215 } 216 child = child.getNextSibling(); 217 } 218 } 219 220 221 public String getAlign() 222 { 223 return capitalize( getAttribute( "align" ) ); 224 } 225 226 227 public void setAlign( String align ) 228 { 229 setAttribute( "align", align ); 230 } 231 232 233 public String getBgColor() 234 { 235 return getAttribute( "bgcolor" ); 236 } 237 238 239 public void setBgColor( String bgColor ) 240 { 241 setAttribute( "bgcolor", bgColor ); 242 } 243 244 245 public String getCh() 246 { 247 String ch; 248 249 ch = getAttribute( "char" ); 251 if ( ch != null && ch.length() > 1 ) 252 ch = ch.substring( 0, 1 ); 253 return ch; 254 } 255 256 257 public void setCh( String ch ) 258 { 259 if ( ch != null && ch.length() > 1 ) 261 ch = ch.substring( 0, 1 ); 262 setAttribute( "char", ch ); 263 } 264 265 266 public String getChOff() 267 { 268 return getAttribute( "charoff" ); 269 } 270 271 272 public void setChOff( String chOff ) 273 { 274 setAttribute( "charoff", chOff ); 275 } 276 277 278 public String getVAlign() 279 { 280 return capitalize( getAttribute( "valign" ) ); 281 } 282 283 284 public void setVAlign( String vAlign ) 285 { 286 setAttribute( "valign", vAlign ); 287 } 288 289 293 public Node cloneNode( boolean deep ) { 294 HTMLTableRowElementImpl clonedNode = (HTMLTableRowElementImpl)super.cloneNode( deep ); 295 clonedNode._cells = null; 296 return clonedNode; 297 } 298 299 304 public HTMLTableRowElementImpl( LazyHTMLDocument owner, LazyElement template, String name ) 305 { 306 super( owner, template, name ); 307 } 308 309 310 HTMLCollection _cells; 311 312 313 } 314 315 | Popular Tags |