JPopupMenuOverlapping.java revision 14851:980da45565c8
1164041Sdds/*
2164041Sdds * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3164041Sdds * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4164041Sdds *
5164041Sdds * This code is free software; you can redistribute it and/or modify it
6164041Sdds * under the terms of the GNU General Public License version 2 only, as
7164041Sdds * published by the Free Software Foundation.
8164041Sdds *
9164041Sdds * This code is distributed in the hope that it will be useful, but WITHOUT
10164041Sdds * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11164041Sdds * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12164041Sdds * version 2 for more details (a copy is included in the LICENSE file that
13164041Sdds * accompanied this code).
14164041Sdds *
15164041Sdds * You should have received a copy of the GNU General Public License version
16164041Sdds * 2 along with this work; if not, write to the Free Software Foundation,
17164041Sdds * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18164041Sdds *
19164041Sdds * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20164041Sdds * or visit www.oracle.com if you need additional information or have any
21164041Sdds * questions.
22164041Sdds */
23164041Sdds
24164041Sdds
25164041Sddsimport java.awt.Color;
26164041Sddsimport java.awt.Point;
27164041Sddsimport java.awt.Robot;
28164041Sddsimport java.awt.event.ActionEvent;
29164041Sddsimport java.awt.event.ActionListener;
30164041Sddsimport java.lang.reflect.InvocationTargetException;
31164041Sddsimport javax.swing.JFrame;
32164041Sddsimport javax.swing.JMenuItem;
33164041Sddsimport javax.swing.JPopupMenu;
34164041Sddsimport javax.swing.SpringLayout;
35164041Sddsimport javax.swing.SwingUtilities;
36164041Sddsimport test.java.awt.regtesthelpers.Util;
37164041Sdds
38164041Sdds/**
39164041Sdds * AWT/Swing overlapping test for {@link javax.swing.JPopupMenu } component.
40164041Sdds * <p>This test creates menu and test if heavyweight component is drawn correctly then menu dropdown is shown.
41164041Sdds * <p>See base class for test info.
42164041Sdds */
43164041Sdds/*
44164041Sdds * @test
45164041Sdds * @key headful
46164041Sdds * @summary Overlapping test for javax.swing.JScrollPane
47164041Sdds * @author sergey.grinev@oracle.com: area=awt.mixing
48164041Sdds * @library /java/awt/patchlib  ../../regtesthelpers
49164041Sdds * @modules java.desktop/sun.awt
50164041Sdds *          java.desktop/java.awt.peer
51164041Sdds * @build java.desktop/java.awt.Helper
52164041Sdds * @build Util
53164041Sdds * @run main JPopupMenuOverlapping
54164041Sdds */
55164041Sddspublic class JPopupMenuOverlapping extends OverlappingTestBase {
56164041Sdds
57164041Sdds    {testEmbeddedFrame = true;}
58164041Sdds
59164041Sdds    private boolean lwClicked = false;
60164041Sdds    private Point loc;
61164041Sdds    private JPopupMenu popup;
62164041Sdds    private JFrame frame=null;
63164041Sdds
64164041Sdds    protected void prepareControls() {
65164041Sdds        if(frame != null) {
66164041Sdds            frame.setVisible(false);
67164041Sdds        }
68164041Sdds        frame = new JFrame("Mixing : Dropdown Overlapping test");
69164041Sdds        frame.setLayout(new SpringLayout());
70164041Sdds        frame.setSize(200, 200);
71164041Sdds
72164041Sdds        popup = new JPopupMenu();
73164041Sdds        ActionListener menuListener = new ActionListener() {
74164041Sdds
75164041Sdds            public void actionPerformed(ActionEvent event) {
76164041Sdds                lwClicked = true;
77164041Sdds            }
78164041Sdds        };
79164041Sdds        JMenuItem item;
80164041Sdds        for (int i = 0; i < petStrings.length; i++) {
81164041Sdds            popup.add(item = new JMenuItem(petStrings[i]));
82164041Sdds            item.addActionListener(menuListener);
83164041Sdds        }
84164041Sdds        propagateAWTControls(frame);
85164041Sdds        frame.setVisible(true);
86164041Sdds        loc = frame.getContentPane().getLocationOnScreen();
87164041Sdds    }
88164041Sdds
89164041Sdds    @Override
90164041Sdds    protected boolean performTest() {
91164041Sdds        // run robot
92164041Sdds        Robot robot = Util.createRobot();
93164041Sdds        robot.setAutoDelay(ROBOT_DELAY);
94164041Sdds
95164041Sdds        loc.translate(75, 75);
96164041Sdds
97164041Sdds        pixelPreCheck(robot, loc, currentAwtControl);
98164041Sdds
99164041Sdds        try {
100164041Sdds            SwingUtilities.invokeAndWait(new Runnable() {
101164041Sdds
102164041Sdds                public void run() {
103164041Sdds                    popup.show(frame.getContentPane(), 15, 15);
104164041Sdds                }
105164041Sdds            });
106164041Sdds
107164041Sdds            robot.waitForIdle();
108164041Sdds
109164041Sdds            clickAndBlink(robot, loc, false);
110164041Sdds
111164041Sdds            SwingUtilities.invokeAndWait(new Runnable() {
112164041Sdds
113164041Sdds                public void run() {
114164041Sdds                    popup.setVisible(false);
115164041Sdds                }
116164041Sdds            });
117164041Sdds        } catch (InterruptedException ex) {
118164041Sdds            fail(ex.getMessage());
119164041Sdds        } catch (InvocationTargetException ex) {
120164041Sdds            fail(ex.getMessage());
121164041Sdds        }
122164041Sdds
123164041Sdds        return lwClicked;
124164041Sdds    }
125164041Sdds
126164041Sdds    // this strange plumbing stuff is required due to "Standard Test Machinery" in base class
127164041Sdds    public static void main(String args[]) throws InterruptedException {
128164041Sdds        instance = new JPopupMenuOverlapping();
129164041Sdds        OverlappingTestBase.doMain(args);
130164041Sdds    }
131164041Sdds}
132164041Sdds