KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lobobrowser > html > domimpl > HTMLOptionElementImpl


1 package org.lobobrowser.html.domimpl;
2
3 import org.w3c.dom.html2.*;
4
5 public class HTMLOptionElementImpl extends HTMLElementImpl implements HTMLOptionElement {
6     public HTMLOptionElementImpl(String JavaDoc name) {
7         super(name, true);
8     }
9
10     public boolean getDefaultSelected() {
11         return this.getAttributeAsBoolean("selected");
12     }
13
14     public boolean getDisabled() {
15         return false;
16     }
17
18     public HTMLFormElement getForm() {
19         return this.getForm();
20     }
21
22     public int getIndex() {
23         Object JavaDoc parent = this.getParentNode();
24         if(parent instanceof HTMLSelectElement) {
25             HTMLOptionsCollectionImpl options = (HTMLOptionsCollectionImpl) ((HTMLSelectElement) parent).getOptions();
26             return options.indexOf(this);
27         }
28         else {
29             return -1;
30         }
31     }
32
33     public String JavaDoc getLabel() {
34         return this.getAttribute("label");
35     }
36
37     public boolean getSelected() {
38         Object JavaDoc parent = this.getParentNode();
39         if(parent instanceof HTMLSelectElement) {
40             return ((HTMLSelectElement) parent).getSelectedIndex() == this.getIndex();
41         }
42         else {
43             return false;
44         }
45     }
46
47     public String JavaDoc getText() {
48         return this.getRawInnerText(false);
49     }
50
51     public String JavaDoc getValue() {
52         return this.getAttribute("value");
53     }
54
55     public void setDefaultSelected(boolean defaultSelected) {
56         this.setAttribute("selected", defaultSelected ? "selected" : null);
57     }
58
59     public void setDisabled(boolean disabled) {
60         //TODO Unsupported
61
}
62
63     public void setLabel(String JavaDoc label) {
64         this.setAttribute("label", label);
65     }
66
67     public void setSelected(boolean selected) {
68         Object JavaDoc parent = this.getParentNode();
69         if(parent instanceof HTMLSelectElement) {
70             if(selected) {
71                 ((HTMLSelectElement) parent).setSelectedIndex(this.getIndex());
72             }
73             else {
74                 ((HTMLSelectElement) parent).setSelectedIndex(-1);
75             }
76         }
77     }
78
79     public void setValue(String JavaDoc value) {
80         this.setAttribute("value", value);
81     }
82 }
83
Popular Tags