KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57 package org.enhydra.apache.html.dom;
58
59
60 import org.enhydra.apache.xerces.dom.ElementImpl;
61 import org.w3c.dom.Node JavaDoc;
62 import org.w3c.dom.NodeList JavaDoc;
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 /**
72  * @version $Revision: 1.3 $ $Date: 2005/01/26 08:28:44 $
73  * @author <a HREF="mailto:arkin@exoffice.com">Assaf Arkin</a>
74  * @see org.w3c.dom.html.HTMLTableRowElement
75  * @see ElementImpl
76  */

77 public class HTMLTableRowElementImpl
78     extends HTMLElementImpl
79     implements HTMLTableRowElement
80 {
81
82     
83     public int getRowIndex()
84     {
85         Node JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc parent;
123         
124         parent = getParentNode();
125         if ( parent instanceof HTMLTableSectionElement )
126             ( (HTMLTableSectionElementImpl) parent ).insertRowX( sectionRowIndex, this );
127     }
128   
129   
130     int getRowIndex( Node JavaDoc parent )
131     {
132         NodeList JavaDoc rows;
133         int i;
134         
135         // Use getElementsByTagName() which creates a snapshot of all the
136
// TR elements under the TABLE/section. Access to the returned NodeList
137
// is very fast and the snapshot solves many synchronization problems.
138
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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc getAlign()
223     {
224         return capitalize( getAttribute( "align" ) );
225     }
226     
227     
228     public void setAlign( String JavaDoc align )
229     {
230         setAttribute( "align", align );
231     }
232
233     
234     public String JavaDoc getBgColor()
235     {
236         return getAttribute( "bgcolor" );
237     }
238     
239     
240     public void setBgColor( String JavaDoc bgColor )
241     {
242         setAttribute( "bgcolor", bgColor );
243     }
244
245   
246     public String JavaDoc getCh()
247     {
248         String JavaDoc ch;
249         
250         // Make sure that the access key is a single character.
251
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 JavaDoc ch )
259     {
260         // Make sure that the access key is a single character.
261
if ( ch != null && ch.length() > 1 )
262             ch = ch.substring( 0, 1 );
263         setAttribute( "char", ch );
264     }
265
266     
267     public String JavaDoc getChOff()
268     {
269         return getAttribute( "charoff" );
270     }
271     
272     
273     public void setChOff( String JavaDoc chOff )
274     {
275         setAttribute( "charoff", chOff );
276     }
277   
278   
279     public String JavaDoc getVAlign()
280     {
281         return capitalize( getAttribute( "valign" ) );
282     }
283     
284     
285     public void setVAlign( String JavaDoc vAlign )
286     {
287         setAttribute( "valign", vAlign );
288     }
289
290     /**
291      * Explicit implementation of cloneNode() to ensure that cache used
292      * for getCells() gets cleared.
293      */

294     public Node JavaDoc cloneNode( boolean deep ) {
295         HTMLTableRowElementImpl clonedNode = (HTMLTableRowElementImpl)super.cloneNode( deep );
296         clonedNode._cells = null;
297         return clonedNode;
298     }
299
300     /**
301      * Constructor requires owner document.
302      *
303      * @param owner The owner HTML document
304      */

305     public HTMLTableRowElementImpl( HTMLDocumentImpl owner, String JavaDoc name )
306     {
307         super( owner, name );
308     }
309   
310   
311     HTMLCollection _cells;
312
313   
314 }
315
316
Popular Tags