1 /* 2 * Copyright (c) 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 import java.awt.*; 25 import java.awt.event.*; 26 import javax.swing.*; 27 /* 28 * @test 29 * @key headful 30 * @bug 8080137 31 * @summary Dragged events for extra mouse buttons (4,5,6) are not generated 32 * on JSplitPane 33 * @author alexandr.scherbatiy area=awt.event 34 * @run main MouseDraggedTest 35 */ 36 public class MouseDraggedTest { 37 38 private static JFrame frame; 39 private static Rectangle frameBounds; 40 private static volatile boolean mouseDragged; 41 42 public static void main(String[] args) throws Exception { 43 try { 44 Robot robot = new Robot(); 45 robot.setAutoDelay(50); 46 47 SwingUtilities.invokeAndWait(MouseDraggedTest::createAndShowGUI); 48 robot.waitForIdle(); 49 50 SwingUtilities.invokeAndWait(() -> frameBounds = frame.getBounds()); 51 robot.waitForIdle(); 52 53 for (int i = 1; i <= MouseInfo.getNumberOfButtons(); i++) { 54 testMouseDrag(i, robot); 55 } 56 } finally { 57 SwingUtilities.invokeLater(() -> { 58 if (frame != null) { 59 frame.dispose(); 60 } 61 }); 62 } 63 } 64 65 private static void testMouseDrag(int button, Robot robot) { 66 67 mouseDragged = false; 68 int x1 = frameBounds.x + frameBounds.width / 4; 69 int y1 = frameBounds.y + frameBounds.height / 4; 70 int x2 = frameBounds.x + frameBounds.width / 2; 71 int y2 = frameBounds.y + frameBounds.height / 2; 72 73 robot.mouseMove(x1, y1); 74 robot.waitForIdle(); 75 76 int buttonMask = InputEvent.getMaskForButton(button); 77 robot.mousePress(buttonMask); 78 robot.mouseMove(x2, y2); 79 robot.mouseRelease(buttonMask); 80 robot.waitForIdle(); 81 82 if (!mouseDragged) { 83 throw new RuntimeException("Mouse button " + button 84 + " is not dragged"); 85 } 86 } 87 88 static void createAndShowGUI() { 89 90 frame = new JFrame(); 91 frame.setSize(400, 400); 92 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 93 JPanel panel = new JPanel(new BorderLayout()); 94 panel.addMouseMotionListener(new MouseAdapter() { 95 96 @Override 97 public void mouseDragged(MouseEvent e) { 98 mouseDragged = true; 99 } 100 }); 101 frame.add(panel, BorderLayout.CENTER); 102 frame.setVisible(true); 103 } 104 }