1 57 package org.enhydra.apache.html.dom; 58 59 60 import org.enhydra.apache.xerces.dom.ElementImpl; 61 import org.w3c.dom.Node ; 62 import org.w3c.dom.NodeList ; 63 import org.w3c.dom.html.HTMLCollection; 64 import org.w3c.dom.html.HTMLElement; 65 import org.w3c.dom.html.HTMLOptionElement; 66 import org.w3c.dom.html.HTMLSelectElement; 67 68 69 75 public class HTMLSelectElementImpl 76 extends HTMLElementImpl 77 implements HTMLSelectElement, HTMLFormControl 78 { 79 80 81 public String getType() 82 { 83 return getAttribute( "type" ); 84 } 85 86 87 public String getValue() 88 { 89 return getAttribute( "value" ); 90 } 91 92 93 public void setValue( String value ) 94 { 95 setAttribute( "value", value ); 96 } 97 98 99 public int getSelectedIndex() 100 { 101 NodeList options; 102 int i; 103 104 options = getElementsByTagName( "OPTION" ); 110 for ( i = 0 ; i < options.getLength() ; ++i ) 111 if ( ( (HTMLOptionElement) options.item( i ) ).getSelected() ) 112 return i; 113 return -1; 114 } 115 116 117 public void setSelectedIndex( int selectedIndex ) 118 { 119 NodeList options; 120 int i; 121 122 options = getElementsByTagName( "OPTION" ); 128 for ( i = 0 ; i < options.getLength() ; ++i ) 129 ( (HTMLOptionElementImpl) options.item( i ) ).setSelected( i == selectedIndex ); 130 } 131 132 133 public HTMLCollection getOptions() 134 { 135 if ( _options == null ) 136 _options = new HTMLCollectionImpl( this, HTMLCollectionImpl.OPTION ); 137 return _options; 138 } 139 140 141 public int getLength() 142 { 143 return getOptions().getLength(); 144 } 145 146 147 public boolean getDisabled() 148 { 149 return getBinary( "disabled" ); 150 } 151 152 153 public void setDisabled( boolean disabled ) 154 { 155 setAttribute( "disabled", disabled ); 156 } 157 158 159 public boolean getMultiple() 160 { 161 return getBinary( "multiple" ); 162 } 163 164 165 public void setMultiple( boolean multiple ) 166 { 167 setAttribute( "multiple", multiple ); 168 } 169 170 171 public String getName() 172 { 173 return getAttribute( "name" ); 174 } 175 176 177 public void setName( String name ) 178 { 179 setAttribute( "name", name ); 180 } 181 182 183 public int getSize() 184 { 185 return getInteger( getAttribute( "size" ) ); 186 } 187 188 189 public void setSize( int size ) 190 { 191 setAttribute( "size", String.valueOf( size ) ); 192 } 193 194 195 public int getTabIndex() 196 { 197 return getInteger( getAttribute( "tabindex" ) ); 198 } 199 200 201 public void setTabIndex( int tabIndex ) 202 { 203 setAttribute( "tabindex", String.valueOf( tabIndex ) ); 204 } 205 206 207 public void add( HTMLElement element, HTMLElement before ) 208 { 209 insertBefore( element, before ); 210 } 211 212 213 public void remove( int index ) 214 { 215 NodeList options; 216 Node removed; 217 218 options = getElementsByTagName( "OPTION" ); 224 removed = options.item( index ); 225 if ( removed != null ) 226 removed.getParentNode().removeChild ( removed ); 227 } 228 229 230 public void blur() 231 { 232 } 234 235 236 public void focus() 237 { 238 } 240 241 245 public NodeList getChildNodes() { 246 return getChildNodesUnoptimized(); 247 } 248 249 253 public Node cloneNode(boolean deep) { 254 HTMLSelectElementImpl clonedNode = (HTMLSelectElementImpl)super.cloneNode( deep ); 255 clonedNode._options = null; 256 return clonedNode; 257 } 258 259 264 public HTMLSelectElementImpl( HTMLDocumentImpl owner, String name ) 265 { 266 super( owner, name ); 267 } 268 269 270 private HTMLCollection _options; 271 272 273 } 274 275 | Popular Tags |