changeset 13891:0c9bc87633bc

8147994: [macosx] JScrollPane jitters up/down during trackpad scrolling on MacOS/Aqua Reviewed-by: alexp, aivanov
author serb
date Wed, 02 Mar 2016 18:28:42 +0300
parents 1aaa07a97e58
children 1b9628b3b8b7
files src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java test/javax/swing/JScrollPane/8033000/bug8033000.java test/javax/swing/JScrollPane/HorizontalMouseWheelOnShiftPressed/HorizontalMouseWheelOnShiftPressed.java
diffstat 3 files changed, 184 insertions(+), 170 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java	Mon Feb 29 09:00:35 2016 -0800
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java	Wed Mar 02 18:28:42 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -962,18 +962,13 @@
                 int orientation = SwingConstants.VERTICAL;
 
                 // find which scrollbar to scroll, or return if none
-                if (toScroll == null || !toScroll.isVisible()) {
+                if (toScroll == null || !toScroll.isVisible()
+                        || e.isShiftDown()) {
                     toScroll = scrollpane.getHorizontalScrollBar();
                     if (toScroll == null || !toScroll.isVisible()) {
                         return;
                     }
                     orientation = SwingConstants.HORIZONTAL;
-                } else if(e.isShiftDown()){
-                    JScrollBar hScroll = scrollpane.getHorizontalScrollBar();
-                    if (hScroll != null && hScroll.isVisible()) {
-                        toScroll = hScroll;
-                        orientation = SwingConstants.HORIZONTAL;
-                    }
                 }
 
                 e.consume();
--- a/test/javax/swing/JScrollPane/8033000/bug8033000.java	Mon Feb 29 09:00:35 2016 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,162 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-import java.awt.BorderLayout;
-import java.awt.Point;
-import java.awt.Robot;
-import java.awt.event.KeyEvent;
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
-import javax.swing.SwingUtilities;
-import javax.swing.UIManager;
-import jdk.testlibrary.OSInfo;
-
-/**
- * @test
- * @bug 8033000
- * @author Alexander Scherbatiy
- * @summary No Horizontal Mouse Wheel Support In BasicScrollPaneUI
- * @library ../../../../lib/testlibrary
- * @build jdk.testlibrary.OSInfo
- * @run main bug8033000
- */
-public class bug8033000 {
-
-    private static JScrollPane scrollPane;
-    private static JTextArea textArea;
-    private static Point point;
-    private static final int delta;
-
-    static {
-        delta = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ? -30 : 30;
-    }
-
-    public static void main(String[] args) throws Exception {
-
-        Robot robot = new Robot();
-        robot.setAutoDelay(50);
-
-        SwingUtilities.invokeAndWait(bug8033000::createAndShowGUI);
-        robot.waitForIdle();
-
-        SwingUtilities.invokeAndWait(() -> {
-            Point locationOnScreen = scrollPane.getLocationOnScreen();
-            point = new Point(
-                    locationOnScreen.x + scrollPane.getWidth() / 2,
-                    locationOnScreen.y + scrollPane.getHeight() / 2);
-        });
-
-        robot.mouseMove(point.x, point.y);
-        robot.waitForIdle();
-
-        // vertical scroll bar is enabled
-        initScrollPane(true, false);
-        robot.waitForIdle();
-        robot.mouseWheel(delta);
-        robot.waitForIdle();
-        checkScrollPane(true);
-
-        // vertical scroll bar is enabled + shift
-        initScrollPane(true, false);
-        robot.waitForIdle();
-        robot.keyPress(KeyEvent.VK_SHIFT);
-        robot.mouseWheel(delta);
-        robot.keyRelease(KeyEvent.VK_SHIFT);
-        robot.waitForIdle();
-        checkScrollPane(true);
-
-        // horizontal scroll bar is enabled
-        initScrollPane(false, true);
-        robot.waitForIdle();
-        robot.mouseWheel(delta);
-        robot.waitForIdle();
-        checkScrollPane(false);
-
-        // horizontal scroll bar is enabled + shift
-        initScrollPane(false, true);
-        robot.waitForIdle();
-        robot.keyPress(KeyEvent.VK_SHIFT);
-        robot.mouseWheel(delta);
-        robot.keyRelease(KeyEvent.VK_SHIFT);
-        robot.waitForIdle();
-        checkScrollPane(false);
-
-        // both scroll bars are enabled
-        initScrollPane(true, true);
-        robot.waitForIdle();
-        robot.mouseWheel(delta);
-        robot.waitForIdle();
-        checkScrollPane(true);
-
-        // both scroll bars are enabled + shift
-        initScrollPane(true, true);
-        robot.waitForIdle();
-        robot.keyPress(KeyEvent.VK_SHIFT);
-        robot.mouseWheel(delta);
-        robot.keyRelease(KeyEvent.VK_SHIFT);
-        robot.waitForIdle();
-        checkScrollPane(false);
-    }
-
-    static void initScrollPane(boolean vVisible, boolean hVisible) throws Exception {
-        SwingUtilities.invokeAndWait(() -> {
-            scrollPane.getVerticalScrollBar().setValue(0);
-            scrollPane.getHorizontalScrollBar().setValue(0);
-
-            textArea.setRows(vVisible ? 100 : 1);
-            textArea.setColumns(hVisible ? 100 : 1);
-            scrollPane.getVerticalScrollBar().setVisible(vVisible);
-            scrollPane.getHorizontalScrollBar().setVisible(hVisible);
-        });
-    }
-
-    static void checkScrollPane(boolean verticalScrolled) throws Exception {
-        SwingUtilities.invokeAndWait(() -> {
-
-            if (verticalScrolled) {
-                if (scrollPane.getVerticalScrollBar().getValue() == 0
-                        || scrollPane.getHorizontalScrollBar().getValue() != 0) {
-                    throw new RuntimeException("Wrong vertical scrolling!");
-                }
-            } else {
-                if (scrollPane.getVerticalScrollBar().getValue() != 0
-                        || scrollPane.getHorizontalScrollBar().getValue() == 0) {
-                    throw new RuntimeException("Wrong horizontal scrolling!");
-                }
-            }
-        });
-    }
-
-    static void createAndShowGUI() {
-        JFrame frame = new JFrame();
-        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-        frame.setSize(300, 300);
-        textArea = new JTextArea("Hello World!");
-        scrollPane = new JScrollPane(textArea);
-        JPanel panel = new JPanel(new BorderLayout());
-        panel.add(scrollPane, BorderLayout.CENTER);
-        frame.getContentPane().add(panel);
-        frame.setVisible(true);
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/JScrollPane/HorizontalMouseWheelOnShiftPressed/HorizontalMouseWheelOnShiftPressed.java	Wed Mar 02 18:28:42 2016 +0300
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.BorderLayout;
+import java.awt.Point;
+import java.awt.Robot;
+import java.awt.event.KeyEvent;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.SwingUtilities;
+
+import jdk.testlibrary.OSInfo;
+
+/**
+ * @test
+ * @bug 8033000 8147994
+ * @author Alexander Scherbatiy
+ * @summary No Horizontal Mouse Wheel Support In BasicScrollPaneUI
+ * @library ../../../../lib/testlibrary
+ * @build jdk.testlibrary.OSInfo
+ * @run main HorizontalMouseWheelOnShiftPressed
+ */
+public class HorizontalMouseWheelOnShiftPressed {
+
+    private static JScrollPane scrollPane;
+    private static JTextArea textArea;
+    private static Point point;
+    private static final int delta;
+    private static JFrame frame;
+
+    static {
+        delta = OSInfo.getOSType().equals(OSInfo.OSType.MACOSX) ? -30 : 30;
+    }
+
+    public static void main(String[] args) throws Exception {
+
+        Robot robot = new Robot();
+        robot.setAutoDelay(50);
+
+        SwingUtilities.invokeAndWait(
+                HorizontalMouseWheelOnShiftPressed::createAndShowGUI);
+        robot.waitForIdle();
+        try {
+            test(robot);
+        } finally {
+            frame.dispose();
+        }
+    }
+
+    private static void test(Robot robot) throws Exception {
+        SwingUtilities.invokeAndWait(() -> {
+            Point locationOnScreen = scrollPane.getLocationOnScreen();
+            point = new Point(
+                    locationOnScreen.x + scrollPane.getWidth() / 2,
+                    locationOnScreen.y + scrollPane.getHeight() / 2);
+        });
+
+        robot.mouseMove(point.x, point.y);
+        robot.waitForIdle();
+
+        // vertical scroll bar is enabled
+        initScrollPane(true, false);
+        robot.waitForIdle();
+        robot.mouseWheel(delta);
+        robot.waitForIdle();
+        checkScrollPane(true, false);
+
+        // vertical scroll bar is enabled + shift
+        initScrollPane(true, false);
+        robot.waitForIdle();
+        robot.keyPress(KeyEvent.VK_SHIFT);
+        robot.mouseWheel(delta);
+        robot.keyRelease(KeyEvent.VK_SHIFT);
+        robot.waitForIdle();
+        checkScrollPane(false, false);
+
+        // horizontal scroll bar is enabled
+        initScrollPane(false, true);
+        robot.waitForIdle();
+        robot.mouseWheel(delta);
+        robot.waitForIdle();
+        checkScrollPane(false, true);
+
+        // horizontal scroll bar is enabled + shift
+        initScrollPane(false, true);
+        robot.waitForIdle();
+        robot.keyPress(KeyEvent.VK_SHIFT);
+        robot.mouseWheel(delta);
+        robot.keyRelease(KeyEvent.VK_SHIFT);
+        robot.waitForIdle();
+        checkScrollPane(false, true);
+
+        // both scroll bars are enabled
+        initScrollPane(true, true);
+        robot.waitForIdle();
+        robot.mouseWheel(delta);
+        robot.waitForIdle();
+        checkScrollPane(true, false);
+
+        // both scroll bars are enabled + shift
+        initScrollPane(true, true);
+        robot.waitForIdle();
+        robot.keyPress(KeyEvent.VK_SHIFT);
+        robot.mouseWheel(delta);
+        robot.keyRelease(KeyEvent.VK_SHIFT);
+        robot.waitForIdle();
+        checkScrollPane(false, true);
+    }
+
+    static void initScrollPane(boolean vVisible, boolean hVisible) throws Exception {
+        SwingUtilities.invokeAndWait(() -> {
+            scrollPane.getVerticalScrollBar().setValue(0);
+            scrollPane.getHorizontalScrollBar().setValue(0);
+
+            textArea.setRows(vVisible ? 100 : 1);
+            textArea.setColumns(hVisible ? 100 : 1);
+            scrollPane.getVerticalScrollBar().setVisible(vVisible);
+            scrollPane.getHorizontalScrollBar().setVisible(hVisible);
+        });
+    }
+
+    static void checkScrollPane(boolean verticalScrolled,
+                                boolean horizontalScrolled) throws Exception {
+        SwingUtilities.invokeAndWait(() -> {
+
+            if (verticalScrolled) {
+                if (scrollPane.getVerticalScrollBar().getValue() == 0) {
+                    throw new RuntimeException("Wrong vertical scrolling!");
+                }
+            } else{
+                if (scrollPane.getVerticalScrollBar().getValue() != 0) {
+                    throw new RuntimeException("Wrong vertical scrolling!");
+                }
+            }
+            if (horizontalScrolled) {
+                if (scrollPane.getHorizontalScrollBar().getValue() == 0) {
+                    throw new RuntimeException("Wrong horizontal scrolling!");
+                }
+            } else {
+                if (scrollPane.getHorizontalScrollBar().getValue() != 0) {
+                    throw new RuntimeException("Wrong horizontal scrolling!");
+                }
+            }
+        });
+    }
+
+    static void createAndShowGUI() {
+        frame = new JFrame();
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        frame.setSize(300, 300);
+        frame.setLocationRelativeTo(null);
+        textArea = new JTextArea("Hello World!");
+        scrollPane = new JScrollPane(textArea);
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(scrollPane, BorderLayout.CENTER);
+        frame.getContentPane().add(panel);
+        frame.setVisible(true);
+    }
+}