KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > html > Button


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     This class creates a &lt;Button&gt; tag.
63                                    
64     @version $Id: Button.java,v 1.4 2003/04/27 09:20:40 rdonkin Exp $
65     @author <a HREF="mailto:snagy@servletapi.com">Stephan Nagy</a>
66     @author <a HREF="mailto:jon@clearink.com">Jon S. Stevens</a>
67 */

68
69 public class Button extends MultiPartElement implements Printable, FocusEvents, MouseEvents, KeyEvents
70 {
71     // convience variables
72
public final static String JavaDoc RESET = "reset";
73     public final static String JavaDoc SUBMIT = "submit";
74     public final static String JavaDoc BUTTON = "button";
75     public final static String JavaDoc reset = "reset";
76     public final static String JavaDoc submit = "submit";
77     public final static String JavaDoc button = "button";
78
79     /**
80         private initializaer.
81     */

82     {
83         setElementType("button");
84     }
85
86     public Button()
87     {
88     }
89
90     /**
91         Set the name of this button.
92         @param name set the name of this button.
93     */

94     public Button setName(String JavaDoc name)
95     {
96         addAttribute("name",name);
97         return(this);
98     }
99
100     /**
101         Set the value of this button.
102         @param value set the value of this button.
103     */

104     public Button setValue(String JavaDoc value)
105     {
106         addAttribute("value",value);
107         return(this);
108     }
109
110     /**
111         Set the type of button this is. Convience variables are<br>
112         Button.SUBMIT<BR>Button.RESET<BR>Button.BUTTON
113         @param button type.
114     */

115     public Button setType(String JavaDoc type)
116     {
117         addAttribute("type",type);
118         return(this);
119     }
120
121     /**
122         Is this button disabled?
123         disabled true|false
124     */

125     public Button setDisabled(boolean disabled)
126     {
127         if(disabled)
128             addAttribute("disabled",NO_ATTRIBUTE_VALUE);
129         else
130             removeAttribute("disabled");
131         return(this);
132     }
133
134     /**
135         Set the elements position in the tabbing order.
136         @param number set the elements position in the tabbing order.
137     */

138     public Button setTabIndex(int number)
139     {
140         addAttribute("tabindex",Integer.toString(number));
141         return(this);
142     }
143
144     /**
145         Set the elements position in the tabbing order.
146         @param number set the elements position in the tabbing order.
147     */

148     public Button setTabIndex(String JavaDoc number)
149     {
150         addAttribute("tabindex",number);
151         return(this);
152     }
153
154     /**
155         Adds an Element to the element.
156         @param hashcode name of element for hash table
157         @param element Adds an Element to the element.
158      */

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

170     public Button addElement(String JavaDoc hashcode,String JavaDoc element)
171     {
172         addElementToRegistry(hashcode,element);
173         return(this);
174     }
175
176     /**
177         Adds an Element to the element.
178         @param element Adds an Element to the element.
179      */

180     public Button addElement(Element element)
181     {
182         addElementToRegistry(element);
183         return(this);
184     }
185     
186     /**
187         Adds an Element to the element.
188         @param element Adds an Element to the element.
189      */

190     public Button addElement(String JavaDoc element)
191     {
192         addElementToRegistry(element);
193         return(this);
194     }
195     /**
196         Removes an Element from the element.
197         @param hashcode the name of the element to be removed.
198     */

199     public Button removeElement(String JavaDoc hashcode)
200     {
201         removeElementFromRegistry(hashcode);
202         return(this);
203     }
204
205     /**
206         The onfocus event occurs when an element receives focus either by the
207         pointing device or by tabbing navigation. This attribute may be used
208         with the following elements: LABEL, INPUT, SELECT, TEXTAREA, and
209         BUTTON.
210         
211         @param The script
212     */

213     public void setOnFocus(String JavaDoc script)
214     {
215         addAttribute ( "onFocus", script );
216     }
217
218     /**
219         The onblur event occurs when an element loses focus either by the
220         pointing device or by tabbing navigation. It may be used with the same
221         elements as onfocus.
222         
223         @param The script
224     */

225     public void setOnBlur(String JavaDoc script)
226     {
227         addAttribute ( "onBlur", script );
228     }
229
230     /**
231         The onclick event occurs when the pointing device button is clicked
232         over an element. This attribute may be used with most elements.
233         
234         @param The script
235     */

236     public void setOnClick(String JavaDoc script)
237     {
238         addAttribute ( "onClick", script );
239     }
240     /**
241         The ondblclick event occurs when the pointing device button is double
242         clicked over an element. This attribute may be used with most elements.
243
244         @param The script
245     */

246     public void setOnDblClick(String JavaDoc script)
247     {
248         addAttribute ( "onDblClick", script );
249     }
250     /**
251         The onmousedown event occurs when the pointing device button is pressed
252         over an element. This attribute may be used with most elements.
253
254         @param The script
255     */

256     public void setOnMouseDown(String JavaDoc script)
257     {
258         addAttribute ( "onMouseDown", script );
259     }
260     /**
261         The onmouseup event occurs when the pointing device button is released
262         over an element. This attribute may be used with most elements.
263
264         @param The script
265     */

266     public void setOnMouseUp(String JavaDoc script)
267     {
268         addAttribute ( "onMouseUp", script );
269     }
270     /**
271         The onmouseover event occurs when the pointing device is moved onto an
272         element. This attribute may be used with most elements.
273
274         @param The script
275     */

276     public void setOnMouseOver(String JavaDoc script)
277     {
278         addAttribute ( "onMouseOver", script );
279     }
280     /**
281         The onmousemove event occurs when the pointing device is moved while it
282         is over an element. This attribute may be used with most elements.
283
284         @param The script
285     */

286     public void setOnMouseMove(String JavaDoc script)
287     {
288         addAttribute ( "onMouseMove", script );
289     }
290     /**
291         The onmouseout event occurs when the pointing device is moved away from
292         an element. This attribute may be used with most elements.
293
294         @param The script
295     */

296     public void setOnMouseOut(String JavaDoc script)
297     {
298         addAttribute ( "onMouseOut", script );
299     }
300
301     /**
302         The onkeypress event occurs when a key is pressed and released over an
303         element. This attribute may be used with most elements.
304         
305         @param The script
306     */

307     public void setOnKeyPress(String JavaDoc script)
308     {
309         addAttribute ( "onKeyPress", script );
310     }
311
312     /**
313         The onkeydown event occurs when a key is pressed down over an element.
314         This attribute may be used with most elements.
315         
316         @param The script
317     */

318     public void setOnKeyDown(String JavaDoc script)
319     {
320         addAttribute ( "onKeyDown", script );
321     }
322
323     /**
324         The onkeyup event occurs when a key is released over an element. This
325         attribute may be used with most elements.
326         
327         @param The script
328     */

329     public void setOnKeyUp(String JavaDoc script)
330     {
331         addAttribute ( "onKeyUp", script );
332     }
333 }
334
Popular Tags