1 /*
   2  * Copyright (c) 2014, 2016, 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.Dimension;
  26 import java.awt.GridLayout;
  27 import java.awt.Point;
  28 import java.awt.Robot;
  29 import java.awt.event.AdjustmentEvent;
  30 import java.awt.event.AdjustmentListener;
  31 import javax.swing.JFrame;
  32 import javax.swing.JPanel;
  33 import javax.swing.JScrollPane;
  34 import javax.swing.SwingUtilities;
  35 import test.java.awt.regtesthelpers.Util;
  36 
  37 /**
  38  * AWT/Swing overlapping test for {@link javax.swing.JScrollPane } component.
  39  * <p>See base class for test info.
  40  */
  41 /*
  42  * @test
  43  * @key headful
  44  * @summary Overlapping test for javax.swing.JScrollPane
  45  * @author sergey.grinev@oracle.com: area=awt.mixing
  46  * @library ../../regtesthelpers
  47  * @modules java.desktop/sun.awt
  48  *          java.desktop/java.awt.peer
  49  * @build Util
  50  * @run main JScrollPaneOverlapping
  51  */
  52 public class JScrollPaneOverlapping extends OverlappingTestBase {
  53 
  54 //    {testEmbeddedFrame = true;}
  55 
  56     private boolean horizontalClicked = false;
  57     private boolean verticalClicked = false;
  58     private Point hLoc;
  59     private Point vLoc;
  60 
  61     private JFrame f;
  62     private JPanel p;
  63     private JScrollPane scrollPane;
  64 
  65     protected void prepareControls() {
  66 
  67         f = new JFrame("JScrollPane");
  68         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  69         f.setSize(120, 120);
  70 
  71         p = new JPanel(new GridLayout(0, 1));
  72 
  73         scrollPane = new JScrollPane(p);
  74         scrollPane.setPreferredSize(new Dimension(300,300));
  75         scrollPane.setHorizontalScrollBarPolicy(
  76                 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  77         scrollPane.setVerticalScrollBarPolicy(
  78                 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  79 
  80         scrollPane.getHorizontalScrollBar().setValue(1);
  81         scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {
  82 
  83             public void adjustmentValueChanged(AdjustmentEvent e) {
  84                 horizontalClicked = true;
  85             }
  86         });
  87 
  88         scrollPane.getVerticalScrollBar().setValue(1);
  89         scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
  90 
  91             public void adjustmentValueChanged(AdjustmentEvent e) {
  92                 verticalClicked = true;
  93             }
  94         });
  95 
  96         f.getContentPane().add(scrollPane);
  97         f.setVisible(true);
  98         propagateAWTControls(p);
  99 //        JButton b = new JButton("Space extender");
 100 //        b.setPreferredSize(new Dimension(150,150));
 101 //        p.add( b );
 102 
 103         //b.requestFocus(); // to change the look of AWT component, especially Choice
 104     }
 105 
 106     @Override
 107     protected boolean performTest() {
 108         // run robot
 109         Robot robot = Util.createRobot();
 110         robot.setAutoDelay(ROBOT_DELAY);
 111 
 112         try {
 113             SwingUtilities.invokeAndWait(new Runnable() {
 114                 public void run() {
 115                     hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen();
 116                     vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen();
 117                 }
 118             });
 119         } catch (Exception e) {
 120         }
 121         hLoc.translate(2, 2);
 122         vLoc.translate(2, 2);
 123 
 124         clickAndBlink(robot, hLoc, false);
 125         clickAndBlink(robot, vLoc, false);
 126 
 127         return horizontalClicked && verticalClicked;
 128     }
 129 
 130     // this strange plumbing stuff is required due to "Standard Test Machinery" in base class
 131     public static void main(String args[]) throws InterruptedException {
 132         instance = new JScrollPaneOverlapping();
 133         OverlappingTestBase.doMain(args);
 134     }
 135 }