Skip to content

Commit b920d29

Browse files
kumarabhi006prsadhuk
authored andcommitted
8271328: User is able to choose the color after disabling the color chooser.
Reviewed-by: psadhukhan, tr
1 parent 5725a93 commit b920d29

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKColorChooserPanel.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ static void compositeRequestFocus(Component component, boolean direction) {
104104
component.requestFocus();
105105
}
106106

107+
@Override
108+
public void setEnabled(boolean enabled) {
109+
super.setEnabled(enabled);
110+
setEnabled(this, enabled);
111+
}
112+
113+
private static void setEnabled(Container container, boolean enabled) {
114+
for (Component component : container.getComponents()) {
115+
component.setEnabled(enabled);
116+
if (component instanceof Container) {
117+
setEnabled((Container) component, enabled);
118+
}
119+
}
120+
}
107121

108122
/**
109123
* Returns a user presentable description of this GTKColorChooserPane.
@@ -674,6 +688,11 @@ int getColorY() {
674688
}
675689

676690
protected void processEvent(AWTEvent e) {
691+
692+
if (!(getGTKColorChooserPanel().isEnabled())) {
693+
return;
694+
}
695+
677696
if (e.getID() == MouseEvent.MOUSE_PRESSED ||
678697
((isSet(FLAGS_DRAGGING) ||isSet(FLAGS_DRAGGING_TRIANGLE)) &&
679698
e.getID() == MouseEvent.MOUSE_DRAGGED)) {
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
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.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
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.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8271328
27+
* @key headful
28+
* @requires (os.family == "linux")
29+
* @summary Verifies if user is not able to select color from disabled ColorChooser
30+
* @run main TestDisabledColorChooser
31+
*/
32+
33+
import java.awt.Color;
34+
import java.awt.event.InputEvent;
35+
import java.awt.event.ItemEvent;
36+
import java.awt.event.ItemListener;
37+
import java.awt.Point;
38+
import java.awt.Robot;
39+
import javax.swing.JColorChooser;
40+
import javax.swing.JFrame;
41+
import javax.swing.SwingUtilities;
42+
import javax.swing.UIManager;
43+
44+
public class TestDisabledColorChooser {
45+
private static JFrame frame;
46+
private static JColorChooser Colorchooser;
47+
48+
public TestDisabledColorChooser() {
49+
createAndShowUI();
50+
}
51+
52+
public static void main(String[] args) throws Exception {
53+
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
54+
Robot robot = new Robot();
55+
robot.setAutoDelay(100);
56+
try {
57+
SwingUtilities.invokeAndWait(() -> {
58+
new TestDisabledColorChooser();
59+
});
60+
61+
robot.waitForIdle();
62+
robot.delay(1000);
63+
64+
Point pt = frame.getLocationOnScreen();
65+
robot.mouseMove(pt.x+75, pt.y+frame.getHeight()/2);
66+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
67+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
68+
Color c1 = Colorchooser.getColor();
69+
70+
Colorchooser.setEnabled(false);
71+
robot.mouseMove(pt.x+85, pt.y+frame.getHeight()/2);
72+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
73+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
74+
Color c2 = Colorchooser.getColor();
75+
robot.delay(1000);
76+
77+
if (c1.getRGB() != c2.getRGB())
78+
throw new RuntimeException("User is able to select color after disabling ColorChooser");
79+
else
80+
System.out.println("passed");
81+
} finally {
82+
SwingUtilities.invokeAndWait(() -> {
83+
if (frame != null) {
84+
frame.dispose();
85+
}
86+
});
87+
}
88+
}
89+
90+
private void createAndShowUI() {
91+
frame = new JFrame("Test Disabled ColorChooser Color Selection");
92+
Colorchooser = new JColorChooser();
93+
frame.add(Colorchooser);
94+
frame.pack();
95+
frame.setLocationRelativeTo(null);
96+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
97+
frame.setVisible(true);
98+
}
99+
}

0 commit comments

Comments
 (0)