Example usage for java.awt.event InputEvent BUTTON1_DOWN_MASK

List of usage examples for java.awt.event InputEvent BUTTON1_DOWN_MASK

Introduction

In this page you can find the example usage for java.awt.event InputEvent BUTTON1_DOWN_MASK.

Prototype

int BUTTON1_DOWN_MASK

To view the source code for java.awt.event InputEvent BUTTON1_DOWN_MASK.

Click Source Link

Document

The Mouse Button1 extended modifier constant.

Usage

From source file:Main.java

static boolean isLeftButtonOnly(final MouseEvent event) {
    final int modifiers = event.getModifiersEx();
    if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) == InputEvent.BUTTON1_DOWN_MASK) {
        for (int button = 11; button <= 30; button++) {
            final int mask = 1 << button;
            if ((modifiers & mask) == mask) {
                return false;
            }//w  w  w  .  ja  v  a  2 s  .  c  o  m
        }
        return true;
    }
    return false;
}

From source file:Main.java

/**
 * Serializes a Keystrike to a String.//  ww w. ja v a 2  s.  co  m
 * It can then be fed into KeyStroke.getKeyStroke(String).
 *
 * See: http://www.exampledepot.com/egs/javax.swing/Key2Str.html
 */
public static String keyStroke2String(KeyStroke key) {
    StringBuffer s = new StringBuffer(50);
    int m = key.getModifiers();

    if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
        s.append("shift ");
    }
    if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
        s.append("ctrl ");
    }
    if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
        s.append("meta ");
    }
    if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
        s.append("alt ");
    }
    if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
        s.append("button1 ");
    }
    if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
        s.append("button2 ");
    }
    if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        s.append("button3 ");
    }

    switch (key.getKeyEventType()) {
    case KeyEvent.KEY_TYPED:
        if (key.getKeyChar() == Character.MAX_VALUE) {
            s.append("unknown-typed-key ");
            break;
        }
        s.append("typed ").append(key.getKeyChar()).append(" ");
        break;
    case KeyEvent.KEY_PRESSED:
        s.append("pressed ").append(getKeyText(key.getKeyCode())).append(" ");
        break;
    case KeyEvent.KEY_RELEASED:
        s.append("released ").append(getKeyText(key.getKeyCode())).append(" ");
        break;
    default:
        s.append("unknown-event-type ");
        break;
    }

    return s.toString();
}

From source file:KeystrokeUtil.java

public static String keyStroke2String(KeyStroke key) {
    if (key == null)
        return "";
    StringBuilder s = new StringBuilder(50);
    int m = key.getModifiers();

    if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
        s.append("Ctrl+");
    }//www  .ja  va2 s  . c  o  m
    if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
        s.append("Meta+");
    }
    if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
        s.append("Alt+");
    }
    if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
        s.append("Shift+");
    }
    if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
        s.append("Button1+");
    }
    if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
        s.append("Button2+");
    }
    if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        s.append("Button3+");
    }

    switch (key.getKeyEventType()) {
    case KeyEvent.KEY_TYPED:
        s.append(key.getKeyChar() + " ");
        break;
    case KeyEvent.KEY_PRESSED:
    case KeyEvent.KEY_RELEASED:
        s.append(getKeyText(key.getKeyCode()) + " ");
        break;
    default:
        s.append("unknown-event-type ");
        break;
    }

    return s.toString();
}

From source file:Main.java

static void keyStroke2String(KeyStroke key) {
    int m = key.getModifiers();

    if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
        System.out.println("shift ");
    }// ww w . ja v a2 s  .  c om
    if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
        System.out.println("ctrl ");
    }
    if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
        System.out.println("meta ");
    }
    if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
        System.out.println("alt ");
    }
    if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
        System.out.println("button1 ");
    }
    if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
        System.out.println("button2 ");
    }
    if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        System.out.println("button3 ");
    }
    switch (key.getKeyEventType()) {
    case KeyEvent.KEY_TYPED:
        System.out.println("typed ");
        System.out.println(key.getKeyChar() + " ");
        break;
    case KeyEvent.KEY_PRESSED:
        System.out.println("pressed ");
        System.out.println(getKeyText(key.getKeyCode()) + " ");
        break;
    case KeyEvent.KEY_RELEASED:
        System.out.println("released ");
        System.out.println(getKeyText(key.getKeyCode()) + " ");
        break;
    default:
        System.out.println("unknown-event-type ");
        break;
    }
}

From source file:Main.java

