Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/JMenuBarOverlapping.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.GridLayout;26import java.awt.Point;27import java.awt.Robot;28import java.awt.event.ActionEvent;29import java.awt.event.ActionListener;30import java.awt.event.MouseAdapter;31import java.awt.event.MouseEvent;32import javax.swing.JFrame;33import javax.swing.JMenu;34import javax.swing.JMenuBar;35import javax.swing.JMenuItem;36import javax.swing.JSeparator;37import javax.swing.SwingUtilities;38import test.java.awt.regtesthelpers.Util;3940/**41* AWT/Swing overlapping test for {@link javax.swing.JMenuBar } and {@link javax.swing.JSeparator} components.42* <p>This test creates menu bar and test if heavyweight component is drawn correctly then menu dropdown is shown.43* <p>See base class for test info.44*/45/*46* @test47* @key headful48* @summary Overlapping test for javax.swing.JScrollPane49* @author [email protected]: area=awt.mixing50* @library /java/awt/patchlib ../../regtesthelpers51* @modules java.desktop/sun.awt52* java.desktop/java.awt.peer53* @build java.desktop/java.awt.Helper54* @build Util55* @run main JMenuBarOverlapping56*/57public class JMenuBarOverlapping extends OverlappingTestBase {5859{testEmbeddedFrame = true;}6061private boolean lwClicked = false;62private boolean spClicked = false;63private Point loc;64private Point loc2;65private Point sepLoc;66private JFrame frame;67private JMenuBar menuBar;68JSeparator separator;6970protected void prepareControls() {71frame = new JFrame("Mixing : Dropdown Overlapping test");72frame.setLayout(new GridLayout(0,1));73frame.setSize(200, 200);74frame.setVisible(true);7576menuBar = new JMenuBar();77JMenu menu = new JMenu("Test Menu");78ActionListener menuListener = new ActionListener() {7980public void actionPerformed(ActionEvent event) {81lwClicked = true;82}83};8485JMenuItem item;86menu.add(item = new JMenuItem("first"));87item.addActionListener(menuListener);88separator = new JSeparator();89separator.addMouseListener(new MouseAdapter() {9091@Override92public void mouseClicked(MouseEvent e) {93spClicked = true;94}95});96menu.add(separator);9798for (int i = 0; i < petStrings.length; i++) {99menu.add(item = new JMenuItem(petStrings[i]));100item.addActionListener(menuListener);101}102menuBar.add(menu);103frame.setJMenuBar(menuBar);104105propagateAWTControls(frame);106frame.setVisible(true);107}108109@Override110protected boolean performTest() {111try {112SwingUtilities.invokeAndWait(new Runnable() {113public void run() {114loc = menuBar.getLocationOnScreen();115loc2 = frame.getContentPane().getLocationOnScreen();116}117});118} catch (Exception e) {119}120// run robot121Robot robot = Util.createRobot();122robot.setAutoDelay(ROBOT_DELAY);123124loc2.translate(75, 75);125pixelPreCheck(robot, loc2, currentAwtControl);126127loc.translate(3, 3);128clickAndBlink(robot, loc, false);129130clickAndBlink(robot, loc2, false);131132clickAndBlink(robot, loc, false);133try {134SwingUtilities.invokeAndWait(new Runnable() {135public void run() {136sepLoc = separator.getLocationOnScreen();137}138});139} catch (Exception e) {140e.printStackTrace();141throw new RuntimeException("Where is separator?");142}143sepLoc.translate(20, 1);144clickAndBlink(robot, sepLoc, false);145146clickAndBlink(robot, loc, false); // close menu before running next step147return lwClicked && spClicked;148}149150// this strange plumbing stuff is required due to "Standard Test Machinery" in base class151public static void main(String args[]) throws InterruptedException {152instance = new JMenuBarOverlapping();153OverlappingTestBase.doMain(args);154}155}156157158