KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom > html > HTMLTableRowElementImpl


1 /**
2  * org/ozone-db/xml/dom/html/HTMLTableRowElementImpl.java
3  *
4  * The contents of this file are subject to the OpenXML Public
5  * License Version 1.0; you may not use this file except in compliance
6  * with the License. You may obtain a copy of the License at
7  * http://www.openxml.org/license.html
8  *
9  * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
10  * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
11  * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
12  * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
13  * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
14  * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
15  *
16  * The Initial Developer of this code under the License is Assaf Arkin.
17  * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
18  * All Rights Reserved.
19  */

20
21
22 package org.ozoneDB.xml.dom.html;
23
24
25 import org.ozoneDB.xml.dom.ElementImpl;
26 import org.w3c.dom.Node JavaDoc;
27 import org.w3c.dom.NodeList JavaDoc;
28 import org.w3c.dom.html.*;
29
30
31 /**
32  * @version $Revision: 1.2 $ $Date: 2003/11/20 23:18:42 $
33  * @author <a HREF="mailto:arkin@trendline.co.il">Assaf Arkin</a>
34  * @see org.w3c.dom.html.HTMLTableRowElement
35  * @see ElementImpl
36  */

37 public final class HTMLTableRowElementImpl extends HTMLElementImpl implements HTMLTableRowElement {
38
39
40     public int getRowIndex() {
41         Node JavaDoc parent;
42
43         parent = getParentNode();
44         if (parent instanceof HTMLTableSectionElement) {
45             parent = parent.getParentNode();
46         }
47         if (parent instanceof HTMLTableElement) {
48             return getRowIndex( parent );
49         }
50         ;
51         return -1;
52     }
53
54
55     public void setRowIndex( int rowIndex ) {
56         Node JavaDoc parent;
57
58         parent = getParentNode();
59         if (parent instanceof HTMLTableSectionElement) {
60             parent = parent.getParentNode();
61         }
62         if (parent instanceof HTMLTableElement) {
63             ((HTMLTableElementImpl)parent).insertRowX( rowIndex, this );
64         }
65     }
66
67
68     public int getSectionRowIndex() {
69         Node JavaDoc parent;
70
71         parent = getParentNode();
72         if (parent instanceof HTMLTableSectionElement) {
73             return getRowIndex( parent );
74         } else {
75             return -1;
76         }
77     }
78
79
80     public void setSectionRowIndex( int sectionRowIndex ) {
81         Node JavaDoc parent;
82
83         parent = getParentNode();
84         if (parent instanceof HTMLTableSectionElement) {
85             ((HTMLTableSectionElementImpl)parent).insertRowX( sectionRowIndex, this );
86         }
87     }
88
89
90     int getRowIndex( Node JavaDoc parent ) {
91         NodeList JavaDoc rows;
92         int i;
93
94         // Use getElementsByTagName() which creates a snapshot of all the
95
// TR elements under the TABLE/section. Access to the returned NodeList
96
// is very fast and the snapshot solves many synchronization problems.
97
rows = ((HTMLElement)parent).getElementsByTagName( "TR" );
98         for (i = 0; i < rows.getLength(); ++i) {
99             if (rows.item( i ) == this) {
100                 return i;
101             }
102         }
103         return -1;
104     }
105
106
107     public HTMLCollection getCells() {
108         if (_cells == null) {
109             _cells = new HTMLCollectionImpl( this, HTMLCollectionImpl.CELL );
110         }
111         return _cells;
112     }
113
114
115     public void setCells( HTMLCollection cells ) {
116         Node JavaDoc child;
117         int i;
118
119         child = getFirstChild();
120         while (child != null) {
121             removeChild( child );
122             child = child.getNextSibling();
123         }
124         i = 0;
125         child = cells.item( i );
126         while (child != null) {
127             appendChild( child );
128             ++i;
129             child = cells.item( i );
130         }
131     }
132
133
134     public HTMLElement insertCell( int index ) {
135         Node JavaDoc child;
136         HTMLElement newCell;
137
138         newCell = new HTMLTableCellElementImpl( (HTMLDocumentImpl)getOwnerDocument(), "TD" );
139         child = getFirstChild();
140         while (child != null) {
141             if (child instanceof HTMLTableCellElement) {
142                 if (index == 0) {
143                     insertBefore( newCell, child );
144                     return newCell;
145                 }
146                 --index;
147             }
148             child = child.getNextSibling();
149         }
150         appendChild( newCell );
151         return newCell;
152     }
153
154
155     public void deleteCell( int index ) {
156         Node JavaDoc child;
157
158         child = getFirstChild();
159         while (child != null) {
160             if (child instanceof HTMLTableCellElement) {
161                 if (index == 0) {
162                     removeChild( child );
163                     return;
164                 }
165                 --index;
166             }
167             child = child.getNextSibling();
168         }
169     }
170
171
172     public String JavaDoc getAlign() {
173         return capitalize( getAttribute( "align" ) );
174     }
175
176
177     public void setAlign( String JavaDoc align ) {
178         setAttribute( "align", align );
179     }
180
181
182     public String JavaDoc getBgColor() {
183         return getAttribute( "bgcolor" );
184     }
185
186
187     public void setBgColor( String JavaDoc bgColor ) {
188         setAttribute( "bgcolor", bgColor );
189     }
190
191
192     public String JavaDoc getCh() {
193         String JavaDoc ch;
194
195         // Make sure that the access key is a single character.
196
ch = getAttribute( "char" );
197         if (ch != null && ch.length() > 1) {
198             ch = ch.substring( 0, 1 );
199         }
200         return ch;
201     }
202
203
204     public void setCh( String JavaDoc ch ) {
205         // Make sure that the access key is a single character.
206
if (ch != null && ch.length() > 1) {
207             ch = ch.substring( 0, 1 );
208         }
209         setAttribute( "char", ch );
210     }
211
212
213     public String JavaDoc getChOff() {
214         return getAttribute( "charoff" );
215     }
216
217
218     public void setChOff( String JavaDoc chOff ) {
219         setAttribute( "charoff", chOff );
220     }
221
222
223     public String JavaDoc getVAlign() {
224         return capitalize( getAttribute( "valign" ) );
225     }
226
227
228     public void setVAlign( String JavaDoc vAlign ) {
229         setAttribute( "valign", vAlign );
230     }
231
232
233     /**
234      * Constructor requires owner document.
235      *
236      * @param owner The owner HTML document
237      */

238     public HTMLTableRowElementImpl( HTMLDocumentImpl owner, String JavaDoc name ) {
239         super( owner, "TR" );
240     }
241
242
243     HTMLCollection _cells;
244
245
246 }
247
Popular Tags