Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/classes/javax/swing/JCheckBox.java
+++ new/src/share/classes/javax/swing/JCheckBox.java
1 1 /*
2 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25 package javax.swing;
26 26
27 27 import java.awt.*;
28 28 import java.awt.event.*;
29 29 import java.beans.*;
30 30
31 31 import javax.swing.plaf.*;
32 32 import javax.accessibility.*;
↓ open down ↓ |
32 lines elided |
↑ open up ↑ |
33 33
34 34 import java.io.ObjectOutputStream;
35 35 import java.io.ObjectInputStream;
36 36 import java.io.IOException;
37 37
38 38
39 39 /**
40 40 * An implementation of a check box -- an item that can be selected or
41 41 * deselected, and which displays its state to the user.
42 42 * By convention, any number of check boxes in a group can be selected.
43 - * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/button.html">How to Use Buttons, Check Boxes, and Radio Buttons</a>
43 + * See <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/button.html">How to Use Buttons, Check Boxes, and Radio Buttons</a>
44 44 * in <em>The Java Tutorial</em>
45 45 * for examples and information on using check boxes.
46 46 * <p>
47 47 * Buttons can be configured, and to some degree controlled, by
48 48 * <code><a href="Action.html">Action</a></code>s. Using an
49 49 * <code>Action</code> with a button has many benefits beyond directly
50 50 * configuring a button. Refer to <a href="Action.html#buttonActions">
51 51 * Swing Components Supporting <code>Action</code></a> for more
52 52 * details, and you can find more information in <a
53 - * href="http://docs.oracle.com/javase/tutorial/uiswing/misc/action.html">How
53 + * href="https://docs.oracle.com/javase/tutorial/uiswing/misc/action.html">How
54 54 * to Use Actions</a>, a section in <em>The Java Tutorial</em>.
55 55 * <p>
56 56 * <strong>Warning:</strong> Swing is not thread safe. For more
57 57 * information see <a
58 58 * href="package-summary.html#threading">Swing's Threading
59 59 * Policy</a>.
60 60 * <p>
61 61 * <strong>Warning:</strong>
62 62 * Serialized objects of this class will not be compatible with
63 63 * future Swing releases. The current serialization support is
64 64 * appropriate for short term storage or RMI between applications running
65 65 * the same version of Swing. As of 1.4, support for long term storage
66 66 * of all JavaBeans™
67 67 * has been added to the <code>java.beans</code> package.
68 68 * Please see {@link java.beans.XMLEncoder}.
69 69 *
70 70 * @see JRadioButton
71 71 *
72 72 * @beaninfo
73 73 * attribute: isContainer false
74 74 * description: A component which can be selected or deselected.
75 75 *
76 76 * @author Jeff Dinkins
77 77 */
78 78 public class JCheckBox extends JToggleButton implements Accessible {
79 79
80 80 /** Identifies a change to the flat property. */
81 81 public static final String BORDER_PAINTED_FLAT_CHANGED_PROPERTY = "borderPaintedFlat";
82 82
83 83 private boolean flat = false;
84 84
85 85 /**
86 86 * @see #getUIClassID
87 87 * @see #readObject
88 88 */
89 89 private static final String uiClassID = "CheckBoxUI";
90 90
91 91
92 92 /**
93 93 * Creates an initially unselected check box button with no text, no icon.
94 94 */
95 95 public JCheckBox () {
96 96 this(null, null, false);
97 97 }
98 98
99 99 /**
100 100 * Creates an initially unselected check box with an icon.
101 101 *
102 102 * @param icon the Icon image to display
103 103 */
104 104 public JCheckBox(Icon icon) {
105 105 this(null, icon, false);
106 106 }
107 107
108 108 /**
109 109 * Creates a check box with an icon and specifies whether
110 110 * or not it is initially selected.
111 111 *
112 112 * @param icon the Icon image to display
113 113 * @param selected a boolean value indicating the initial selection
114 114 * state. If <code>true</code> the check box is selected
115 115 */
116 116 public JCheckBox(Icon icon, boolean selected) {
117 117 this(null, icon, selected);
118 118 }
119 119
120 120 /**
121 121 * Creates an initially unselected check box with text.
122 122 *
123 123 * @param text the text of the check box.
124 124 */
125 125 public JCheckBox (String text) {
126 126 this(text, null, false);
127 127 }
128 128
129 129 /**
130 130 * Creates a check box where properties are taken from the
131 131 * Action supplied.
132 132 *
133 133 * @since 1.3
134 134 */
135 135 public JCheckBox(Action a) {
136 136 this();
137 137 setAction(a);
138 138 }
139 139
140 140
141 141 /**
142 142 * Creates a check box with text and specifies whether
143 143 * or not it is initially selected.
144 144 *
145 145 * @param text the text of the check box.
146 146 * @param selected a boolean value indicating the initial selection
147 147 * state. If <code>true</code> the check box is selected
148 148 */
149 149 public JCheckBox (String text, boolean selected) {
150 150 this(text, null, selected);
151 151 }
152 152
153 153 /**
154 154 * Creates an initially unselected check box with
155 155 * the specified text and icon.
156 156 *
157 157 * @param text the text of the check box.
158 158 * @param icon the Icon image to display
159 159 */
160 160 public JCheckBox(String text, Icon icon) {
161 161 this(text, icon, false);
162 162 }
163 163
164 164 /**
165 165 * Creates a check box with text and icon,
166 166 * and specifies whether or not it is initially selected.
167 167 *
168 168 * @param text the text of the check box.
169 169 * @param icon the Icon image to display
170 170 * @param selected a boolean value indicating the initial selection
171 171 * state. If <code>true</code> the check box is selected
172 172 */
173 173 public JCheckBox (String text, Icon icon, boolean selected) {
174 174 super(text, icon, selected);
175 175 setUIProperty("borderPainted", Boolean.FALSE);
176 176 setHorizontalAlignment(LEADING);
177 177 }
178 178
179 179 /**
180 180 * Sets the <code>borderPaintedFlat</code> property,
181 181 * which gives a hint to the look and feel as to the
182 182 * appearance of the check box border.
183 183 * This is usually set to <code>true</code> when a
184 184 * <code>JCheckBox</code> instance is used as a
185 185 * renderer in a component such as a <code>JTable</code> or
186 186 * <code>JTree</code>. The default value for the
187 187 * <code>borderPaintedFlat</code> property is <code>false</code>.
188 188 * This method fires a property changed event.
189 189 * Some look and feels might not implement flat borders;
190 190 * they will ignore this property.
191 191 *
192 192 * @param b <code>true</code> requests that the border be painted flat;
193 193 * <code>false</code> requests normal borders
194 194 * @see #isBorderPaintedFlat
195 195 * @beaninfo
196 196 * bound: true
197 197 * attribute: visualUpdate true
198 198 * description: Whether the border is painted flat.
199 199 * @since 1.3
200 200 */
201 201 public void setBorderPaintedFlat(boolean b) {
202 202 boolean oldValue = flat;
203 203 flat = b;
204 204 firePropertyChange(BORDER_PAINTED_FLAT_CHANGED_PROPERTY, oldValue, flat);
205 205 if (b != oldValue) {
206 206 revalidate();
207 207 repaint();
208 208 }
209 209 }
210 210
211 211 /**
212 212 * Gets the value of the <code>borderPaintedFlat</code> property.
213 213 *
214 214 * @return the value of the <code>borderPaintedFlat</code> property
215 215 * @see #setBorderPaintedFlat
216 216 * @since 1.3
217 217 */
218 218 public boolean isBorderPaintedFlat() {
219 219 return flat;
220 220 }
221 221
222 222 /**
223 223 * Resets the UI property to a value from the current look and feel.
224 224 *
225 225 * @see JComponent#updateUI
226 226 */
227 227 public void updateUI() {
228 228 setUI((ButtonUI)UIManager.getUI(this));
229 229 }
230 230
231 231
232 232 /**
233 233 * Returns a string that specifies the name of the L&F class
234 234 * that renders this component.
235 235 *
236 236 * @return the string "CheckBoxUI"
237 237 * @see JComponent#getUIClassID
238 238 * @see UIDefaults#getUI
239 239 * @beaninfo
240 240 * expert: true
241 241 * description: A string that specifies the name of the L&F class
242 242 */
243 243 public String getUIClassID() {
244 244 return uiClassID;
245 245 }
246 246
247 247
248 248 /**
249 249 * The icon for checkboxs comes from the look and feel,
250 250 * not the Action; this is overriden to do nothing.
251 251 */
252 252 void setIconFromAction(Action a) {
253 253 }
254 254
255 255 /*
256 256 * See readObject and writeObject in JComponent for more
257 257 * information about serialization in Swing.
258 258 */
259 259 private void writeObject(ObjectOutputStream s) throws IOException {
260 260 s.defaultWriteObject();
261 261 if (getUIClassID().equals(uiClassID)) {
262 262 byte count = JComponent.getWriteObjCounter(this);
263 263 JComponent.setWriteObjCounter(this, --count);
264 264 if (count == 0 && ui != null) {
265 265 ui.installUI(this);
266 266 }
267 267 }
268 268 }
269 269
270 270
271 271 /**
272 272 * See JComponent.readObject() for information about serialization
273 273 * in Swing.
274 274 */
275 275 private void readObject(ObjectInputStream s)
276 276 throws IOException, ClassNotFoundException
277 277 {
278 278 s.defaultReadObject();
279 279 if (getUIClassID().equals(uiClassID)) {
280 280 updateUI();
281 281 }
282 282 }
283 283
284 284
285 285 /**
286 286 * Returns a string representation of this JCheckBox. This method
287 287 * is intended to be used only for debugging purposes, and the
288 288 * content and format of the returned string may vary between
289 289 * implementations. The returned string may be empty but may not
290 290 * be <code>null</code>.
291 291 * specific new aspects of the JFC components.
292 292 *
293 293 * @return a string representation of this JCheckBox.
294 294 */
295 295 protected String paramString() {
296 296 return super.paramString();
297 297 }
298 298
299 299 /////////////////
300 300 // Accessibility support
301 301 ////////////////
302 302
303 303 /**
304 304 * Gets the AccessibleContext associated with this JCheckBox.
305 305 * For JCheckBoxes, the AccessibleContext takes the form of an
306 306 * AccessibleJCheckBox.
307 307 * A new AccessibleJCheckBox instance is created if necessary.
308 308 *
309 309 * @return an AccessibleJCheckBox that serves as the
310 310 * AccessibleContext of this JCheckBox
311 311 * @beaninfo
312 312 * expert: true
313 313 * description: The AccessibleContext associated with this CheckBox.
314 314 */
315 315 public AccessibleContext getAccessibleContext() {
316 316 if (accessibleContext == null) {
317 317 accessibleContext = new AccessibleJCheckBox();
318 318 }
319 319 return accessibleContext;
320 320 }
321 321
322 322 /**
323 323 * This class implements accessibility support for the
324 324 * <code>JCheckBox</code> class. It provides an implementation of the
325 325 * Java Accessibility API appropriate to check box user-interface
326 326 * elements.
327 327 * <p>
328 328 * <strong>Warning:</strong>
329 329 * Serialized objects of this class will not be compatible with
330 330 * future Swing releases. The current serialization support is
331 331 * appropriate for short term storage or RMI between applications running
332 332 * the same version of Swing. As of 1.4, support for long term storage
333 333 * of all JavaBeans™
334 334 * has been added to the <code>java.beans</code> package.
335 335 * Please see {@link java.beans.XMLEncoder}.
336 336 */
337 337 protected class AccessibleJCheckBox extends AccessibleJToggleButton {
338 338
339 339 /**
340 340 * Get the role of this object.
341 341 *
342 342 * @return an instance of AccessibleRole describing the role of the object
343 343 * @see AccessibleRole
344 344 */
345 345 public AccessibleRole getAccessibleRole() {
346 346 return AccessibleRole.CHECK_BOX;
347 347 }
348 348
349 349 } // inner class AccessibleJCheckBox
350 350 }
↓ open down ↓ |
287 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX