KickJava   Java API By Example, From Geeks To Geeks.

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


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;select&gt; tag.
64
65     @version $Id: select.java,v 1.2 2003/04/27 09:36:30 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 select extends MultiPartElement implements Printable, PageEvents, FormEvents, MouseEvents, KeyEvents
71 {
72     /**
73         Private initializer
74     */

75     {
76         setElementType("select");
77         setCase(LOWERCASE);
78         setAttributeQuote(true);
79     }
80     /**
81         Basic constructor. Use the set* methods.
82     */

83     public select()
84     {
85     }
86
87     /**
88         Basic Constructor.
89         @param name set the NAME="" attribute
90     */

91     public select(String JavaDoc name)
92     {
93         setName(name);
94     }
95
96     /**
97         Basic Constructor.
98         @param name set the name="" attribute
99         @param name set the size="" attribute
100     */

101     public select(String JavaDoc name, String JavaDoc size)
102     {
103         setName(name);
104         setSize(size);
105     }
106
107     /**
108         Basic Constructor.
109         @param name set the name="" attribute
110         @param name set the size="" attribute
111     */

112     public select(String JavaDoc name, int size)
113     {
114         setName(name);
115         setSize(size);
116     }
117
118     /**
119         Basic Constructor.
120         @param name set the name="" attribute
121         @param element provide a group of strings to be converted to options elements.
122     */

123     public select(String JavaDoc name, String JavaDoc[] element)
124     {
125         setName(name);
126         addElement(element);
127     }
128
129     /**
130         Basic Constructor.
131         @param name set the name="" attribute
132         @param element provide a group of strings to be converted to options elements.
133     */

134     public select(String JavaDoc name, option[] element)
135     {
136         setName(name);
137         addElement(element);
138     }
139
140     /**
141         Sets the lang="" and xml:lang="" attributes
142         @param lang the lang="" and xml:lang="" attributes
143     */

144     public Element setLang(String JavaDoc lang)
145     {
146         addAttribute("lang",lang);
147         addAttribute("xml:lang",lang);
148         return this;
149     }
150
151     /**
152         Adds an Element to the element.
153         @param hashcode name of element for hash table
154         @param element Adds an Element to the element.
155      */

156     public select addElement(String JavaDoc hashcode,Element element)
157     {
158         addElementToRegistry(hashcode,element);
159         return(this);
160     }
161
162     /**
163         Adds an Element to the element.
164         @param hashcode name of element for hash table
165         @param element Adds an Element to the element.
166      */

167     public select addElement(String JavaDoc hashcode,String JavaDoc element)
168     {
169         addElementToRegistry(hashcode,element);
170         return(this);
171     }
172
173     /**
174         Adds an Element to the Element.
175         @param element adds and Element to the Element.
176     */

177     public select addElement(Element element)
178     {
179         addElementToRegistry(element);
180         return(this);
181     }
182
183     /**
184         Adds a group of elements to the select element.
185         @param element adds a group of elements to the select element.
186     */

187     public select addElement(option[] element)
188     {
189         for(int x = 0 ; x < element.length; x++)
190         {
191             addElementToRegistry(element[x]);
192         }
193         return(this);
194     }
195
196     /**
197         Adds an Element to the Element.
198         @param element adds and Element to the Element.
199     */

200     public select addElement(String JavaDoc element)
201     {
202         addElementToRegistry(element);
203         return(this);
204     }
205
206     /**
207         Creates a group of option elements and adds them to this select.
208         @param element adds a group of option elements to this select.
209     */

210     public select addElement(String JavaDoc[] element)
211     {
212         option[] options = new option().addElement(element);
213         addElement(options);
214         return(this);
215     }
216
217     /**
218         Sets the name="" attribute
219         @param name the name="" attribute
220     */

221     public select setName(String JavaDoc name)
222     {
223         addAttribute("name",name);
224         return this;
225     }
226
227     /**
228         Sets the size="" attribute
229         @param size the size="" attribute
230     */

231     public select setSize(String JavaDoc size)
232     {
233         addAttribute("size",size);
234         return this;
235     }
236     
237     /**
238         Sets the size="" attribute
239         @param size the size="" attribute
240     */

241     public select setSize(int size)
242     {
243         setSize(Integer.toString(size));
244         return this;
245     }
246
247     /**
248         Sets the multiple value
249         @param multiple true or false
250     */

251     public select setMultiple(boolean multiple)
252     {
253         if ( multiple == true )
254             addAttribute("multiple", "multiple");
255         else
256             removeAttribute("multiple");
257             
258         return(this);
259     }
260
261     /**
262         Sets the tabindex="" attribute
263         @param alt the tabindex="" attribute
264     */

265     public select setTabindex(String JavaDoc index)
266     {
267         addAttribute("tabindex",index);
268         return this;
269     }
270     
271     /**
272         Sets the tabindex="" attribute
273         @param alt the tabindex="" attribute
274     */

275     public select setTabindex(int index)
276     {
277         setTabindex(Integer.toString(index));
278         return this;
279     }
280     
281     /**
282         Sets the disabled value
283         @param disabled true or false
284     */

285     public select setDisabled(boolean disabled)
286     {
287         if ( disabled == true )
288             addAttribute("disabled", "disabled");
289         else
290             removeAttribute("disabled");
291             
292         return(this);
293     }
294     /**
295         Removes an Element from the element.
296         @param hashcode the name of the element to be removed.
297     */

298     public select removeElement(String JavaDoc hashcode)
299     {
300         removeElementFromRegistry(hashcode);
301         return(this);
302     }
303
304     /**
305         The onload event occurs when the user agent finishes loading a window
306         or all frames within a frameset. This attribute may be used with body
307         and frameset elements.
308         
309         @param The script
310     */

311     public void setOnLoad(String JavaDoc script)
312     {
313         addAttribute ( "onload", script );
314     }
315
316     /**
317         The onunload event occurs when the user agent removes a document from a
318         window or frame. This attribute may be used with body and frameset
319         elements.
320         
321         @param The script
322     */

323     public void setOnUnload(String JavaDoc script)
324     {
325         addAttribute ( "onunload", script );
326     }
327
328     /**
329         The onsubmit event occurs when a form is submitted. It only applies to
330         the FORM element.
331         
332         @param The script
333     */

334     public void setOnSubmit(String JavaDoc script)
335     {
336         addAttribute ( "onsubmit", script );
337     }
338
339     /**
340         The onreset event occurs when a form is reset. It only applies to the
341         FORM element.
342         
343         @param The script
344     */

345     public void setOnReset(String JavaDoc script)
346     {
347         addAttribute ( "onreset", script );
348     }
349
350     /**
351         The onselect event occurs when a user selects some text in a text
352         field. This attribute may be used with the input and textarea elements.
353         
354         @param The script
355     */

356     public void setOnSelect(String JavaDoc script)
357     {
358         addAttribute ( "onselect", script );
359     }
360
361     /**
362         The onchange event occurs when a control loses the input focus and its
363         value has been modified since gaining focus. This attribute applies to
364         the following elements: input, select, and textarea.
365         
366         @param The script
367     */

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

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

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

399     public void setOnMouseDown(String JavaDoc script)
400     {
401         addAttribute ( "onmousedown", script );
402     }
403     /**
404         The onmouseup event occurs when the pointing device button is released
405         over an element. This attribute may be used with most elements.
406
407         @param The script
408     */

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

419     public void setOnMouseOver(String JavaDoc script)
420     {
421         addAttribute ( "onmouseover", script );
422     }
423     /**
424         The onmousemove event occurs when the pointing device is moved while it
425         is over an element. This attribute may be used with most elements.
426
427         @param The script
428     */

429     public void setOnMouseMove(String JavaDoc script)
430     {
431         addAttribute ( "onmousemove", script );
432     }
433     /**
434         The onmouseout event occurs when the pointing device is moved away from
435         an element. This attribute may be used with most elements.
436
437         @param The script
438     */

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

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

461     public void setOnKeyDown(String JavaDoc script)
462     {
463         addAttribute ( "onkeydown", script );
464     }
465
466     /**
467         The onkeyup event occurs when a key is released over an element. This
468         attribute may be used with most elements.
469         
470         @param The script
471     */

472     public void setOnKeyUp(String JavaDoc script)
473     {
474         addAttribute ( "onkeyup", script );
475     }
476 }
477
Popular Tags