Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JPopupMenu/6580930/bug6580930.java
38918 views
/*1* Copyright (c) 2007, 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*/22/*23@test24@bug 6580930 718495625@summary Swing Popups should overlap taskbar26@author Alexander Potochkin27@library ../../../../lib/testlibrary28@build ExtendedRobot29@run main bug658093030*/3132import javax.swing.*;33import java.awt.*;34import java.awt.event.InputEvent;35import java.awt.event.KeyEvent;3637public class bug6580930 {38private static ExtendedRobot robot;39private static JFrame frame;40private static JPopupMenu popup;41private static Toolkit toolkit;42private static volatile boolean skipTest = false;4344private static void createGui() {45frame = new JFrame();46frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);47frame.setUndecorated(true);4849popup = new JPopupMenu("Menu");50for (int i = 0; i < 7; i++) {51popup.add(new JMenuItem("MenuItem"));52}53JPanel panel = new JPanel();54panel.setComponentPopupMenu(popup);55frame.add(panel);5657frame.setSize(200, 200);58}596061public static void main(String[] args) throws Exception {62SwingUtilities.invokeAndWait(new Runnable() {63public void run() {64JPopupMenu.setDefaultLightWeightPopupEnabled(true);65bug6580930.createGui();66}67});6869toolkit = Toolkit.getDefaultToolkit();70robot = new ExtendedRobot();71robot.setAutoDelay(10);72robot.waitForIdle();7374SwingUtilities.invokeAndWait(new Runnable() {75public void run() {76Insets insets = toolkit.getScreenInsets(frame.getGraphicsConfiguration());77if (insets.bottom == 0) {78System.out.println("This test is only for configurations with taskbar on the bottom");7980skipTest = true;81}8283Dimension screenSize = toolkit.getScreenSize();84frame.setLocation(screenSize.width/2, screenSize.height - frame.getHeight() - insets.bottom + 10);85frame.setVisible(true);86}87});8889robot.waitForIdle();9091if(skipTest) {92return;93}94Point loc = frame.getLocationOnScreen();9596robot.mouseMove(loc.x, loc.y);97showPopup();98robot.waitForIdle();99if (isHeavyWeightMenuVisible()) {100throw new RuntimeException("HeavyWeightPopup is unexpectedly visible");101}102103robot.keyPress(KeyEvent.VK_ESCAPE);104robot.keyRelease(KeyEvent.VK_ESCAPE);105106int x = loc.x;107int y = loc.y + (frame.getHeight() - popup.getPreferredSize().height) + 1;108robot.mouseMove(x, y);109110showPopup();111112if (!popup.getLocationOnScreen().equals(new Point(x, y))) {113throw new RuntimeException("Popup is unexpectedly shifted");114}115116if (!isHeavyWeightMenuVisible()) {117throw new RuntimeException("HeavyWeightPopup is unexpectedly hidden");118}119}120121private static void showPopup() {122robot.mousePress(InputEvent.BUTTON1_MASK);123robot.mouseRelease(InputEvent.BUTTON1_MASK);124robot.waitForIdle();125if (!popup.isShowing()) {126robot.mousePress(InputEvent.BUTTON2_MASK);127robot.mouseRelease(InputEvent.BUTTON2_MASK);128robot.waitForIdle();129if (!popup.isShowing()) {130robot.mousePress(InputEvent.BUTTON3_MASK);131robot.mouseRelease(InputEvent.BUTTON3_MASK);132robot.waitForIdle();133}134}135}136137private static boolean isHeavyWeightMenuVisible() {138Window[] windows = Window.getWindows();139for (Window window : windows) {140if (window.getClass().getSimpleName().equals("HeavyWeightWindow")141&& window.isVisible()) {142return true;143}144}145return false;146}147}148149150