1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47:
48:
53: public class DomHTMLSelectElement
54: extends DomHTMLElement
55: implements HTMLSelectElement
56: {
57:
58: protected DomHTMLSelectElement(DomHTMLDocument owner, String namespaceURI,
59: String name)
60: {
61: super(owner, namespaceURI, name);
62: }
63:
64: public String getType()
65: {
66: return getHTMLAttribute("type");
67: }
68:
69: public int getSelectedIndex()
70: {
71: HTMLOptionsCollection options = getOptions();
72: int len = options.getLength();
73: for (int i = 0; i < len; i++)
74: {
75: HTMLOptionElement option = (HTMLOptionElement) options.item(i);
76: if (option.getSelected())
77: {
78: return i;
79: }
80: }
81: return -1;
82: }
83:
84: public void setSelectedIndex(int selectedIndex)
85: {
86: HTMLOptionsCollection options = getOptions();
87: int len = options.getLength();
88: if (selectedIndex < 0 || selectedIndex >= len)
89: {
90: throw new DomDOMException(DOMException.INDEX_SIZE_ERR);
91: }
92: for (int i = 0; i < len; i++)
93: {
94: HTMLOptionElement option = (HTMLOptionElement) options.item(i);
95: option.setSelected(i == selectedIndex);
96: }
97: }
98:
99: public String getValue()
100: {
101: return getHTMLAttribute("value");
102: }
103:
104: public void setValue(String value)
105: {
106: setHTMLAttribute("value", value);
107: }
108:
109: public int getLength()
110: {
111: return getIntHTMLAttribute("length");
112: }
113:
114: public void setLength(int length)
115: {
116: setIntHTMLAttribute("length", length);
117: }
118:
119: public HTMLFormElement getForm()
120: {
121: return (HTMLFormElement) getParentElement("form");
122: }
123:
124: public HTMLOptionsCollection getOptions()
125: {
126: DomHTMLCollection ret =
127: new DomHTMLCollection((DomHTMLDocument) getOwnerDocument(), this);
128: ret.addNodeName("option");
129: ret.evaluate();
130: return ret;
131: }
132:
133: public boolean getDisabled()
134: {
135: return getBooleanHTMLAttribute("disabled");
136: }
137:
138: public void setDisabled(boolean disabled)
139: {
140: setBooleanHTMLAttribute("disabled", disabled);
141: }
142:
143: public boolean getMultiple()
144: {
145: return getBooleanHTMLAttribute("multiple");
146: }
147:
148: public void setMultiple(boolean multiple)
149: {
150: setBooleanHTMLAttribute("multiple", multiple);
151: }
152:
153: public String getName()
154: {
155: return getHTMLAttribute("name");
156: }
157:
158: public void setName(String name)
159: {
160: setHTMLAttribute("name", name);
161: }
162:
163: public int getSize()
164: {
165: return getIntHTMLAttribute("size");
166: }
167:
168: public void setSize(int size)
169: {
170: setIntHTMLAttribute("size", size);
171: }
172:
173: public int getTabIndex()
174: {
175: return getIntHTMLAttribute("tabindex");
176: }
177:
178: public void setTabIndex(int tabIndex)
179: {
180: setIntHTMLAttribute("tabindex", tabIndex);
181: }
182:
183: public void add(HTMLElement element, HTMLElement before)
184: {
185: insertBefore(before, element);
186: }
187:
188: public void remove(int index)
189: {
190: HTMLOptionsCollection options = getOptions();
191: int len = options.getLength();
192: if (index < 0 || index >= len)
193: {
194: throw new DomDOMException(DOMException.INDEX_SIZE_ERR);
195: }
196: HTMLOptionElement option = (HTMLOptionElement) options.item(index);
197: option.getParentNode().removeChild(option);
198: }
199:
200: public void blur()
201: {
202: dispatchUIEvent("blur");
203: }
204:
205: public void focus()
206: {
207: dispatchUIEvent("focus");
208: }
209:
210: }