KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xhtml > dom > xerces > XHTMLSelectElementImpl


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Original Code is DigitalSesame
15  * Portions created by DigitalSesame are Copyright (C) 1997-2000 DigitalSesame
16  * All Rights Reserved.
17  *
18  * Contributor(s):
19  * Rex Tsai <chihchun@digitalsesame.com>
20  * David Li <david@digitalsesam.com>
21  *
22  * $Id: XHTMLSelectElementImpl.java,v 1.6 2005/01/26 08:29:24 jkjome Exp $
23  */

24
25 package org.enhydra.xml.xhtml.dom.xerces;
26
27 import org.w3c.dom.Node JavaDoc;
28 import org.w3c.dom.NodeList JavaDoc;
29 import org.w3c.dom.html.HTMLCollection;
30 import org.w3c.dom.html.HTMLElement;
31 import org.w3c.dom.html.HTMLOptionElement;
32
33 public class XHTMLSelectElementImpl
34     extends XHTMLElementImpl
35     implements org.enhydra.xml.xhtml.dom.XHTMLSelectElement
36 {
37
38     public XHTMLSelectElementImpl (XHTMLDocumentBase owner, String JavaDoc namespaceURI, String JavaDoc tagName) {
39     super( owner, namespaceURI, tagName);
40     }
41
42     /*
43      * Explicit implementation of getChildNodes() to avoid problems with
44      * overriding the getLength() method hidden in the super class.
45      */

46     public NodeList JavaDoc getChildNodes() {
47         return getChildNodesUnoptimized();
48     }
49
50         public void setId (String JavaDoc newValue) {
51     setAttribute("id", newValue);
52     }
53
54     public String JavaDoc getId () {
55     return getAttribute ("id");
56     }
57     public void setLang (String JavaDoc newValue) {
58     setAttribute("lang", newValue);
59     }
60
61     public String JavaDoc getLang () {
62     return getAttribute ("lang");
63     }
64     public void setDir (String JavaDoc newValue) {
65     setAttribute("dir", newValue);
66     }
67
68     public String JavaDoc getDir () {
69     return getAttribute ("dir");
70     }
71     public void setClassName (String JavaDoc newValue) {
72     setAttribute("class", newValue);
73     }
74
75     public String JavaDoc getClassName () {
76     return getAttribute ("class");
77     }
78     public void setTitle (String JavaDoc newValue) {
79     setAttribute("title", newValue);
80     }
81
82     public String JavaDoc getTitle () {
83     return getAttribute ("title");
84     }
85     public void setName (String JavaDoc newValue) {
86     setAttribute("name", newValue);
87     }
88
89     public String JavaDoc getName () {
90     return getAttribute ("name");
91     }
92     public void setValue (String JavaDoc newValue) {
93     setAttribute("value", newValue);
94     }
95
96     public String JavaDoc getValue () {
97     return getAttribute ("value");
98     }
99     public void setType (String JavaDoc newValue) {
100     setAttribute("type", newValue);
101     }
102
103     public String JavaDoc getType () {
104     return getAttribute ("type");
105     }
106     public void setSize (int newValue) {
107     setAttribute("size", newValue);
108     }
109
110     public int getSize () {
111     return getIntAttribute ("size");
112     }
113     public void setTabIndex (int newValue) {
114     setAttribute("tabindex", newValue);
115     }
116
117     public int getTabIndex () {
118     return getIntAttribute ("tabindex");
119     }
120     public void setDisabled (boolean newValue) {
121     setAttribute("disabled", newValue);
122     }
123
124     public boolean getDisabled () {
125     return getBooleanAttribute("disabled");
126     }
127     public void setMultiple (boolean newValue) {
128     setAttribute("multiple", newValue);
129     }
130
131     public boolean getMultiple () {
132     return getBooleanAttribute("multiple");
133     }
134     public void setOnKeyUp (String JavaDoc newValue) {
135     setAttribute("onkeyup", newValue);
136     }
137
138     public String JavaDoc getOnKeyUp () {
139     return getAttribute ("onkeyup");
140     }
141     public void setStyle (String JavaDoc newValue) {
142     setAttribute("style", newValue);
143     }
144
145     public String JavaDoc getStyle () {
146     return getAttribute ("style");
147     }
148     public void setOnMouseDown (String JavaDoc newValue) {
149     setAttribute("onmousedown", newValue);
150     }
151
152     public String JavaDoc getOnMouseDown () {
153     return getAttribute ("onmousedown");
154     }
155     public void setOnKeyPress (String JavaDoc newValue) {
156     setAttribute("onkeypress", newValue);
157     }
158
159     public String JavaDoc getOnKeyPress () {
160     return getAttribute ("onkeypress");
161     }
162     public void setOnDblClick (String JavaDoc newValue) {
163     setAttribute("ondblclick", newValue);
164     }
165
166     public String JavaDoc getOnDblClick () {
167     return getAttribute ("ondblclick");
168     }
169     public void setOnKeyDown (String JavaDoc newValue) {
170     setAttribute("onkeydown", newValue);
171     }
172
173     public String JavaDoc getOnKeyDown () {
174     return getAttribute ("onkeydown");
175     }
176     public void setOnMouseMove (String JavaDoc newValue) {
177     setAttribute("onmousemove", newValue);
178     }
179
180     public String JavaDoc getOnMouseMove () {
181     return getAttribute ("onmousemove");
182     }
183     public void setOnMouseUp (String JavaDoc newValue) {
184     setAttribute("onmouseup", newValue);
185     }
186
187     public String JavaDoc getOnMouseUp () {
188     return getAttribute ("onmouseup");
189     }
190     public void setXmlLang (String JavaDoc newValue) {
191     setAttribute("xml:lang", newValue);
192     }
193
194     public String JavaDoc getXmlLang () {
195     return getAttribute ("xml:lang");
196     }
197     public void setOnMouseOut (String JavaDoc newValue) {
198     setAttribute("onmouseout", newValue);
199     }
200
201     public String JavaDoc getOnMouseOut () {
202     return getAttribute ("onmouseout");
203     }
204     public void setOnClick (String JavaDoc newValue) {
205     setAttribute("onclick", newValue);
206     }
207
208     public String JavaDoc getOnClick () {
209     return getAttribute ("onclick");
210     }
211     public void setOnMouseOver (String JavaDoc newValue) {
212     setAttribute("onmouseover", newValue);
213     }
214
215     public String JavaDoc getOnMouseOver () {
216     return getAttribute ("onmouseover");
217     }
218     public void setOnBlur (String JavaDoc newValue) {
219     setAttribute("onblur", newValue);
220     }
221
222     public String JavaDoc getOnBlur () {
223     return getAttribute ("onblur");
224     }
225     public void setOnFocus (String JavaDoc newValue) {
226     setAttribute("onfocus", newValue);
227     }
228
229     public String JavaDoc getOnFocus () {
230     return getAttribute ("onfocus");
231     }
232     public void setOnChange (String JavaDoc newValue) {
233     setAttribute("onchange", newValue);
234     }
235
236     public String JavaDoc getOnChange () {
237     return getAttribute ("onchange");
238     }
239 ;
240
241     
242     public int getLength() {
243         return getOptions().getLength();
244     }
245
246     public int getSelectedIndex() {
247         NodeList JavaDoc options;
248         int i;
249         
250         // Use getElementsByTagName() which creates a snapshot of all the
251
// OPTION elements under this SELECT. Access to the returned NodeList
252
// is very fast and the snapshot solves many synchronization problems.
253
// Locate the first selected OPTION and return its index. Note that
254
// the OPTION might be under an OPTGROUP.
255
options = getElementsByTagName( "OPTION" );
256         for ( i = 0 ; i < options.getLength() ; ++i )
257             if ( ( (HTMLOptionElement) options.item( i ) ).getSelected() )
258                 return i;
259         return -1;
260     }
261     
262     
263     public void setSelectedIndex( int selectedIndex ) {
264         NodeList JavaDoc options;
265         int i;
266         
267         // Use getElementsByTagName() which creates a snapshot of all the
268
// OPTION elements under this SELECT. Access to the returned NodeList
269
// is very fast and the snapshot solves many synchronization problems.
270
// Change the select so all OPTIONs are off, except for the
271
// selectIndex-th one.
272
options = getElementsByTagName( "OPTION" );
273         for ( i = 0 ; i < options.getLength() ; ++i )
274             ( (XHTMLOptionElementImpl) options.item( i ) ).setSelected( i == selectedIndex );
275     }
276
277   
278     public HTMLCollection getOptions() {
279         if ( _options == null )
280             _options = new XHTMLCollectionImpl( this, XHTMLCollectionImpl.OPTION );
281         return _options;
282     }
283     
284     public void add( HTMLElement element, HTMLElement before ) {
285         insertBefore( element, before );
286     }
287     
288     public void remove( int index ) {
289         NodeList JavaDoc options;
290         Node JavaDoc removed;
291         
292         // Use getElementsByTagName() which creates a snapshot of all the
293
// OPTION elements under this SELECT. Access to the returned NodeList
294
// is very fast and the snapshot solves many synchronization problems.
295
// Remove the indexed OPTION from it's parent, this might be this
296
// SELECT or an OPTGROUP.
297
options = getElementsByTagName( "OPTION" );
298         removed = options.item( index );
299         if ( removed != null )
300             removed.getParentNode().removeChild ( removed );
301     }
302
303     public void blur() {
304         // No scripting in server-side DOM. This method is moot.
305
}
306       
307       
308     public void focus() {
309         // No scripting in server-side DOM. This method is moot.
310
}
311
312     private HTMLCollection _options;
313
314
315 ;
316 }
317
318
319
Popular Tags