KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > html > TD


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

58 package org.apache.ecs.html;
59
60 import org.apache.ecs.*;
61
62 /**
63     This class creates a &lt;TD&gt; object.
64     @version $Id: TD.java,v 1.8 2003/04/27 09:03:39 rdonkin Exp $
65     @author <a HREF="mailto:snagy@servletapi.com">Stephan Nagy</a>
66     @author <a HREF="mailto:jon@clearink.com">Jon S. Stevens</a>
67 */

68 public class TD extends MultiPartElement implements Printable, MouseEvents, KeyEvents
69 {
70     /**
71         private initializer.
72     */

73     {
74         setElementType("td");
75     }
76
77     /**
78         Basic Constructor.
79         Use set* methods to change attributes.
80     */

81     public TD()
82     {
83     }
84
85     /**
86         Constructor adds element.
87         Use set* methods to change attributes.
88         @param element element to add.
89     */

90     public TD(Element element)
91     {
92         addElement(element);
93     }
94
95     /**
96         Constructor adds element.
97         Use set* methods to change attributes.
98         @param element element to add.
99     */

100     public TD(String element)
101     {
102         addElement(element);
103     }
104
105     /**
106         Constructor sets closing tag.
107         Use set* methods to change attributes.
108         @param close print the closing tag?
109     */

110     public TD(boolean close)
111     {
112         setNeedClosingTag(close);
113     }
114     
115     /**
116         Sets the ABBR="" attribute.
117         @param cdata sets the ABBR="" attribute.
118     */

119     public TD setAbbr(String cdata)
120     {
121         addAttribute("abbr",cdata);
122         return(this);
123     }
124
125     /**
126         Sets the AXIS="" attribute
127         @param cdata sets the AXIS="" attribute
128     */

129     public TD setAxis(String cdata)
130     {
131         addAttribute("axis",cdata);
132         return(this);
133     }
134
135     /**
136         Sets the AXES="" attribute
137         @param id_refs list of id's for header cells
138     */

139     public TD setAxes(String id_refs)
140     {
141         addAttribute("axes",id_refs);
142         return(this);
143     }
144
145     /**
146         Sets the ROWSPAN="" attribute
147         @param rowspan Number of rows spaned by cell
148     */

149     public TD setRowSpan(int rowspan)
150     {
151         addAttribute("rowspan",Integer.toString(rowspan));
152         return(this);
153     }
154
155     /**
156         Sets the ROWSPAN="" attribute
157         @param rowspan Number of rows spaned by cell
158     */

159     public TD setRowSpan(String rowspan)
160     {
161         addAttribute("rowspan",rowspan);
162         return(this);
163     }
164
165     /**
166         Sets the COLSPAN="" attribute
167         @param colspan Number of columns spanned by cell
168     */

169     public TD setColSpan(int colspan)
170     {
171         addAttribute("colspan",Integer.toString(colspan));
172         return(this);
173     }
174
175     /**
176         Sets the COLSPAN="" attribute
177         @param colspan Number of columns spanned by cell
178     */

179     public TD setColSpan(String colspan)
180     {
181         addAttribute("colspan",colspan);
182         return(this);
183     }
184
185     /**
186         Sets word wrap on or off.
187         @param wrap turn word wrap on or off.
188     */

189     public TD setNoWrap(boolean wrap)
190     {
191         if ( wrap == true )
192             addAttribute("nowrap", NO_ATTRIBUTE_VALUE);
193         else
194             removeAttribute("nowrap");
195
196         return(this);
197     }
198
199     /**
200         Supplies user agents with a recommended cell width. (Pixel Values)
201         @param width how many pixels to make cell
202     */

203     public TD setWidth(int width)
204     {
205         addAttribute("width",Integer.toString(width));
206         return(this);
207     }
208     
209     /**
210         Supplies user agents with a recommended cell width. (Pixel Values)
211         @param width how many pixels to make cell
212     */

213     public TD setWidth(String width)
214     {
215         addAttribute("width",width);
216         return(this);
217     }
218
219     /**
220         Supplies user agents with a recommended cell height. (Pixel Values)
221         @param height how many pixels to make cell
222     */

223     public TD setHeight(int height)
224     {
225         addAttribute("height",Integer.toString(height));
226         return(this);
227     }
228
229     /**
230         Supplies user agents with a recommended cell height. (Pixel Values)
231         @param height how many pixels to make cell
232     */

233     public TD setHeight(String height)
234     {
235         addAttribute("height",height);
236         return(this);
237     }
238
239     /**
240         Sets the ALIGN="" attribute convience variables are provided in the AlignType interface
241         @param align Sets the ALIGN="" attribute
242     */

243     public TD setAlign(String align)
244     {
245         addAttribute("align",align);
246         return(this);
247     }
248
249     /**
250         Sets the VALIGN="" attribute convience variables are provided in the AlignType interface
251         @param valign Sets the ALIGN="" attribute
252     */

253     public TD setVAlign(String valign)
254     {
255         addAttribute("valign",valign);
256         return(this);
257     }
258
259     /**
260         Sets the CHAR="" attribute.
261         @param character the character to use for alignment.
262     */

263     public TD setChar(String character)
264     {
265         addAttribute("char",character);
266         return(this);
267     }
268
269     /**
270         Sets the CHAROFF="" attribute.
271         @param char_off When present this attribute specifies the offset
272         of the first occurrence of the alignment character on each line.
273     */

274     public TD setCharOff(int char_off)
275     {
276         addAttribute("charoff",Integer.toString(char_off));
277         return(this);
278     }
279
280     /**
281         Sets the CHAROFF="" attribute.
282         @param char_off When present this attribute specifies the offset
283         of the first occurrence of the alignment character on each line.
284     */

285     public TD setCharOff(String char_off)
286     {
287         addAttribute("charoff",char_off);
288         return(this);
289     }
290
291     /**
292         Sets the BGCOLOR="" attribute
293         @param color sets the background color of the cell.
294     */

295     public TD setBgColor(String color)
296     {
297         addAttribute("bgcolor",HtmlColor.convertColor(color));
298         return(this);
299     }
300
301     /**
302         Sets the BACKGROUND="" attribute
303         @param url sets the background to some image specified by url.
304     */

305     public TD setBackground(String url)
306     {
307         addAttribute("background",url);
308         return(this);
309     }
310
311     /**
312         Adds an Element to the element.
313         @param hashcode name of element for hash table
314         @param element Adds an Element to the element.
315      */

316     public TD addElement(String hashcode,Element element)
317     {
318         addElementToRegistry(hashcode,element);
319         return(this);
320     }
321
322     /**
323         Adds an Element to the element.
324         @param hashcode name of element for hash table
325         @param element Adds an Element to the element.
326      */

327     public TD addElement(String hashcode,String element)
328     {
329         addElementToRegistry(hashcode,element);
330         return(this);
331     }
332
333      /**
334         Adds an Element to the element.
335         @param element Adds an Element to the element.
336      */

337     public TD addElement(Element element)
338     {
339         addElementToRegistry(element);
340         return(this);
341     }
342
343     /**
344         Adds an Element to the element.
345         @param element Adds an Element to the element.
346      */

347     public TD addElement(String element)
348     {
349         addElementToRegistry(element);
350         return(this);
351     }
352     /**
353         Removes an Element from the element.
354         @param hashcode the name of the element to be removed.
355     */

356     public TD removeElement(String hashcode)
357     {
358         removeElementFromRegistry(hashcode);
359         return(this);
360     }
361
362     /**
363         The onclick event occurs when the pointing device button is clicked
364         over an element. This attribute may be used with most elements.
365         
366         @param The script
367     */

368     public void setOnClick(String script)
369     {
370         addAttribute ( "onClick", script );
371     }
372     /**
373         The ondblclick event occurs when the pointing device button is double
374         clicked over an element. This attribute may be used with most elements.
375
376         @param The script
377     */

378     public void setOnDblClick(String script)
379     {
380         addAttribute ( "onDblClick", script );
381     }
382     /**
383         The onmousedown event occurs when the pointing device button is pressed
384         over an element. This attribute may be used with most elements.
385
386         @param The script
387     */

388     public void setOnMouseDown(String script)
389     {
390         addAttribute ( "onMouseDown", script );
391     }
392     /**
393         The onmouseup event occurs when the pointing device button is released
394         over an element. This attribute may be used with most elements.
395
396         @param The script
397     */

398     public void setOnMouseUp(String script)
399     {
400         addAttribute ( "onMouseUp", script );
401     }
402     /**
403         The onmouseover event occurs when the pointing device is moved onto an
404         element. This attribute may be used with most elements.
405
406         @param The script
407     */

408     public void setOnMouseOver(String script)
409     {
410         addAttribute ( "onMouseOver", script );
411     }
412     /**
413         The onmousemove event occurs when the pointing device is moved while it
414         is over an element. This attribute may be used with most elements.
415
416         @param The script
417     */

418     public void setOnMouseMove(String script)
419     {
420         addAttribute ( "onMouseMove", script );
421     }
422     /**
423         The onmouseout event occurs when the pointing device is moved away from
424         an element. This attribute may be used with most elements.
425
426         @param The script
427     */

428     public void setOnMouseOut(String script)
429     {
430         addAttribute ( "onMouseOut", script );
431     }
432
433     /**
434         The onkeypress event occurs when a key is pressed and released over an
435         element. This attribute may be used with most elements.
436         
437         @param The script
438     */

439     public void setOnKeyPress(String script)
440     {
441         addAttribute ( "onKeyPress", script );
442     }
443
444     /**
445         The onkeydown event occurs when a key is pressed down over an element.
446         This attribute may be used with most elements.
447         
448         @param The script
449     */

450     public void setOnKeyDown(String script)
451     {
452         addAttribute ( "onKeyDown", script );
453     }
454
455     /**
456         The onkeyup event occurs when a key is released over an element. This
457         attribute may be used with most elements.
458         
459         @param The script
460     */

461     public void setOnKeyUp(String script)
462     {
463         addAttribute ( "onKeyUp", script );
464     }
465     
466     /**
467         Determine if this element needs a line break, if pretty printing.
468     */

469     public boolean getNeedLineBreak()
470     {
471         java.util.Enumeration enum = elements();
472         int i=0;
473         int j=0;
474         while(enum.hasMoreElements())
475         {
476             j++;
477             Object obj = enum.nextElement();
478             if( obj instanceof IMG || obj instanceof A )
479                 i++;
480         }
481         if ( i==j)
482             return false;
483         return true;
484     }
485
486 }
487
Popular Tags