Path: blob/master/test/jdk/java/awt/Mouse/MouseDragEvent/MouseDraggedTest.java
41153 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.*;24import java.awt.event.*;25import javax.swing.*;26/*27* @test28* @key headful29* @bug 808013730* @summary Dragged events for extra mouse buttons (4,5,6) are not generated31* on JSplitPane32* @author alexandr.scherbatiy area=awt.event33* @run main MouseDraggedTest34*/35public class MouseDraggedTest {3637private static JFrame frame;38private static Rectangle frameBounds;39private static volatile boolean mouseDragged;4041public static void main(String[] args) throws Exception {42try {43Robot robot = new Robot();44robot.setAutoDelay(50);4546SwingUtilities.invokeAndWait(MouseDraggedTest::createAndShowGUI);47robot.waitForIdle();4849SwingUtilities.invokeAndWait(() -> frameBounds = frame.getBounds());50robot.waitForIdle();5152for (int i = 1; i <= MouseInfo.getNumberOfButtons(); i++) {53testMouseDrag(i, robot);54}55} finally {56SwingUtilities.invokeLater(() -> {57if (frame != null) {58frame.dispose();59}60});61}62}6364private static void testMouseDrag(int button, Robot robot) {6566mouseDragged = false;67int x1 = frameBounds.x + frameBounds.width / 4;68int y1 = frameBounds.y + frameBounds.height / 4;69int x2 = frameBounds.x + frameBounds.width / 2;70int y2 = frameBounds.y + frameBounds.height / 2;7172robot.mouseMove(x1, y1);73robot.waitForIdle();7475int buttonMask = InputEvent.getMaskForButton(button);76robot.mousePress(buttonMask);77robot.mouseMove(x2, y2);78robot.mouseRelease(buttonMask);79robot.waitForIdle();8081if (!mouseDragged) {82throw new RuntimeException("Mouse button " + button83+ " is not dragged");84}85}8687static void createAndShowGUI() {8889frame = new JFrame();90frame.setSize(400, 400);91frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);92JPanel panel = new JPanel(new BorderLayout());93panel.addMouseMotionListener(new MouseAdapter() {9495@Override96public void mouseDragged(MouseEvent e) {97mouseDragged = true;98}99});100frame.add(panel, BorderLayout.CENTER);101frame.setVisible(true);102}103}104105106