Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/JGlassPaneInternalFrameOverlapping.java
41152 views
/*1* Copyright (c) 2014, 2016, 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*/2223import java.awt.BorderLayout;24import java.awt.Color;25import java.awt.Container;26import java.awt.Point;27import java.awt.Robot;28import java.awt.event.MouseAdapter;29import java.awt.event.MouseEvent;30import javax.swing.JFrame;31import javax.swing.JInternalFrame;32import javax.swing.SwingUtilities;33import test.java.awt.regtesthelpers.Util;3435/**36* AWT/Swing overlapping test with JInternalFrame being put in GlassPane.37* See <a href="https://bugs.openjdk.java.net/browse/JDK-6637655">JDK-6637655</a> and38* <a href="https://bugs.openjdk.java.net/browse/JDK-6985776">JDK-6985776</a>.39* <p>See base class for details.40*/41/*42* @test43* @key headful44* @bug 6637655 698577645* @summary Overlapping test for javax.swing.JScrollPane46* @author [email protected]: area=awt.mixing47* @library /java/awt/patchlib ../../regtesthelpers48* @modules java.desktop/sun.awt49* java.desktop/java.awt.peer50* @build java.desktop/java.awt.Helper51* @build Util52* @run main JGlassPaneInternalFrameOverlapping53*/54public class JGlassPaneInternalFrameOverlapping extends OverlappingTestBase {5556private boolean lwClicked = true;57private Point lLoc;58private Point lLoc2;59private JInternalFrame internalFrame;6061protected boolean performTest() {62try {63SwingUtilities.invokeAndWait(new Runnable() {64public void run() {65lLoc = internalFrame.getContentPane().getLocationOnScreen();66lLoc2 = lLoc.getLocation();67lLoc2.translate(0, internalFrame.getContentPane().getHeight() + 10);68}69});70} catch (Exception e) {71e.printStackTrace();72throw new RuntimeException("Where is internal frame?");73}74// run robot75Robot robot = Util.createRobot();76robot.setAutoDelay(ROBOT_DELAY);7778clickAndBlink(robot, lLoc);7980Color c = robot.getPixelColor(lLoc2.x, lLoc2.y);81robot.mouseMove(lLoc2.x, lLoc2.y);82if (!c.equals(AWT_BACKGROUND_COLOR) &&83currentAwtControl.getClass() != java.awt.Scrollbar.class &&84currentAwtControl.getClass() != java.awt.Choice.class) {85fail("The HW component did not pass pixel color check and is not drawn correctly");86}8788return lwClicked;89}9091// {debugClassName = "Choice";}9293@Override94protected void prepareControls() {95JFrame frame = new JFrame("Glass Pane children test");96frame.setLayout(null);9798Container contentPane = frame.getContentPane();99contentPane.setLayout(new BorderLayout());100super.propagateAWTControls(contentPane);101102Container glassPane = (Container) frame.getRootPane().getGlassPane();103glassPane.setVisible(true);104glassPane.setLayout(null);105106internalFrame = new JInternalFrame("Internal Frame", true);107internalFrame.setBounds(50, 0, 200, 100);108internalFrame.setVisible(true);109glassPane.add(internalFrame);110111internalFrame.addMouseListener(new MouseAdapter() {112113@Override114public void mouseClicked(MouseEvent e) {115lwClicked = true;116}117});118119frame.setSize(300, 180);120frame.setLocationRelativeTo(null);121frame.setVisible(true);122}123124// this strange plumbing stuff is required due to "Standard Test Machinery" in base class125public static void main(String args[]) throws InterruptedException {126if (System.getProperty("os.name").toLowerCase().contains("os x")) {127System.out.println("Aqua L&F ignores setting color to component. Test passes on Mac OS X.");128return;129}130instance = new JGlassPaneInternalFrameOverlapping();131OverlappingTestBase.doMain(args);132}133}134135136