4548N/A/*
4548N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4548N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4548N/A *
4548N/A * This code is free software; you can redistribute it and/or modify it
4548N/A * under the terms of the GNU General Public License version 2 only, as
4548N/A * published by the Free Software Foundation.
4548N/A *
4548N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4548N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4548N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4548N/A * version 2 for more details (a copy is included in the LICENSE file that
4548N/A * accompanied this code).
4548N/A *
4548N/A * You should have received a copy of the GNU General Public License version
4548N/A * 2 along with this work; if not, write to the Free Software Foundation,
4548N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4548N/A *
4548N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4548N/A * or visit www.oracle.com if you need additional information or have any
4548N/A * questions.
4548N/A */
4548N/A
4548N/A/*
4548N/A * @test
4548N/A * @bug 4708809
4548N/A * @summary JScrollBar functionality slightly different from native scrollbar
4548N/A * @author Andrey Pikalev
4548N/A * @run main bug4708809
4548N/A */
4548N/Aimport javax.swing.*;
4548N/Aimport java.awt.*;
4548N/Aimport java.awt.Point;
4548N/Aimport java.awt.event.*;
4548N/Aimport sun.awt.SunToolkit;
4548N/A
4548N/Apublic class bug4708809 {
4548N/A
4548N/A private static volatile boolean do_test = false;
4548N/A private static volatile boolean passed = true;
4548N/A private static JScrollPane spane;
4548N/A private static JScrollBar sbar;
4548N/A
4548N/A public static void main(String[] args) throws Exception {
4548N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
4548N/A Robot robot = new Robot();
4549N/A robot.setAutoDelay(350);
4548N/A
4548N/A SwingUtilities.invokeAndWait(new Runnable() {
4548N/A
4548N/A public void run() {
4548N/A createAndShowGUI();
4548N/A }
4548N/A });
4548N/A
4548N/A toolkit.realSync();
4548N/A
4548N/A SwingUtilities.invokeAndWait(new Runnable() {
4548N/A
4548N/A public void run() {
4548N/A spane.requestFocus();
4548N/A sbar.setValue(sbar.getMaximum());
4548N/A }
4548N/A });
4548N/A
4548N/A toolkit.realSync();
4548N/A
4548N/A Point point = getClickPoint(0.5, 0.5);
4548N/A robot.mouseMove(point.x, point.y);
4548N/A robot.mousePress(InputEvent.BUTTON1_MASK);
4548N/A
4548N/A toolkit.realSync();
4548N/A
4548N/A SwingUtilities.invokeAndWait(new Runnable() {
4548N/A
4548N/A public void run() {
4548N/A final int oldValue = sbar.getValue();
4548N/A sbar.addAdjustmentListener(new AdjustmentListener() {
4548N/A
4548N/A public void adjustmentValueChanged(AdjustmentEvent e) {
4548N/A if (e.getValue() >= oldValue) {
4548N/A passed = false;
4548N/A }
4548N/A do_test = true;
4548N/A }
4548N/A });
4548N/A
4548N/A }
4548N/A });
4548N/A
4548N/A toolkit.realSync();
4548N/A
4548N/A point = getClickPoint(0.5, 0.2);
4548N/A robot.mouseMove(point.x, point.y);
4548N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
4548N/A toolkit.realSync();
4548N/A
4548N/A if (!do_test || !passed) {
4548N/A throw new Exception("The scrollbar moved with incorrect direction");
4548N/A }
4548N/A
4548N/A }
4548N/A
4548N/A private static Point getClickPoint(final double scaleX, final double scaleY) throws Exception {
4548N/A final Point[] result = new Point[1];
4548N/A
4548N/A SwingUtilities.invokeAndWait(new Runnable() {
4548N/A
4548N/A @Override
4548N/A public void run() {
4548N/A Point p = sbar.getLocationOnScreen();
4548N/A Rectangle rect = sbar.getBounds();
4548N/A result[0] = new Point((int) (p.x + scaleX * rect.width),
4548N/A (int) (p.y + scaleY * rect.height));
4548N/A }
4548N/A });
4548N/A
4548N/A return result[0];
4548N/A
4548N/A }
4548N/A
4548N/A private static void createAndShowGUI() {
4548N/A JFrame fr = new JFrame("Test");
4548N/A
4548N/A JLabel label = new JLabel("picture");
4548N/A label.setPreferredSize(new Dimension(500, 500));
4548N/A spane = new JScrollPane(label);
4548N/A fr.getContentPane().add(spane);
4548N/A sbar = spane.getVerticalScrollBar();
4548N/A
4548N/A fr.setSize(200, 200);
4548N/A fr.setVisible(true);
4548N/A }
4548N/A}