author | duke |
Wed, 05 Jul 2017 19:21:47 +0200 | |
changeset 21538 | a2533d997389 |
parent 6105 | de4af6e215ad |
permissions | -rw-r--r-- |
6105
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
1 |
/* |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
4 |
* |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
8 |
* |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
13 |
* accompanied this code). |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
14 |
* |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
18 |
* |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
21 |
* questions. |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
22 |
*/ |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
23 |
|
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
24 |
/* |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
25 |
* @test |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
26 |
* @bug 6199676 |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
27 |
* @summary Tests preview panel after L&F changing |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
28 |
* @author Sergey Malenkov |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
29 |
*/ |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
30 |
|
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
31 |
import java.awt.Component; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
32 |
import java.awt.Container; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
33 |
import javax.swing.JColorChooser; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
34 |
import javax.swing.JFrame; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
35 |
import javax.swing.JPanel; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
36 |
import javax.swing.SwingUtilities; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
37 |
import javax.swing.UIManager; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
38 |
import javax.swing.UIManager.LookAndFeelInfo; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
39 |
|
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
40 |
public class Test6199676 implements Runnable { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
41 |
public static void main(String[] args) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
42 |
SwingUtilities.invokeLater(new Test6199676()); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
43 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
44 |
|
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
45 |
private static void exit(String error) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
46 |
if (error != null) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
47 |
System.err.println(error); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
48 |
System.exit(1); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
49 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
50 |
else { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
51 |
System.exit(0); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
52 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
53 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
54 |
|
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
55 |
private static Component getPreview(Container container) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
56 |
String name = "ColorChooser.previewPanelHolder"; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
57 |
for (Component component : container.getComponents()) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
58 |
if (!name.equals(component.getName())) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
59 |
component = (component instanceof Container) |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
60 |
? getPreview((Container) component) |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
61 |
: null; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
62 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
63 |
if (component instanceof Container) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
64 |
container = (Container) component; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
65 |
return 1 == container.getComponentCount() |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
66 |
? container.getComponent(0) |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
67 |
: null; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
68 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
69 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
70 |
return null; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
71 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
72 |
|
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
73 |
private static boolean isShowing(Component component) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
74 |
return (component != null) && component.isShowing(); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
75 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
76 |
|
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
77 |
private int index; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
78 |
private boolean updated; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
79 |
private JColorChooser chooser; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
80 |
|
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
81 |
public synchronized void run() { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
82 |
if (this.chooser == null) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
83 |
this.chooser = new JColorChooser(); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
84 |
|
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
85 |
JFrame frame = new JFrame(getClass().getName()); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
86 |
frame.add(this.chooser); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
87 |
frame.setVisible(true); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
88 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
89 |
else if (this.updated) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
90 |
if (isShowing(this.chooser.getPreviewPanel())) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
91 |
exit("custom preview panel is showing"); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
92 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
93 |
exit(null); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
94 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
95 |
else { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
96 |
Component component = this.chooser.getPreviewPanel(); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
97 |
if (component == null) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
98 |
component = getPreview(this.chooser); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
99 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
100 |
if (!isShowing(component)) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
101 |
exit("default preview panel is not showing"); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
102 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
103 |
this.updated = true; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
104 |
this.chooser.setPreviewPanel(new JPanel()); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
105 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
106 |
LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels(); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
107 |
LookAndFeelInfo info = infos[++this.index % infos.length]; |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
108 |
try { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
109 |
UIManager.setLookAndFeel(info.getClassName()); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
110 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
111 |
catch (Exception exception) { |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
112 |
exit("could not change L&F"); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
113 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
114 |
SwingUtilities.updateComponentTreeUI(this.chooser); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
115 |
SwingUtilities.invokeLater(this); |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
116 |
} |
de4af6e215ad
6199676: REGRESSION: ColorChooser loses preview when change LandF in Java5
malenkov
parents:
diff
changeset
|
117 |
} |