author | hseigel |
Wed, 01 Mar 2017 08:00:02 -0500 | |
changeset 46194 | 5596e6f63072 |
parent 40128 | e635645d2a8a |
permissions | -rw-r--r-- |
32488
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
1 |
/* |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
4 |
* |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
8 |
* |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
13 |
* accompanied this code). |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
14 |
* |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
18 |
* |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
21 |
* questions. |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
22 |
*/ |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
23 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
24 |
import java.awt.Color; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
25 |
import java.awt.Component; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
26 |
import java.awt.Container; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
27 |
import java.awt.Frame; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
28 |
import java.awt.Robot; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
29 |
import java.awt.event.KeyEvent; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
30 |
import java.util.function.Predicate; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
31 |
import javax.swing.JColorChooser; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
32 |
import javax.swing.JFormattedTextField; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
33 |
import javax.swing.JFrame; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
34 |
import javax.swing.JTabbedPane; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
35 |
import javax.swing.SwingUtilities; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
36 |
import javax.swing.colorchooser.AbstractColorChooserPanel; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
37 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
38 |
/* |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
39 |
* @test |
40128
e635645d2a8a
8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents:
32488
diff
changeset
|
40 |
* @key headful |
32488
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
41 |
* @bug 8051548 |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
42 |
* @summary JColorChooser should have a way to disable transparency controls |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
43 |
* @author Alexandr Scherbatiy |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
44 |
* @run main Test8051548 |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
45 |
*/ |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
46 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
47 |
public class Test8051548 { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
48 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
49 |
private static final String[][] TABS = { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
50 |
{"HSV", "0"}, |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
51 |
{"HSL", "0"}, |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
52 |
{"RGB", "255"}, |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
53 |
{"CMYK", "255"} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
54 |
}; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
55 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
56 |
private static JColorChooser colorChooser; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
57 |
private static boolean propertyChangeListenerInvoked; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
58 |
private static volatile Color color; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
59 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
60 |
public static void main(String[] args) throws Exception { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
61 |
testColorPanels(); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
62 |
testShowDialog(true); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
63 |
testShowDialog(false); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
64 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
65 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
66 |
private static void testColorPanels() throws Exception { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
67 |
SwingUtilities.invokeAndWait(() -> createAndShowGUI()); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
68 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
69 |
Robot robot = new Robot(); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
70 |
robot.setAutoDelay(50); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
71 |
robot.waitForIdle(); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
72 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
73 |
for (String[] tabs : TABS) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
74 |
final String tab = tabs[0]; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
75 |
final String initialValue = tabs[1]; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
76 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
77 |
SwingUtilities.invokeAndWait(() -> { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
78 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
79 |
colorChooser.setColor(new Color(50, 100, 85)); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
80 |
JTabbedPane tabbedPane = |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
81 |
(JTabbedPane) findComponent(colorChooser, "JTabbedPane"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
82 |
int index = tabbedPane.indexOfTab(tab); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
83 |
tabbedPane.setSelectedIndex(index); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
84 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
85 |
AbstractColorChooserPanel colorChooserPanel |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
86 |
= (AbstractColorChooserPanel) findComponent( |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
87 |
tabbedPane.getComponent(index), "ColorChooserPanel"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
88 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
89 |
propertyChangeListenerInvoked = false; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
90 |
colorChooserPanel.addPropertyChangeListener((e) -> { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
91 |
if (AbstractColorChooserPanel.TRANSPARENCY_ENABLED_PROPERTY. |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
92 |
equals(e.getPropertyName())) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
93 |
propertyChangeListenerInvoked = true; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
94 |
if(!(Boolean)e.getOldValue()){ |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
95 |
throw new RuntimeException("Old color transparency" |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
96 |
+ " selection property should be true!"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
97 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
98 |
if((Boolean)e.getNewValue()){ |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
99 |
throw new RuntimeException("New color transparency" |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
100 |
+ " selection property should be false!"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
101 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
102 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
103 |
}); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
104 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
105 |
if (!colorChooserPanel.isColorTransparencySelectionEnabled()) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
106 |
throw new RuntimeException("Color transparency selection" |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
107 |
+ " should be enabled by default"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
108 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
109 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
110 |
JFormattedTextField transparencyTextField = (JFormattedTextField) |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
111 |
findTextField(colorChooserPanel, initialValue); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
112 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
113 |
if (!transparencyTextField.isEnabled()) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
114 |
throw new RuntimeException("Transparency controls are" |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
115 |
+ " disabled by default!"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
116 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
117 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
118 |
transparencyTextField.setValue(50); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
119 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
120 |
if(!colorHasAlpha()){ |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
121 |
throw new RuntimeException("Transparency selection should" |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
122 |
+ " be enabled!"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
123 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
124 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
125 |
colorChooserPanel.setColorTransparencySelectionEnabled(false); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
126 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
127 |
if (colorChooserPanel.isColorTransparencySelectionEnabled()) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
128 |
throw new RuntimeException("Color transparency selection" |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
129 |
+ " should be disabled!"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
130 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
131 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
132 |
if(!propertyChangeListenerInvoked){ |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
133 |
throw new RuntimeException("Property change listener is not" |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
134 |
+ " invoked!"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
135 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
136 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
137 |
if(colorHasAlpha()){ |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
138 |
throw new RuntimeException("Transparency selection should" |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
139 |
+ " be disabled!"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
140 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
141 |
}); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
142 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
143 |
robot.waitForIdle(); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
144 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
145 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
146 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
147 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
148 |
static void testShowDialog(boolean colorTransparencySelectionEnabled) throws Exception { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
149 |
int alphaValue = 123; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
150 |
Robot robot = new Robot(); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
151 |
robot.setAutoDelay(50); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
152 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
153 |
SwingUtilities.invokeLater(() -> { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
154 |
color = JColorChooser.showDialog(null, "Change Color", |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
155 |
new Color(10, 20, 30, alphaValue), |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
156 |
colorTransparencySelectionEnabled); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
157 |
}); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
158 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
159 |
SwingUtilities.invokeAndWait(() -> { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
160 |
// wait for dialog is shown |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
161 |
}); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
162 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
163 |
robot.waitForIdle(); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
164 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
165 |
robot.keyPress(KeyEvent.VK_ENTER); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
166 |
robot.keyRelease(KeyEvent.VK_ENTER); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
167 |
robot.waitForIdle(); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
168 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
169 |
if (colorTransparencySelectionEnabled) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
170 |
if (color.getAlpha() != alphaValue) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
171 |
throw new RuntimeException("Color alpha has not bee reseted!"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
172 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
173 |
} else { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
174 |
if (color.getAlpha() != 255) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
175 |
throw new RuntimeException("Color alpha has not bee reseted!"); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
176 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
177 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
178 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
179 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
180 |
private static boolean colorHasAlpha(){ |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
181 |
return colorChooser.getColor().getAlpha() != 255; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
182 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
183 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
184 |
private static void createAndShowGUI() { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
185 |
JFrame frame = new JFrame(); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
186 |
frame.setSize(700, 500); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
187 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
188 |
colorChooser = new JColorChooser(); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
189 |
frame.getContentPane().add(colorChooser); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
190 |
frame.setVisible(true); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
191 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
192 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
193 |
private static Component findComponent(Component component, String name) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
194 |
return findComponent(component, |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
195 |
(comp) -> comp.getClass().getName().contains(name)); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
196 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
197 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
198 |
private static Component findTextField(Component component, String value) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
199 |
return findComponent(component, (comp) -> { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
200 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
201 |
if (comp instanceof JFormattedTextField) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
202 |
JFormattedTextField textField = (JFormattedTextField) comp; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
203 |
return value.equals(textField.getText()); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
204 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
205 |
return false; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
206 |
}); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
207 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
208 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
209 |
private static Component findComponent(Component component, |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
210 |
Predicate<Component> predicate) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
211 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
212 |
if (predicate.test(component)) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
213 |
return component; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
214 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
215 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
216 |
if (component instanceof Container) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
217 |
Container container = (Container) component; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
218 |
for (int i = 0; i < container.getComponentCount(); i++) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
219 |
Component child = findComponent(container.getComponent(i), |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
220 |
predicate); |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
221 |
if (child != null) { |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
222 |
return child; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
223 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
224 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
225 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
226 |
|
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
227 |
return null; |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
228 |
} |
02db7857c66d
8051548: JColorChooser should have a way to disable transparency controls
alexsch
parents:
diff
changeset
|
229 |
} |