Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JWindow/ShapedAndTranslucentWindows/TranslucentJComboBox.java
38853 views
/*1* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.swing.*;24import java.awt.*;25import java.awt.event.MouseAdapter;26import java.awt.event.MouseEvent;2728/*29* @test30* @bug 802462731* @summary Check if a JComboBox present in a window set with opacity less than32* 1.0 shows a translucent drop down33* Test Description: Check if TRANSLUCENT translucency type is supported on the34* current platform. Proceed if supported. Show a window which contains an35* JComboBox and set with opacity less than 1.0. Another Window having a canvas36* component drawn with an image can be used as the background for the test37* window. Click on the ComboBox to show the drop down. Check if the drop down38* appears translucent. Repeat this for JWindow, JDialog and JFrame39* Expected Result: If TRANSLUCENT Translucency type is supported, the drop down40* should appear translucent.41* @author mrkam42* @library ../../../../lib/testlibrary43* @build Common ExtendedRobot44* @run main TranslucentJComboBox45*/4647public class TranslucentJComboBox extends Common {4849JComponent south;50JComponent center;51JPanel north;52volatile boolean southClicked = false;5354public static void main(String[] args) throws Exception {55if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.TRANSLUCENT))56for (Class<Window> windowClass: WINDOWS_TO_TEST)57new TranslucentJComboBox(windowClass).doTest();58}5960public TranslucentJComboBox(Class windowClass) throws Exception {61super(windowClass, 0.3f, 1.0f, false);62}6364@Override65public void initBackgroundFrame() {66super.initBackgroundFrame();67}6869@Override70public void createSwingComponents() {71Container contentPane = RootPaneContainer.class.cast(window).getContentPane();72window.setLayout(new BorderLayout());7374north = new JPanel();75contentPane.add(north, BorderLayout.NORTH);7677center = new JList(new String [] { "Center" });78contentPane.add(center, BorderLayout.CENTER);7980JComboBox jComboBox = new JComboBox();81for(int i = 0; i < 20; i++) {82jComboBox.addItem("item " + i);83}84south = jComboBox;8586south.addMouseListener(new MouseAdapter() {87@Override88public void mouseClicked(MouseEvent e) {89southClicked = true;90}91});92contentPane.add(south, BorderLayout.SOUTH);93}949596@Override97public void doTest() throws Exception {98robot.waitForIdle(delay);99// Make window an active100Point ls = north.getLocationOnScreen();101robot.mouseMove(ls.x + north.getWidth()/2, ls.y + north.getHeight()/2);102robot.click();103104// Invoke list105ls = south.getLocationOnScreen();106107Point p1 = new Point(108(int) (ls.x + south.getWidth() * 0.75),109ls.y + south.getHeight() * 3);110111Point p2 = new Point(112(int) (ls.x + south.getWidth() * 0.75),113ls.y - south.getHeight() * 2);114115Color c1 = robot.getPixelColor(p1.x, p1.y);116Color c2 = robot.getPixelColor(p2.x, p2.y);117118int x = ls.x + south.getWidth()/2;119int y = ls.y + south.getHeight()/2;120121System.out.println("Trying to click point "+x+", "+y+122", looking for flag to trigger.");123124robot.mouseMove(x, y);125robot.waitForIdle(delay);126robot.click();127robot.waitForIdle(delay);128129if (!southClicked)130throw new RuntimeException("Flag is not triggered for point "+x+", "+y+"!");131132robot.waitForIdle();133134Color c1b = robot.getPixelColor(p1.x, p1.y);135Color c2b = robot.getPixelColor(p2.x, p2.y);136137if (!c1.equals(c1b) && !south.getBackground().equals(c1b))138throw new RuntimeException(139"Check for opaque drop down failed at point " + p1 +140". Before click: " + c1 + ", after click: " + c1b +141", expected is " + south.getBackground());142143if (!c2.equals(c2b) && !south.getBackground().equals(c2b))144throw new RuntimeException(145"Check for opaque drop down failed at point " + p2 +146". Before click: " + c2 + ", after click: " + c2b +147", expected is " + south.getBackground());148149EventQueue.invokeAndWait(this::dispose);150}151}152153154