Example usage for java.awt.event InputEvent BUTTON2_MASK

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

Introduction

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

Prototype

int BUTTON2_MASK

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

Click Source Link

Document

The Mouse Button2 modifier constant.

Usage

From source file:com.jcraft.weirdx.DDXWindowImp.java

@SuppressWarnings("unused")
public void mouseDragged(MouseEvent e) {

    if (threeButton) {
        if (threeBstate != s) {
            if (threeBstate == sp) {
                procPressed(threeBPressed);
                threeBPressed = null;/*from w  w w . j ava  2 s  .  c o m*/
                threeBstate = s;
            } else if (threeBstate == spp) {
                e = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(),
                        (e.getModifiers() & (~(InputEvent.BUTTON1_MASK | InputEvent.BUTTON3_MASK)))
                                | InputEvent.BUTTON2_MASK,
                        e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger());
            } else if (threeBstate == sppr) {
                return;
            }
        }
    }

    if (window == null)
        return;

    // calc abs cursor position use old window position for calculation
    // as mouseDragged (if you use Panel) delivers its coordinates relative to the position after mousepressed
    // UPDATE: this was a bug of the IBM JDK
    //    int x=e.getX()+oldwindowx;
    //    int y=e.getY()+oldwindowy;
    int x = e.getX() + window.x;
    int y = e.getY() + window.y;

    // set new drag position (absolute)
    XWindow.sprite.hot.x = x;
    XWindow.sprite.hot.y = y;

    int mod = e.getModifiers();

    // button 1 -> 16
    // button 2 -> 8
    // button 3 -> 4
    // shift -> 1
    // control -> 2
    // alt -> 12 ?? 

    int state = 0;
    int detail = 0;

    if ((mod & InputEvent.BUTTON1_MASK) != 0) {
        state |= (1 << 8);
        detail = 1;
    }
    if ((mod & InputEvent.BUTTON2_MASK) != 0) {
        state |= (1 << 9);
        detail = 2;
    }
    if ((mod & InputEvent.BUTTON3_MASK) != 0) {
        state |= (1 << 10);
        detail = 3;
    }
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;
    XWindow.sprite.hot.state = state;

    px = x;
    py = y;

    event.mkMotionNotify(1, window.screen.rootId, XWindow.sprite.win.id, 0, px, py, e.getX(), e.getY(), state,
            1);

    try {
        if (!XWindow.checkMotion(event, window)) {
            return;
        }
        event.mkMotionNotify(1, window.screen.rootId, XWindow.sprite.win.id, 0, px, py,
                px - XWindow.sprite.win.x, py - XWindow.sprite.win.y, state, 1);
        if (XWindow.grab != null) {
            XWindow.sendGrabbedEvent(event, false, 1);
        } else {
            XWindow.sendDeviceEvent(XWindow.sprite.win, event, XWindow.grab, null, 1);
        }
    } catch (Exception ee) {
    }
}

From source file:com.jcraft.weirdx.DDXWindowImp.java

public void mouseMoved(MouseEvent e) {
    int x = e.getX() + window.x;
    int y = e.getY() + window.y;

    XWindow.sprite.hot.x = x;/*from   w  ww.j  av a 2s. c  o m*/
    XWindow.sprite.hot.y = y;

    int mod = e.getModifiers();
    int state = 0;

    px = x;
    py = y;

    if ((mod & InputEvent.BUTTON1_MASK) != 0)
        state |= (1 << 8);
    if ((mod & InputEvent.BUTTON2_MASK) != 0)
        state |= (1 << 9);
    if ((mod & InputEvent.BUTTON3_MASK) != 0)
        state |= (1 << 10);
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;
    XWindow.sprite.hot.state = state;

    event.mkMotionNotify(0, window.screen.rootId, window.id, 0, x, y, x - window.x, y - window.y, state, 1);

    try {
        if (!XWindow.checkMotion(event, window)) {
            return;
        }
        if (XWindow.grab != null)
            XWindow.sendGrabbedEvent(event, false, 1);
        else
            XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }
}

From source file:ExText.java

