KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > html > dom > HTMLTableRowElementImpl


1 /*
2  * Copyright 1999,2000,2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.html.dom;
17
18 import org.w3c.dom.Node JavaDoc;
19 import org.w3c.dom.NodeList JavaDoc;
20 import org.w3c.dom.html.HTMLCollection;
21 import org.w3c.dom.html.HTMLElement;
22 import org.w3c.dom.html.HTMLTableCellElement;
23 import org.w3c.dom.html.HTMLTableElement;
24 import org.w3c.dom.html.HTMLTableRowElement;
25 import org.w3c.dom.html.HTMLTableSectionElement;
26
27 /**
28  * @xerces.internal
29  * @version $Revision: 1.10 $ $Date: 2005/04/18 01:20:21 $
30  * @author <a HREF="mailto:arkin@exoffice.com">Assaf Arkin</a>
31  * @see org.w3c.dom.html.HTMLTableRowElement
32  * @see org.apache.xerces.dom.ElementImpl
33  */

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

252     public Node JavaDoc cloneNode( boolean deep ) {
253         HTMLTableRowElementImpl clonedNode = (HTMLTableRowElementImpl)super.cloneNode( deep );
254         clonedNode._cells = null;
255         return clonedNode;
256     }
257     
258     /**
259      * Constructor requires owner document.
260      *
261      * @param owner The owner HTML document
262      */

263     public HTMLTableRowElementImpl( HTMLDocumentImpl owner, String JavaDoc name )
264     {
265         super( owner, name );
266     }
267   
268   
269     HTMLCollection _cells;
270
271   
272 }
273
274
Popular Tags