1 /*
   2  * Copyright (c) 2013, 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  * @test
  26  * @bug 7163696
  27  * @summary Tests that JScrollBar scrolls to the left
  28  * @author Sergey Malenkov
  29  */
  30 
  31 import sun.awt.SunToolkit;
  32 
  33 import java.awt.Dimension;
  34 import java.awt.Point;
  35 import java.awt.Robot;
  36 import java.awt.Toolkit;
  37 import java.awt.event.InputEvent;
  38 
  39 import javax.swing.JFrame;
  40 import javax.swing.JScrollBar;
  41 import javax.swing.SwingUtilities;
  42 import javax.swing.UIManager;
  43 import javax.swing.UIManager.LookAndFeelInfo;
  44 
  45 public class Test7163696 implements Runnable {
  46 
  47     private static final boolean AUTO = null != System.getProperty("test.src", null);
  48 
  49     public static void main(String[] args) throws Exception {
  50         new Test7163696().test();
  51     }
  52 
  53     private JScrollBar bar;
  54 
  55     private void test() throws Exception {
  56         Robot robot = new Robot();
  57         SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
  58         for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
  59             UIManager.setLookAndFeel(info.getClassName());
  60 
  61             SwingUtilities.invokeAndWait(this);
  62             toolkit.realSync(); // after creation
  63             Thread.sleep(1000);
  64 
  65             Point point = this.bar.getLocation();
  66             SwingUtilities.convertPointToScreen(point, this.bar);
  67             point.x += this.bar.getWidth() >> 2;
  68             point.y += this.bar.getHeight() >> 1;
  69             robot.mouseMove(point.x, point.y);
  70             robot.mousePress(InputEvent.BUTTON1_MASK);
  71             robot.mouseRelease(InputEvent.BUTTON1_MASK);
  72 
  73             toolkit.realSync(); // before validation
  74             Thread.sleep(1000);
  75             SwingUtilities.invokeAndWait(this);
  76 
  77             if (this.bar != null) {
  78                 this.bar = null; // allows to reuse the instance
  79                 if (AUTO) { // error reporting only for automatic testing
  80                     throw new Error("TEST FAILED");
  81                 }
  82             }
  83         }
  84     }
  85 
  86     public void run() {
  87         if (this.bar == null) {
  88             this.bar = new JScrollBar(JScrollBar.HORIZONTAL, 50, 10, 0, 100);
  89             this.bar.setPreferredSize(new Dimension(400, 20));
  90 
  91             JFrame frame = new JFrame();
  92             frame.add(this.bar);
  93             frame.pack();
  94             frame.setVisible(true);
  95         }
  96         else if (40 != this.bar.getValue()) {
  97             System.out.println("name = " + UIManager.getLookAndFeel().getName());
  98             System.out.println("value = " + this.bar.getValue());
  99         }
 100         else {
 101             SwingUtilities.getWindowAncestor(this.bar).dispose();
 102             this.bar = null;
 103         }
 104     }
 105 }