Example usage for java.awt.event MouseEvent MOUSE_DRAGGED

List of usage examples for java.awt.event MouseEvent MOUSE_DRAGGED

Introduction

In this page you can find the example usage for java.awt.event MouseEvent MOUSE_DRAGGED.

Prototype

int MOUSE_DRAGGED

To view the source code for java.awt.event MouseEvent MOUSE_DRAGGED.

Click Source Link

Document

The "mouse dragged" event.

Usage

From source file:MouseNavigateTest.java

protected boolean isStartBehaviorEvent(java.awt.event.MouseEvent evt) {
    int nId = evt.getID();
    return ((nId == MouseEvent.MOUSE_DRAGGED) && (evt.isAltDown() == false) && (evt.isMetaDown() != false));
}

From source file:ExText.java

/**
 * Initializes the behavior.//from  w  w w . ja v  a  2 s  .c  o  m
 */
public void initialize() {
    super.initialize();
    savedMouseCriterion = mouseCriterion; // from parent class
    mouseAndAnimationEvents = new WakeupCriterion[4];
    mouseAndAnimationEvents[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED);
    mouseAndAnimationEvents[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
    mouseAndAnimationEvents[2] = new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED);
    mouseAndAnimationEvents[3] = new WakeupOnElapsedFrames(0);
    mouseAndAnimationCriterion = new WakeupOr(mouseAndAnimationEvents);
    // Don't use the above criterion until a button 1 down event
}

From source file:com.projity.contrib.calendar.JXXMonthView.java

/**
 * {@inheritDoc}/*from   w w w .j  a v a2 s  . c  om*/
 */
protected void processMouseMotionEvent(MouseEvent e) {
    if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
        selectFromEvent(e);
    }
    super.processMouseMotionEvent(e);
}

From source file:ExText.java

/**
 * Initialize the behavior./*from w  ww  . j  a v  a 2s  . c o m*/
 */
public void initialize() {
    // Wakeup when the mouse is dragged or when a mouse button
    // is pressed or released.
    mouseEvents = new WakeupCriterion[3];
    mouseEvents[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED);
    mouseEvents[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
    mouseEvents[2] = new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED);
    mouseCriterion = new WakeupOr(mouseEvents);
    wakeupOn(mouseCriterion);
}

From source file:ExText.java

