KickJava   Java API By Example, From Geeks To Geeks.

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


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 a &lt;input&gt; tag.
64
65     @version $Id: input.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 input extends SinglePartElement implements Printable,
71   FormEvents, PageEvents, FocusEvents, MouseEvents, KeyEvents
72 {
73     public static final String JavaDoc text = "text";
74     public static final String JavaDoc password = "password";
75     public static final String JavaDoc checkbox = "checkbox";
76     public static final String JavaDoc radio = "radio";
77     public static final String JavaDoc file = "file";
78     public static final String JavaDoc button = "button";
79     public static final String JavaDoc image = "image";
80     public static final String JavaDoc hidden = "hidden";
81     public static final String JavaDoc submit = "submit";
82     public static final String JavaDoc reset = "reset";
83
84     /**
85         Private initialization routine.
86     */

87     {
88         setElementType("input");
89         setCase(LOWERCASE);
90         setAttributeQuote(true);
91         setBeginEndModifier('/');
92     }
93     
94     /**
95         Basic constructor. Use the set* methods to set the values
96         of the attributes.
97     */

98     public input()
99     {
100     }
101     
102     /**
103         Basic constructor. Use the set* methods to set the values
104         of the attributes.
105     */

106     public input(String JavaDoc type, String JavaDoc name, String JavaDoc value)
107     {
108         setType(type);
109         setName(name);
110         setValue(value);
111     }
112
113     /**
114         Basic constructor. Use the set* methods to set the values
115         of the attributes.
116     */

117     public input(String JavaDoc type, String JavaDoc name, int value)
118     {
119         setType(type);
120         setName(name);
121         setValue(value);
122     }
123
124     /**
125         Basic constructor. Use the set* methods to set the values
126         of the attributes.
127     */

128     public input(String JavaDoc type, String JavaDoc name, Integer JavaDoc value)
129     {
130         setType(type);
131         setName(name);
132         setValue(value);
133     }
134
135     /**
136         Basic constructor. Use the set* methods to set the values
137         of the attributes.
138     */

139     public input(String JavaDoc type, String JavaDoc name, double value)
140     {
141         setType(type);
142         setName(name);
143         setValue(value);
144     }
145
146     /**
147         Sets the type="" attribute
148         @param type the type="" attribute
149     */

150     public input setType(String JavaDoc type)
151     {
152         addAttribute("type",type);
153         return this;
154     }
155
156     /**
157         Sets the SRC="" attribute
158         @param src the SRC="" attribute
159     */

160     public input setSrc(String JavaDoc src)
161     {
162         addAttribute("src",src);
163         return this;
164     }
165     
166     /**
167         Sets the border="" attribute
168         @param border the border="" attribute
169     */

170     public input setBorder(int border)
171     {
172         addAttribute("border", Integer.toString(border));
173         return this;
174     }
175
176     /**
177         Sets the alt="" attribute
178         @param alt the alt="" attribute
179     */

180     public input setAlt(String JavaDoc alt)
181     {
182         addAttribute("alt",alt);
183         return this;
184     }
185
186     /**
187         Sets the name="" attribute
188         @param name the name="" attribute
189     */

190     public input setName(String JavaDoc name)
191     {
192         addAttribute("name",name);
193         return this;
194     }
195     
196     /**
197         Sets the value="" attribute
198         @param value the value="" attribute
199     */

200     public input setValue(String JavaDoc value)
201     {
202         addAttribute("value",value);
203         return this;
204     }
205     
206     /**
207         Sets the value="" attribute
208         @param value the value="" attribute
209     */

210     public input setValue(int value)
211     {
212         addAttribute("value",Integer.toString(value));
213         return this;
214     }
215
216     /**
217         Sets the value="" attribute
218         @param value the value="" attribute
219     */

220     public input setValue(Integer JavaDoc value)
221     {
222         addAttribute("value",value.toString());
223         return this;
224     }
225
226     /**
227         Sets the value="" attribute
228         @param value the value="" attribute
229     */

230     public input setValue(double value)
231     {
232         addAttribute("value",Double.toString(value));
233         return this;
234     }
235
236     /**
237         Sets the accept="" attribute
238         @param accept the accept="" attribute
239     */

240     public input setAccept(String JavaDoc accept)
241     {
242         addAttribute("accept",accept);
243         return this;
244     }
245     
246     /**
247         Sets the size="" attribute
248         @param size the size="" attribute
249     */

250     public input setSize(String JavaDoc size)
251     {
252         addAttribute("size",size);
253         return this;
254     }
255     
256     /**
257         Sets the size="" attribute
258         @param size the size="" attribute
259     */

260     public input setSize(int size)
261     {
262         setSize(Integer.toString(size));
263         return this;
264     }
265     
266     /**
267         Sets the maxlength="" attribute
268         @param maxlength the maxlength="" attribute
269     */

270     public input setMaxlength(String JavaDoc maxlength)
271     {
272         addAttribute("maxlength",maxlength);
273         return this;
274     }
275     
276     /**
277         Sets the maxlength="" attribute
278         @param maxlength the maxlength="" attribute
279     */

280     public input setMaxlength(int maxlength)
281     {
282         setMaxlength(Integer.toString(maxlength));
283         return this;
284     }
285     
286     /**
287         Sets the usemap="" attribute
288         @param usemap the usemap="" attribute
289     */

290     public input setUsemap(String JavaDoc usemap)
291     {
292         addAttribute("usemap",usemap);
293         return this;
294     }
295     
296     /**
297         Sets the tabindex="" attribute
298         @param alt the tabindex="" attribute
299     */

300     public input setTabindex(String JavaDoc index)
301     {
302         addAttribute("tabindex",index);
303         return this;
304     }
305     
306     /**
307         Sets the tabindex="" attribute
308         @param alt the tabindex="" attribute
309     */

310     public input setTabindex(int index)
311     {
312         setTabindex(Integer.toString(index));
313         return this;
314     }
315     
316     /**
317         Sets the checked value
318         @param checked true or false
319     */

320     public input setChecked(boolean checked)
321     {
322         if ( checked == true )
323             addAttribute("checked", "checked");
324         else
325             removeAttribute("checked");
326             
327         return(this);
328     }
329
330     /**
331         Sets the readonly value
332         @param readonly true or false
333     */

334     public input setReadOnly(boolean readonly)
335     {
336         if ( readonly == true )
337             addAttribute("readonly", "readonly");
338         else
339             removeAttribute("readonly");
340             
341         return(this);
342     }
343
344     /**
345         Sets the disabled value
346         @param disabled true or false
347     */

348     public input setDisabled(boolean disabled)
349     {
350         if ( disabled == true )
351             addAttribute("disabled", "disabled");
352         else
353             removeAttribute("disabled");
354             
355         return(this);
356     }
357
358     /**
359         Sets the lang="" and xml:lang="" attributes
360         @param lang the lang="" and xml:lang="" attributes
361     */

362     public Element setLang(String JavaDoc lang)
363     {
364         addAttribute("lang",lang);
365         addAttribute("xml:lang",lang);
366         return this;
367     }
368
369     /**
370         Adds an Element to the element.
371         @param hashcode name of element for hash table
372         @param element Adds an Element to the element.
373      */

374     public input addElement(String JavaDoc hashcode,Element element)
375     {
376         addElementToRegistry(hashcode,element);
377         return(this);
378     }
379
380     /**
381         Adds an Element to the element.
382         @param hashcode name of element for hash table
383         @param element Adds an Element to the element.
384      */

385     public input addElement(String JavaDoc hashcode,String JavaDoc element)
386     {
387         addElementToRegistry(hashcode,element);
388         return(this);
389     }
390     /**
391         Adds an Element to the element.
392         @param element Adds an Element to the element.
393      */

394     public input addElement(Element element)
395     {
396         addElementToRegistry(element);
397         return(this);
398     }
399
400     /**
401         Adds an Element to the element.
402         @param element Adds an Element to the element.
403      */

404     public input addElement(String JavaDoc element)
405     {
406         addElementToRegistry(element);
407         return(this);
408     }
409     /**
410         Removes an Element from the element.
411         @param hashcode the name of the element to be removed.
412     */

413     public input removeElement(String JavaDoc hashcode)
414     {
415         removeElementFromRegistry(hashcode);
416         return(this);
417     }
418
419     /**
420         The onsubmit event occurs when a form is submitted. It only applies to
421         the FORM element.
422         
423         @param The script
424     */

425     public void setOnSubmit(String JavaDoc script)
426     {
427         addAttribute ( "onsubmit", script );
428     }
429
430     /**
431         The onreset event occurs when a form is reset. It only applies to the
432         FORM element.
433         
434         @param The script
435     */

436     public void setOnReset(String JavaDoc script)
437     {
438         addAttribute ( "onreset", script );
439     }
440
441     /**
442         The onselect event occurs when a user selects some text in a text
443         field. This attribute may be used with the INPUT and TEXTAREA elements.
444         
445         @param The script
446     */

447     public void setOnSelect(String JavaDoc script)
448     {
449         addAttribute ( "onselect", script );
450     }
451
452     /**
453         The onchange event occurs when a control loses the input focus and its
454         value has been modified since gaining focus. This attribute applies to
455         the following elements: INPUT, SELECT, and TEXTAREA.
456         
457         @param The script
458     */

459     public void setOnChange(String JavaDoc script)
460     {
461         addAttribute ( "onchange", script );
462     }
463
464     /**
465         The onload event occurs when the user agent finishes loading a window
466         or all frames within a FRAMESET. This attribute may be used with BODY
467         and FRAMESET elements.
468         
469         @param The script
470     */

471     public void setOnLoad(String JavaDoc script)
472     {
473         addAttribute ( "onload", script );
474     }
475
476     /**
477         The onunload event occurs when the user agent removes a document from a
478         window or frame. This attribute may be used with BODY and FRAMESET
479         elements.
480         
481         @param The script
482     */

483     public void setOnUnload(String JavaDoc script)
484     {
485         addAttribute ( "onunload", script );
486     }
487
488     /**
489         The onfocus event occurs when an element receives focus either by the
490         pointing device or by tabbing navigation. This attribute may be used
491         with the following elements: LABEL, INPUT, SELECT, TEXTAREA, and
492         BUTTON.
493         
494         @param The script
495     */

496     public void setOnFocus(String JavaDoc script)
497     {
498         addAttribute ( "onfocus", script );
499     }
500
501     /**
502         The onblur event occurs when an element loses focus either by the
503         pointing device or by tabbing navigation. It may be used with the same
504         elements as onfocus.
505         
506         @param The script
507     */

508     public void setOnBlur(String JavaDoc script)
509     {
510         addAttribute ( "onblur", script );
511     }
512
513     /**
514         The onclick event occurs when the pointing device button is clicked
515         over an element. This attribute may be used with most elements.
516         
517         @param The script
518     */

519     public void setOnClick(String JavaDoc script)
520     {
521         addAttribute ( "onclick", script );
522     }
523     /**
524         The ondblclick event occurs when the pointing device button is double
525         clicked over an element. This attribute may be used with most elements.
526
527         @param The script
528     */

529     public void setOnDblClick(String JavaDoc script)
530     {
531         addAttribute ( "ondblclick", script );
532     }
533     /**
534         The onmousedown event occurs when the pointing device button is pressed
535         over an element. This attribute may be used with most elements.
536
537         @param The script
538     */

539     public void setOnMouseDown(String JavaDoc script)
540     {
541         addAttribute ( "onmousedown", script );
542     }
543     /**
544         The onmouseup event occurs when the pointing device button is released
545         over an element. This attribute may be used with most elements.
546
547         @param The script
548     */

549     public void setOnMouseUp(String JavaDoc script)
550     {
551         addAttribute ( "onmouseup", script );
552     }
553     /**
554         The onmouseover event occurs when the pointing device is moved onto an
555         element. This attribute may be used with most elements.
556
557         @param The script
558     */

559     public void setOnMouseOver(String JavaDoc script)
560     {
561         addAttribute ( "onmouseover", script );
562     }
563     /**
564         The onmousemove event occurs when the pointing device is moved while it
565         is over an element. This attribute may be used with most elements.
566
567         @param The script
568     */

569     public void setOnMouseMove(String JavaDoc script)
570     {
571         addAttribute ( "onmousemove", script );
572     }
573     /**
574         The onmouseout event occurs when the pointing device is moved away from
575         an element. This attribute may be used with most elements.
576
577         @param The script
578     */

579     public void setOnMouseOut(String JavaDoc script)
580     {
581         addAttribute ( "onmouseout", script );
582     }
583
584     /**
585         The onkeypress event occurs when a key is pressed and released over an
586         element. This attribute may be used with most elements.
587         
588         @param The script
589     */

590     public void setOnKeyPress(String JavaDoc script)
591     {
592         addAttribute ( "onkeypress", script );
593     }
594
595     /**
596         The onkeydown event occurs when a key is pressed down over an element.
597         This attribute may be used with most elements.
598         
599         @param The script
600     */

601     public void setOnKeyDown(String JavaDoc script)
602     {
603         addAttribute ( "onkeydown", script );
604     }
605
606     /**
607         The onkeyup event occurs when a key is released over an element. This
608         attribute may be used with most elements.
609         
610         @param The script
611     */

612     public void setOnKeyUp(String JavaDoc script)
613     {
614         addAttribute ( "onkeyup", script );
615     }
616 }
617
Popular Tags