jdk/test/javax/swing/JPopupMenu/6694823/bug6694823.java
author rupashka
Fri, 12 Aug 2011 15:53:29 +0400
changeset 10315 303a387c2ebc
parent 5506 202f599c92aa
child 12828 8e71b2ed3d5f
permissions -rw-r--r--
7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10 Reviewed-by: alexp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 675
diff changeset
     2
 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     4
 *
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     8
 *
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    13
 * accompanied this code).
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    14
 *
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 675
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 675
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 675
diff changeset
    21
 * questions.
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    22
 */
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    23
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    24
/*
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    25
 * @test
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    26
 * @bug 6694823
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    27
 * @summary Checks that popup menu cannot be partially hidden
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    28
 * by the task bar in applets.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    29
 * @author Mikhail Lapshin
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    30
 * @run main bug6694823
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    31
 */
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    32
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    33
import javax.swing.*;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    34
import java.awt.*;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    35
import sun.awt.SunToolkit;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    36
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    37
public class bug6694823 {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    38
    private static JFrame frame;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    39
    private static JPopupMenu popup;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    40
    private static SunToolkit toolkit;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    41
    private static Insets screenInsets;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    42
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    44
        toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    45
        SwingUtilities.invokeAndWait(new Runnable() {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    46
            public void run() {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    47
                createGui();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    48
            }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    49
        });
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    50
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    51
        // Get screen insets
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    52
        screenInsets = toolkit.getScreenInsets(frame.getGraphicsConfiguration());
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    53
        if (screenInsets.bottom == 0) {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    54
            // This test is only for configurations with taskbar on the bottom
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    55
            return;
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    56
        }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    57
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    58
        // Show popup as if from a standalone application
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    59
        // The popup should be able to overlap the task bar
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    60
        showPopup(false);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    61
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    62
        // Emulate applet security restrictions
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    63
        toolkit.realSync();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    64
        System.setSecurityManager(new SecurityManager());
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    65
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    66
        // Show popup as if from an applet
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    67
        // The popup shouldn't overlap the task bar. It should be shifted up.
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    68
        showPopup(true);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    69
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    70
        toolkit.realSync();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    71
        System.out.println("Test passed!");
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
    72
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
    73
        SwingUtilities.invokeAndWait(new Runnable() {
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
    74
            public void run() {
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
    75
                frame.dispose();
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
    76
            }
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
    77
        });
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    78
    }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    79
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    80
    private static void createGui() {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    81
        frame = new JFrame();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    82
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    83
        frame.setUndecorated(true);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    84
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    85
        popup = new JPopupMenu("Menu");
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    86
        for (int i = 0; i < 7; i++) {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    87
            popup.add(new JMenuItem("MenuItem"));
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    88
        }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    89
        JPanel panel = new JPanel();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    90
        panel.setComponentPopupMenu(popup);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    91
        frame.add(panel);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    92
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    93
        frame.setSize(200, 200);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    94
    }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    95
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
    96
    private static void showPopup(final boolean shouldBeShifted) throws Exception {
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
    97
        SwingUtilities.invokeAndWait(new Runnable() {
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    98
            public void run() {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
    99
                // Place frame just above the task bar
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   100
                Dimension screenSize = toolkit.getScreenSize();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   101
                frame.setLocation(screenSize.width / 2,
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   102
                        screenSize.height - frame.getHeight() - screenInsets.bottom);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   103
                frame.setVisible(true);
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   104
            }
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   105
        });
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   106
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   107
        // Ensure frame is visible
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   108
        toolkit.realSync();
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   109
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   110
        final Point point = new Point();
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   111
        SwingUtilities.invokeAndWait(new Runnable() {
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   112
            public void run() {
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   113
                // Place popup over the task bar
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   114
                point.x = 0;
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   115
                point.y = frame.getHeight() - popup.getPreferredSize().height + screenInsets.bottom;
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   116
                popup.show(frame, point.x, point.y);
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   117
            }
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   118
        });
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   119
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   120
        // Ensure popup is visible
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   121
        toolkit.realSync();
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   122
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   123
        SwingUtilities.invokeAndWait(new Runnable() {
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   124
            public void run() {
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   125
                Point frameLoc = frame.getLocationOnScreen();
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   126
                if (shouldBeShifted) {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   127
                    if (popup.getLocationOnScreen()
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   128
                            .equals(new Point(frameLoc.x, frameLoc.y + point.y))) {
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   129
                        throw new RuntimeException("Popup is not shifted");
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   130
                    }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   131
                } else {
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   132
                    if (!popup.getLocationOnScreen()
10315
303a387c2ebc 7071609: javax/swing/JPopupMenu/6694823/bug6694823.java failed on solaris10
rupashka
parents: 5506
diff changeset
   133
                            .equals(new Point(frameLoc.x, frameLoc.y + point.y))) {
675
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   134
                        throw new RuntimeException("Popup is unexpectedly shifted");
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   135
                    }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   136
                }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   137
                popup.setVisible(false);
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   138
            }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   139
        });
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   140
    }
4f26ea16c5c1 6694823: A popup menu can be partially hidden under the task bar in applets
mlapshin
parents:
diff changeset
   141
}