1/*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25import java.awt.Point;
26import java.awt.Robot;
27import java.awt.event.MouseAdapter;
28import java.awt.event.MouseEvent;
29import javax.swing.JButton;
30import javax.swing.JDesktopPane;
31import javax.swing.JFrame;
32import javax.swing.JInternalFrame;
33import test.java.awt.regtesthelpers.Util;
34
35/**
36 * AWT/Swing overlapping test for {@link javax.swing.JInternalFrame } component.
37 * <p>See base class for test info.
38 */
39/*
40 * @test
41 * @key headful
42 * @summary Overlapping test for javax.swing.JScrollPane
43 * @author sergey.grinev@oracle.com: area=awt.mixing
44 * @library /java/awt/patchlib  ../../regtesthelpers
45 * @modules java.desktop/sun.awt
46 *          java.desktop/java.awt.peer
47 * @build java.desktop/java.awt.Helper
48 * @build Util
49 * @run main JInternalFrameOverlapping
50 */
51public class JInternalFrameOverlapping extends OverlappingTestBase {
52
53    private boolean lwClicked = true;
54    private Point lLoc;
55
56    protected boolean performTest() {
57
58
59        // run robot
60        Robot robot = Util.createRobot();
61        robot.setAutoDelay(ROBOT_DELAY);
62
63        clickAndBlink(robot, lLoc);
64
65        return lwClicked;
66    }
67
68    /**
69     * Creating two JInternalFrames in JDesktopPanes. Put lightweight component into one frame and heavyweight into another.
70     */
71    @Override
72    protected void prepareControls() {
73        JDesktopPane desktopPane = new JDesktopPane();
74
75        JFrame frame = new JFrame("Test Window");
76        frame.setSize(300, 300);
77        frame.setContentPane(desktopPane);
78        frame.setVisible(true);
79        JInternalFrame bottomFrame = new JInternalFrame("bottom frame", false, false, false, false);
80        bottomFrame.setSize(220, 220);
81        desktopPane.add(bottomFrame);
82        bottomFrame.setVisible(true);
83
84        super.propagateAWTControls(bottomFrame);
85        JInternalFrame topFrame = new JInternalFrame("top frame", false, false, false, false);
86        topFrame.setSize(200, 200);
87        JButton jbutton = new JButton("LW Button") {{
88                addMouseListener(new MouseAdapter() {
89
90                    @Override
91                    public void mouseClicked(MouseEvent e) {
92                        lwClicked = true;
93                    }
94                });
95            }};
96        topFrame.add(jbutton);
97        desktopPane.add(topFrame);
98        topFrame.setVisible(true);
99        lLoc = jbutton.getLocationOnScreen();
100        lLoc.translate(jbutton.getWidth()/2, jbutton.getWidth()/2); //click at middle of the button
101    }
102
103    // this strange plumbing stuff is required due to "Standard Test Machinery" in base class
104    public static void main(String args[]) throws InterruptedException {
105        instance = new JInternalFrameOverlapping();
106        OverlappingTestBase.doMain(args);
107    }
108
109}
110