author | peterz |
Fri, 25 Dec 2009 17:47:08 +0300 | |
changeset 4842 | c9f791782a29 |
parent 2658 | 43e06bc950ec |
child 5506 | 202f599c92aa |
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; |
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
30 |
import java.util.Iterator; |
2 | 31 |
import java.util.Locale; |
2658 | 32 |
import java.util.Map.Entry; |
33 |
import java.util.Set; |
|
2 | 34 |
|
35 |
||
36 |
||
37 |
/** |
|
38 |
* |
|
39 |
* @author Hans Muller |
|
40 |
*/ |
|
41 |
class MultiUIDefaults extends UIDefaults |
|
42 |
{ |
|
43 |
private UIDefaults[] tables; |
|
44 |
||
45 |
public MultiUIDefaults(UIDefaults[] defaults) { |
|
46 |
super(); |
|
47 |
tables = defaults; |
|
48 |
} |
|
49 |
||
50 |
public MultiUIDefaults() { |
|
51 |
super(); |
|
52 |
tables = new UIDefaults[0]; |
|
53 |
} |
|
54 |
||
2658 | 55 |
@Override |
2 | 56 |
public Object get(Object key) |
57 |
{ |
|
58 |
Object value = super.get(key); |
|
59 |
if (value != null) { |
|
60 |
return value; |
|
61 |
} |
|
62 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
63 |
for (UIDefaults table : tables) { |
2 | 64 |
value = (table != null) ? table.get(key) : null; |
65 |
if (value != null) { |
|
66 |
return value; |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
return null; |
|
71 |
} |
|
72 |
||
2658 | 73 |
@Override |
2 | 74 |
public Object get(Object key, Locale l) |
75 |
{ |
|
76 |
Object value = super.get(key,l); |
|
77 |
if (value != null) { |
|
78 |
return value; |
|
79 |
} |
|
80 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
81 |
for (UIDefaults table : tables) { |
2 | 82 |
value = (table != null) ? table.get(key,l) : null; |
83 |
if (value != null) { |
|
84 |
return value; |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
return null; |
|
89 |
} |
|
90 |
||
2658 | 91 |
@Override |
2 | 92 |
public int size() { |
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
93 |
return entrySet().size(); |
2 | 94 |
} |
95 |
||
2658 | 96 |
@Override |
2 | 97 |
public boolean isEmpty() { |
98 |
return size() == 0; |
|
99 |
} |
|
100 |
||
2658 | 101 |
@Override |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
102 |
public Enumeration<Object> keys() |
2 | 103 |
{ |
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
104 |
return new MultiUIDefaultsEnumerator( |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
105 |
MultiUIDefaultsEnumerator.Type.KEYS, entrySet()); |
2 | 106 |
} |
107 |
||
2658 | 108 |
@Override |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
109 |
public Enumeration<Object> elements() |
2 | 110 |
{ |
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
111 |
return new MultiUIDefaultsEnumerator( |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
112 |
MultiUIDefaultsEnumerator.Type.ELEMENTS, entrySet()); |
2 | 113 |
} |
114 |
||
2658 | 115 |
@Override |
116 |
public Set<Entry<Object, Object>> entrySet() { |
|
117 |
Set<Entry<Object, Object>> set = new HashSet<Entry<Object, Object>>(); |
|
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
118 |
for (int i = tables.length - 1; i >= 0; i--) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
119 |
if (tables[i] != null) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
120 |
set.addAll(tables[i].entrySet()); |
2658 | 121 |
} |
122 |
} |
|
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
123 |
set.addAll(super.entrySet()); |
2658 | 124 |
return set; |
125 |
} |
|
126 |
||
127 |
@Override |
|
2 | 128 |
protected void getUIError(String msg) { |
129 |
if (tables.length > 0) { |
|
130 |
tables[0].getUIError(msg); |
|
131 |
} else { |
|
132 |
super.getUIError(msg); |
|
133 |
} |
|
134 |
} |
|
135 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
136 |
private static class MultiUIDefaultsEnumerator implements Enumeration<Object> |
2 | 137 |
{ |
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
138 |
public static enum Type { KEYS, ELEMENTS }; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
139 |
private Iterator<Entry<Object, Object>> iterator; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
140 |
private Type type; |
2 | 141 |
|
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
142 |
MultiUIDefaultsEnumerator(Type type, Set<Entry<Object, Object>> entries) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
143 |
this.type = type; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
144 |
this.iterator = entries.iterator(); |
2 | 145 |
} |
146 |
||
147 |
public boolean hasMoreElements() { |
|
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
148 |
return iterator.hasNext(); |
2 | 149 |
} |
150 |
||
151 |
public Object nextElement() { |
|
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
152 |
switch (type) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
153 |
case KEYS: return iterator.next().getKey(); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
154 |
case ELEMENTS: return iterator.next().getValue(); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
155 |
default: return null; |
2 | 156 |
} |
157 |
} |
|
158 |
} |
|
159 |
||
2658 | 160 |
@Override |
2 | 161 |
public Object remove(Object key) |
162 |
{ |
|
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
163 |
Object value = null; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
164 |
for (int i = tables.length - 1; i >= 0; i--) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
165 |
if (tables[i] != null) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
166 |
Object v = tables[i].remove(key); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
167 |
if (v != null) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
168 |
value = v; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
169 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
170 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
171 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
172 |
Object v = super.remove(key); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
173 |
if (v != null) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
174 |
value = v; |
2 | 175 |
} |
176 |
||
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
177 |
return value; |
2 | 178 |
} |
179 |
||
2658 | 180 |
@Override |
2 | 181 |
public void clear() { |
182 |
super.clear(); |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
183 |
for (UIDefaults table : tables) { |
2 | 184 |
if (table != null) { |
185 |
table.clear(); |
|
186 |
} |
|
187 |
} |
|
188 |
} |
|
189 |
||
2658 | 190 |
@Override |
2 | 191 |
public synchronized String toString() { |
192 |
StringBuffer buf = new StringBuffer(); |
|
193 |
buf.append("{"); |
|
194 |
Enumeration keys = keys(); |
|
195 |
while (keys.hasMoreElements()) { |
|
196 |
Object key = keys.nextElement(); |
|
197 |
buf.append(key + "=" + get(key) + ", "); |
|
198 |
} |
|
199 |
int length = buf.length(); |
|
200 |
if (length > 1) { |
|
201 |
buf.delete(length-2, length); |
|
202 |
} |
|
203 |
buf.append("}"); |
|
204 |
return buf.toString(); |
|
205 |
} |
|
206 |
} |