1 /* 2 * Copyright (c) 2014, 2015, 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 25 import java.awt.BorderLayout; 26 import java.awt.Dimension; 27 import java.awt.GridLayout; 28 import java.awt.Point; 29 import java.awt.Robot; 30 import java.awt.event.InputEvent; 31 import java.awt.event.MouseAdapter; 32 import java.awt.event.MouseEvent; 33 import javax.swing.BorderFactory; 34 import javax.swing.JButton; 35 import javax.swing.JComponent; 36 import javax.swing.JFrame; 37 import javax.swing.JPanel; 38 import javax.swing.JScrollPane; 39 import javax.swing.SwingUtilities; 40 import 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 @bug 6778882 51 @summary Viewport overlapping test for each AWT component 52 @author sergey.grinev@oracle.com: area=awt.mixing 53 @library ../../regtesthelpers 54 @modules java.desktop/sun.awt 55 @build Util 56 @run main ViewportOverlapping 57 */ 58 public class ViewportOverlapping extends OverlappingTestBase { 59 60 private volatile int frameClicked; 61 private Point hLoc; 62 private Point vLoc; 63 private Point testLoc; 64 private Point resizeLoc; 65 66 private JFrame f; 67 private JPanel p; 68 private JButton b; 69 private JScrollPane scrollPane; 70 71 protected void prepareControls() { 72 p = new JPanel(new GridLayout(0, 1)); 73 propagateAWTControls(p); 74 b = new JButton("Space extender"); 75 p.add(b); 76 p.setPreferredSize(new Dimension(500, 500)); 77 scrollPane = new JScrollPane(p); 78 79 f = new JFrame(); 80 f.addMouseListener(new MouseAdapter() { 81 82 @Override 83 public void mouseClicked(MouseEvent e) { 84 frameClicked++; 85 } 86 }); 87 f.getContentPane().add(scrollPane, BorderLayout.CENTER); 88 ((JComponent) f.getContentPane()).setBorder( 89 BorderFactory.createEmptyBorder(50, 50, 50, 50)); 90 f.setSize(400, 400); 91 f.setLocationRelativeTo(null); 92 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 93 f.setVisible(true); 94 } 95 96 @Override 97 protected boolean performTest() { 98 try { 99 SwingUtilities.invokeAndWait(new Runnable() { 100 public void run() { 101 // prepare test data 102 frameClicked = 0; 103 104 b.requestFocus(); 105 106 scrollPane.getHorizontalScrollBar().setUnitIncrement(40); 107 scrollPane.getVerticalScrollBar().setUnitIncrement(40); 108 109 hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen(); 110 hLoc.translate(scrollPane.getHorizontalScrollBar().getWidth() - 3, 3); 111 vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen(); 112 vLoc.translate(3, scrollPane.getVerticalScrollBar().getHeight() - 3); 113 114 testLoc = p.getLocationOnScreen(); 115 testLoc.translate(-3, -3); 116 117 resizeLoc = f.getLocationOnScreen(); 118 resizeLoc.translate(f.getWidth() - 1, f.getHeight() - 1); 119 } 120 }); 121 } catch (Exception e) { 122 e.printStackTrace(); 123 throw new RuntimeException("Problem preparing test GUI."); 124 } 125 // run robot 126 Robot robot = Util.createRobot(); 127 robot.setAutoDelay(ROBOT_DELAY); 128 129 robot.mouseMove(hLoc.x, hLoc.y); 130 robot.mousePress(InputEvent.BUTTON1_MASK); 131 robot.mouseRelease(InputEvent.BUTTON1_MASK); 132 Util.waitForIdle(robot); 133 134 robot.mouseMove(vLoc.x, vLoc.y); 135 robot.mousePress(InputEvent.BUTTON1_MASK); 136 robot.mouseRelease(InputEvent.BUTTON1_MASK); 137 Util.waitForIdle(robot); 138 139 clickAndBlink(robot, testLoc, false); 140 robot.mouseMove(resizeLoc.x, resizeLoc.y); 141 robot.mousePress(InputEvent.BUTTON1_MASK); 142 robot.mouseMove(resizeLoc.x + 5, resizeLoc.y + 5); 143 robot.mouseRelease(InputEvent.BUTTON1_MASK); 144 Util.waitForIdle(robot); 145 146 clickAndBlink(robot, testLoc, false); 147 return frameClicked == 2; 148 } 149 150 // this strange plumbing stuff is required due to "Standard Test Machinery" in base class 151 public static void main(String args[]) throws InterruptedException { 152 instance = new ViewportOverlapping(); 153 OverlappingTestBase.doMain(args); 154 } 155 }