Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/JPopupMenuOverlapping.java
41152 views
/*1* Copyright (c) 2014, 2016, 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 java.awt.Color;25import java.awt.Point;26import java.awt.Robot;27import java.awt.event.ActionEvent;28import java.awt.event.ActionListener;29import java.lang.reflect.InvocationTargetException;30import javax.swing.JFrame;31import javax.swing.JMenuItem;32import javax.swing.JPopupMenu;33import javax.swing.SpringLayout;34import javax.swing.SwingUtilities;35import test.java.awt.regtesthelpers.Util;3637/**38* AWT/Swing overlapping test for {@link javax.swing.JPopupMenu } component.39* <p>This test creates menu and test if heavyweight component is drawn correctly then menu dropdown is shown.40* <p>See base class for test info.41*/42/*43* @test44* @key headful45* @summary Overlapping test for javax.swing.JScrollPane46* @author [email protected]: area=awt.mixing47* @library /java/awt/patchlib ../../regtesthelpers48* @modules java.desktop/sun.awt49* java.desktop/java.awt.peer50* @build java.desktop/java.awt.Helper51* @build Util52* @run main JPopupMenuOverlapping53*/54public class JPopupMenuOverlapping extends OverlappingTestBase {5556{testEmbeddedFrame = true;}5758private boolean lwClicked = false;59private Point loc;60private JPopupMenu popup;61private JFrame frame=null;6263protected void prepareControls() {64if(frame != null) {65frame.setVisible(false);66}67frame = new JFrame("Mixing : Dropdown Overlapping test");68frame.setLayout(new SpringLayout());69frame.setSize(200, 200);7071popup = new JPopupMenu();72ActionListener menuListener = new ActionListener() {7374public void actionPerformed(ActionEvent event) {75lwClicked = true;76}77};78JMenuItem item;79for (int i = 0; i < petStrings.length; i++) {80popup.add(item = new JMenuItem(petStrings[i]));81item.addActionListener(menuListener);82}83propagateAWTControls(frame);84frame.setVisible(true);85loc = frame.getContentPane().getLocationOnScreen();86}8788@Override89protected boolean performTest() {90// run robot91Robot robot = Util.createRobot();92robot.setAutoDelay(ROBOT_DELAY);9394loc.translate(75, 75);9596pixelPreCheck(robot, loc, currentAwtControl);9798try {99SwingUtilities.invokeAndWait(new Runnable() {100101public void run() {102popup.show(frame.getContentPane(), 15, 15);103}104});105106robot.waitForIdle();107108clickAndBlink(robot, loc, false);109110SwingUtilities.invokeAndWait(new Runnable() {111112public void run() {113popup.setVisible(false);114}115});116} catch (InterruptedException ex) {117fail(ex.getMessage());118} catch (InvocationTargetException ex) {119fail(ex.getMessage());120}121122return lwClicked;123}124125// this strange plumbing stuff is required due to "Standard Test Machinery" in base class126public static void main(String args[]) throws InterruptedException {127instance = new JPopupMenuOverlapping();128OverlappingTestBase.doMain(args);129}130}131132133