KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lobobrowser > html > domimpl > HTMLTableRowElementImpl


1 /*
2     GNU LESSER GENERAL PUBLIC LICENSE
3     Copyright (C) 2006 The Lobo Project
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19     Contact info: xamjadmin@users.sourceforge.net
20 */

21 /*
22  * Created on Dec 4, 2005
23  */

24 package org.lobobrowser.html.domimpl;
25
26 import java.util.ArrayList JavaDoc;
27
28 import org.w3c.dom.DOMException JavaDoc;
29 import org.w3c.dom.Node JavaDoc;
30 import org.w3c.dom.html2.HTMLCollection;
31 import org.w3c.dom.html2.HTMLElement;
32 import org.w3c.dom.html2.HTMLTableRowElement;
33
34 public class HTMLTableRowElementImpl extends HTMLElementImpl implements
35         HTMLTableRowElement {
36     public HTMLTableRowElementImpl(String JavaDoc name) {
37         super(name, true);
38     }
39     
40     public HTMLTableRowElementImpl() {
41         super("TR", true);
42     }
43     
44     public int getRowIndex() {
45         NodeImpl parent = (NodeImpl) this.getParentNode();
46         if(parent == null) {
47             return -1;
48         }
49         try {
50             parent.visit(new NodeVisitor() {
51                 private int count = 0;
52                 
53                 public void visit(Node JavaDoc node) {
54                     if(node instanceof HTMLTableRowElementImpl) {
55                         if(HTMLTableRowElementImpl.this == node) {
56                             throw new StopVisitorException(new Integer JavaDoc(this.count));
57                         }
58                         this.count++;
59                     }
60                 }
61             });
62         } catch(StopVisitorException sve) {
63             return ((Integer JavaDoc) sve.getTag()).intValue();
64         }
65         return -1;
66     }
67     
68     public int getSectionRowIndex() {
69         // TODO Auto-generated method stub
70
return 0;
71     }
72
73     public HTMLCollection getCells() {
74         NodeFilter filter = new NodeFilter() {
75             public boolean accept(Node JavaDoc node) {
76                 return node instanceof HTMLTableCellElementImpl;
77             }
78         };
79         return new DescendentHTMLCollection(this, filter);
80     }
81
82     public String JavaDoc getAlign() {
83         return this.getAttribute("align");
84     }
85
86     public void setAlign(String JavaDoc align) {
87         this.setAttribute("align", align);
88     }
89
90     public String JavaDoc getBgColor() {
91         return this.getAttribute("bgcolor");
92     }
93
94     public void setBgColor(String JavaDoc bgColor) {
95         this.setAttribute("bgcolor", bgColor);
96     }
97
98     public String JavaDoc getCh() {
99         return this.getAttribute("ch");
100     }
101
102     public void setCh(String JavaDoc ch) {
103         this.setAttribute("ch", ch);
104     }
105
106     public String JavaDoc getChOff() {
107         return this.getAttribute("choff");
108     }
109
110     public void setChOff(String JavaDoc chOff) {
111         this.setAttribute("choff", chOff);
112     }
113
114     public String JavaDoc getVAlign() {
115         return this.getAttribute("valign");
116     }
117
118     public void setVAlign(String JavaDoc vAlign) {
119         this.setAttribute("valign", vAlign);
120     }
121
122     public HTMLElement insertCell(int index) throws DOMException JavaDoc {
123         org.w3c.dom.Document JavaDoc doc = this.document;
124         if(doc == null) {
125             throw new DOMException JavaDoc(DOMException.WRONG_DOCUMENT_ERR, "Orphan element");
126         }
127         HTMLElement cellElement = (HTMLElement) doc.createElement("TD");
128         synchronized(this.treeLock) {
129             if(index == -1) {
130                 this.appendChild(cellElement);
131                 return cellElement;
132             }
133             ArrayList JavaDoc nl = this.nodeList;
134             if(nl != null) {
135                 int size = nl.size();
136                 int trcount = 0;
137                 for(int i = 0; i < size; i++) {
138                     Node JavaDoc node = (Node JavaDoc) nl.get(i);
139                     if(node instanceof org.w3c.dom.html2.HTMLTableCellElement) {
140                         if(trcount == index) {
141                             this.insertAt(cellElement, i);
142                             return cellElement;
143                         }
144                         trcount++;
145                     }
146                 }
147             }
148             else {
149                 this.appendChild(cellElement);
150                 return cellElement;
151             }
152         }
153         throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "Index out of range");
154     }
155
156     public void deleteCell(int index) throws DOMException JavaDoc {
157         synchronized(this.treeLock) {
158             ArrayList JavaDoc nl = this.nodeList;
159             if(nl != null) {
160                 int size = nl.size();
161                 int trcount = 0;
162                 for(int i = 0; i < size; i++) {
163                     Node JavaDoc node = (Node JavaDoc) nl.get(i);
164                     if(node instanceof org.w3c.dom.html2.HTMLTableCellElement) {
165                         if(trcount == index) {
166                             this.removeChildAt(index);
167                         }
168                         trcount++;
169                     }
170                 }
171             }
172         }
173         throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "Index out of range");
174     }
175 }
176
Popular Tags