author | yan |
Thu, 19 Jun 2014 16:57:14 +0400 | |
changeset 25148 | 1026dc322690 |
parent 22574 | 7f8ce0c8c20a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
20458
diff
changeset
|
2 |
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package javax.swing.text.html; |
|
26 |
||
27 |
import java.io.Serializable; |
|
28 |
import javax.swing.text.*; |
|
29 |
||
30 |
/** |
|
31 |
* Value for the ListModel used to represent |
|
32 |
* <option> elements. This is the object |
|
33 |
* installed as items of the DefaultComboBoxModel |
|
34 |
* used to represent the <select> element. |
|
35 |
* <p> |
|
36 |
* <strong>Warning:</strong> |
|
37 |
* Serialized objects of this class will not be compatible with |
|
38 |
* future Swing releases. The current serialization support is |
|
39 |
* appropriate for short term storage or RMI between applications running |
|
40 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 41 |
* of all JavaBeans™ |
2 | 42 |
* has been added to the <code>java.beans</code> package. |
43 |
* Please see {@link java.beans.XMLEncoder}. |
|
44 |
* |
|
45 |
* @author Timothy Prinzing |
|
46 |
*/ |
|
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
20458
diff
changeset
|
47 |
@SuppressWarnings("serial") // Same-version serialization only |
2 | 48 |
public class Option implements Serializable { |
49 |
||
50 |
/** |
|
51 |
* Creates a new Option object. |
|
52 |
* |
|
53 |
* @param attr the attributes associated with the |
|
54 |
* option element. The attributes are copied to |
|
55 |
* ensure they won't change. |
|
56 |
*/ |
|
57 |
public Option(AttributeSet attr) { |
|
58 |
this.attr = attr.copyAttributes(); |
|
59 |
selected = (attr.getAttribute(HTML.Attribute.SELECTED) != null); |
|
60 |
} |
|
61 |
||
62 |
/** |
|
63 |
* Sets the label to be used for the option. |
|
25148
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
64 |
* |
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
65 |
* @param label a label. |
2 | 66 |
*/ |
67 |
public void setLabel(String label) { |
|
68 |
this.label = label; |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Fetch the label associated with the option. |
|
25148
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
73 |
* |
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
74 |
* @return the label associated with the option. |
2 | 75 |
*/ |
76 |
public String getLabel() { |
|
77 |
return label; |
|
78 |
} |
|
79 |
||
80 |
/** |
|
81 |
* Fetch the attributes associated with this option. |
|
25148
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
82 |
* |
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
83 |
* @return the attributes associated with this option. |
2 | 84 |
*/ |
85 |
public AttributeSet getAttributes() { |
|
86 |
return attr; |
|
87 |
} |
|
88 |
||
89 |
/** |
|
90 |
* String representation is the label. |
|
91 |
*/ |
|
92 |
public String toString() { |
|
93 |
return label; |
|
94 |
} |
|
95 |
||
96 |
/** |
|
97 |
* Sets the selected state. |
|
25148
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
98 |
* |
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
99 |
* @param state a selection state |
2 | 100 |
*/ |
101 |
protected void setSelection(boolean state) { |
|
102 |
selected = state; |
|
103 |
} |
|
104 |
||
105 |
/** |
|
106 |
* Fetches the selection state associated with this option. |
|
25148
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
107 |
* |
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
108 |
* @return the selection state. |
2 | 109 |
*/ |
110 |
public boolean isSelected() { |
|
111 |
return selected; |
|
112 |
} |
|
113 |
||
114 |
/** |
|
25148
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
115 |
* Convenient method to return the string associated |
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
116 |
* with the {@code value} attribute. If the |
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
117 |
* {@code value} has not been specified, the {@code label} will be |
2 | 118 |
* returned. |
25148
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
119 |
* |
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
120 |
* @return the string associated with the {@code value} attribute, |
1026dc322690
8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents:
22574
diff
changeset
|
121 |
* or {@code label} if the value has been not specified. |
2 | 122 |
*/ |
123 |
public String getValue() { |
|
124 |
String value = (String) attr.getAttribute(HTML.Attribute.VALUE); |
|
125 |
if (value == null) { |
|
126 |
value = label; |
|
127 |
} |
|
128 |
return value; |
|
129 |
} |
|
130 |
||
131 |
private boolean selected; |
|
132 |
private String label; |
|
133 |
private AttributeSet attr; |
|
134 |
} |