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