KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > text > html > Option


1 /*
2  * @(#)Option.java 1.10 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing.text.html;
8
9 import java.awt.*;
10 import javax.swing.*;
11 import javax.swing.text.*;
12
13 /**
14  * Value for the ListModel used to represent
15  * <option> elements. This is the object
16  * installed as items of the DefaultComboBoxModel
17  * used to represent the <select> element.
18  *
19  * @author Timothy Prinzing
20  * @version 1.10 12/19/03
21  */

22 public class Option {
23
24     /**
25      * Creates a new Option object.
26      *
27      * @param attr the attributes associated with the
28      * option element. The attributes are copied to
29      * ensure they won't change.
30      */

31     public Option(AttributeSet attr) {
32     this.attr = attr.copyAttributes();
33     selected = (attr.getAttribute(HTML.Attribute.SELECTED) != null);
34     }
35
36     /**
37      * Sets the label to be used for the option.
38      */

39     public void setLabel(String JavaDoc label) {
40     this.label = label;
41     }
42
43     /**
44      * Fetch the label associated with the option.
45      */

46     public String JavaDoc getLabel() {
47     return label;
48     }
49
50     /**
51      * Fetch the attributes associated with this option.
52      */

53     public AttributeSet getAttributes() {
54     return attr;
55     }
56
57     /**
58      * String representation is the label.
59      */

60     public String JavaDoc toString() {
61     return label;
62     }
63
64     /**
65      * Sets the selected state.
66      */

67     protected void setSelection(boolean state) {
68     selected = state;
69     }
70
71     /**
72      * Fetches the selection state associated with this option.
73      */

74     public boolean isSelected() {
75     return selected;
76     }
77
78     /**
79      * Convenience method to return the string associated
80      * with the <code>value</code> attribute. If the
81      * value has not been specified, the label will be
82      * returned.
83      */

84     public String JavaDoc getValue() {
85     String JavaDoc value = (String JavaDoc) attr.getAttribute(HTML.Attribute.VALUE);
86     if (value == null) {
87         value = label;
88     }
89     return value;
90     }
91
92     private boolean selected;
93     private String JavaDoc label;
94     private AttributeSet attr;
95 }
96
97
Popular Tags