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