/**
 * Process a new wakeup. Interpret mouse button presses, releases, and mouse
 * drags./* ww w  .ja  v  a 2s  . 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:FourByFour.java

public void initialize() {
    x = 0;//from   w  w w. j  a  v a 2  s . co  m
    y = 0;
    x_last = 0;
    y_last = 0;
    x_angle = 0;
    y_angle = 0;
    x_factor = .02;
    y_factor = .02;

    mouseEvents = new WakeupCriterion[2];
    mouseEvents[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED);
    mouseEvents[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
    mouseCriterion = new WakeupOr(mouseEvents);
    wakeupOn(mouseCriterion);
}

From source file:FourByFour.java

public void processStimulus(Enumeration criteria) {
    WakeupCriterion wakeup;/*from   w w  w.java2 s .  co  m*/
    AWTEvent[] event;
    int id;
    int dx, dy;

    while (criteria.hasMoreElements()) {
        wakeup = (WakeupCriterion) criteria.nextElement();
        if (wakeup instanceof WakeupOnAWTEvent) {
            event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
            for (int i = 0; i < event.length; i++) {
                id = event[i].getID();
                if (id == MouseEvent.MOUSE_DRAGGED) {

                    x = ((MouseEvent) event[i]).getX();
                    y = ((MouseEvent) event[i]).getY();

                    dx = x - x_last;
                    dy = y - y_last;

                    x_angle = dy * y_factor;
                    y_angle = dx * x_factor;

                    transformX.rotX(x_angle);
                    transformY.rotY(y_angle);

                    modelTrans.mul(transformX, modelTrans);
                    modelTrans.mul(transformY, modelTrans);

                    transformGroup.setTransform(modelTrans);

                    x_last = x;
                    y_last = y;
                } else if (id == MouseEvent.MOUSE_PRESSED) {

                    x = x_last = ((MouseEvent) event[i]).getX();
                    y = y_last = ((MouseEvent) event[i]).getY();

                    Point3d eyePos = new Point3d();
                    canvas3D.getCenterEyeInImagePlate(eyePos);

                    Point3d mousePos = new Point3d();
                    canvas3D.getPixelLocationInImagePlate(x, y, mousePos);

                    Transform3D transform3D = new Transform3D();
                    canvas3D.getImagePlateToVworld(transform3D);

                    transform3D.transform(eyePos);
                    transform3D.transform(mousePos);

                    Vector3d mouseVec;
                    if (parallel) {
                        mouseVec = new Vector3d(0.f, 0.f, -1.f);
                    } else {
                        mouseVec = new Vector3d();
                        mouseVec.sub(mousePos, eyePos);
                        mouseVec.normalize();
                    }

                    pickRay.set(mousePos, mouseVec);
                    sceneGraphPath = branchGroup.pickAllSorted(pickRay);

                    if (sceneGraphPath != null) {
                        for (int j = 0; j < sceneGraphPath.length; j++) {
                            if (sceneGraphPath[j] != null) {
                                Node node = sceneGraphPath[j].getObject();
                                if (node instanceof Shape3D) {
                                    try {
                                        ID posID = (ID) node.getUserData();
                                        if (posID != null) {
                                            int pos = posID.get();
                                            positions.set(pos, Positions.HUMAN);
                                            canvas2D.repaint();
                                            break;
                                        }
                                    } catch (CapabilityNotSetException e) {
                                        // Catch all CapabilityNotSet
                                        // exceptions and
                                        // throw them away, prevents
                                        // renderer from
                                        // locking up when encountering
                                        // "non-selectable"
                                        // objects.
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    wakeupOn(mouseCriterion);
}

From source file:net.sourceforge.squirrel_sql.fw.gui.debug.DebugEventListener.java

public void eventDispatched(AWTEvent event) {
    Object o = event.getSource();
    if (o instanceof JComponent && o != null) {
        JComponent source = (JComponent) o;
        switch (event.getID()) {
        case MouseEvent.MOUSE_DRAGGED:
            printDebugInfo(source, event);
            break;
        case MouseEvent.MOUSE_ENTERED:
            printDebugInfo(source, event);
            setToolTipText(source, event);
            setBorder(source, event);/*from w  w  w  . j  av  a2  s.com*/
            break;
        case MouseEvent.MOUSE_EXITED:
            printDebugInfo(source, event);
            setBorder(source, event);
            break;
        }
    }
}

From source file:net.sourceforge.squirrel_sql.fw.gui.debug.DebugEventListener.java

private String getEventMessagePrefix(AWTEvent event) {
    String result = null;//from   ww  w.  ja  v a2s.  co  m
    switch (event.getID()) {
    case MouseEvent.MOUSE_DRAGGED:
        result = "Mouse dragged: ";
        break;
    case MouseEvent.MOUSE_ENTERED:
        result = "Mouse entered: ";
        break;
    case MouseEvent.MOUSE_EXITED:
        result = "Mouse exited: ";
        break;
    default:
        result = "Unknown EventType: ";
    }
    return result;
}

From source file:org.kalypso.mt.input.MTMouseInput.java

@Override
public void processAction() {
    if (invocCounter++ % 6 == 0 || eventQueue.isEmpty())
        return;//w  w  w  .ja va 2s. c  o  m

    // purge all events waiting if mouse is blocked
    if (m_mouseBlocks > 0) {
        eventQueue.clear();
        return;
    }

    // otherwise process events
    final long time = System.currentTimeMillis();
    while (!eventQueue.isEmpty()) {
        final long dist = time - eventQueue.peekFirst().timestamp;

        if (dist > 200) {
            // ok, process this one
            final MTMouseEventData e = eventQueue.pollFirst();
            switch (e.event.getID()) {
            case MouseEvent.MOUSE_PRESSED:
                this.mousePressed(e.event);
                break;
            case MouseEvent.MOUSE_RELEASED:
                this.mouseReleased(e.event);
                break;
            case MouseEvent.MOUSE_CLICKED:
                this.mouseClicked(e.event);
                break;
            case MouseEvent.MOUSE_DRAGGED:
                this.mouseDragged(e.event);
                break;
            case MouseEvent.MOUSE_MOVED:
                this.mouseMoved(e.event);
                break;
            }

        } else {
            break;
        }

    }

}