Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JWindow/ShapedAndTranslucentWindows/TranslucentWindowClickSwing.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* @summary Check if swing components present in a window set with opacity less31* than 1.0 appears translucent32* Test Description: Check if TRANSLUCENT Translucency type is supported for the33* current platform. Proceed if supported. Show a window containing some swing34* components and set it with opacity less than 1.0. Check if the swing components35* appear translucent and check if events trigger correctly for the components36* Expected Result: If TRANSLUCENT Translucency type is supported, the components37* should appear translucent showing the background. They should trigger events38* correctly39* @author mrkam40* @library ../../../../lib/testlibrary41* @build Common ExtendedRobot42* @run main TranslucentWindowClickSwing43*/4445public class TranslucentWindowClickSwing extends Common {4647private Component south;48private Component center;49private Component north;5051public static void main(String[] args) throws Exception{52if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.TRANSLUCENT))53new TranslucentWindowClickSwing(JWindow.class).doTest();54}5556public TranslucentWindowClickSwing(Class windowClass) throws Exception {57super(windowClass, 0.2f, 1.0f, false);58}5960@Override61public void createSwingComponents() {62south = new JButton("South");63south.addMouseListener(new MouseAdapter() {64@Override65public void mouseClicked(MouseEvent e) { clicked |= 1 << 2; }66});67window.add(south, BorderLayout.SOUTH);6869center = new JList();70center.addMouseListener(new MouseAdapter() {71@Override72public void mouseClicked(MouseEvent e) { clicked |= 1 << 1; }73});74window.add(center, BorderLayout.CENTER);7576north = new JTextField("North");77north.addMouseListener(new MouseAdapter() {78@Override79public void mouseClicked(MouseEvent e) { clicked |= 1 << 0; }80});81window.add(north, BorderLayout.NORTH);82}8384@Override85public void doTest() throws Exception {86Point ls;87robot.waitForIdle();8889ls = north.getLocationOnScreen();90checkClick(ls.x + north.getWidth() / 3, ls.y + north.getHeight() / 2, 0);9192ls = center.getLocationOnScreen();93checkClick(ls.x + center.getWidth() / 4, ls.y + center.getHeight() / 4, 1);9495ls = center.getLocationOnScreen();96checkClick(ls.x + center.getWidth() * 3 / 4, ls.y + center.getHeight() * 3 / 4, 1);9798ls = south.getLocationOnScreen();99checkClick(ls.x + south.getWidth() * 2 / 3, ls.y + south.getHeight() / 2, 2);100101EventQueue.invokeAndWait(this::dispose);102robot.waitForIdle();103}104}105106107