Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mixing/AWT_Mixing/ViewportOverlapping.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*/222324import java.awt.BorderLayout;25import java.awt.Dimension;26import java.awt.GridLayout;27import java.awt.Point;28import java.awt.Robot;29import java.awt.event.InputEvent;30import java.awt.event.MouseAdapter;31import java.awt.event.MouseEvent;32import javax.swing.BorderFactory;33import javax.swing.JButton;34import javax.swing.JComponent;35import javax.swing.JFrame;36import javax.swing.JPanel;37import javax.swing.JScrollPane;38import javax.swing.SwingUtilities;39import test.java.awt.regtesthelpers.Util;4041/**42* AWT/Swing overlapping test for viewport43* <p>This test verify if AWT components are drawn correctly being partially shown through viewport44* <p>See <a href="http://monaco.sfbay.sun.com/detail.jsf?cr=6778882">CR6778882</a> for details45* <p>See base class for test info.46*/47/*48@test49@bug 677888250@summary Viewport overlapping test for each AWT component51@author [email protected]: area=awt.mixing52@library ../../regtesthelpers53@build Util54@run main ViewportOverlapping55*/56public class ViewportOverlapping extends OverlappingTestBase {5758private volatile int frameClicked;59private Point hLoc;60private Point vLoc;61private Point testLoc;62private Point resizeLoc;6364private JFrame f;65private JPanel p;66private JButton b;67private JScrollPane scrollPane;6869protected void prepareControls() {70p = new JPanel(new GridLayout(0, 1));71propagateAWTControls(p);72b = new JButton("Space extender");73p.add(b);74p.setPreferredSize(new Dimension(500, 500));75scrollPane = new JScrollPane(p);7677f = new JFrame();78f.addMouseListener(new MouseAdapter() {7980@Override81public void mouseClicked(MouseEvent e) {82frameClicked++;83}84});85f.getContentPane().add(scrollPane, BorderLayout.CENTER);86((JComponent) f.getContentPane()).setBorder(87BorderFactory.createEmptyBorder(50, 50, 50, 50));88f.setSize(400, 400);89f.setLocationRelativeTo(null);90f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);91f.setVisible(true);92}9394@Override95protected boolean performTest() {96try {97SwingUtilities.invokeAndWait(new Runnable() {98public void run() {99// prepare test data100frameClicked = 0;101102b.requestFocus();103104scrollPane.getHorizontalScrollBar().setUnitIncrement(40);105scrollPane.getVerticalScrollBar().setUnitIncrement(40);106107hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen();108hLoc.translate(scrollPane.getHorizontalScrollBar().getWidth() - 3, 3);109vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen();110vLoc.translate(3, scrollPane.getVerticalScrollBar().getHeight() - 3);111112testLoc = p.getLocationOnScreen();113testLoc.translate(-3, -3);114115resizeLoc = f.getLocationOnScreen();116resizeLoc.translate(f.getWidth() - 1, f.getHeight() - 1);117}118});119} catch (Exception e) {120e.printStackTrace();121throw new RuntimeException("Problem preparing test GUI.");122}123// run robot124Robot robot = Util.createRobot();125robot.setAutoDelay(ROBOT_DELAY);126127robot.mouseMove(hLoc.x, hLoc.y);128robot.mousePress(InputEvent.BUTTON1_MASK);129robot.mouseRelease(InputEvent.BUTTON1_MASK);130Util.waitForIdle(robot);131132robot.mouseMove(vLoc.x, vLoc.y);133robot.mousePress(InputEvent.BUTTON1_MASK);134robot.mouseRelease(InputEvent.BUTTON1_MASK);135Util.waitForIdle(robot);136137clickAndBlink(robot, testLoc, false);138robot.mouseMove(resizeLoc.x, resizeLoc.y);139robot.mousePress(InputEvent.BUTTON1_MASK);140robot.mouseMove(resizeLoc.x + 5, resizeLoc.y + 5);141robot.mouseRelease(InputEvent.BUTTON1_MASK);142Util.waitForIdle(robot);143144clickAndBlink(robot, testLoc, false);145return frameClicked == 2;146}147148// this strange plumbing stuff is required due to "Standard Test Machinery" in base class149public static void main(String args[]) throws InterruptedException {150instance = new ViewportOverlapping();151OverlappingTestBase.doMain(args);152}153}154155156