KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > lazydom > html > 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.xml.lazydom.html;
58 import org.enhydra.xml.lazydom.LazyElement;
59 import org.enhydra.xml.lazydom.LazyElementNoNS;
60 import org.w3c.dom.Node JavaDoc;
61 import org.w3c.dom.NodeList JavaDoc;
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 /**
71  * @version $Revision: 1.3 $ $Date: 2005/01/26 08:29:24 $
72  * @author <a HREF="mailto:arkin@exoffice.com">Assaf Arkin</a>
73  * @see org.w3c.dom.html.HTMLTableRowElement
74  * @see LazyElementNoNS
75  */

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

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

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