KickJava   Java API By Example, From Geeks To Geeks.

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


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;option&gt; tag.
64     The option tag defaults to not having a closing &lt;/option&gt;
65     because it is optional in the spec. This can be
66     overridden by setNeedClosingTag(true)
67
68     @version $Id: option.java,v 1.2 2003/04/27 09:37:58 rdonkin Exp $
69     @author <a HREF="mailto:snagy@servletapi.com">Stephan Nagy</a>
70     @author <a HREF="mailto:jon@clearink.com">Jon S. Stevens</a>
71     @author <a HREF="mailto:bojan@binarix.com">Bojan Smojver</a>
72 */

73 public class option extends MultiPartElement implements Printable, FocusEvents, FormEvents, MouseEvents, KeyEvents
74
75 {
76
77     /**
78         Private initialization routine.
79     */

80     {
81         setElementType("option");
82         setCase(LOWERCASE);
83         setAttributeQuote(true);
84     }
85     
86     /**
87         Basic constructor. Use the set* methods to set the values
88         of the attributes.
89     */

90     public option()
91     {
92     }
93     
94     /**
95         Basic constructor. Use the set* methods to set the values
96         of the attributes.
97         
98         @param value sets the attribute value=""
99     */

100     public option(String JavaDoc value)
101     {
102         setValue(value);
103     }
104
105     /**
106         Basic constructor. Use the set* methods to set the values
107         of the attributes.
108         
109         @param label sets the attribute label=""
110         @param value sets the attribute value=""
111     */

112     public option(String JavaDoc label, String JavaDoc value)
113     {
114         setLabel(label);
115         setValue(value);
116     }
117
118     /**
119         Basic constructor. Use the set* methods to set the values
120         of the attributes.
121         
122         @param label sets the attribute label=""
123         @param value sets the attribute value=""
124     */

125     public option(String JavaDoc label, int value)
126     {
127         setLabel(label);
128         setValue(value);
129     }
130
131     /**
132         Basic constructor. Use the set* methods to set the values
133         of the attributes.
134         
135         @param label sets the attribute label=""
136         @param value sets the attribute value=""
137     */

138     public option(String JavaDoc label, double value)
139     {
140         setLabel(label);
141         setValue(value);
142     }
143
144     /**
145         Sets the label="" attribute
146         @param label the label="" attribute
147     */

148     public option setLabel(String JavaDoc label)
149     {
150         addAttribute("label",label);
151         return this;
152     }
153
154     /**
155         Sets the value="" attribute
156         @param value the value="" attribute
157     */

158     public option setValue(String JavaDoc value)
159     {
160         addAttribute("value",value);
161         return this;
162     }
163
164     /**
165         Sets the value="" attribute
166         @param value the value="" attribute
167     */

168     public option setValue(int value)
169     {
170         addAttribute("value",Integer.toString(value));
171         return this;
172     }
173
174     /**
175         Sets the value="" attribute
176         @param value the value="" attribute
177     */

178     public option setValue(double value)
179     {
180         addAttribute("value",Double.toString(value));
181         return this;
182     }
183
184     /**
185         Sets the selected value
186         @param selected true or false
187     */

188     public option setSelected(boolean selected)
189     {
190         if ( selected == true )
191             addAttribute("selected", "selected");
192         else
193             removeAttribute("selected");
194             
195         return(this);
196     }
197
198     /**
199         Sets the disabled value
200         @param disabled true or false
201     */

202     public option setDisabled(boolean disabled)
203     {
204         if ( disabled == true )
205             addAttribute("disabled", "disabled");
206         else
207             removeAttribute("disabled");
208             
209         return(this);
210     }
211     
212     /**
213         Sets the lang="" and xml:lang="" attributes
214         @param lang the lang="" and xml:lang="" attributes
215     */

216     public Element setLang(String JavaDoc lang)
217     {
218         addAttribute("lang",lang);
219         addAttribute("xml:lang",lang);
220         return this;
221     }
222
223     /**
224         Adds an Element to the element.
225         @param hashcode name of element for hash table
226         @param element Adds an Element to the element.
227      */

228     public option addElement(String JavaDoc hashcode,Element element)
229     {
230         addElementToRegistry(hashcode,element);
231         return(this);
232     }
233
234     /**
235         Adds an Element to the element.
236         @param hashcode name of element for hash table
237         @param element Adds an Element to the element.
238      */

239     public option addElement(String JavaDoc hashcode,String JavaDoc element)
240     {
241         addElementToRegistry(hashcode,element);
242         return(this);
243     }
244
245     /**
246         Adds an Element to the element.
247         @param element Adds an Element to the element.
248      */

249     public option addElement(Element element)
250     {
251         addElementToRegistry(element);
252         return(this);
253     }
254     
255     /**
256         Adds an Element to the element.
257         @param element Adds an Element to the element.
258      */

259     public option addElement(String JavaDoc element)
260     {
261         addElementToRegistry(element);
262         return(this);
263     }
264
265     /**
266         Creates a group of options.
267         @param Creates a group of options.
268      */

269     public option[] addElement(String JavaDoc[] element)
270     {
271         option[] option = new option[element.length];
272         for(int x = 0; x < element.length; x++)
273         {
274             option[x]= new option().addElement(element[x]);
275         }
276         return(option);
277     }
278     /**
279         Removes an Element from the element.
280         @param hashcode the name of the element to be removed.
281     */

282     public option removeElement(String JavaDoc hashcode)
283     {
284         removeElementFromRegistry(hashcode);
285         return(this);
286     }
287
288     /**
289         The onfocus event occurs when an element receives focus either by the
290         pointing device or by tabbing navigation. This attribute may be used
291         with the following elements: label, input, select, textarea, and
292         button.
293         
294         @param The script
295     */

296     public void setOnFocus(String JavaDoc script)
297     {
298         addAttribute ( "onfocus", script );
299     }
300
301     /**
302         The onblur event occurs when an element loses focus either by the
303         pointing device or by tabbing navigation. It may be used with the same
304         elements as onfocus.
305         
306         @param The script
307     */

308     public void setOnBlur(String JavaDoc script)
309     {
310         addAttribute ( "onblur", script );
311     }
312
313     /**
314         The onsubmit event occurs when a form is submitted. It only applies to
315         the FORM element.
316         
317         @param The script
318     */

319     public void setOnSubmit(String JavaDoc script)
320     {
321         addAttribute ( "onsubmit", script );
322     }
323
324     /**
325         The onreset event occurs when a form is reset. It only applies to the
326         FORM element.
327         
328         @param The script
329     */

330     public void setOnReset(String JavaDoc script)
331     {
332         addAttribute ( "onreset", script );
333     }
334
335     /**
336         The onselect event occurs when a user selects some text in a text
337         field. This attribute may be used with the INPUT and TEXTAREA elements.
338         
339         @param The script
340     */

341     public void setOnSelect(String JavaDoc script)
342     {
343         addAttribute ( "onselect", script );
344     }
345
346     /**
347         The onchange event occurs when a control loses the input focus and its
348         value has been modified since gaining focus. This attribute applies to
349         the following elements: input, select, and textarea.
350         
351         @param The script
352     */

353     public void setOnChange(String JavaDoc script)
354     {
355         addAttribute ( "onchange", script );
356     }
357
358     /**
359         The onclick event occurs when the pointing device button is clicked
360         over an element. This attribute may be used with most elements.
361         
362         @param The script
363     */

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

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

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

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

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

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

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

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

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

457     public void setOnKeyUp(String JavaDoc script)
458     {
459         addAttribute ( "onkeyup", script );
460     }
461 }
462
Popular Tags