static void keyStroke2String(KeyStroke key) {
    int m = key.getModifiers();

    if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
        System.out.println("shift ");
    }//from   w  w w . ja v a2s  . c o m
    if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
        System.out.println("ctrl ");
    }
    if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
        System.out.println("meta ");
    }
    if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
        System.out.println("alt ");
    }
    if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
        System.out.println("button1 ");
    }
    if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
        System.out.println("button2 ");
    }
    if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        System.out.println("button3 ");
    }

    switch (key.getKeyEventType()) {
    case KeyEvent.KEY_TYPED:
        System.out.println("typed ");
        System.out.println(key.getKeyChar() + " ");
        break;
    case KeyEvent.KEY_PRESSED:
        System.out.println("pressed ");
        System.out.println(getKeyText(key.getKeyCode()) + " ");
        break;
    case KeyEvent.KEY_RELEASED:
        System.out.println("released ");
        System.out.println(getKeyText(key.getKeyCode()) + " ");
        break;
    default:
        System.out.println("unknown-event-type ");
        break;
    }
}

From source file:org.suren.autotest.web.framework.awt.AwtMouse.java

@Override
public void click() {
    try {/*from   w ww .j a va  2 s  .c om*/
        Robot robot = new Robot();
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
    } catch (AWTException e) {
        e.printStackTrace();
    }
}

From source file:org.jcurl.demo.editor.SpeedController.java

public void mouseDragged(MouseEvent e) {
    if (e.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK) {
        if (RockEditDisplay.HotObject.ROCK.equals(hot.what)) {
            // move a rock
            final Point2D wc = getWc(e, tmp);
            int idx = PositionSet.findRockIndexTouchingRockAtPos(rocks, wc, hot.idx);
            if (idx >= 0)
                log.debug("new position blocked");
            else {
                rocks.getRock(hot.idx).setLocation(wc);
                rocks.notifyChange();/*from  w w w .  j  a  v  a  2  s . c om*/
                log.debug("relocated");
            }
        }
        if (RockEditDisplay.HotObject.SPEED.equals(hot.what)) {
            // change the speed of a rock
            final Point2D wc = getWc(e, tmp);
            panel.setSpeedSpot(hot.idx, wc);
        }
    }
}

From source file:org.jcurl.demo.editor.LocationController.java

public void mouseDragged(final MouseEvent e) {
    if (hotRockIdx < 0) {
        log.debug("no hot rock");
        return;/*from   ww  w  .  java2s  . c  o  m*/
    }
    if (e.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK) {
        // move a rock
        final Point2D wc = getWc(e, tmpWc);
        int idx = PositionSet.findRockIndexTouchingRockAtPos(locations, wc, hotRockIdx);
        if (idx >= 0)
            log.debug("new position blocked");
        else {
            locations.getRock(hotRockIdx).setLocation(wc);
            locations.notifyChange();
            log.debug("relocated");
        }
    }
}

From source file:com.o2d.pkayjava.editor.Main.java

private void toggleVisible() {
    mainFrame.setVisible(!mainFrame.isVisible());
    if (mainFrame.isVisible()) {
        mainFrame.toFront();/*from   www .  j  a  v a2  s  . c  o  m*/
        mainFrame.requestFocus();
        mainFrame.setAlwaysOnTop(true);
        try {
            //remember the last location of mouse
            final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation();

            //simulate a mouse click on title bar of window
            Robot robot = new Robot();
            robot.mouseMove(mainFrame.getX() + 100, mainFrame.getY() + 5);
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

            //move mouse to old location
            robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY());
        } catch (Exception ex) {
            //just ignore exception, or you can handle it as you want
        } finally {
            mainFrame.setAlwaysOnTop(false);
        }
    }
}

From source file:com.seleniumtests.ut.driver.TestCustomEventFiringWebDriver.java

/**
 * Test left click in local mode/*ww  w  .  j a v  a  2 s . c  o  m*/
 */
@Test(groups = { "ut" })
public void testLeftClickOnDesktop() {
    CustomEventFiringWebDriver.leftClicOnDesktopAt(0, 0, DriverMode.LOCAL, gridConnector);

    verify(robot).mousePress(eq(InputEvent.BUTTON1_DOWN_MASK));
    verify(robot).mouseRelease(eq(InputEvent.BUTTON1_DOWN_MASK));
    verify(robot).mouseMove(eq(0), eq(0));
    verify(gridConnector, never()).leftClic(eq(0), eq(0));
}