/**
 * Process a new wakeup. Interpret mouse button presses, releases, and mouse
 * drags.//from  ww w .j  ava 2  s. c o m
 * 
 * @param criteria
 *            The wakeup criteria causing the behavior wakeup.
 */
public void processStimulus(Enumeration criteria) {
    WakeupCriterion wakeup = null;
    AWTEvent[] event = null;
    int whichButton = BUTTONNONE;

    // Process all pending wakeups
    while (criteria.hasMoreElements()) {
        wakeup = (WakeupCriterion) criteria.nextElement();
        if (wakeup instanceof WakeupOnAWTEvent) {
            event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();

            // Process all pending events
            for (int i = 0; i < event.length; i++) {
                if (event[i].getID() != MouseEvent.MOUSE_PRESSED
                        && event[i].getID() != MouseEvent.MOUSE_RELEASED
                        && event[i].getID() != MouseEvent.MOUSE_DRAGGED)
                    // Ignore uninteresting mouse events
                    continue;

                //
                // Regretably, Java event handling (or perhaps
                // underlying OS event handling) doesn't always
                // catch button bounces (redundant presses and
                // releases), or order events so that the last
                // drag event is delivered before a release.
                // This means we can get stray events that we
                // filter out here.
                //
                if (event[i].getID() == MouseEvent.MOUSE_PRESSED && buttonPressed != BUTTONNONE)
                    // Ignore additional button presses until a release
                    continue;

                if (event[i].getID() == MouseEvent.MOUSE_RELEASED && buttonPressed == BUTTONNONE)
                    // Ignore additional button releases until a press
                    continue;

                if (event[i].getID() == MouseEvent.MOUSE_DRAGGED && buttonPressed == BUTTONNONE)
                    // Ignore drags until a press
                    continue;

                MouseEvent mev = (MouseEvent) event[i];
                int modifiers = mev.getModifiers();

                //
                // Unfortunately, the underlying event handling
                // doesn't do a "grab" operation when a mouse button
                // is pressed. This means that once a button is
                // pressed, if another mouse button or a keyboard
                // modifier key is pressed, the delivered mouse event
                // will show that a different button is being held
                // down. For instance:
                //
                // Action Event
                //  Button 1 press Button 1 press
                //  Drag with button 1 down Button 1 drag
                //  ALT press -
                //  Drag with ALT & button 1 down Button 2 drag
                //  Button 1 release Button 2 release
                //
                // The upshot is that we can get a button press
                // without a matching release, and the button
                // associated with a drag can change mid-drag.
                //
                // To fix this, we watch for an initial button
                // press, and thenceforth consider that button
                // to be the one held down, even if additional
                // buttons get pressed, and despite what is
                // reported in the event. Only when a button is
                // released, do we end such a grab.
                //

                if (buttonPressed == BUTTONNONE) {
                    // No button is pressed yet, figure out which
                    // button is down now and how to direct events
                    if (((modifiers & InputEvent.BUTTON3_MASK) != 0)
                            || (((modifiers & InputEvent.BUTTON1_MASK) != 0)
                                    && ((modifiers & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK))) {
                        // Button 3 activity (META or CTRL down)
                        whichButton = BUTTON3;
                    } else if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
                        // Button 2 activity (ALT down)
                        whichButton = BUTTON2;
                    } else {
                        // Button 1 activity (no modifiers down)
                        whichButton = BUTTON1;
                    }

                    // If the event is to press a button, then
                    // record that that button is now down
                    if (event[i].getID() == MouseEvent.MOUSE_PRESSED)
                        buttonPressed = whichButton;
                } else {
                    // Otherwise a button was pressed earlier and
                    // hasn't been released yet. Assign all further
                    // events to it, even if ALT, META, CTRL, or
                    // another button has been pressed as well.
                    whichButton = buttonPressed;
                }

                // Distribute the event
                switch (whichButton) {
                case BUTTON1:
                    onButton1(mev);
                    break;
                case BUTTON2:
                    onButton2(mev);
                    break;
                case BUTTON3:
                    onButton3(mev);
                    break;
                default:
                    break;
                }

                // If the event is to release a button, then
                // record that that button is now up
                if (event[i].getID() == MouseEvent.MOUSE_RELEASED)
                    buttonPressed = BUTTONNONE;
            }
            continue;
        }

        if (wakeup instanceof WakeupOnElapsedFrames) {
            onElapsedFrames((WakeupOnElapsedFrames) wakeup);
            continue;
        }
    }

    // Reschedule us for another wakeup
    wakeupOn(mouseCriterion);
}

