author | peterz |
Sat, 25 Apr 2009 21:17:50 +0400 | |
changeset 2658 | 43e06bc950ec |
parent 1639 | a97859015238 |
child 4842 | c9f791782a29 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1639 | 2 |
* Copyright 1997-2008 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package javax.swing; |
|
27 |
||
28 |
import java.util.Enumeration; |
|
2658 | 29 |
import java.util.HashSet; |
2 | 30 |
import java.util.Locale; |
2658 | 31 |
import java.util.Map.Entry; |
32 |
import java.util.Set; |
|
2 | 33 |
|
34 |
||
35 |
||
36 |
/** |
|
37 |
* |
|
38 |
* @author Hans Muller |
|
39 |
*/ |
|
40 |
class MultiUIDefaults extends UIDefaults |
|
41 |
{ |
|
42 |
private UIDefaults[] tables; |
|
43 |
||
44 |
public MultiUIDefaults(UIDefaults[] defaults) { |
|
45 |
super(); |
|
46 |
tables = defaults; |
|
47 |
} |
|
48 |
||
49 |
public MultiUIDefaults() { |
|
50 |
super(); |
|
51 |
tables = new UIDefaults[0]; |
|
52 |
} |
|
53 |
||
2658 | 54 |
@Override |
2 | 55 |
public Object get(Object key) |
56 |
{ |
|
57 |
Object value = super.get(key); |
|
58 |
if (value != null) { |
|
59 |
return value; |
|
60 |
} |
|
61 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
62 |
for (UIDefaults table : tables) { |
2 | 63 |
value = (table != null) ? table.get(key) : null; |
64 |
if (value != null) { |
|
65 |
return value; |
|
66 |
} |
|
67 |
} |
|
68 |
||
69 |
return null; |
|
70 |
} |
|
71 |
||
2658 | 72 |
@Override |
2 | 73 |
public Object get(Object key, Locale l) |
74 |
{ |
|
75 |
Object value = super.get(key,l); |
|
76 |
if (value != null) { |
|
77 |
return value; |
|
78 |
} |
|
79 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
80 |
for (UIDefaults table : tables) { |
2 | 81 |
value = (table != null) ? table.get(key,l) : null; |
82 |
if (value != null) { |
|
83 |
return value; |
|
84 |
} |
|
85 |
} |
|
86 |
||
87 |
return null; |
|
88 |
} |
|
89 |
||
2658 | 90 |
@Override |
2 | 91 |
public int size() { |
92 |
int n = super.size(); |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
93 |
for (UIDefaults table : tables) { |
2 | 94 |
n += (table != null) ? table.size() : 0; |
95 |
} |
|
96 |
return n; |
|
97 |
} |
|
98 |
||
2658 | 99 |
@Override |
2 | 100 |
public boolean isEmpty() { |
101 |
return size() == 0; |
|
102 |
} |
|
103 |
||
2658 | 104 |
@Override |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
105 |
public Enumeration<Object> keys() |
2 | 106 |
{ |
107 |
Enumeration[] enums = new Enumeration[1 + tables.length]; |
|
108 |
enums[0] = super.keys(); |
|
109 |
for(int i = 0; i < tables.length; i++) { |
|
110 |
UIDefaults table = tables[i]; |
|
111 |
if (table != null) { |
|
112 |
enums[i + 1] = table.keys(); |
|
113 |
} |
|
114 |
} |
|
115 |
return new MultiUIDefaultsEnumerator(enums); |
|
116 |
} |
|
117 |
||
2658 | 118 |
@Override |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
119 |
public Enumeration<Object> elements() |
2 | 120 |
{ |
121 |
Enumeration[] enums = new Enumeration[1 + tables.length]; |
|
122 |
enums[0] = super.elements(); |
|
123 |
for(int i = 0; i < tables.length; i++) { |
|
124 |
UIDefaults table = tables[i]; |
|
125 |
if (table != null) { |
|
126 |
enums[i + 1] = table.elements(); |
|
127 |
} |
|
128 |
} |
|
129 |
return new MultiUIDefaultsEnumerator(enums); |
|
130 |
} |
|
131 |
||
2658 | 132 |
@Override |
133 |
public Set<Entry<Object, Object>> entrySet() { |
|
134 |
Set<Entry<Object, Object>> set = new HashSet<Entry<Object, Object>>(); |
|
135 |
if (tables == null) return set; |
|
136 |
for (UIDefaults table : tables) { |
|
137 |
if (table != null) { |
|
138 |
set.addAll(table.entrySet()); |
|
139 |
} |
|
140 |
} |
|
141 |
return set; |
|
142 |
} |
|
143 |
||
144 |
@Override |
|
2 | 145 |
protected void getUIError(String msg) { |
146 |
if (tables.length > 0) { |
|
147 |
tables[0].getUIError(msg); |
|
148 |
} else { |
|
149 |
super.getUIError(msg); |
|
150 |
} |
|
151 |
} |
|
152 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
153 |
private static class MultiUIDefaultsEnumerator implements Enumeration<Object> |
2 | 154 |
{ |
155 |
Enumeration[] enums; |
|
156 |
int n = 0; |
|
157 |
||
158 |
MultiUIDefaultsEnumerator(Enumeration[] enums) { |
|
159 |
this.enums = enums; |
|
160 |
} |
|
161 |
||
162 |
public boolean hasMoreElements() { |
|
163 |
for(int i = n; i < enums.length; i++) { |
|
164 |
Enumeration e = enums[i]; |
|
165 |
if ((e != null) && (e.hasMoreElements())) { |
|
166 |
return true; |
|
167 |
} |
|
168 |
} |
|
169 |
return false; |
|
170 |
} |
|
171 |
||
172 |
public Object nextElement() { |
|
173 |
for(; n < enums.length; n++) { |
|
174 |
Enumeration e = enums[n]; |
|
175 |
if ((e != null) && (e.hasMoreElements())) { |
|
176 |
return e.nextElement(); |
|
177 |
} |
|
178 |
} |
|
179 |
return null; |
|
180 |
} |
|
181 |
} |
|
182 |
||
2658 | 183 |
@Override |
2 | 184 |
public Object remove(Object key) |
185 |
{ |
|
186 |
Object value = super.remove(key); |
|
187 |
if (value != null) { |
|
188 |
return value; |
|
189 |
} |
|
190 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
191 |
for (UIDefaults table : tables) { |
2 | 192 |
value = (table != null) ? table.remove(key) : null; |
193 |
if (value != null) { |
|
194 |
return value; |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
return null; |
|
199 |
} |
|
200 |
||
2658 | 201 |
@Override |
2 | 202 |
public void clear() { |
203 |
super.clear(); |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
204 |
for (UIDefaults table : tables) { |
2 | 205 |
if (table != null) { |
206 |
table.clear(); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
||
2658 | 211 |
@Override |
2 | 212 |
public synchronized String toString() { |
213 |
StringBuffer buf = new StringBuffer(); |
|
214 |
buf.append("{"); |
|
215 |
Enumeration keys = keys(); |
|
216 |
while (keys.hasMoreElements()) { |
|
217 |
Object key = keys.nextElement(); |
|
218 |
buf.append(key + "=" + get(key) + ", "); |
|
219 |
} |
|
220 |
int length = buf.length(); |
|
221 |
if (length > 1) { |
|
222 |
buf.delete(length-2, length); |
|
223 |
} |
|
224 |
buf.append("}"); |
|
225 |
return buf.toString(); |
|
226 |
} |
|
227 |
} |