1 16 package org.apache.html.dom; 17 18 import org.w3c.dom.Node ; 19 import org.w3c.dom.NodeList ; 20 import org.w3c.dom.html.HTMLCollection; 21 import org.w3c.dom.html.HTMLElement; 22 import org.w3c.dom.html.HTMLOptionElement; 23 import org.w3c.dom.html.HTMLSelectElement; 24 25 32 public class HTMLSelectElementImpl 33 extends HTMLElementImpl 34 implements HTMLSelectElement, HTMLFormControl 35 { 36 37 private static final long serialVersionUID = 3256722883588665912L; 38 39 public String getType() 40 { 41 return getAttribute( "type" ); 42 } 43 44 45 public String getValue() 46 { 47 return getAttribute( "value" ); 48 } 49 50 51 public void setValue( String value ) 52 { 53 setAttribute( "value", value ); 54 } 55 56 57 public int getSelectedIndex() 58 { 59 NodeList options; 60 int i; 61 62 options = getElementsByTagName( "OPTION" ); 68 for ( i = 0 ; i < options.getLength() ; ++i ) 69 if ( ( (HTMLOptionElement) options.item( i ) ).getSelected() ) 70 return i; 71 return -1; 72 } 73 74 75 public void setSelectedIndex( int selectedIndex ) 76 { 77 NodeList options; 78 int i; 79 80 options = getElementsByTagName( "OPTION" ); 86 for ( i = 0 ; i < options.getLength() ; ++i ) 87 ( (HTMLOptionElementImpl) options.item( i ) ).setSelected( i == selectedIndex ); 88 } 89 90 91 public HTMLCollection getOptions() 92 { 93 if ( _options == null ) 94 _options = new HTMLCollectionImpl( this, HTMLCollectionImpl.OPTION ); 95 return _options; 96 } 97 98 99 public int getLength() 100 { 101 return getOptions().getLength(); 102 } 103 104 105 public boolean getDisabled() 106 { 107 return getBinary( "disabled" ); 108 } 109 110 111 public void setDisabled( boolean disabled ) 112 { 113 setAttribute( "disabled", disabled ); 114 } 115 116 117 public boolean getMultiple() 118 { 119 return getBinary( "multiple" ); 120 } 121 122 123 public void setMultiple( boolean multiple ) 124 { 125 setAttribute( "multiple", multiple ); 126 } 127 128 129 public String getName() 130 { 131 return getAttribute( "name" ); 132 } 133 134 135 public void setName( String name ) 136 { 137 setAttribute( "name", name ); 138 } 139 140 141 public int getSize() 142 { 143 return getInteger( getAttribute( "size" ) ); 144 } 145 146 147 public void setSize( int size ) 148 { 149 setAttribute( "size", String.valueOf( size ) ); 150 } 151 152 153 public int getTabIndex() 154 { 155 return getInteger( getAttribute( "tabindex" ) ); 156 } 157 158 159 public void setTabIndex( int tabIndex ) 160 { 161 setAttribute( "tabindex", String.valueOf( tabIndex ) ); 162 } 163 164 165 public void add( HTMLElement element, HTMLElement before ) 166 { 167 insertBefore( element, before ); 168 } 169 170 171 public void remove( int index ) 172 { 173 NodeList options; 174 Node removed; 175 176 options = getElementsByTagName( "OPTION" ); 182 removed = options.item( index ); 183 if ( removed != null ) 184 removed.getParentNode().removeChild ( removed ); 185 } 186 187 188 public void blur() 189 { 190 } 192 193 194 public void focus() 195 { 196 } 198 199 203 public NodeList getChildNodes() { 204 return getChildNodesUnoptimized(); 205 } 206 207 211 public Node cloneNode(boolean deep) { 212 HTMLSelectElementImpl clonedNode = (HTMLSelectElementImpl)super.cloneNode( deep ); 213 clonedNode._options = null; 214 return clonedNode; 215 } 216 217 222 public HTMLSelectElementImpl( HTMLDocumentImpl owner, String name ) 223 { 224 super( owner, name ); 225 } 226 227 228 private HTMLCollection _options; 229 230 231 } 232 233 | Popular Tags |