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 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.InputEvent;
  30 import java.awt.event.MouseAdapter;
  31 import java.awt.event.MouseEvent;
  32 import javax.swing.JFrame;
  33 import javax.swing.JInternalFrame;
  34 import javax.swing.SwingUtilities;
  35 import test.java.awt.regtesthelpers.Util;
  36 
  37 /**
  38  * AWT/Swing overlapping test with JInternalFrame being moved in GlassPane.
  39  * See <a href="https://bugs.openjdk.java.net/browse/JDK-6637655">JDK-6637655</a> and
  40  * <a href="https://bugs.openjdk.java.net/browse/JDK-6981919">JDK-6981919</a>.
  41  * <p>See base class for details.
  42  */
  43 /*
  44  * @test
  45  * @key headful
  46  * @bug 6637655 6981919
  47  * @summary Overlapping test for javax.swing.JScrollPane
  48  * @author sergey.grinev@oracle.com: area=awt.mixing
  49  * @library ../../regtesthelpers
  50  * @modules java.desktop/sun.awt
  51  *          java.desktop/java.awt.peer

  52  * @build Util
  53  * @run main JGlassPaneMoveOverlapping
  54  */
  55 public class JGlassPaneMoveOverlapping extends OverlappingTestBase {
  56 
  57     private boolean lwClicked = true;
  58     private volatile Point lLoc;
  59     private volatile Point lLoc2;
  60 
  61     private JInternalFrame internalFrame;
  62     private JFrame frame = null;
  63     private volatile Point frameLoc;
  64 
  65     protected boolean performTest() {
  66 
  67         try {
  68             SwingUtilities.invokeAndWait(new Runnable() {
  69                 public void run() {
  70                     lLoc = internalFrame.getContentPane().getLocationOnScreen();
  71                     lLoc2 = lLoc.getLocation();
  72                     lLoc2.translate(0, internalFrame.getHeight());
  73                     frameLoc = frame.getLocationOnScreen();
  74                     frameLoc.translate(frame.getWidth()/2, 3);
  75                 }
  76             });
  77         } catch (Exception e) {
  78             e.printStackTrace();
  79             throw new RuntimeException("Where is internal frame?");
  80         }
  81 
  82         // run robot
  83         Robot robot = Util.createRobot();
  84         robot.setAutoDelay(ROBOT_DELAY);
  85 
  86         // force focus on JFrame (jtreg workaround)
  87         robot.mouseMove(frameLoc.x, frameLoc.y);
  88         Util.waitForIdle(robot);
  89         robot.mousePress(InputEvent.BUTTON1_MASK);
  90         robot.delay(50);
  91         robot.mouseRelease(InputEvent.BUTTON1_MASK);
  92         Util.waitForIdle(robot);
  93 
  94 
  95         //slow move
  96         robot.mouseMove(lLoc.x +  25, lLoc.y - 5);
  97         robot.mousePress(InputEvent.BUTTON1_MASK);
  98         robot.delay(100);
  99         robot.mouseMove(lLoc.x +  45, lLoc.y - 5);
 100         robot.delay(100);
 101         robot.mouseMove(lLoc.x +  internalWidth - 75, lLoc.y - 5);
 102         robot.delay(100);
 103         robot.mouseMove(lLoc.x +  internalWidth - 55, lLoc.y - 5);
 104         robot.delay(100);
 105         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 106 
 107         Color c2 = robot.getPixelColor(lLoc.x +  internalWidth + 15, lLoc.y - 5);
 108         if (c2.equals(AWT_BACKGROUND_COLOR)) {
 109             error("Foreground frame is not drawn properly");
 110         }
 111         Color c = robot.getPixelColor(lLoc.x +  internalWidth - 95, lLoc.y + 5);
 112         robot.mouseMove(lLoc.x +  internalWidth - 95, lLoc.y + 5);
 113         System.out.println("color: " + c + " " + AWT_BACKGROUND_COLOR);
 114         if (!c.equals(AWT_BACKGROUND_COLOR) && currentAwtControl.getClass() != java.awt.Scrollbar.class) {
 115             error("Background AWT component is not drawn properly");
 116         }
 117 
 118         return true;
 119     }
 120 
 121     // {debugClassName = "Choice";}
 122 
 123     private static void error(String st) {
 124         //System.out.println(st);
 125         fail(st);
 126     }
 127 
 128     private static final int internalWidth = 200;
 129 
 130     @Override
 131     protected void prepareControls() {
 132         if(frame != null) {
 133             frame.setVisible(false);
 134         }
 135         frame = new JFrame("Glass Pane children test");
 136         frame.setLayout(null);
 137 
 138         Container contentPane = frame.getContentPane();
 139         contentPane.setLayout(new BorderLayout());
 140         super.propagateAWTControls(contentPane);
 141 
 142         Container glassPane = (Container) frame.getRootPane().getGlassPane();
 143         glassPane.setVisible(true);
 144         glassPane.setLayout(null);
 145 
 146         internalFrame = new JInternalFrame("Internal Frame", true);
 147         internalFrame.setBounds(50, 0, internalWidth, 100);
 148         internalFrame.setVisible(true);
 149         glassPane.add(internalFrame);
 150 
 151         internalFrame.addMouseListener(new MouseAdapter() {
 152 
 153             @Override
 154             public void mouseClicked(MouseEvent e) {
 155                 lwClicked = true;
 156             }
 157         });
 158 
 159         frame.setSize(400, 180);
 160         frame.setLocationRelativeTo(null);
 161         frame.setVisible(true);
 162     }
 163 
 164     // this strange plumbing stuff is required due to "Standard Test Machinery" in base class
 165     public static void main(String args[]) throws InterruptedException {
 166         if (System.getProperty("os.name").toLowerCase().contains("os x")) {
 167             System.out.println("Aqua L&F ignores setting color to component. Test passes on Mac OS X.");
 168             return;
 169         }
 170         instance = new JGlassPaneMoveOverlapping();
 171         OverlappingTestBase.doMain(args);
 172     }
 173 }
--- EOF ---