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 import javax.swing.*;
25 import java.awt.*;
26 import java.awt.event.MouseAdapter;
27 import java.awt.event.MouseEvent;
28
29 /*
30 * @test
31 * @key headful
32 * @bug 8024627
33 * @summary Check if a JComboBox present in a window set with opacity less than
34 * 1.0 shows a translucent drop down
35 * Test Description: Check if TRANSLUCENT translucency type is supported on the
36 * current platform. Proceed if supported. Show a window which contains an
37 * JComboBox and set with opacity less than 1.0. Another Window having a canvas
38 * component drawn with an image can be used as the background for the test
39 * window. Click on the ComboBox to show the drop down. Check if the drop down
40 * appears translucent. Repeat this for JWindow, JDialog and JFrame
41 * Expected Result: If TRANSLUCENT Translucency type is supported, the drop down
42 * should appear translucent.
43 * @author mrkam
44 * @library ../../../../lib/testlibrary
45 * @build Common ExtendedRobot
46 * @run main TranslucentJComboBox
47 */
48
49 public class TranslucentJComboBox extends Common {
50
51 JComponent south;
52 JComponent center;
53 JPanel north;
54 volatile boolean southClicked = false;
55
56 public static void main(String[] args) throws Exception {
57 if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.TRANSLUCENT))
58 for (Class<Window> windowClass: WINDOWS_TO_TEST)
59 new TranslucentJComboBox(windowClass).doTest();
60 }
61
62 public TranslucentJComboBox(Class windowClass) throws Exception {
63 super(windowClass, 0.3f, 1.0f, false);
64 }
65
66 @Override
67 public void initBackgroundFrame() {
68 super.initBackgroundFrame();
69 }
70
71 @Override
72 public void createSwingComponents() {
73 Container contentPane = RootPaneContainer.class.cast(window).getContentPane();
74 window.setLayout(new BorderLayout());
75
76 north = new JPanel();
77 contentPane.add(north, BorderLayout.NORTH);
78
79 center = new JList(new String [] { "Center" });
80 contentPane.add(center, BorderLayout.CENTER);
81
82 JComboBox jComboBox = new JComboBox();
83 for(int i = 0; i < 20; i++) {
84 jComboBox.addItem("item " + i);
85 }
86 south = jComboBox;
87
88 south.addMouseListener(new MouseAdapter() {
89 @Override
90 public void mouseClicked(MouseEvent e) {
91 southClicked = true;
92 }
93 });
94 contentPane.add(south, BorderLayout.SOUTH);
95 }
96
97
98 @Override
99 public void doTest() throws Exception {
100 robot.waitForIdle(delay);
101 // Make window an active
102 Point ls = north.getLocationOnScreen();
103 robot.mouseMove(ls.x + north.getWidth()/2, ls.y + north.getHeight()/2);
104 robot.click();
105
106 // Invoke list
125
126 robot.mouseMove(x, y);
127 robot.waitForIdle(delay);
128 robot.click();
129 robot.waitForIdle(delay);
130
131 if (!southClicked)
132 throw new RuntimeException("Flag is not triggered for point "+x+", "+y+"!");
133
134 robot.waitForIdle();
135
136 Color c1b = robot.getPixelColor(p1.x, p1.y);
137 Color c2b = robot.getPixelColor(p2.x, p2.y);
138
139 if (!c1.equals(c1b) && !south.getBackground().equals(c1b))
140 throw new RuntimeException(
141 "Check for opaque drop down failed at point " + p1 +
142 ". Before click: " + c1 + ", after click: " + c1b +
143 ", expected is " + south.getBackground());
144
145 if (!c2.equals(c2b) && !south.getBackground().equals(c2b))
146 throw new RuntimeException(
147 "Check for opaque drop down failed at point " + p2 +
148 ". Before click: " + c2 + ", after click: " + c2b +
149 ", expected is " + south.getBackground());
150
151 EventQueue.invokeAndWait(this::dispose);
152 }
153 }
|
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 import javax.swing.JComponent;
25 import javax.swing.JPanel;
26 import javax.swing.RootPaneContainer;
27 import javax.swing.JList;
28 import javax.swing.JComboBox;
29 import javax.swing.JPopupMenu;
30 import javax.swing.event.PopupMenuEvent;
31 import javax.swing.event.PopupMenuListener;
32 import java.awt.GraphicsDevice;
33 import java.awt.Container;
34 import java.awt.BorderLayout;
35 import java.awt.Point;
36 import java.awt.Color;
37 import java.awt.Window;
38 import java.awt.EventQueue;
39 import java.awt.event.MouseAdapter;
40 import java.awt.event.MouseEvent;
41
42 /*
43 * @test
44 * @key headful
45 * @bug 8024627
46 * @summary Check if a JComboBox present in a window set with opacity less than
47 * 1.0 shows a translucent drop down
48 * Test Description: Check if TRANSLUCENT translucency type is supported on the
49 * current platform. Proceed if supported. Show a window which contains an
50 * JComboBox and set with opacity less than 1.0. Another Window having a canvas
51 * component drawn with an image can be used as the background for the test
52 * window. Click on the ComboBox to show the drop down. Check if the drop down
53 * appears translucent. Repeat this for JWindow, JDialog and JFrame
54 * Expected Result: If TRANSLUCENT Translucency type is supported, the drop down
55 * should appear translucent.
56 * @author mrkam
57 * @library ../../../../lib/testlibrary
58 * @build Common ExtendedRobot
59 * @run main TranslucentJComboBox
60 */
61
62 public class TranslucentJComboBox extends Common {
63
64 JComponent south;
65 JComponent center;
66 JPanel north;
67 volatile boolean southClicked = false;
68
69 JPopupMenu popup = null;
70
71 public static void main(String[] args) throws Exception {
72 if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.TRANSLUCENT))
73 for (Class<Window> windowClass: WINDOWS_TO_TEST)
74 new TranslucentJComboBox(windowClass).doTest();
75 }
76
77 public TranslucentJComboBox(Class windowClass) throws Exception {
78 super(windowClass, 0.3f, 1.0f, false);
79 }
80
81 @Override
82 public void initBackgroundFrame() {
83 super.initBackgroundFrame();
84 }
85
86 @Override
87 public void createSwingComponents() {
88 Container contentPane = RootPaneContainer.class.cast(window).getContentPane();
89 window.setLayout(new BorderLayout());
90
91 north = new JPanel();
92 contentPane.add(north, BorderLayout.NORTH);
93
94 center = new JList(new String [] { "Center" });
95 contentPane.add(center, BorderLayout.CENTER);
96
97 JComboBox jComboBox = new JComboBox();
98 for(int i = 0; i < 20; i++) {
99 jComboBox.addItem("item " + i);
100 }
101 south = jComboBox;
102 jComboBox.addPopupMenuListener(new PopupMenuListener() {
103
104 @Override
105 public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
106 popup = (JPopupMenu) jComboBox.getUI()
107 .getAccessibleChild(jComboBox, 0);
108 }
109
110 @Override
111 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
112
113 }
114
115 @Override
116 public void popupMenuCanceled(PopupMenuEvent e) {
117
118 }
119 });
120
121 south.addMouseListener(new MouseAdapter() {
122 @Override
123 public void mouseClicked(MouseEvent e) {
124 southClicked = true;
125 }
126 });
127 contentPane.add(south, BorderLayout.SOUTH);
128 }
129
130
131 @Override
132 public void doTest() throws Exception {
133 robot.waitForIdle(delay);
134 // Make window an active
135 Point ls = north.getLocationOnScreen();
136 robot.mouseMove(ls.x + north.getWidth()/2, ls.y + north.getHeight()/2);
137 robot.click();
138
139 // Invoke list
158
159 robot.mouseMove(x, y);
160 robot.waitForIdle(delay);
161 robot.click();
162 robot.waitForIdle(delay);
163
164 if (!southClicked)
165 throw new RuntimeException("Flag is not triggered for point "+x+", "+y+"!");
166
167 robot.waitForIdle();
168
169 Color c1b = robot.getPixelColor(p1.x, p1.y);
170 Color c2b = robot.getPixelColor(p2.x, p2.y);
171
172 if (!c1.equals(c1b) && !south.getBackground().equals(c1b))
173 throw new RuntimeException(
174 "Check for opaque drop down failed at point " + p1 +
175 ". Before click: " + c1 + ", after click: " + c1b +
176 ", expected is " + south.getBackground());
177
178 //This following check is only valid if the popup was created below the
179 // JComboBox and will be opaque or it is created above the JComboBox
180 // and it can not fit inside the JWindow along with JComboBox and will
181 // be opaque
182 if ( !c2.equals(c2b) && !south.getBackground().equals(c2b) &&
183 (popup.getLocationOnScreen().y > ls.y ||
184 window.getHeight() < popup.getHeight() + south.getHeight()))
185 throw new RuntimeException(
186 "Check for opaque drop down failed at point " + p2 +
187 ". Before click: " + c2 + ", after click: " + c2b +
188 ", expected is " + south.getBackground());
189
190 EventQueue.invokeAndWait(this::dispose);
191 }
192 }
|