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