Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mixing/AWT_Mixing/JGlassPaneMoveOverlapping.java
47626 views
/*1* Copyright (c) 2014, 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.InputEvent;29import java.awt.event.MouseAdapter;30import java.awt.event.MouseEvent;31import javax.swing.JFrame;32import javax.swing.JInternalFrame;33import javax.swing.SwingUtilities;34import test.java.awt.regtesthelpers.Util;3536/**37* AWT/Swing overlapping test with JInternalFrame being moved in GlassPane.38* See <a href="https://bugs.openjdk.java.net/browse/JDK-6637655">JDK-6637655</a> and39* <a href="https://bugs.openjdk.java.net/browse/JDK-6981919">JDK-6981919</a>.40* <p>See base class for details.41*/42/*43@test44@bug 6637655 698191945@summary Overlapping test for javax.swing.JScrollPane46@author [email protected]: area=awt.mixing47@library ../../regtesthelpers48@build Util49@run main JGlassPaneMoveOverlapping50*/51public class JGlassPaneMoveOverlapping extends OverlappingTestBase {5253private boolean lwClicked = true;54private volatile Point lLoc;55private volatile Point lLoc2;5657private JInternalFrame internalFrame;58private JFrame frame = null;59private volatile Point frameLoc;6061protected boolean performTest() {6263try {64SwingUtilities.invokeAndWait(new Runnable() {65public void run() {66lLoc = internalFrame.getContentPane().getLocationOnScreen();67lLoc2 = lLoc.getLocation();68lLoc2.translate(0, internalFrame.getHeight());69frameLoc = frame.getLocationOnScreen();70frameLoc.translate(frame.getWidth()/2, 3);71}72});73} catch (Exception e) {74e.printStackTrace();75throw new RuntimeException("Where is internal frame?");76}7778// run robot79Robot robot = Util.createRobot();80robot.setAutoDelay(ROBOT_DELAY);8182// force focus on JFrame (jtreg workaround)83robot.mouseMove(frameLoc.x, frameLoc.y);84Util.waitForIdle(robot);85robot.mousePress(InputEvent.BUTTON1_MASK);86robot.delay(50);87robot.mouseRelease(InputEvent.BUTTON1_MASK);88Util.waitForIdle(robot);899091//slow move92robot.mouseMove(lLoc.x + 25, lLoc.y - 5);93robot.mousePress(InputEvent.BUTTON1_MASK);94robot.delay(100);95robot.mouseMove(lLoc.x + 45, lLoc.y - 5);96robot.delay(100);97robot.mouseMove(lLoc.x + internalWidth - 75, lLoc.y - 5);98robot.delay(100);99robot.mouseMove(lLoc.x + internalWidth - 55, lLoc.y - 5);100robot.delay(100);101robot.mouseRelease(InputEvent.BUTTON1_MASK);102103Color c2 = robot.getPixelColor(lLoc.x + internalWidth + 15, lLoc.y - 5);104if (c2.equals(AWT_BACKGROUND_COLOR)) {105error("Foreground frame is not drawn properly");106}107Color c = robot.getPixelColor(lLoc.x + internalWidth - 95, lLoc.y + 5);108robot.mouseMove(lLoc.x + internalWidth - 95, lLoc.y + 5);109System.out.println("color: " + c + " " + AWT_BACKGROUND_COLOR);110if (!c.equals(AWT_BACKGROUND_COLOR) && currentAwtControl.getClass() != java.awt.Scrollbar.class) {111error("Background AWT component is not drawn properly");112}113114return true;115}116117// {debugClassName = "Choice";}118119private static void error(String st) {120//System.out.println(st);121fail(st);122}123124private static final int internalWidth = 200;125126@Override127protected void prepareControls() {128if(frame != null) {129frame.setVisible(false);130}131frame = new JFrame("Glass Pane children test");132frame.setLayout(null);133134Container contentPane = frame.getContentPane();135contentPane.setLayout(new BorderLayout());136super.propagateAWTControls(contentPane);137138Container glassPane = (Container) frame.getRootPane().getGlassPane();139glassPane.setVisible(true);140glassPane.setLayout(null);141142internalFrame = new JInternalFrame("Internal Frame", true);143internalFrame.setBounds(50, 0, internalWidth, 100);144internalFrame.setVisible(true);145glassPane.add(internalFrame);146147internalFrame.addMouseListener(new MouseAdapter() {148149@Override150public void mouseClicked(MouseEvent e) {151lwClicked = true;152}153});154155frame.setSize(400, 180);156frame.setLocationRelativeTo(null);157frame.setVisible(true);158}159160// this strange plumbing stuff is required due to "Standard Test Machinery" in base class161public static void main(String args[]) throws InterruptedException {162if (System.getProperty("os.name").toLowerCase().contains("os x")) {163System.out.println("Aqua L&F ignores setting color to component. Test passes on Mac OS X.");164return;165}166instance = new JGlassPaneMoveOverlapping();167OverlappingTestBase.doMain(args);168}169}170171172