KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > xhtml > img


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.xhtml;
59
60 import org.apache.ecs.*;
61
62 /**
63     This class creates an &lt;img&gt; tag.
64
65     @version $Id: img.java,v 1.2 2003/04/27 09:39:23 rdonkin Exp $
66     @author <a HREF="mailto:snagy@servletapi.com">Stephan Nagy</a>
67     @author <a HREF="mailto:jon@clearink.com">Jon S. Stevens</a>
68     @author <a HREF="mailto:bojan@binarix.com">Bojan Smojver</a>
69 */

70 public class img extends SinglePartElement implements Printable, MouseEvents, KeyEvents
71 {
72     /**
73             Private initialization routine.
74     */

75
76     {
77         setElementType("img");
78         setCase(LOWERCASE);
79         setAttributeQuote(true);
80         setBeginEndModifier('/');
81     }
82
83     /**
84         Basic constructor. Use the set* methods to set the attibutes.
85     */

86     public img()
87     {
88     }
89
90     /**
91         Creates an img tag
92
93         @param src the SRC="" attribute
94     */

95     public img(String JavaDoc src)
96     {
97         setSrc(src);
98     }
99
100     /**
101         Creates an img tag
102
103         @param src the SRC="" attribute
104         @param border the border="" attribute
105     */

106     public img(String JavaDoc src, int border)
107     {
108         setSrc(src);
109         setBorder(border);
110     }
111
112     /**
113         Creates an img tag
114
115         @param src the SRC="" attribute
116         @param name the name="" attribute
117     */

118     public img(String JavaDoc src, String JavaDoc name)
119     {
120         setSrc(src);
121         setName(name);
122     }
123
124     /**
125         Creates an img tag
126
127         @param src the SRC="" attribute
128         @param name the name="" attribute
129         @param border the border="" attribute
130     */

131     public img(String JavaDoc src, String JavaDoc name, int border)
132     {
133         setSrc(src);
134         setName(name);
135         setBorder(border);
136     }
137
138     /**
139         Sets the SRC="" attribute
140         @param src the SRC="" attribute
141     */

142     public img setSrc(String JavaDoc src)
143     {
144         addAttribute("src",src);
145         return this;
146     }
147
148     /**
149         Sets the border="" attribute
150         @param border the border="" attribute
151     */

152     public img setBorder(int border)
153     {
154         addAttribute("border",Integer.toString(border));
155         return this;
156     }
157
158     /**
159         Sets the name="" attribute
160         @param name the name="" attribute
161     */

162     public img setName(String JavaDoc name)
163     {
164         addAttribute("name",name);
165         return this;
166     }
167
168     /**
169         Sets the height="" attribute
170         @param height the height="" attribute
171     */

172     public img setHeight(String JavaDoc height)
173     {
174         addAttribute("height",height);
175         return this;
176     }
177
178     /**
179         Sets the height="" attribute
180         @param height the height="" attribute
181     */

182     public img setHeight(int height)
183     {
184         addAttribute("height",Integer.toString(height));
185         return this;
186     }
187
188     /**
189         Sets the width="" attribute
190         @param width the width="" attribute
191     */

192     public img setWidth(String JavaDoc width)
193     {
194         addAttribute("width",width);
195         return this;
196     }
197
198     /**
199         Sets the width="" attribute
200         @param width the width="" attribute
201     */

202     public img setWidth(int width)
203     {
204         addAttribute("width",Integer.toString(width));
205         return this;
206     }
207
208     /**
209         Sets the alt="" attribute
210         @param alt the alt="" attribute
211     */

212     public img setAlt(String JavaDoc alt)
213     {
214         addAttribute("alt",alt);
215         return this;
216     }
217
218     /**
219         Sets the ismap attribute
220         @param ismap the ismap attribute
221     */

222     public img setIsMap(boolean ismap)
223     {
224         if(ismap == true)
225             addAttribute("ismap","ismap");
226         else
227             removeAttribute("ismap");
228             
229         return this;
230     }
231
232     /**
233         Sets the usmap="" attribute
234         @param usemap the usmap="" attribute
235     */

236     public img setUseMap(String JavaDoc usemap)
237     {
238         addAttribute("usemap",usemap);
239         return this;
240     }
241
242     /**
243         Sets the align="" attribute
244         @param align the align="" attribute
245     */

246     public img setAlign(String JavaDoc align)
247     {
248         addAttribute("align",align);
249         return this;
250     }
251
252     /**
253         Sets the hspace="" attribute
254         @param hspace the hspace="" attribute
255     */

256     public img setHspace(String JavaDoc hspace)
257     {
258         addAttribute("hspace",hspace);
259         return this;
260     }
261
262     /**
263         Sets the hspace="" attribute
264         @param hspace the hspace="" attribute
265     */

266     public img setHspace(int hspace)
267     {
268         addAttribute("hspace",Integer.toString(hspace));
269         return this;
270     }
271
272     /**
273         Sets the vspace="" attribute
274         @param vspace the vspace="" attribute
275     */

276     public img setVspace(String JavaDoc vspace)
277     {
278         addAttribute("vspace",vspace);
279         return this;
280     }
281
282     /**
283         Sets the vspace="" attribute
284         @param vspace the vspace="" attribute
285     */

286     public img setVspace(int vspace)
287     {
288         addAttribute("vspace",Integer.toString(vspace));
289         return this;
290     }
291
292     /**
293         Sets the lang="" and xml:lang="" attributes
294         @param lang the lang="" and xml:lang="" attributes
295     */

296     public Element setLang(String JavaDoc lang)
297     {
298         addAttribute("lang",lang);
299         addAttribute("xml:lang",lang);
300         return this;
301     }
302
303     /**
304         Adds an Element to the element.
305         @param hashcode name of element for hash table
306         @param element Adds an Element to the element.
307      */

308     public img addElement(String JavaDoc hashcode,Element element)
309     {
310         addElementToRegistry(hashcode,element);
311         return(this);
312     }
313
314     /**
315         Adds an Element to the element.
316         @param hashcode name of element for hash table
317         @param element Adds an Element to the element.
318      */

319     public img addElement(String JavaDoc hashcode,String JavaDoc element)
320     {
321         addElementToRegistry(hashcode,element);
322         return(this);
323     }
324
325     /**
326         Adds an Element to the element.
327         @param element Adds an Element to the element.
328      */

329     public img addElement(Element element)
330     {
331         addElementToRegistry(element);
332         return(this);
333     }
334
335     /**
336         Adds an Element to the element.
337         @param element Adds an Element to the element.
338      */

339     public img addElement(String JavaDoc element)
340     {
341         addElementToRegistry(element);
342         return(this);
343     }
344     /**
345         Removes an Element from the element.
346         @param hashcode the name of the element to be removed.
347     */

348     public img removeElement(String JavaDoc hashcode)
349     {
350         removeElementFromRegistry(hashcode);
351         return(this);
352     }
353
354     /**
355         The onclick event occurs when the pointing device button is clicked
356         over an element. This attribute may be used with most elements.
357         
358         @param The script
359     */

360     public void setOnClick(String JavaDoc script)
361     {
362         addAttribute ( "onclick", script );
363     }
364     /**
365         The ondblclick event occurs when the pointing device button is double
366         clicked over an element. This attribute may be used with most elements.
367
368         @param The script
369     */

370     public void setOnDblClick(String JavaDoc script)
371     {
372         addAttribute ( "ondblclick", script );
373     }
374     /**
375         The onmousedown event occurs when the pointing device button is pressed
376         over an element. This attribute may be used with most elements.
377
378         @param The script
379     */

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

390     public void setOnMouseUp(String JavaDoc script)
391     {
392         addAttribute ( "onmouseup", script );
393     }
394     /**
395         The onmouseover event occurs when the pointing device is moved onto an
396         element. This attribute may be used with most elements.
397
398         @param The script
399     */

400     public void setOnMouseOver(String JavaDoc script)
401     {
402         addAttribute ( "onmouseover", script );
403     }
404     /**
405         The onmousemove event occurs when the pointing device is moved while it
406         is over an element. This attribute may be used with most elements.
407
408         @param The script
409     */

410     public void setOnMouseMove(String JavaDoc script)
411     {
412         addAttribute ( "onmousemove", script );
413     }
414     /**
415         The onmouseout event occurs when the pointing device is moved away from
416         an element. This attribute may be used with most elements.
417
418         @param The script
419     */

420     public void setOnMouseOut(String JavaDoc script)
421     {
422         addAttribute ( "onmouseout", script );
423     }
424
425     /**
426         The onkeypress event occurs when a key is pressed and released over an
427         element. This attribute may be used with most elements.
428         
429         @param The script
430     */

431     public void setOnKeyPress(String JavaDoc script)
432     {
433         addAttribute ( "onkeypress", script );
434     }
435
436     /**
437         The onkeydown event occurs when a key is pressed down over an element.
438         This attribute may be used with most elements.
439         
440         @param The script
441     */

442     public void setOnKeyDown(String JavaDoc script)
443     {
444         addAttribute ( "onkeydown", script );
445     }
446
447     /**
448         The onkeyup event occurs when a key is released over an element. This
449         attribute may be used with most elements.
450         
451         @param The script
452     */

453     public void setOnKeyUp(String JavaDoc script)
454     {
455         addAttribute ( "onkeyup", script );
456     }
457 }
458
Popular Tags