Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mixing/AWT_Mixing/JMenuBarOverlapping.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.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@summary Overlapping test for javax.swing.JScrollPane48@author [email protected]: area=awt.mixing49@library ../../regtesthelpers50@build Util51@run main JMenuBarOverlapping52*/53public class JMenuBarOverlapping extends OverlappingTestBase {5455{testEmbeddedFrame = true;}5657private boolean lwClicked = false;58private boolean spClicked = false;59private Point loc;60private Point loc2;61private Point sepLoc;62private JFrame frame;63private JMenuBar menuBar;64JSeparator separator;6566protected void prepareControls() {67frame = new JFrame("Mixing : Dropdown Overlapping test");68frame.setLayout(new GridLayout(0,1));69frame.setSize(200, 200);70frame.setVisible(true);7172menuBar = new JMenuBar();73JMenu menu = new JMenu("Test Menu");74ActionListener menuListener = new ActionListener() {7576public void actionPerformed(ActionEvent event) {77lwClicked = true;78}79};8081JMenuItem item;82menu.add(item = new JMenuItem("first"));83item.addActionListener(menuListener);84separator = new JSeparator();85separator.addMouseListener(new MouseAdapter() {8687@Override88public void mouseClicked(MouseEvent e) {89spClicked = true;90}91});92menu.add(separator);9394for (int i = 0; i < petStrings.length; i++) {95menu.add(item = new JMenuItem(petStrings[i]));96item.addActionListener(menuListener);97}98menuBar.add(menu);99frame.setJMenuBar(menuBar);100101propagateAWTControls(frame);102frame.setVisible(true);103}104105@Override106protected boolean performTest() {107try {108SwingUtilities.invokeAndWait(new Runnable() {109public void run() {110loc = menuBar.getLocationOnScreen();111loc2 = frame.getContentPane().getLocationOnScreen();112}113});114} catch (Exception e) {115}116// run robot117Robot robot = Util.createRobot();118robot.setAutoDelay(ROBOT_DELAY);119120loc2.translate(75, 75);121pixelPreCheck(robot, loc2, currentAwtControl);122123loc.translate(3, 3);124clickAndBlink(robot, loc, false);125126clickAndBlink(robot, loc2, false);127128clickAndBlink(robot, loc, false);129try {130SwingUtilities.invokeAndWait(new Runnable() {131public void run() {132sepLoc = separator.getLocationOnScreen();133}134});135} catch (Exception e) {136e.printStackTrace();137throw new RuntimeException("Where is separator?");138}139sepLoc.translate(20, 1);140clickAndBlink(robot, sepLoc, false);141142clickAndBlink(robot, loc, false); // close menu before running next step143return lwClicked && spClicked;144}145146// this strange plumbing stuff is required due to "Standard Test Machinery" in base class147public static void main(String args[]) throws InterruptedException {148instance = new JMenuBarOverlapping();149OverlappingTestBase.doMain(args);150}151}152153154