001: /**
002: * org/ozone-db/xml/dom/html/HTMLSelectElementImpl.java
003: *
004: * The contents of this file are subject to the OpenXML Public
005: * License Version 1.0; you may not use this file except in compliance
006: * with the License. You may obtain a copy of the License at
007: * http://www.openxml.org/license.html
008: *
009: * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
010: * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
011: * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
012: * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
013: * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
014: * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
015: *
016: * The Initial Developer of this code under the License is Assaf Arkin.
017: * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
018: * All Rights Reserved.
019: */package org.ozoneDB.xml.dom.html;
020:
021: import org.ozoneDB.xml.dom.*;
022: import org.w3c.dom.*;
023: import org.w3c.dom.html.*;
024:
025: /**
026: * @version $Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
027: * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a>
028: * @see org.w3c.dom.html.HTMLSelectElement
029: * @see ElementImpl
030: */
031: public final class HTMLSelectElementImpl extends HTMLElementImpl
032: implements HTMLSelectElement, HTMLFormControl {
033:
034: public String getType() {
035: return getAttribute("type");
036: }
037:
038: public String getValue() {
039: return getAttribute("value");
040: }
041:
042: public void setValue(String value) {
043: setAttribute("value", value);
044: }
045:
046: public int getSelectedIndex() {
047: NodeList options;
048: int i;
049:
050: // Use getElementsByTagName() which creates a snapshot of all the
051: // OPTION elements under this SELECT. Access to the returned NodeList
052: // is very fast and the snapshot solves many synchronization problems.
053: // Locate the first selected OPTION and return its index. Note that
054: // the OPTION might be under an OPTGROUP.
055: options = getElementsByTagName("OPTION");
056: for (i = 0; i < options.getLength(); ++i) {
057: if (((HTMLOptionElement) options.item(i)).getSelected()) {
058: return i;
059: }
060: }
061: return -1;
062: }
063:
064: public void setSelectedIndex(int selectedIndex) {
065: NodeList options;
066: int i;
067:
068: // Use getElementsByTagName() which creates a snapshot of all the
069: // OPTION elements under this SELECT. Access to the returned NodeList
070: // is very fast and the snapshot solves many synchronization problems.
071: // Change the select so all OPTIONs are off, except for the
072: // selectIndex-th one.
073: options = getElementsByTagName("OPTION");
074: for (i = 0; i < options.getLength(); ++i) {
075: ((HTMLOptionElementImpl) options.item(i))
076: .setSelected(i == selectedIndex);
077: }
078: }
079:
080: public HTMLCollection getOptions() {
081: if (_options == null) {
082: _options = new HTMLCollectionImpl(this ,
083: HTMLCollectionImpl.OPTION);
084: }
085: return _options;
086: }
087:
088: public int getLength() {
089: return getOptions().getLength();
090: }
091:
092: public boolean getDisabled() {
093: return getAttribute("disabled") != null;
094: }
095:
096: public void setDisabled(boolean disabled) {
097: setAttribute("disabled", disabled ? "" : null);
098: }
099:
100: public boolean getMultiple() {
101: return getAttribute("multiple") != null;
102: }
103:
104: public void setMultiple(boolean multiple) {
105: setAttribute("multiple", multiple ? "" : null);
106: }
107:
108: public String getName() {
109: return getAttribute("name");
110: }
111:
112: public void setName(String name) {
113: setAttribute("name", name);
114: }
115:
116: public int getSize() {
117: return toInteger(getAttribute("size"));
118: }
119:
120: public void setSize(int size) {
121: setAttribute("size", String.valueOf(size));
122: }
123:
124: public int getTabIndex() {
125: return toInteger(getAttribute("tabindex"));
126: }
127:
128: public void setTabIndex(int tabIndex) {
129: setAttribute("tabindex", String.valueOf(tabIndex));
130: }
131:
132: public void add(HTMLElement element, HTMLElement before) {
133: insertBefore(element, before);
134: }
135:
136: public void remove(int index) {
137: NodeList options;
138: Node removed;
139:
140: // Use getElementsByTagName() which creates a snapshot of all the
141: // OPTION elements under this SELECT. Access to the returned NodeList
142: // is very fast and the snapshot solves many synchronization problems.
143: // Remove the indexed OPTION from it's parent, this might be this
144: // SELECT or an OPTGROUP.
145: options = getElementsByTagName("OPTION");
146: removed = options.item(index);
147: if (removed != null) {
148: removed.getParentNode().removeChild(removed);
149: }
150: }
151:
152: public void blur() {
153: // No scripting in server-side DOM. This method is moot.
154: }
155:
156: public void focus() {
157: // No scripting in server-side DOM. This method is moot.
158: }
159:
160: /**
161: * Constructor requires owner document.
162: *
163: * @param owner The owner HTML document
164: */
165: public HTMLSelectElementImpl(HTMLDocumentImpl owner, String name) {
166: super (owner, "SELECT");
167: }
168:
169: private HTMLCollection _options;
170:
171: }
|