Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mixing/AWT_Mixing/OpaqueOverlapping.java
47626 views
/*1* Copyright (c) 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*/222324import com.sun.awt.AWTUtilities;25import java.awt.Frame;26import java.awt.Panel;27import java.awt.Point;28import java.awt.Rectangle;29import java.awt.Robot;30import java.awt.event.InputEvent;31import java.awt.event.MouseAdapter;32import java.awt.event.MouseEvent;33import javax.swing.JButton;34import javax.swing.SwingUtilities;35import test.java.awt.regtesthelpers.Util;3637/**38* AWT/Swing overlapping test for opaque Swing components.39* <p>This test verify if AWT components are drawn correctly under opaque components.40* <p>See <a href="https://bugs.openjdk.java.net/browse/JDK-6776743">JDK-6776743</a> for details41* <p>See base class for test info.42*/43/*44@test45@bug 677674346@summary Opaque overlapping test for each AWT component47@library ../../regtesthelpers48@build Util49@run main OpaqueOverlapping50*/51public class OpaqueOverlapping extends OverlappingTestBase {5253{54useClickValidation = false;55failMessage = "Opacity test mismatchs";5657// CR 6994264 (Choice autohides dropdown on Solaris 10)58skipClassNames = new String[] { "Choice" };59}60private String testSeq;61private final static String checkSeq = "010000101";62private Point heavyLoc;63private JButton light;64private Frame frame = null;6566protected void prepareControls() {67testSeq = "";68// Create components69if(frame != null) {70frame.setVisible(false);71}72frame = new Frame("OpaqueOverlapping mixing test");73final Panel panel = new Panel();74panel.setLayout(null);7576propagateAWTControls(panel);7778// Overlap the buttons79currentAwtControl.setBounds(30, 30, 200, 200);8081light = new JButton(" LW Button ");82light.setBounds(10, 10, 50, 50);8384// Put the components into the frame85panel.add(light);86frame.add(panel);87frame.setBounds(50, 50, 400, 400);88frame.setVisible(true);8990currentAwtControl.addMouseListener(new MouseAdapter() {91@Override92public void mouseClicked(MouseEvent e) {93panel.setComponentZOrder(light, 0);94frame.validate();95testSeq = testSeq + "0";96}97});98light.addActionListener(new java.awt.event.ActionListener() {99public void actionPerformed(java.awt.event.ActionEvent e) {100panel.setComponentZOrder(currentAwtControl, 0);101frame.validate();102testSeq = testSeq + "1";103}104});105}106107@Override108protected boolean performTest() {109try {110SwingUtilities.invokeAndWait(new Runnable() {111public void run() {112heavyLoc = currentAwtControl.getLocationOnScreen();113}114});115} catch (Exception e) {116}117Robot robot = Util.createRobot();118robot.setAutoDelay(ROBOT_DELAY);119120Util.waitForIdle(robot);121122// Move the mouse pointer to the position where both123// components overlap124robot.mouseMove(heavyLoc.x + 5, heavyLoc.y + 5);125126// Now perform the click at this point for 9 times127// In the middle of the process toggle the opaque128// flag value.129for (int i = 0; i < 9; ++i) {130if (i == 3) {131AWTUtilities.setComponentMixingCutoutShape(light,132new Rectangle());133}134if (i == 6) {135AWTUtilities.setComponentMixingCutoutShape(light,136null);137}138139robot.mousePress(InputEvent.BUTTON1_MASK);140robot.mouseRelease(InputEvent.BUTTON1_MASK);141Util.waitForIdle(robot);142143if (currentAwtControl.getClass() == java.awt.Choice.class && i != 1 && i != 6 && i != 8) {144// due to the fact that Choice doesn't get mouseClicked event if its dropdown is shown145robot.mousePress(InputEvent.BUTTON1_MASK);146robot.mouseRelease(InputEvent.BUTTON1_MASK);147Util.waitForIdle(robot);148}149}150151Util.waitForIdle(robot);152153boolean result = testSeq.equals(checkSeq);154if (!result) {155System.err.println("Expected: " + checkSeq);156System.err.println("Observed: " + testSeq);157}158return result;159}160161// this strange plumbing stuff is required due to "Standard Test Machinery" in base class162public static void main(String args[]) throws InterruptedException {163instance = new OpaqueOverlapping();164OverlappingTestBase.doMain(args);165}166}167168169