Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/ViewportOverlapping.java
41152 views
/*1* Copyright (c) 2014, 2016, 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* @key headful50* @bug 677888251* @summary Viewport overlapping test for each AWT component52* @author [email protected]: area=awt.mixing53* @library /java/awt/patchlib ../../regtesthelpers54* @modules java.desktop/sun.awt55* java.desktop/java.awt.peer56* @build java.desktop/java.awt.Helper57* @build Util58* @run main ViewportOverlapping59*/60public class ViewportOverlapping extends OverlappingTestBase {6162private volatile int frameClicked;63private Point hLoc;64private Point vLoc;65private Point testLoc;66private Point resizeLoc;6768private JFrame f;69private JPanel p;70private JButton b;71private JScrollPane scrollPane;7273protected void prepareControls() {74p = new JPanel(new GridLayout(0, 1));75propagateAWTControls(p);76b = new JButton("Space extender");77p.add(b);78p.setPreferredSize(new Dimension(500, 500));79scrollPane = new JScrollPane(p);8081f = new JFrame();82f.addMouseListener(new MouseAdapter() {8384@Override85public void mouseClicked(MouseEvent e) {86frameClicked++;87}88});89f.getContentPane().add(scrollPane, BorderLayout.CENTER);90((JComponent) f.getContentPane()).setBorder(91BorderFactory.createEmptyBorder(50, 50, 50, 50));92f.setSize(400, 400);93f.setLocationRelativeTo(null);94f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);95f.setVisible(true);96}9798@Override99protected boolean performTest() {100try {101SwingUtilities.invokeAndWait(new Runnable() {102public void run() {103// prepare test data104frameClicked = 0;105106b.requestFocus();107108scrollPane.getHorizontalScrollBar().setUnitIncrement(40);109scrollPane.getVerticalScrollBar().setUnitIncrement(40);110111hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen();112hLoc.translate(scrollPane.getHorizontalScrollBar().getWidth() - 3, 3);113vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen();114vLoc.translate(3, scrollPane.getVerticalScrollBar().getHeight() - 3);115116testLoc = p.getLocationOnScreen();117testLoc.translate(-3, -3);118119resizeLoc = f.getLocationOnScreen();120resizeLoc.translate(f.getWidth() - 1, f.getHeight() - 1);121}122});123} catch (Exception e) {124e.printStackTrace();125throw new RuntimeException("Problem preparing test GUI.");126}127// run robot128Robot robot = Util.createRobot();129robot.setAutoDelay(ROBOT_DELAY);130131robot.mouseMove(hLoc.x, hLoc.y);132robot.mousePress(InputEvent.BUTTON1_MASK);133robot.mouseRelease(InputEvent.BUTTON1_MASK);134Util.waitForIdle(robot);135136robot.mouseMove(vLoc.x, vLoc.y);137robot.mousePress(InputEvent.BUTTON1_MASK);138robot.mouseRelease(InputEvent.BUTTON1_MASK);139Util.waitForIdle(robot);140141clickAndBlink(robot, testLoc, false);142robot.mouseMove(resizeLoc.x, resizeLoc.y);143robot.mousePress(InputEvent.BUTTON1_MASK);144robot.mouseMove(resizeLoc.x + 5, resizeLoc.y + 5);145robot.mouseRelease(InputEvent.BUTTON1_MASK);146Util.waitForIdle(robot);147148clickAndBlink(robot, testLoc, false);149return frameClicked == 2;150}151152// this strange plumbing stuff is required due to "Standard Test Machinery" in base class153public static void main(String args[]) throws InterruptedException {154instance = new ViewportOverlapping();155OverlappingTestBase.doMain(args);156}157}158159160