KickJava   Java API By Example, From Geeks To Geeks.

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


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 3, 2005
23  */

24 package org.lobobrowser.html.domimpl;
25
26 import org.lobobrowser.html.style.*;
27 import org.w3c.dom.DOMException JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29 import org.w3c.dom.html2.HTMLCollection;
30 import org.w3c.dom.html2.HTMLElement;
31 import org.w3c.dom.html2.HTMLTableCaptionElement;
32 import org.w3c.dom.html2.HTMLTableElement;
33 import org.w3c.dom.html2.HTMLTableSectionElement;
34 import java.util.*;
35
36 public class HTMLTableElementImpl extends HTMLAbstractUIElement implements
37         HTMLTableElement {
38     
39     public HTMLTableElementImpl() {
40         super("TABLE");
41     }
42
43     public HTMLTableElementImpl(String JavaDoc name) {
44         super(name);
45     }
46
47     private HTMLTableCaptionElement caption;
48     
49     public HTMLTableCaptionElement getCaption() {
50         return this.caption;
51     }
52
53     public void setCaption(HTMLTableCaptionElement caption) throws DOMException JavaDoc {
54         this.caption = caption;
55     }
56
57     private HTMLTableSectionElement thead;
58     
59     public HTMLTableSectionElement getTHead() {
60         return this.thead;
61     }
62
63     public void setTHead(HTMLTableSectionElement tHead) throws DOMException JavaDoc {
64         this.thead = tHead;
65     }
66
67     private HTMLTableSectionElement tfoot;
68     
69     public HTMLTableSectionElement getTFoot() {
70         return this.tfoot;
71     }
72
73     public void setTFoot(HTMLTableSectionElement tFoot) throws DOMException JavaDoc {
74         this.tfoot = tFoot;
75     }
76
77     public HTMLCollection getRows() {
78         return new DescendentHTMLCollection(this, new ElementFilter("TR"));
79     }
80
81     public HTMLCollection getTBodies() {
82         return new DescendentHTMLCollection(this, new ElementFilter("TBODY"));
83     }
84
85     public String JavaDoc getAlign() {
86         return this.getAttribute("align");
87     }
88
89     public void setAlign(String JavaDoc align) {
90         this.setAttribute("align", align);
91     }
92
93     public String JavaDoc getBgColor() {
94         return this.getAttribute("bgcolor");
95     }
96
97     public void setBgColor(String JavaDoc bgColor) {
98         this.setAttribute("bgcolor", bgColor);
99     }
100
101     public String JavaDoc getBorder() {
102         return this.getAttribute("border");
103     }
104
105     public void setBorder(String JavaDoc border) {
106         this.setAttribute("border", border);
107     }
108
109     public String JavaDoc getCellPadding() {
110         return this.getAttribute("cellpadding");
111     }
112
113     public void setCellPadding(String JavaDoc cellPadding) {
114         this.setAttribute("cellpadding", cellPadding);
115     }
116
117     public String JavaDoc getCellSpacing() {
118         return this.getAttribute("cellspacing");
119     }
120
121     public void setCellSpacing(String JavaDoc cellSpacing) {
122         this.setAttribute("cellspacing", cellSpacing);
123     }
124
125     public String JavaDoc getFrame() {
126         return this.getAttribute("frame");
127     }
128
129     public void setFrame(String JavaDoc frame) {
130         this.setAttribute("frame", frame);
131     }
132
133     public String JavaDoc getRules() {
134         return this.getAttribute("rules");
135     }
136
137     public void setRules(String JavaDoc rules) {
138         this.setAttribute("rules", rules);
139     }
140
141     public String JavaDoc getSummary() {
142         return this.getAttribute("summary");
143     }
144
145     public void setSummary(String JavaDoc summary) {
146         this.setAttribute("summary", summary);
147     }
148
149     public String JavaDoc getWidth() {
150         return this.getAttribute("width");
151     }
152
153     public void setWidth(String JavaDoc width) {
154         this.setAttribute("width", width);
155     }
156
157     /* (non-Javadoc)
158      * @see org.xamjwg.html.renderer.RenderableContext#getHeightLength()
159      */

160     public HtmlLength getHeightLength(int availHeight) {
161         try {
162             CSS2PropertiesImpl props = this.getCurrentStyle();
163             String JavaDoc heightText = props == null ? null : props.getHeight();
164             if(heightText == null) {
165                 return new HtmlLength(this.getAttribute("height"));
166             }
167             else {
168                 return new HtmlLength(HtmlValues.getPixelSize(heightText, this.getRenderState(), 0, availHeight));
169             }
170         } catch(Exception JavaDoc err) {
171             return null;
172         }
173     }
174
175     /* (non-Javadoc)
176      * @see org.xamjwg.html.renderer.RenderableContext#getWidthLength()
177      */

178     public HtmlLength getWidthLength(int availWidth) {
179         try {
180             CSS2PropertiesImpl props = this.getCurrentStyle();
181             String JavaDoc widthText = props == null ? null : props.getWidth();
182             if(widthText == null) {
183                 return new HtmlLength(this.getAttribute("width"));
184             }
185             else {
186                 return new HtmlLength(HtmlValues.getPixelSize(widthText, this.getRenderState(), 0, availWidth));
187             }
188         } catch(Exception JavaDoc err) {
189             return null;
190         }
191     }
192
193     public HTMLElement createTHead() {
194         org.w3c.dom.Document JavaDoc doc = this.document;
195         return doc == null ? null : (HTMLElement) doc.createElement("thead");
196     }
197
198     public void deleteTHead() {
199         this.removeChildren(new ElementFilter("THEAD"));
200     }
201
202     public HTMLElement createTFoot() {
203         org.w3c.dom.Document JavaDoc doc = this.document;
204         return doc == null ? null : (HTMLElement) doc.createElement("tfoot");
205     }
206
207     public void deleteTFoot() {
208         this.removeChildren(new ElementFilter("TFOOT"));
209     }
210
211     public HTMLElement createCaption() {
212         org.w3c.dom.Document JavaDoc doc = this.document;
213         return doc == null ? null : (HTMLElement) doc.createElement("caption");
214     }
215
216     public void deleteCaption() {
217         this.removeChildren(new ElementFilter("CAPTION"));
218     }
219
220     /**
221      * Inserts a row at the index given. If <code>index</code> is <code>-1</code>,
222      * the row is appended as the last row.
223      */

224     public HTMLElement insertRow(int index) throws DOMException JavaDoc {
225         org.w3c.dom.Document JavaDoc doc = this.document;
226         if(doc == null) {
227             throw new DOMException JavaDoc(DOMException.WRONG_DOCUMENT_ERR, "Orphan element");
228         }
229         HTMLElement rowElement = (HTMLElement) doc.createElement("TR");
230         synchronized(this.treeLock) {
231             if(index == -1) {
232                 this.appendChild(rowElement);
233                 return rowElement;
234             }
235             ArrayList nl = this.nodeList;
236             if(nl != null) {
237                 int size = nl.size();
238                 int trcount = 0;
239                 for(int i = 0; i < size; i++) {
240                     Node JavaDoc node = (Node JavaDoc) nl.get(i);
241                     if("TR".equalsIgnoreCase(node.getNodeName())) {
242                         if(trcount == index) {
243                             this.insertAt(rowElement, i);
244                             return rowElement;
245                         }
246                         trcount++;
247                     }
248                 }
249             }
250             else {
251                 this.appendChild(rowElement);
252                 return rowElement;
253             }
254         }
255         throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "Index out of range");
256     }
257
258     public void deleteRow(int index) throws DOMException JavaDoc {
259         synchronized(this.treeLock) {
260             ArrayList nl = this.nodeList;
261             if(nl != null) {
262                 int size = nl.size();
263                 int trcount = 0;
264                 for(int i = 0; i < size; i++) {
265                     Node JavaDoc node = (Node JavaDoc) nl.get(i);
266                     if("TR".equalsIgnoreCase(node.getNodeName())) {
267                         if(trcount == index) {
268                             this.removeChildAt(i);
269                             return;
270                         }
271                         trcount++;
272                     }
273                 }
274             }
275         }
276         throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "Index out of range");
277     }
278
279     protected RenderState createRenderState(RenderState prevRenderState) {
280         return new TableRenderState(prevRenderState, this);
281     }
282 }
283
Popular Tags