Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / xml / dom / html2 / DomHTMLSelectElement.java
blob09752e1ffe49ca180b8a17565a19f9a075683c9d
1 /* DomHTMLSelectElement.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package gnu.xml.dom.html2;
40 import gnu.xml.dom.DomDOMException;
41 import org.w3c.dom.DOMException;
42 import org.w3c.dom.html2.HTMLElement;
43 import org.w3c.dom.html2.HTMLFormElement;
44 import org.w3c.dom.html2.HTMLOptionElement;
45 import org.w3c.dom.html2.HTMLOptionsCollection;
46 import org.w3c.dom.html2.HTMLSelectElement;
48 /**
49 * An HTML 'SELECT' element node.
51 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
53 public class DomHTMLSelectElement
54 extends DomHTMLElement
55 implements HTMLSelectElement
58 protected DomHTMLSelectElement(DomHTMLDocument owner, String namespaceURI,
59 String name)
61 super(owner, namespaceURI, name);
64 public String getType()
66 return getHTMLAttribute("type");
69 public int getSelectedIndex()
71 HTMLOptionsCollection options = getOptions();
72 int len = options.getLength();
73 for (int i = 0; i < len; i++)
75 HTMLOptionElement option = (HTMLOptionElement) options.item(i);
76 if (option.getSelected())
78 return i;
81 return -1;
84 public void setSelectedIndex(int selectedIndex)
86 HTMLOptionsCollection options = getOptions();
87 int len = options.getLength();
88 if (selectedIndex < 0 || selectedIndex >= len)
90 throw new DomDOMException(DOMException.INDEX_SIZE_ERR);
92 for (int i = 0; i < len; i++)
94 HTMLOptionElement option = (HTMLOptionElement) options.item(i);
95 option.setSelected(i == selectedIndex);
99 public String getValue()
101 return getHTMLAttribute("value");
104 public void setValue(String value)
106 setHTMLAttribute("value", value);
109 public int getLength()
111 return getIntHTMLAttribute("length");
114 public void setLength(int length)
116 setIntHTMLAttribute("length", length);
119 public HTMLFormElement getForm()
121 return (HTMLFormElement) getParentElement("form");
124 public HTMLOptionsCollection getOptions()
126 DomHTMLCollection ret =
127 new DomHTMLCollection((DomHTMLDocument) getOwnerDocument(), this);
128 ret.addNodeName("option");
129 ret.evaluate();
130 return ret;
133 public boolean getDisabled()
135 return getBooleanHTMLAttribute("disabled");
138 public void setDisabled(boolean disabled)
140 setBooleanHTMLAttribute("disabled", disabled);
143 public boolean getMultiple()
145 return getBooleanHTMLAttribute("multiple");
148 public void setMultiple(boolean multiple)
150 setBooleanHTMLAttribute("multiple", multiple);
153 public String getName()
155 return getHTMLAttribute("name");
158 public void setName(String name)
160 setHTMLAttribute("name", name);
163 public int getSize()
165 return getIntHTMLAttribute("size");
168 public void setSize(int size)
170 setIntHTMLAttribute("size", size);
173 public int getTabIndex()
175 return getIntHTMLAttribute("tabindex");
178 public void setTabIndex(int tabIndex)
180 setIntHTMLAttribute("tabindex", tabIndex);
183 public void add(HTMLElement element, HTMLElement before)
185 insertBefore(before, element);
188 public void remove(int index)
190 HTMLOptionsCollection options = getOptions();
191 int len = options.getLength();
192 if (index < 0 || index >= len)
194 throw new DomDOMException(DOMException.INDEX_SIZE_ERR);
196 HTMLOptionElement option = (HTMLOptionElement) options.item(index);
197 option.getParentNode().removeChild(option);
200 public void blur()
202 dispatchUIEvent("blur");
205 public void focus()
207 dispatchUIEvent("focus");