1 /* 2 * Copyright (c) 2014, 2015, 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 import java.awt.BorderLayout; 25 import java.awt.Color; 26 import java.awt.Container; 27 import java.awt.Point; 28 import java.awt.Robot; 29 import java.awt.event.MouseAdapter; 30 import java.awt.event.MouseEvent; 31 import javax.swing.JFrame; 32 import javax.swing.JInternalFrame; 33 import javax.swing.SwingUtilities; 34 import test.java.awt.regtesthelpers.Util; 35 36 /** 37 * AWT/Swing overlapping test with JInternalFrame being put in GlassPane. 38 * See <a href="https://bugs.openjdk.java.net/browse/JDK-6637655">JDK-6637655</a> and 39 * <a href="https://bugs.openjdk.java.net/browse/JDK-6985776">JDK-6985776</a>. 40 * <p>See base class for details. 41 */ 42 /* 43 @test 44 @bug 6637655 6985776 45 @summary Overlapping test for javax.swing.JScrollPane 46 @author sergey.grinev@oracle.com: area=awt.mixing 47 @library ../../regtesthelpers 48 @modules java.desktop/sun.awt 49 @build Util 50 @run main JGlassPaneInternalFrameOverlapping 51 */ 52 public class JGlassPaneInternalFrameOverlapping extends OverlappingTestBase { 53 54 private boolean lwClicked = true; 55 private Point lLoc; 56 private Point lLoc2; 57 private JInternalFrame internalFrame; 58 59 protected boolean performTest() { 60 try { 61 SwingUtilities.invokeAndWait(new Runnable() { 62 public void run() { 63 lLoc = internalFrame.getContentPane().getLocationOnScreen(); 64 lLoc2 = lLoc.getLocation(); 65 lLoc2.translate(0, internalFrame.getContentPane().getHeight() + 10); 66 } 67 }); 68 } catch (Exception e) { 69 e.printStackTrace(); 70 throw new RuntimeException("Where is internal frame?"); 71 } 72 // run robot 73 Robot robot = Util.createRobot(); 74 robot.setAutoDelay(ROBOT_DELAY); 75 76 clickAndBlink(robot, lLoc); 77 78 Color c = robot.getPixelColor(lLoc2.x, lLoc2.y); 79 robot.mouseMove(lLoc2.x, lLoc2.y); 80 if (!c.equals(AWT_BACKGROUND_COLOR) && 81 currentAwtControl.getClass() != java.awt.Scrollbar.class && 82 currentAwtControl.getClass() != java.awt.Choice.class) { 83 fail("The HW component did not pass pixel color check and is not drawn correctly"); 84 } 85 86 return lwClicked; 87 } 88 89 // {debugClassName = "Choice";} 90 91 @Override 92 protected void prepareControls() { 93 JFrame frame = new JFrame("Glass Pane children test"); 94 frame.setLayout(null); 95 96 Container contentPane = frame.getContentPane(); 97 contentPane.setLayout(new BorderLayout()); 98 super.propagateAWTControls(contentPane); 99 100 Container glassPane = (Container) frame.getRootPane().getGlassPane(); 101 glassPane.setVisible(true); 102 glassPane.setLayout(null); 103 104 internalFrame = new JInternalFrame("Internal Frame", true); 105 internalFrame.setBounds(50, 0, 200, 100); 106 internalFrame.setVisible(true); 107 glassPane.add(internalFrame); 108 109 internalFrame.addMouseListener(new MouseAdapter() { 110 111 @Override 112 public void mouseClicked(MouseEvent e) { 113 lwClicked = true; 114 } 115 }); 116 117 frame.setSize(300, 180); 118 frame.setLocationRelativeTo(null); 119 frame.setVisible(true); 120 } 121 122 // this strange plumbing stuff is required due to "Standard Test Machinery" in base class 123 public static void main(String args[]) throws InterruptedException { 124 if (System.getProperty("os.name").toLowerCase().contains("os x")) { 125 System.out.println("Aqua L&F ignores setting color to component. Test passes on Mac OS X."); 126 return; 127 } 128 instance = new JGlassPaneInternalFrameOverlapping(); 129 OverlappingTestBase.doMain(args); 130 } 131 }