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