Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/java/awt/CheckboxGroup.java
41152 views
1
/*
2
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
24
*/
25
26
package java.awt;
27
28
import java.io.Serial;
29
30
/**
31
* The {@code CheckboxGroup} class is used to group together
32
* a set of {@code Checkbox} buttons.
33
* <p>
34
* Exactly one check box button in a {@code CheckboxGroup} can
35
* be in the "on" state at any given time. Pushing any
36
* button sets its state to "on" and forces any other button that
37
* is in the "on" state into the "off" state.
38
* <p>
39
* The following code example produces a new check box group,
40
* with three check boxes:
41
*
42
* <hr><blockquote><pre>
43
* setLayout(new GridLayout(3, 1));
44
* CheckboxGroup cbg = new CheckboxGroup();
45
* add(new Checkbox("one", cbg, true));
46
* add(new Checkbox("two", cbg, false));
47
* add(new Checkbox("three", cbg, false));
48
* </pre></blockquote><hr>
49
* <p>
50
* This image depicts the check box group created by this example:
51
* <p>
52
* <img src="doc-files/CheckboxGroup-1.gif" alt="Shows three checkboxes,
53
* arranged vertically, labeled one, two, and three. Checkbox one is in the on
54
* state." style="margin: 7px 10px;">
55
*
56
* @author Sami Shaio
57
* @see java.awt.Checkbox
58
* @since 1.0
59
*/
60
public class CheckboxGroup implements java.io.Serializable {
61
/**
62
* The current choice.
63
* @serial
64
* @see #getCurrent()
65
* @see #setCurrent(Checkbox)
66
*/
67
Checkbox selectedCheckbox = null;
68
69
/**
70
* Use serialVersionUID from JDK 1.1 for interoperability.
71
*/
72
@Serial
73
private static final long serialVersionUID = 3729780091441768983L;
74
75
/**
76
* Creates a new instance of {@code CheckboxGroup}.
77
*/
78
public CheckboxGroup() {
79
}
80
81
/**
82
* Gets the current choice from this check box group.
83
* The current choice is the check box in this
84
* group that is currently in the "on" state,
85
* or {@code null} if all check boxes in the
86
* group are off.
87
* @return the check box that is currently in the
88
* "on" state, or {@code null}.
89
* @see java.awt.Checkbox
90
* @see java.awt.CheckboxGroup#setSelectedCheckbox
91
* @since 1.1
92
*/
93
public Checkbox getSelectedCheckbox() {
94
return getCurrent();
95
}
96
97
/**
98
* Returns the current choice from this check box group
99
* or {@code null} if none of checkboxes are selected.
100
*
101
* @return the selected checkbox
102
* @deprecated As of JDK version 1.1,
103
* replaced by {@code getSelectedCheckbox()}.
104
*/
105
@Deprecated
106
public Checkbox getCurrent() {
107
return selectedCheckbox;
108
}
109
110
/**
111
* Sets the currently selected check box in this group
112
* to be the specified check box.
113
* This method sets the state of that check box to "on" and
114
* sets all other check boxes in the group to be off.
115
* <p>
116
* If the check box argument is {@code null}, all check boxes
117
* in this check box group are deselected. If the check box argument
118
* belongs to a different check box group, this method does
119
* nothing.
120
* @param box the {@code Checkbox} to set as the
121
* current selection.
122
* @see java.awt.Checkbox
123
* @see java.awt.CheckboxGroup#getSelectedCheckbox
124
* @since 1.1
125
*/
126
public void setSelectedCheckbox(Checkbox box) {
127
setCurrent(box);
128
}
129
130
/**
131
* Sets the currently selected check box in this group
132
* to be the specified check box and unsets all others.
133
*
134
* @param box the {@code Checkbox} to set as the
135
* current selection.
136
* @deprecated As of JDK version 1.1,
137
* replaced by {@code setSelectedCheckbox(Checkbox)}.
138
*/
139
@Deprecated
140
public synchronized void setCurrent(Checkbox box) {
141
if (box != null && box.group != this) {
142
return;
143
}
144
Checkbox oldChoice = this.selectedCheckbox;
145
this.selectedCheckbox = box;
146
if (oldChoice != null && oldChoice != box && oldChoice.group == this) {
147
oldChoice.setState(false);
148
}
149
if (box != null && oldChoice != box && !box.getState()) {
150
box.setStateInternal(true);
151
}
152
}
153
154
/**
155
* Returns a string representation of this check box group,
156
* including the value of its current selection.
157
* @return a string representation of this check box group.
158
*/
159
public String toString() {
160
return getClass().getName() + "[selectedCheckbox=" + selectedCheckbox + "]";
161
}
162
163
}
164
165