KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > html > 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.html;
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.9 2003/04/27 09:20:29 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 */

69 public class Input extends SinglePartElement implements Printable,
70   FormEvents, PageEvents, FocusEvents, MouseEvents, KeyEvents
71 {
72     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
73     public static final String JavaDoc TEXT = "TEXT";
74     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
75     public static final String JavaDoc PASSWORD = "PASSWORD";
76     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
77     public static final String JavaDoc CHECKBOX = "CHECKBOX";
78     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
79     public static final String JavaDoc RADIO = "RADIO";
80     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
81     public static final String JavaDoc FILE = "FILE";
82     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
83     public static final String JavaDoc BUTTON = "BUTTON";
84     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
85     public static final String JavaDoc IMAGE = "IMAGE";
86     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
87     public static final String JavaDoc HIDDEN = "HIDDEN";
88     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
89     public static final String JavaDoc SUBMIT = "SUBMIT";
90     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
91     public static final String JavaDoc RESET = "RESET";
92     
93     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
94     public static final String JavaDoc text = "text";
95     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
96     public static final String JavaDoc password = "password";
97     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
98     public static final String JavaDoc checkbox = "checkbox";
99     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
100     public static final String JavaDoc radio = "radio";
101     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
102     public static final String JavaDoc file = "file";
103     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
104     public static final String JavaDoc button = "button";
105     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
106     public static final String JavaDoc image = "image";
107     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
108     public static final String JavaDoc hidden = "hidden";
109     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
110     public static final String JavaDoc submit = "submit";
111     /**A type of &lt;input&gt;. Use this to set the type attribute.*/
112     public static final String JavaDoc reset = "reset";
113
114     /**
115         Private initialization routine.
116     */

117     {
118         setElementType("input");
119     }
120     
121     /**
122         Basic constructor. Use the set* methods to set the values
123         of the attributes.
124     */

125     public Input()
126     {
127     }
128
129     /**
130         Constructor sets the type attributes.
131         Use the set* methods to set the values
132         of the other attributes.
133         
134         @param type used to set type attribute
135     */

136     public Input(String JavaDoc type)
137     {
138         setType(type);
139     }
140
141     /**
142         Constructor sets the type and name attributes.
143         Use the set* methods to set the values
144         of the other attributes.
145         
146         @param type used to set type attribute
147         @param name used to set name attribute
148     */

149     public Input(String JavaDoc type, String JavaDoc name)
150     {
151         setType(type);
152         setName(name);
153     }
154
155     /**
156         Constructor sets the type, name and value attributes.
157         Use the set* methods to set the values
158         of the other attributes.
159         
160         @param type used to set type attribute
161         @param name used to set name attribute
162         @param value used to set value attribute
163     */

164     public Input(String JavaDoc type, String JavaDoc name, String JavaDoc value)
165     {
166         setType(type);
167         setName(name);
168         setValue(value);
169     }
170
171     /**
172         Constructor sets the type, name and value attributes.
173         Use the set* methods to set the values
174         of the other attributes.
175         
176         @param type used to set type attribute
177         @param name used to set name attribute
178         @param value used to set value attribute
179     */

180     public Input(String JavaDoc type, String JavaDoc name, int value)
181     {
182         setType(type);
183         setName(name);
184         setValue(value);
185     }
186
187     /**
188         Constructor sets the type, name and value attributes.
189         Use the set* methods to set the values
190         of the other attributes.
191         
192         @param type used to set type attribute
193         @param name used to set name attribute
194         @param value used to set value attribute
195     */

196     public Input(String JavaDoc type, String JavaDoc name, Integer JavaDoc value)
197     {
198         setType(type);
199         setName(name);
200         setValue(value);
201     }
202
203     /**
204         Constructor sets the type, name and value attributes.
205         Use the set* methods to set the values
206         of the other attributes.
207         
208         @param type used to set type attribute
209         @param name used to set name attribute
210         @param value used to set value attribute
211     */

212     public Input(String JavaDoc type, String JavaDoc name, double value)
213     {
214         setType(type);
215         setName(name);
216         setValue(value);
217     }
218
219     /**
220         Sets the TYPE="" attribute
221         @param type the TYPE="" attribute
222     */

223     public Input setType(String JavaDoc type)
224     {
225         addAttribute("type",type);
226         return this;
227     }
228
229     /**
230         Sets the SRC="" attribute
231         @param src the SRC="" attribute
232     */

233     public Input setSrc(String JavaDoc src)
234     {
235         addAttribute("src",src);
236         return this;
237     }
238     
239     /**
240         Sets the BORDER="" attribute
241         @param border the BORDER="" attribute
242     */

243     public Input setBorder(int border)
244     {
245         addAttribute("border", Integer.toString(border));
246         return this;
247     }
248
249     /**
250         Sets the ALT="" attribute
251         @param alt the ALT="" attribute
252     */

253     public Input setAlt(String JavaDoc alt)
254     {
255         addAttribute("alt",alt);
256         return this;
257     }
258
259     /**
260         Sets the NAME="" attribute
261         @param name the NAME="" attribute
262     */

263     public Input setName(String JavaDoc name)
264     {
265         addAttribute("name",name);
266         return this;
267     }
268     
269     /**
270         Sets the VALUE="" attribute
271         @param value the VALUE="" attribute
272     */

273     public Input setValue(String JavaDoc value)
274     {
275         addAttribute("value",value);
276         return this;
277     }
278     
279     /**
280         Sets the VALUE="" attribute
281         @param value the VALUE="" attribute
282     */

283     public Input setValue(int value)
284     {
285         addAttribute("value",Integer.toString(value));
286         return this;
287     }
288
289     /**
290         Sets the VALUE="" attribute
291         @param value the VALUE="" attribute
292     */

293     public Input setValue(Integer JavaDoc value)
294     {
295         addAttribute("value",value.toString());
296         return this;
297     }
298
299     /**
300         Sets the VALUE="" attribute
301         @param value the VALUE="" attribute
302     */

303     public Input setValue(double value)
304     {
305         addAttribute("value",Double.toString(value));
306         return this;
307     }
308
309     /**
310         Sets the ACCEPT="" attribute
311         @param accept the ACCEPT="" attribute
312     */

313     public Input setAccept(String JavaDoc accept)
314     {
315         addAttribute("accept",accept);
316         return this;
317     }
318     
319     /**
320         Sets the SIZE="" attribute
321         @param size the SIZE="" attribute
322     */

323     public Input setSize(String JavaDoc size)
324     {
325         addAttribute("size",size);
326         return this;
327     }
328     
329     /**
330         Sets the SIZE="" attribute
331         @param size the SIZE="" attribute
332     */

333     public Input setSize(int size)
334     {
335         setSize(Integer.toString(size));
336         return this;
337     }
338     
339     /**
340         Sets the MAXLENGTH="" attribute
341         @param maxlength the MAXLENGTH="" attribute
342     */

343     public Input setMaxlength(String JavaDoc maxlength)
344     {
345         addAttribute("maxlength",maxlength);
346         return this;
347     }
348     
349     /**
350         Sets the MAXLENGTH="" attribute
351         @param maxlength the MAXLENGTH="" attribute
352     */

353     public Input setMaxlength(int maxlength)
354     {
355         setMaxlength(Integer.toString(maxlength));
356         return this;
357     }
358     
359     /**
360         Sets the USEMAP="" attribute
361         @param usemap the USEMAP="" attribute
362     */

363     public Input setUsemap(String JavaDoc usemap)
364     {
365         addAttribute("usemap",usemap);
366         return this;
367     }
368     
369     /**
370         Sets the TABINDEX="" attribute
371         @param alt the TABINDEX="" attribute
372     */

373     public Input setTabindex(String JavaDoc index)
374     {
375         addAttribute("tabindex",index);
376         return this;
377     }
378     
379     /**
380         Sets the TABINDEX="" attribute
381         @param alt the TABINDEX="" attribute
382     */

383     public Input setTabindex(int index)
384     {
385         setTabindex(Integer.toString(index));
386         return this;
387     }
388     
389     /**
390         Sets the checked value
391         @param checked true or false
392     */

393     public Input setChecked(boolean checked)
394     {
395         if ( checked == true )
396             addAttribute("checked", NO_ATTRIBUTE_VALUE);
397         else
398             removeAttribute("checked");
399             
400         return(this);
401     }
402
403     /**
404         Sets the readonly value
405         @param readonly true or false
406     */

407     public Input setReadOnly(boolean readonly)
408     {
409         if ( readonly == true )
410             addAttribute("readonly", NO_ATTRIBUTE_VALUE);
411         else
412             removeAttribute("readonly");
413             
414         return(this);
415     }
416
417     /**
418         Sets the disabled value
419         @param disabled true or false
420     */

421     public Input setDisabled(boolean disabled)
422     {
423         if ( disabled == true )
424             addAttribute("disabled", NO_ATTRIBUTE_VALUE);
425         else
426             removeAttribute("disabled");
427             
428         return(this);
429     }
430
431     /**
432         Adds an Element to the element.
433         @param hashcode name of element for hash table
434         @param element Adds an Element to the element.
435      */

436     public Input addElement(String JavaDoc hashcode,Element element)
437     {
438         addElementToRegistry(hashcode,element);
439         return(this);
440     }
441
442     /**
443         Adds an Element to the element.
444         @param hashcode name of element for hash table
445         @param element Adds an Element to the element.
446      */

447     public Input addElement(String JavaDoc hashcode,String JavaDoc element)
448     {
449         addElementToRegistry(hashcode,element);
450         return(this);
451     }
452     /**
453         Adds an Element to the element.
454         @param element Adds an Element to the element.
455      */

456     public Input addElement(Element element)
457     {
458         addElementToRegistry(element);
459         return(this);
460     }
461
462     /**
463         Adds an Element to the element.
464         @param element Adds an Element to the element.
465      */

466     public Input addElement(String JavaDoc element)
467     {
468         addElementToRegistry(element);
469         return(this);
470     }
471     /**
472         Removes an Element from the element.
473         @param hashcode the name of the element to be removed.
474     */

475     public Input removeElement(String JavaDoc hashcode)
476     {
477         removeElementFromRegistry(hashcode);
478         return(this);
479     }
480
481     /**
482         The onsubmit event occurs when a form is submitted. It only applies to
483         the FORM element.
484         
485         @param The script
486     */

487     public void setOnSubmit(String JavaDoc script)
488     {
489         addAttribute ( "onSubmit", script );
490     }
491
492     /**
493         The onreset event occurs when a form is reset. It only applies to the
494         FORM element.
495         
496         @param The script
497     */

498     public void setOnReset(String JavaDoc script)
499     {
500         addAttribute ( "onReset", script );
501     }
502
503     /**
504         The onselect event occurs when a user selects some text in a text
505         field. This attribute may be used with the INPUT and TEXTAREA elements.
506         
507         @param The script
508     */

509     public void setOnSelect(String JavaDoc script)
510     {
511         addAttribute ( "onSelect", script );
512     }
513
514     /**
515         The onchange event occurs when a control loses the input focus and its
516         value has been modified since gaining focus. This attribute applies to
517         the following elements: INPUT, SELECT, and TEXTAREA.
518         
519         @param The script
520     */

521     public void setOnChange(String JavaDoc script)
522     {
523         addAttribute ( "onChange", script );
524     }
525
526     /**
527         The onload event occurs when the user agent finishes loading a window
528         or all frames within a FRAMESET. This attribute may be used with BODY
529         and FRAMESET elements.
530         
531         @param The script
532     */

533     public void setOnLoad(String JavaDoc script)
534     {
535         addAttribute ( "onLoad", script );
536     }
537
538     /**
539         The onunload event occurs when the user agent removes a document from a
540         window or frame. This attribute may be used with BODY and FRAMESET
541         elements.
542         
543         @param The script
544     */

545     public void setOnUnload(String JavaDoc script)
546     {
547         addAttribute ( "onUnload", script );
548     }
549
550     /**
551         The onfocus event occurs when an element receives focus either by the
552         pointing device or by tabbing navigation. This attribute may be used
553         with the following elements: LABEL, INPUT, SELECT, TEXTAREA, and
554         BUTTON.
555         
556         @param The script
557     */

558     public void setOnFocus(String JavaDoc script)
559     {
560         addAttribute ( "onFocus", script );
561     }
562
563     /**
564         The onblur event occurs when an element loses focus either by the
565         pointing device or by tabbing navigation. It may be used with the same
566         elements as onfocus.
567         
568         @param The script
569     */

570     public void setOnBlur(String JavaDoc script)
571     {
572         addAttribute ( "onBlur", script );
573     }
574
575     /**
576         The onclick event occurs when the pointing device button is clicked
577         over an element. This attribute may be used with most elements.
578         
579         @param The script
580     */

581     public void setOnClick(String JavaDoc script)
582     {
583         addAttribute ( "onClick", script );
584     }
585     /**
586         The ondblclick event occurs when the pointing device button is double
587         clicked over an element. This attribute may be used with most elements.
588
589         @param The script
590     */

591     public void setOnDblClick(String JavaDoc script)
592     {
593         addAttribute ( "onDblClick", script );
594     }
595     /**
596         The onmousedown event occurs when the pointing device button is pressed
597         over an element. This attribute may be used with most elements.
598
599         @param The script
600     */

601     public void setOnMouseDown(String JavaDoc script)
602     {
603         addAttribute ( "onMouseDown", script );
604     }
605     /**
606         The onmouseup event occurs when the pointing device button is released
607         over an element. This attribute may be used with most elements.
608
609         @param The script
610     */

611     public void setOnMouseUp(String JavaDoc script)
612     {
613         addAttribute ( "onMouseUp", script );
614     }
615     /**
616         The onmouseover event occurs when the pointing device is moved onto an
617         element. This attribute may be used with most elements.
618
619         @param The script
620     */

621     public void setOnMouseOver(String JavaDoc script)
622     {
623         addAttribute ( "onMouseOver", script );
624     }
625     /**
626         The onmousemove event occurs when the pointing device is moved while it
627         is over an element. This attribute may be used with most elements.
628
629         @param The script
630     */

631     public void setOnMouseMove(String JavaDoc script)
632     {
633         addAttribute ( "onMouseMove", script );
634     }
635     /**
636         The onmouseout event occurs when the pointing device is moved away from
637         an element. This attribute may be used with most elements.
638
639         @param The script
640     */

641     public void setOnMouseOut(String JavaDoc script)
642     {
643         addAttribute ( "onMouseOut", script );
644     }
645
646     /**
647         The onkeypress event occurs when a key is pressed and released over an
648         element. This attribute may be used with most elements.
649         
650         @param The script
651     */

652     public void setOnKeyPress(String JavaDoc script)
653     {
654         addAttribute ( "onKeyPress", script );
655     }
656
657     /**
658         The onkeydown event occurs when a key is pressed down over an element.
659         This attribute may be used with most elements.
660         
661         @param The script
662     */

663     public void setOnKeyDown(String JavaDoc script)
664     {
665         addAttribute ( "onKeyDown", script );
666     }
667
668     /**
669         The onkeyup event occurs when a key is released over an element. This
670         attribute may be used with most elements.
671         
672         @param The script
673     */

674     public void setOnKeyUp(String JavaDoc script)
675     {
676         addAttribute ( "onKeyUp", script );
677     }
678 }
679
Popular Tags