Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/javax/accessibility/AccessibleStateSet.java
41153 views
1
/*
2
* Copyright (c) 1997, 2017, 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 javax.accessibility;
27
28
import java.util.Vector;
29
30
/**
31
* Class {@code AccessibleStateSet} determines a component's state set. The
32
* state set of a component is a set of {@code AccessibleState} objects and
33
* descriptions. E.G., The current overall state of the object, such as whether
34
* it is enabled, has focus, etc.
35
*
36
* @author Willie Walker
37
* @see AccessibleState
38
*/
39
public class AccessibleStateSet {
40
41
/**
42
* Each entry in the {@code Vector} represents an {@code AccessibleState}.
43
*
44
* @see #add
45
* @see #addAll
46
* @see #remove
47
* @see #contains
48
* @see #toArray
49
* @see #clear
50
*/
51
protected Vector<AccessibleState> states = null;
52
53
/**
54
* Creates a new empty state set.
55
*/
56
public AccessibleStateSet() {
57
states = null;
58
}
59
60
/**
61
* Creates a new state with the initial set of states contained in the array
62
* of states passed in. Duplicate entries are ignored.
63
*
64
* @param states an array of {@code AccessibleState} describing the state
65
* set
66
*/
67
public AccessibleStateSet(AccessibleState[] states) {
68
if (states.length != 0) {
69
this.states = new Vector<>(states.length);
70
for (int i = 0; i < states.length; i++) {
71
if (!this.states.contains(states[i])) {
72
this.states.addElement(states[i]);
73
}
74
}
75
}
76
}
77
78
/**
79
* Adds a new state to the current state set if it is not already present.
80
* If the state is already in the state set, the state set is unchanged and
81
* the return value is {@code false}. Otherwise, the state is added to the
82
* state set and the return value is {@code true}.
83
*
84
* @param state the state to add to the state set
85
* @return {@code true} if state is added to the state set; {@code false} if
86
* the state set is unchanged
87
*/
88
public boolean add(AccessibleState state) {
89
// [[[ PENDING: WDW - the implementation of this does not need
90
// to always use a vector of states. It could be improved by
91
// caching the states as a bit set.]]]
92
if (states == null) {
93
states = new Vector<>();
94
}
95
96
if (!states.contains(state)) {
97
states.addElement(state);
98
return true;
99
} else {
100
return false;
101
}
102
}
103
104
/**
105
* Adds all of the states to the existing state set. Duplicate entries are
106
* ignored.
107
*
108
* @param states {@code AccessibleState} array describing the state set
109
*/
110
public void addAll(AccessibleState[] states) {
111
if (states.length != 0) {
112
if (this.states == null) {
113
this.states = new Vector<>(states.length);
114
}
115
for (int i = 0; i < states.length; i++) {
116
if (!this.states.contains(states[i])) {
117
this.states.addElement(states[i]);
118
}
119
}
120
}
121
}
122
123
/**
124
* Removes a state from the current state set. If the state is not in the
125
* set, the state set will be unchanged and the return value will be
126
* {@code false}. If the state is in the state set, it will be removed from
127
* the set and the return value will be {@code true}.
128
*
129
* @param state the state to remove from the state set
130
* @return {@code true} if the state is in the state set; {@code false} if
131
* the state set will be unchanged
132
*/
133
public boolean remove(AccessibleState state) {
134
if (states == null) {
135
return false;
136
} else {
137
return states.removeElement(state);
138
}
139
}
140
141
/**
142
* Removes all the states from the current state set.
143
*/
144
public void clear() {
145
if (states != null) {
146
states.removeAllElements();
147
}
148
}
149
150
/**
151
* Checks if the current state is in the state set.
152
*
153
* @param state the state
154
* @return {@code true} if the state is in the state set; otherwise
155
* {@code false}
156
*/
157
public boolean contains(AccessibleState state) {
158
if (states == null) {
159
return false;
160
} else {
161
return states.contains(state);
162
}
163
}
164
165
/**
166
* Returns the current state set as an array of {@code AccessibleState}.
167
*
168
* @return {@code AccessibleState} array containing the current state
169
*/
170
public AccessibleState[] toArray() {
171
if (states == null) {
172
return new AccessibleState[0];
173
} else {
174
AccessibleState[] stateArray = new AccessibleState[states.size()];
175
for (int i = 0; i < stateArray.length; i++) {
176
stateArray[i] = states.elementAt(i);
177
}
178
return stateArray;
179
}
180
}
181
182
/**
183
* Creates a localized string representing all the states in the set using
184
* the default locale.
185
*
186
* @return comma separated localized string
187
* @see AccessibleBundle#toDisplayString
188
*/
189
public String toString() {
190
String ret = null;
191
if ((states != null) && (states.size() > 0)) {
192
ret = states.elementAt(0).toDisplayString();
193
for (int i = 1; i < states.size(); i++) {
194
ret = ret + ","
195
+ states.elementAt(i).toDisplayString();
196
}
197
}
198
return ret;
199
}
200
}
201
202