1 package org.lobobrowser.html.domimpl; 2 3 import org.lobobrowser.html.FormInput; 4 import org.w3c.dom.DOMException ; 5 import org.w3c.dom.html2.HTMLElement; 6 import org.w3c.dom.html2.HTMLOptionsCollection; 7 import org.w3c.dom.html2.HTMLSelectElement; 8 9 public class HTMLSelectElementImpl extends HTMLBaseInputElement implements 10 HTMLSelectElement { 11 public HTMLSelectElementImpl(String name) { 12 super(name); 13 } 14 15 public void add(HTMLElement element, HTMLElement before) 16 throws DOMException { 17 this.insertBefore(element, before); 18 } 19 20 public int getLength() { 21 return this.getOptions().getLength(); 22 } 23 24 public boolean getMultiple() { 25 InputContext ic = this.inputContext; 26 if(ic != null) { 27 return ic.getMultiple(); 28 } 29 else { 30 return false; 31 } 32 } 33 34 private HTMLOptionsCollection options; 35 36 public HTMLOptionsCollection getOptions() { 37 synchronized(this) { 38 if(this.options == null) { 39 this.options = new HTMLOptionsCollectionImpl(this); 40 } 41 return this.options; 42 } 43 } 44 45 public int getSelectedIndex() { 46 InputContext ic = this.inputContext; 47 if(ic != null) { 48 return ic.getSelectedIndex(); 49 } 50 else { 51 return -1; 52 } 53 } 54 55 public int getSize() { 56 InputContext ic = this.inputContext; 57 if(ic != null) { 58 return ic.getVisibleSize(); 59 } 60 else { 61 return 0; 62 } 63 } 64 65 public String getType() { 66 return this.getMultiple() ? "select-multiple" : "select-one"; 67 } 68 69 public void remove(int index) { 70 try { 71 this.removeChild(this.getOptions().item(index)); 72 } catch(DOMException de) { 73 this.warn("remove(): Unable to remove option at index " + index + ".", de); 74 } 75 } 76 77 public void setLength(int length) throws DOMException { 78 this.getOptions().setLength(length); 79 } 80 81 public void setMultiple(boolean multiple) { 82 InputContext ic = this.inputContext; 83 if(ic != null) { 84 ic.setMultiple(multiple); 85 } 86 } 87 88 public void setSelectedIndex(int selectedIndex) { 89 InputContext ic = this.inputContext; 90 if(ic != null) { 91 ic.setSelectedIndex(selectedIndex); 92 } 93 } 94 95 public void setSize(int size) { 96 InputContext ic = this.inputContext; 97 if(ic != null) { 98 ic.setVisibleSize(size); 99 } 100 } 101 102 protected FormInput[] getFormInputs() { 103 String name = this.getName(); 105 if(name == null) { 106 return null; 107 } 108 return new FormInput[] { new FormInput(name, this.getValue()) }; 109 } 110 111 public void resetInput() { 112 InputContext ic = this.inputContext; 113 if(ic != null) { 114 ic.resetInput(); 115 } 116 } 117 } 118 | Popular Tags |