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