Path: blob/master/test/jdk/java/awt/Mixing/MixingInHwPanel.java
41149 views
/*1* Copyright (c) 2009, 2018, 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*/2223/*24@test25@key headful26@bug 682985827@summary Mixing should work inside heavyweight containers28@author [email protected]: area=awt.mixing29@library ../regtesthelpers30@build Util31@run main MixingInHwPanel32*/333435/**36* MixingInHwPanel.java37*38* summary: Mixing should work inside heavyweight containers39*/4041import java.awt.*;42import java.awt.event.*;43import javax.swing.*;44import test.java.awt.regtesthelpers.Util;45464748public class MixingInHwPanel49{50static volatile boolean failed = true;5152private static void init()53{54// Create the components: frame -> hwPanel -> JDesktopPane ->55// -> JInternalFrame -> hwButton56Frame frame = new Frame("Mixing in a heavyweight Panel");57frame.setBounds(100, 100, 640, 480);5859Panel hwPanel = new Panel(new BorderLayout());60frame.add(hwPanel);6162JDesktopPane desktop = new JDesktopPane();63hwPanel.add(desktop);6465JInternalFrame iFrame = new JInternalFrame("one",66true, true, true, true);67iFrame.setPreferredSize(new Dimension(150, 55));68iFrame.setBounds(600, 100, 150, 55);69iFrame.setVisible(true);70desktop.add(iFrame);7172Button button = new Button("HW Button");73button.addActionListener(new ActionListener() {74public void actionPerformed(ActionEvent e) {75failed = false;76}77});78iFrame.add(button);7980// Show the frame with the hwButton slightly hidden initially81frame.setVisible(true);8283Robot robot = Util.createRobot();84robot.setAutoDelay(20);8586Util.waitForIdle(robot);8788// Now resize the frame so that the button is fully visible89frame.setBounds(100, 100, 800, 480);90frame.validate();9192Util.waitForIdle(robot);9394// And click the part of the button that has been previously hidden95Point bLoc = button.getLocationOnScreen();96robot.mouseMove(bLoc.x + button.getWidth() - 15, bLoc.y + button.getHeight() / 2);9798Util.waitForIdle(robot);99100robot.mousePress(InputEvent.BUTTON1_MASK);101robot.mouseRelease(InputEvent.BUTTON1_MASK);102103Util.waitForIdle(robot);104105// If the click happens (the shape is reapplied), the button's action106// listener will make failed == false.107if (failed) {108MixingInHwPanel.fail("The HW button did not receive the click.");109} else {110MixingInHwPanel.pass();111}112}//End init()113114115116/*****************************************************117* Standard Test Machinery Section118* DO NOT modify anything in this section -- it's a119* standard chunk of code which has all of the120* synchronisation necessary for the test harness.121* By keeping it the same in all tests, it is easier122* to read and understand someone else's test, as123* well as insuring that all tests behave correctly124* with the test harness.125* There is a section following this for test-126* classes127******************************************************/128private static boolean theTestPassed = false;129private static boolean testGeneratedInterrupt = false;130private static String failureMessage = "";131132private static Thread mainThread = null;133134private static int sleepTime = 300000;135136// Not sure about what happens if multiple of this test are137// instantiated in the same VM. Being static (and using138// static vars), it aint gonna work. Not worrying about139// it for now.140public static void main( String args[] ) throws InterruptedException141{142mainThread = Thread.currentThread();143try144{145init();146}147catch( TestPassedException e )148{149//The test passed, so just return from main and harness will150// interepret this return as a pass151return;152}153//At this point, neither test pass nor test fail has been154// called -- either would have thrown an exception and ended the155// test, so we know we have multiple threads.156157//Test involves other threads, so sleep and wait for them to158// called pass() or fail()159try160{161Thread.sleep( sleepTime );162//Timed out, so fail the test163throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );164}165catch (InterruptedException e)166{167//The test harness may have interrupted the test. If so, rethrow the exception168// so that the harness gets it and deals with it.169if( ! testGeneratedInterrupt ) throw e;170171//reset flag in case hit this code more than once for some reason (just safety)172testGeneratedInterrupt = false;173174if ( theTestPassed == false )175{176throw new RuntimeException( failureMessage );177}178}179180}//main181182public static synchronized void setTimeoutTo( int seconds )183{184sleepTime = seconds * 1000;185}186187public static synchronized void pass()188{189System.out.println( "The test passed." );190System.out.println( "The test is over, hit Ctl-C to stop Java VM" );191//first check if this is executing in main thread192if ( mainThread == Thread.currentThread() )193{194//Still in the main thread, so set the flag just for kicks,195// and throw a test passed exception which will be caught196// and end the test.197theTestPassed = true;198throw new TestPassedException();199}200theTestPassed = true;201testGeneratedInterrupt = true;202mainThread.interrupt();203}//pass()204205public static synchronized void fail()206{207//test writer didn't specify why test failed, so give generic208fail( "it just plain failed! :-)" );209}210211public static synchronized void fail( String whyFailed )212{213System.out.println( "The test failed: " + whyFailed );214System.out.println( "The test is over, hit Ctl-C to stop Java VM" );215//check if this called from main thread216if ( mainThread == Thread.currentThread() )217{218//If main thread, fail now 'cause not sleeping219throw new RuntimeException( whyFailed );220}221theTestPassed = false;222testGeneratedInterrupt = true;223failureMessage = whyFailed;224mainThread.interrupt();225}//fail()226227}// class MixingInHwPanel228229//This exception is used to exit from any level of call nesting230// when it's determined that the test has passed, and immediately231// end the test.232class TestPassedException extends RuntimeException233{234}235236237