From source file:gda.plots.SimplePlot.java

/**
 * Part of the implementation of MouseMotionListener - overrides the super class (ChartPanel) implementation so that
 * the mouse can be used to select a rectangle as well as for zooming.
 * //from   ww  w .j a v  a  2s . c  o m
 * @param e
 *            the mouse event which caused the call
 */
@Override
public void mouseDragged(MouseEvent e) {
    // If the rectangle dragger is not in operation then call the
    // super class method (to deal with any possible zooming) then
    // deal with magnifyingImage or magnifyingData.

    if (rd == null) {
        super.mouseDragged(e);
        if ((magnifyingImage || magnifyingData) && (e.getModifiers() & InputEvent.BUTTON3_MASK) == 0) {
            Graphics2D g2 = (Graphics2D) getGraphics();
            g2.setXORMode(dragColour);
            if (magnifyRectangle != null) {
                if (magnifyRectangleIsNew) {
                    magnifyRectangleIsNew = false;
                } else {
                    g2.fill(magnifyRectangle);
                }
            }
            if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {
                magnifyWidth = e.getX() - magnifyXPoint;
                magnifyHeight = e.getY() - magnifyYPoint;
            }
            recalculateMagnifyRectangle(e);

            if ((e.getModifiers() & InputEvent.BUTTON2_MASK) != 0) {
                magnifier.update(magnifyRectangle);
            }

            if (magnifyRectangle != null) {
                g2.fill(magnifyRectangle);
            }
            g2.dispose();
        }
    } else {
        rd.mouseDragged(e);
    }
}

From source file:org.eclipse.jubula.rc.swing.driver.RobotAwtImpl.java

/**
 * Gets the InputEvent-ButtonMask of the given mouse button number
 * @param button the button number//from   w  w  w .ja  v a 2  s .co  m
 * @return the InputEvent button mask
 */
private int getButtonMask(int button) {
    switch (button) {
    case InputConstants.MOUSE_BUTTON_LEFT:
        return InputEvent.BUTTON1_MASK;
    case InputConstants.MOUSE_BUTTON_MIDDLE:
        return InputEvent.BUTTON2_MASK;
    case InputConstants.MOUSE_BUTTON_RIGHT:
        return InputEvent.BUTTON3_MASK;
    default:
        throw new RobotException("unsupported mouse button", null); //$NON-NLS-1$
    }
}

From source file:org.squidy.nodes.MouseIO.java

protected void setSingleMousePress(int button) {
    if (button == MouseEvent.BUTTON1) {
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
    } else if (button == MouseEvent.BUTTON2) {
        robot.mousePress(InputEvent.BUTTON2_MASK);
        robot.mouseRelease(InputEvent.BUTTON2_MASK);

    } else if (button == MouseEvent.BUTTON3) {
        robot.mousePress(InputEvent.BUTTON3_MASK);
        robot.mouseRelease(InputEvent.BUTTON3_MASK);
    }/*from   www  . j  av a2s.c  o  m*/
}

From source file:org.squidy.nodes.MouseIO.java

protected void setMouseStatus(int button, boolean status) {
    if (button == MouseEvent.BUTTON1) {
        if (status) {
            robot.mousePress(InputEvent.BUTTON1_MASK);
        } else {/*from www . j a v  a 2 s  .c o m*/
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
        }
    } else if (button == MouseEvent.BUTTON2) {
        if (status) {
            robot.mousePress(InputEvent.BUTTON2_MASK);
        } else {
            robot.mouseRelease(InputEvent.BUTTON2_MASK);
        }
    } else if (button == MouseEvent.BUTTON3) {
        if (status) {
            robot.mousePress(InputEvent.BUTTON3_MASK);
        } else {
            robot.mouseRelease(InputEvent.BUTTON3_MASK);
        }
    }
}