Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mixing/AWT_Mixing/JPopupMenuOverlapping.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 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@summary Overlapping test for javax.swing.JScrollPane45@author [email protected]: area=awt.mixing46@library ../../regtesthelpers47@build Util48@run main JPopupMenuOverlapping49*/50public class JPopupMenuOverlapping extends OverlappingTestBase {5152{testEmbeddedFrame = true;}5354private boolean lwClicked = false;55private Point loc;56private JPopupMenu popup;57private JFrame frame=null;5859protected void prepareControls() {60if(frame != null) {61frame.setVisible(false);62}63frame = new JFrame("Mixing : Dropdown Overlapping test");64frame.setLayout(new SpringLayout());65frame.setSize(200, 200);6667popup = new JPopupMenu();68ActionListener menuListener = new ActionListener() {6970public void actionPerformed(ActionEvent event) {71lwClicked = true;72}73};74JMenuItem item;75for (int i = 0; i < petStrings.length; i++) {76popup.add(item = new JMenuItem(petStrings[i]));77item.addActionListener(menuListener);78}79propagateAWTControls(frame);80frame.setVisible(true);81loc = frame.getContentPane().getLocationOnScreen();82}8384@Override85protected boolean performTest() {86// run robot87Robot robot = Util.createRobot();88robot.setAutoDelay(ROBOT_DELAY);8990loc.translate(75, 75);9192pixelPreCheck(robot, loc, currentAwtControl);9394try {95SwingUtilities.invokeAndWait(new Runnable() {9697public void run() {98popup.show(frame.getContentPane(), 15, 15);99}100});101102robot.waitForIdle();103104clickAndBlink(robot, loc, false);105106SwingUtilities.invokeAndWait(new Runnable() {107108public void run() {109popup.setVisible(false);110}111});112} catch (InterruptedException ex) {113fail(ex.getMessage());114} catch (InvocationTargetException ex) {115fail(ex.getMessage());116}117118return lwClicked;119}120121// this strange plumbing stuff is required due to "Standard Test Machinery" in base class122public static void main(String args[]) throws InterruptedException {123instance = new JPopupMenuOverlapping();124OverlappingTestBase.doMain(args);125}126}127128129