Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mouse/MouseDragEvent/MouseDraggedTest.java
47512 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* @bug 808013729* @summary Dragged events for extra mouse buttons (4,5,6) are not generated30* on JSplitPane31* @author alexandr.scherbatiy area=awt.event32* @run main MouseDraggedTest33*/34public class MouseDraggedTest {3536private static JFrame frame;37private static Rectangle frameBounds;38private static volatile boolean mouseDragged;3940public static void main(String[] args) throws Exception {41try {42Robot robot = new Robot();43robot.setAutoDelay(50);4445SwingUtilities.invokeAndWait(MouseDraggedTest::createAndShowGUI);46robot.waitForIdle();4748SwingUtilities.invokeAndWait(() -> frameBounds = frame.getBounds());49robot.waitForIdle();5051for (int i = 1; i <= MouseInfo.getNumberOfButtons(); i++) {52testMouseDrag(i, robot);53}54} finally {55SwingUtilities.invokeLater(() -> {56if (frame != null) {57frame.dispose();58}59});60}61}6263private static void testMouseDrag(int button, Robot robot) {6465mouseDragged = false;66int x1 = frameBounds.x + frameBounds.width / 4;67int y1 = frameBounds.y + frameBounds.height / 4;68int x2 = frameBounds.x + frameBounds.width / 2;69int y2 = frameBounds.y + frameBounds.height / 2;7071robot.mouseMove(x1, y1);72robot.waitForIdle();7374int buttonMask = InputEvent.getMaskForButton(button);75robot.mousePress(buttonMask);76robot.mouseMove(x2, y2);77robot.mouseRelease(buttonMask);78robot.waitForIdle();7980if (!mouseDragged) {81throw new RuntimeException("Mouse button " + button82+ " is not dragged");83}84}8586static void createAndShowGUI() {8788frame = new JFrame();89frame.setSize(400, 400);90frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);91JPanel panel = new JPanel(new BorderLayout());92panel.addMouseMotionListener(new MouseAdapter() {9394@Override95public void mouseDragged(MouseEvent e) {96mouseDragged = true;97}98});99frame.add(panel, BorderLayout.CENTER);100frame.setVisible(true);101}102}103104