author | malenkov |
Wed, 30 Apr 2014 19:28:05 +0400 | |
changeset 24544 | c0133e7c7162 |
parent 23697 | e556a715949f |
child 24969 | afa6934dd8e8 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23697 | 2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 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 |
*/ |
|
23697 | 41 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 42 |
class MultiUIDefaults extends UIDefaults |
43 |
{ |
|
44 |
private UIDefaults[] tables; |
|
45 |
||
46 |
public MultiUIDefaults(UIDefaults[] defaults) { |
|
47 |
super(); |
|
48 |
tables = defaults; |
|
49 |
} |
|
50 |
||
51 |
public MultiUIDefaults() { |
|
52 |
super(); |
|
53 |
tables = new UIDefaults[0]; |
|
54 |
} |
|
55 |
||
2658 | 56 |
@Override |
2 | 57 |
public Object get(Object key) |
58 |
{ |
|
59 |
Object value = super.get(key); |
|
60 |
if (value != null) { |
|
61 |
return value; |
|
62 |
} |
|
63 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
64 |
for (UIDefaults table : tables) { |
2 | 65 |
value = (table != null) ? table.get(key) : null; |
66 |
if (value != null) { |
|
67 |
return value; |
|
68 |
} |
|
69 |
} |
|
70 |
||
71 |
return null; |
|
72 |
} |
|
73 |
||
2658 | 74 |
@Override |
2 | 75 |
public Object get(Object key, Locale l) |
76 |
{ |
|
77 |
Object value = super.get(key,l); |
|
78 |
if (value != null) { |
|
79 |
return value; |
|
80 |
} |
|
81 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
82 |
for (UIDefaults table : tables) { |
2 | 83 |
value = (table != null) ? table.get(key,l) : null; |
84 |
if (value != null) { |
|
85 |
return value; |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
return null; |
|
90 |
} |
|
91 |
||
2658 | 92 |
@Override |
2 | 93 |
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
|
94 |
return entrySet().size(); |
2 | 95 |
} |
96 |
||
2658 | 97 |
@Override |
2 | 98 |
public boolean isEmpty() { |
99 |
return size() == 0; |
|
100 |
} |
|
101 |
||
2658 | 102 |
@Override |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
103 |
public Enumeration<Object> keys() |
2 | 104 |
{ |
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
105 |
return new MultiUIDefaultsEnumerator( |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
106 |
MultiUIDefaultsEnumerator.Type.KEYS, entrySet()); |
2 | 107 |
} |
108 |
||
2658 | 109 |
@Override |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
110 |
public Enumeration<Object> elements() |
2 | 111 |
{ |
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
112 |
return new MultiUIDefaultsEnumerator( |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
113 |
MultiUIDefaultsEnumerator.Type.ELEMENTS, entrySet()); |
2 | 114 |
} |
115 |
||
2658 | 116 |
@Override |
117 |
public Set<Entry<Object, Object>> entrySet() { |
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
set.addAll(tables[i].entrySet()); |
2658 | 122 |
} |
123 |
} |
|
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
124 |
set.addAll(super.entrySet()); |
2658 | 125 |
return set; |
126 |
} |
|
127 |
||
128 |
@Override |
|
2 | 129 |
protected void getUIError(String msg) { |
130 |
if (tables.length > 0) { |
|
131 |
tables[0].getUIError(msg); |
|
132 |
} else { |
|
133 |
super.getUIError(msg); |
|
134 |
} |
|
135 |
} |
|
136 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
137 |
private static class MultiUIDefaultsEnumerator implements Enumeration<Object> |
2 | 138 |
{ |
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
private Type type; |
2 | 142 |
|
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
143 |
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
|
144 |
this.type = type; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
145 |
this.iterator = entries.iterator(); |
2 | 146 |
} |
147 |
||
148 |
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
|
149 |
return iterator.hasNext(); |
2 | 150 |
} |
151 |
||
152 |
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
|
153 |
switch (type) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
154 |
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
|
155 |
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
|
156 |
default: return null; |
2 | 157 |
} |
158 |
} |
|
159 |
} |
|
160 |
||
2658 | 161 |
@Override |
2 | 162 |
public Object remove(Object key) |
163 |
{ |
|
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
164 |
Object value = null; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
if (v != null) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
169 |
value = v; |
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 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
173 |
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
|
174 |
if (v != null) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
175 |
value = v; |
2 | 176 |
} |
177 |
||
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
2658
diff
changeset
|
178 |
return value; |
2 | 179 |
} |
180 |
||
2658 | 181 |
@Override |
2 | 182 |
public void clear() { |
183 |
super.clear(); |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
184 |
for (UIDefaults table : tables) { |
2 | 185 |
if (table != null) { |
186 |
table.clear(); |
|
187 |
} |
|
188 |
} |
|
189 |
} |
|
190 |
||
2658 | 191 |
@Override |
2 | 192 |
public synchronized String toString() { |
193 |
StringBuffer buf = new StringBuffer(); |
|
194 |
buf.append("{"); |
|
195 |
Enumeration keys = keys(); |
|
196 |
while (keys.hasMoreElements()) { |
|
197 |
Object key = keys.nextElement(); |
|
198 |
buf.append(key + "=" + get(key) + ", "); |
|
199 |
} |
|
200 |
int length = buf.length(); |
|
201 |
if (length > 1) { |
|
202 |
buf.delete(length-2, length); |
|
203 |
} |
|
204 |
buf.append("}"); |
|
205 |
return buf.toString(); |
|
206 |
} |
|
207 |
} |