ViewportOverlapping.java revision 14851:980da45565c8
1151497Sru/* 2151497Sru * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 3151497Sru * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4151497Sru * 5151497Sru * This code is free software; you can redistribute it and/or modify it 6151497Sru * under the terms of the GNU General Public License version 2 only, as 7151497Sru * published by the Free Software Foundation. 8151497Sru * 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 25import java.awt.BorderLayout; 26import java.awt.Dimension; 27import java.awt.GridLayout; 28import java.awt.Point; 29import java.awt.Robot; 30import java.awt.event.InputEvent; 31import java.awt.event.MouseAdapter; 32import java.awt.event.MouseEvent; 33import javax.swing.BorderFactory; 34import javax.swing.JButton; 35import javax.swing.JComponent; 36import javax.swing.JFrame; 37import javax.swing.JPanel; 38import javax.swing.JScrollPane; 39import javax.swing.SwingUtilities; 40import test.java.awt.regtesthelpers.Util; 41 42/** 43 * AWT/Swing overlapping test for viewport 44 * <p>This test verify if AWT components are drawn correctly being partially shown through viewport 45 * <p>See <a href="http://monaco.sfbay.sun.com/detail.jsf?cr=6778882">CR6778882</a> for details 46 * <p>See base class for test info. 47 */ 48/* 49 * @test 50 * @key headful 51 * @bug 6778882 52 * @summary Viewport overlapping test for each AWT component 53 * @author sergey.grinev@oracle.com: area=awt.mixing 54 * @library /java/awt/patchlib ../../regtesthelpers 55 * @modules java.desktop/sun.awt 56 * java.desktop/java.awt.peer 57 * @build java.desktop/java.awt.Helper 58 * @build Util 59 * @run main ViewportOverlapping 60 */ 61public class ViewportOverlapping extends OverlappingTestBase { 62 63 private volatile int frameClicked; 64 private Point hLoc; 65 private Point vLoc; 66 private Point testLoc; 67 private Point resizeLoc; 68 69 private JFrame f; 70 private JPanel p; 71 private JButton b; 72 private JScrollPane scrollPane; 73 74 protected void prepareControls() { 75 p = new JPanel(new GridLayout(0, 1)); 76 propagateAWTControls(p); 77 b = new JButton("Space extender"); 78 p.add(b); 79 p.setPreferredSize(new Dimension(500, 500)); 80 scrollPane = new JScrollPane(p); 81 82 f = new JFrame(); 83 f.addMouseListener(new MouseAdapter() { 84 85 @Override 86 public void mouseClicked(MouseEvent e) { 87 frameClicked++; 88 } 89 }); 90 f.getContentPane().add(scrollPane, BorderLayout.CENTER); 91 ((JComponent) f.getContentPane()).setBorder( 92 BorderFactory.createEmptyBorder(50, 50, 50, 50)); 93 f.setSize(400, 400); 94 f.setLocationRelativeTo(null); 95 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 96 f.setVisible(true); 97 } 98 99 @Override 100 protected boolean performTest() { 101 try { 102 SwingUtilities.invokeAndWait(new Runnable() { 103 public void run() { 104 // prepare test data 105 frameClicked = 0; 106 107 b.requestFocus(); 108 109 scrollPane.getHorizontalScrollBar().setUnitIncrement(40); 110 scrollPane.getVerticalScrollBar().setUnitIncrement(40); 111 112 hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen(); 113 hLoc.translate(scrollPane.getHorizontalScrollBar().getWidth() - 3, 3); 114 vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen(); 115 vLoc.translate(3, scrollPane.getVerticalScrollBar().getHeight() - 3); 116 117 testLoc = p.getLocationOnScreen(); 118 testLoc.translate(-3, -3); 119 120 resizeLoc = f.getLocationOnScreen(); 121 resizeLoc.translate(f.getWidth() - 1, f.getHeight() - 1); 122 } 123 }); 124 } catch (Exception e) { 125 e.printStackTrace(); 126 throw new RuntimeException("Problem preparing test GUI."); 127 } 128 // run robot 129 Robot robot = Util.createRobot(); 130 robot.setAutoDelay(ROBOT_DELAY); 131 132 robot.mouseMove(hLoc.x, hLoc.y); 133 robot.mousePress(InputEvent.BUTTON1_MASK); 134 robot.mouseRelease(InputEvent.BUTTON1_MASK); 135 Util.waitForIdle(robot); 136 137 robot.mouseMove(vLoc.x, vLoc.y); 138 robot.mousePress(InputEvent.BUTTON1_MASK); 139 robot.mouseRelease(InputEvent.BUTTON1_MASK); 140 Util.waitForIdle(robot); 141 142 clickAndBlink(robot, testLoc, false); 143 robot.mouseMove(resizeLoc.x, resizeLoc.y); 144 robot.mousePress(InputEvent.BUTTON1_MASK); 145 robot.mouseMove(resizeLoc.x + 5, resizeLoc.y + 5); 146 robot.mouseRelease(InputEvent.BUTTON1_MASK); 147 Util.waitForIdle(robot); 148 149 clickAndBlink(robot, testLoc, false); 150 return frameClicked == 2; 151 } 152 153 // this strange plumbing stuff is required due to "Standard Test Machinery" in base class 154 public static void main(String args[]) throws InterruptedException { 155 instance = new ViewportOverlapping(); 156 OverlappingTestBase.doMain(args); 157 } 158} 159