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