author | hseigel |
Wed, 01 Mar 2017 08:00:02 -0500 | |
changeset 46194 | 5596e6f63072 |
parent 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
4 |
* |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
8 |
* |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
13 |
* accompanied this code). |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
14 |
* |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
18 |
* |
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
4842
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
22 |
*/ |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
23 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
24 |
/* @test |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
25 |
@bug 6860438 |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
26 |
@summary Tests various MultiUIDefaults methods |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
27 |
@author Peter Zhelezniakov |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
28 |
@run main Test6860438 |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
29 |
*/ |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
30 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
31 |
import java.util.Enumeration; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
32 |
import java.util.Map.Entry; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
33 |
import java.util.Set; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
34 |
import javax.swing.UIManager; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
35 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
36 |
public class Test6860438 |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
37 |
{ |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
38 |
static final String KEY = "Test6860438.key"; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
39 |
static final String VALUE = "Test6860438.value"; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
40 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
41 |
void check(Object key, Object value, boolean present, int size) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
42 |
check(UIManager.get(key) == value, "UIManager.get()"); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
43 |
check(UIManager.getDefaults().size() == size, "MultiUIDefaults.size()"); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
44 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
45 |
checkEnumeration(UIManager.getDefaults().keys(), |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
46 |
key, present, "MultiUIDefaults.keys()"); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
47 |
checkEnumeration(UIManager.getDefaults().elements(), |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
48 |
value, present, "MultiUIDefaults.elements()"); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
49 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
50 |
// check MultiUIDefaults.entrySet() |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
51 |
boolean found = false; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
52 |
Set<Entry<Object, Object>> entries = UIManager.getDefaults().entrySet(); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
53 |
for (Entry<Object, Object> e: entries) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
54 |
if (e.getKey() == key) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
55 |
check(e.getValue() == value, "MultiUIDefaults.entrySet()"); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
56 |
found = true; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
57 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
58 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
59 |
check(found == present, "MultiUIDefaults.entrySet()"); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
60 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
61 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
62 |
void checkEnumeration(Enumeration<Object> e, Object elem, |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
63 |
boolean present, String error) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
64 |
boolean found = false; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
65 |
while (e.hasMoreElements()) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
66 |
if (e.nextElement() == elem) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
67 |
found = true; |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
68 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
69 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
70 |
check(found == present, error); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
71 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
72 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
73 |
void check(boolean condition, String methodName) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
74 |
if (! condition) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
75 |
throw new RuntimeException(methodName + " failed"); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
76 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
77 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
78 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
79 |
void test() { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
80 |
int size = UIManager.getDefaults().size(); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
81 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
82 |
// create a new value, size increases |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
83 |
UIManager.getLookAndFeelDefaults().put(KEY, VALUE); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
84 |
check(KEY, VALUE, true, size + 1); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
85 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
86 |
// override the value, size remains the same |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
87 |
UIManager.put(KEY, VALUE); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
88 |
check(KEY, VALUE, true, size + 1); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
89 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
90 |
// remove the value, size decreases |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
91 |
UIManager.getDefaults().remove(KEY); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
92 |
check(KEY, null, false, size); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
93 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
94 |
|
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
95 |
public static void main(String[] args) { |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
96 |
new Test6860438().test(); |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
97 |
} |
c9f791782a29
6860438: [Nimbus] Code to globally set slider's thumb background doesn't work as specified
peterz
parents:
diff
changeset
|
98 |
} |