870N/A/*
870N/A @test %I% %E%
870N/A @bug 6315717
870N/A @summary verifies that drag events are coming for every button if the property is set to true
870N/A @author Andrei Dmitriev : area=awt.mouse
870N/A @run main ExtraButtonDrag
870N/A */
870N/A
870N/A//events from standard should also come
870N/A
870N/Aimport java.awt.*;
870N/Aimport java.awt.event.*;
870N/A
870N/Apublic class ExtraButtonDrag extends Frame {
870N/A static String tk = Toolkit.getDefaultToolkit().getClass().getName();
870N/A static Robot robot;
870N/A static int [] buttonsPressed;
870N/A static int [] buttonsReleased;
870N/A static int [] buttonsClicked;
870N/A volatile static boolean dragged = false;
870N/A volatile static boolean moved = false;
870N/A
870N/A public ExtraButtonDrag(){
870N/A super("ExtraButtonDrag");
870N/A }
870N/A
870N/A public static void main(String []s){
870N/A Frame frame = new ExtraButtonDrag();
870N/A
870N/A MouseAdapter ma = new MouseAdapter() {
870N/A public void mouseDragged(MouseEvent e) {
870N/A System.out.println("Dragged "+e);// +" : "+ e.getButton() + " : " +e.getButtonState(e.getButton()));
870N/A dragged = true;
870N/A }
870N/A public void mouseMoved(MouseEvent e) {
870N/A System.out.println("Moved "+e);
870N/A moved = true;
870N/A }
870N/A public void mousePressed(MouseEvent e) {
870N/A System.out.println(">>> "+e);
870N/A }
870N/A public void mouseReleased(MouseEvent e) {
870N/A System.out.println(">>> "+e);
870N/A }
870N/A
870N/A };
870N/A
870N/A frame.addMouseMotionListener(ma);
870N/A frame.addMouseListener(ma);
870N/A
870N/A frame.setSize(300, 300);
870N/A frame.setVisible(true);
870N/A
870N/A int [] buttonMask = new int [MouseInfo.getNumberOfButtons()]; //InputEvent.getButtonMasks();
870N/A
870N/A for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
870N/A buttonMask[i] = InputEvent.getMaskForButton(i+1);
870N/A // System.out.println("TEST: "+tmp[i]);
870N/A }
870N/A
870N/A try {
870N/A robot = new Robot();
870N/A robot.delay(1000);
870N/A Point centerFrame = new Point(frame.getLocationOnScreen().x + frame.getWidth()/2, frame.getLocationOnScreen().y + frame.getHeight()/2);
870N/A Point outboundsFrame = new Point(frame.getLocationOnScreen().x + frame.getWidth()*3/2, frame.getLocationOnScreen().y + frame.getHeight()/2);
870N/A
870N/A System.out.println("areExtraMouseButtonsEnabled() == " + Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled() );
870N/A
870N/A for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
870N/A System.out.println("button to drag = " +(i+1) + " : value passed to robot = " +buttonMask[i]);
870N/A
870N/A try {
870N/A dragMouse(buttonMask[i], centerFrame.x, centerFrame.y, outboundsFrame.x, outboundsFrame.y);
870N/A } catch (IllegalArgumentException e){
870N/A throw new RuntimeException("Test failed. Exception occured.", e);
870N/A }
870N/A
870N/A robot.delay(500);
870N/A //this is a choice-case for X protocol issue: native events from extra buttons doesn't contain
870N/A // the correct state so it's unable to decide if there is a drag or move. By default we send MOVED event.
870N/A //XToolkit: extra buttons should report MOVED events only
870N/A //WToolkit: extra buttons should report DRAGGED events only
870N/A if (i > 2){ //extra buttons only
870N/A if (tk.equals("sun.awt.X11.XToolkit") || tk.equals("sun.awt.motif.MToolkit")) {
870N/A if (!moved || dragged) {
870N/A throw new RuntimeException("Test failed."+ tk +" Button = " +(i+1) + " moved = "+moved +" : dragged = " +dragged);
870N/A }
870N/A } else { //WToolkit
870N/A if (moved || !dragged) {
870N/A throw new RuntimeException("Test failed."+ tk +" Button = " +(i+1) + " moved = "+moved +" : dragged = " +dragged);
870N/A }
870N/A }
870N/A } else {
870N/A if (moved || !dragged){
870N/A throw new RuntimeException("Test failed. Button = " +(i+1) + " not dragged.");
870N/A }
870N/A }
870N/A }
870N/A } catch (Exception e){
870N/A throw new RuntimeException("", e);
870N/A }
870N/A }
870N/A
870N/A public static void dragMouse(int button, int x0, int y0, int x1, int y1){
870N/A int curX = x0;
870N/A int curY = y0;
870N/A int dx = x0 < x1 ? 1 : -1;
870N/A int dy = y0 < y1 ? 1 : -1;
870N/A robot.mouseMove(x0, y0);
870N/A
870N/A robot.delay(200);
870N/A dragged = false;
870N/A moved = false;
870N/A
870N/A robot.mousePress(button);
870N/A
870N/A while (curX != x1){
870N/A curX += dx;
870N/A robot.mouseMove(curX, curY);
870N/A robot.delay(5);
870N/A }
870N/A while (curY != y1 ){
870N/A curY += dy;
870N/A robot.mouseMove(curX, curY);
870N/A robot.delay(5);
870N/A }
870N/A robot.mouseRelease(button);
870N/A }
870N/A
870N/A}
870N/A