Example usage for java.awt.event MouseEvent MOUSE_RELEASED

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

Introduction

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

Prototype

int MOUSE_RELEASED

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

Click Source Link

Document

The "mouse released" event.

Usage

From source file:ExText.java

/**
 * Respond to a button2 event (press, release, or drag).
 * /*ww  w . jav a 2  s  . c  o  m*/
 * @param mouseEvent
 *            A MouseEvent to respond to.
 */
public void onButton2(MouseEvent mev) {
    if (subjectTransformGroup == null)
        return;

    int x = mev.getX();
    int y = mev.getY();

    if (mev.getID() == MouseEvent.MOUSE_PRESSED) {
        // Mouse button pressed: record position
        previousX = x;
        previousY = y;

        // Change to a "move" cursor
        if (parentComponent != null) {
            savedCursor = parentComponent.getCursor();
            parentComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        }
        return;
    }
    if (mev.getID() == MouseEvent.MOUSE_RELEASED) {
        // Mouse button released: do nothing

        // Switch the cursor back
        if (parentComponent != null)
            parentComponent.setCursor(savedCursor);
        return;
    }

    //
    // Mouse moved while button down: create a translation
    //
    // Compute the delta in Y from the previous
    // position. Use the delta to compute translation
    // distances with the mapping:
    //
    //   positive Y mouse delta --> positive Y-axis translation
    //
    // where positive X mouse movement is to the right, and
    // positive Y mouse movement is **down** the screen.
    //
    int deltaY = y - previousY;

    if (deltaY > UNUSUAL_YDELTA || deltaY < -UNUSUAL_YDELTA) {
        // Deltas are too huge to be believable. Probably a glitch.
        // Don't record the new XY location, or do anything.
        return;
    }

    double zTranslationDistance = deltaY * ZTranslationFactor;

    //
    // Build transforms
    //
    translate.set(0.0, 0.0, zTranslationDistance);
    transform1.set(translate);

    // Get and save the current transform
    subjectTransformGroup.getTransform(currentTransform);

    // Translate as needed
    currentTransform.mul(transform1, currentTransform);

    // Update the transform group
    subjectTransformGroup.setTransform(currentTransform);

    previousX = x;
    previousY = y;
}

From source file:ExText.java

/**
 * Respond to a button3 event (press, release, or drag).
 * /*from  www  . jav a  2  s  . c  om*/
 * @param mouseEvent
 *            A MouseEvent to respond to.
 */
public void onButton3(MouseEvent mev) {
    if (subjectTransformGroup == null)
        return;

    int x = mev.getX();
    int y = mev.getY();

    if (mev.getID() == MouseEvent.MOUSE_PRESSED) {
        // Mouse button pressed: record position
        previousX = x;
        previousY = y;

        // Change to a "move" cursor
        if (parentComponent != null) {
            savedCursor = parentComponent.getCursor();
            parentComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        }
        return;
    }
    if (mev.getID() == MouseEvent.MOUSE_RELEASED) {
        // Mouse button released: do nothing

        // Switch the cursor back
        if (parentComponent != null)
            parentComponent.setCursor(savedCursor);
        return;
    }

    //
    // Mouse moved while button down: create a translation
    //
    // Compute the delta in X and Y from the previous
    // position. Use the delta to compute translation
    // distances with the mapping:
    //
    //   positive X mouse delta --> positive X-axis translation
    //   positive Y mouse delta --> negative Y-axis translation
    //
    // where positive X mouse movement is to the right, and
    // positive Y mouse movement is **down** the screen.
    //
    int deltaX = x - previousX;
    int deltaY = y - previousY;

    if (deltaX > UNUSUAL_XDELTA || deltaX < -UNUSUAL_XDELTA || deltaY > UNUSUAL_YDELTA
            || deltaY < -UNUSUAL_YDELTA) {
        // Deltas are too huge to be believable. Probably a glitch.
        // Don't record the new XY location, or do anything.
        return;
    }

    double xTranslationDistance = deltaX * XTranslationFactor;
    double yTranslationDistance = -deltaY * YTranslationFactor;

    //
    // Build transforms
    //
    translate.set(xTranslationDistance, yTranslationDistance, 0.0);
    transform1.set(translate);

    // Get and save the current transform
    subjectTransformGroup.getTransform(currentTransform);

    // Translate as needed
    currentTransform.mul(transform1, currentTransform);

    // Update the transform group
    subjectTransformGroup.setTransform(currentTransform);

    previousX = x;
    previousY = y;
}

From source file:ExText.java

/**
 * Initializes the behavior.//  w  ww.ja  v a2s . c om
 */
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:ExText.java

/**
 * Responds to a button1 event (press, release, or drag). On a press, the
 * method adds a wakeup criterion to the behavior's set, callling for the
 * behavior to be awoken on each frame. On a button prelease, this criterion
 * is removed from the set.//from  www. jav a2  s .c  o m
 * 
 * @param mouseEvent
 *            the MouseEvent to respond to
 */
public void onButton1(MouseEvent mev) {
    if (subjectTransformGroup == null)
        return;

    int x = mev.getX();
    int y = mev.getY();

    if (mev.getID() == MouseEvent.MOUSE_PRESSED) {
        // Mouse button pressed: record position and change
        // the wakeup criterion to include elapsed time wakeups
        // so we can animate.
        previousX = x;
        previousY = y;
        initialX = x;
        initialY = y;

        // Swap criterion... parent class will not reschedule us
        mouseCriterion = mouseAndAnimationCriterion;

        // Change to a "move" cursor
        if (parentComponent != null) {
            savedCursor = parentComponent.getCursor();
            parentComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }
        return;
    }
    if (mev.getID() == MouseEvent.MOUSE_RELEASED) {
        // Mouse button released: restore original wakeup
        // criterion which only includes mouse activity, not
        // elapsed time
        mouseCriterion = savedMouseCriterion;

        // Switch the cursor back
        if (parentComponent != null)
            parentComponent.setCursor(savedCursor);
        return;
    }

    previousX = x;
    previousY = y;
}

From source file:ExText.java

/**
 * Responds to a button2 event (press, release, or drag). On a press, the
 * method records the initial cursor location. On a drag, the difference
 * between the current and previous cursor location provides a delta that
 * controls the amount by which to rotate in X and Y.
 * //from   w w  w. j av a2s  . co  m
 * @param mouseEvent
 *            the MouseEvent to respond to
 */
public void onButton2(MouseEvent mev) {
    if (subjectTransformGroup == null)
        return;

    int x = mev.getX();
    int y = mev.getY();

    if (mev.getID() == MouseEvent.MOUSE_PRESSED) {
        // Mouse button pressed: record position
        previousX = x;
        previousY = y;
        initialX = x;
        initialY = y;

        // Change to a "rotate" cursor
        if (parentComponent != null) {
            savedCursor = parentComponent.getCursor();
            parentComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        }
        return;
    }
    if (mev.getID() == MouseEvent.MOUSE_RELEASED) {
        // Mouse button released: do nothing

        // Switch the cursor back
        if (parentComponent != null)
            parentComponent.setCursor(savedCursor);
        return;
    }

    //
    // Mouse moved while button down: create a rotation
    //
    // Compute the delta in X and Y from the previous
    // position. Use the delta to compute rotation
    // angles with the mapping:
    //
    //   positive X mouse delta --> negative Y-axis rotation
    //   positive Y mouse delta --> negative X-axis rotation
    //
    // where positive X mouse movement is to the right, and
    // positive Y mouse movement is **down** the screen.
    //
    int deltaX = x - previousX;
    int deltaY = 0;

    if (Math.abs(y - initialY) > DELTAY_DEADZONE) {
        // Cursor has moved far enough vertically to consider
        // it intentional, so get it's delta.
        deltaY = y - previousY;
    }

    if (deltaX > UNUSUAL_XDELTA || deltaX < -UNUSUAL_XDELTA || deltaY > UNUSUAL_YDELTA
            || deltaY < -UNUSUAL_YDELTA) {
        // Deltas are too huge to be believable. Probably a glitch.
        // Don't record the new XY location, or do anything.
        return;
    }

    double xRotationAngle = -deltaY * XRotationFactor;
    double yRotationAngle = -deltaX * YRotationFactor;

    //
    // Build transforms
    //
    transform1.rotX(xRotationAngle);
    transform2.rotY(yRotationAngle);

    // Get and save the current transform matrix
    subjectTransformGroup.getTransform(currentTransform);
    currentTransform.get(matrix);
    translate.set(matrix.m03, matrix.m13, matrix.m23);

    // Translate to the origin, rotate, then translate back
    currentTransform.setTranslation(origin);
    currentTransform.mul(transform2, currentTransform);
    currentTransform.mul(transform1);
    currentTransform.setTranslation(translate);

    // Update the transform group
    subjectTransformGroup.setTransform(currentTransform);

    previousX = x;
    previousY = y;
}

From source file:ExText.java

/**
 * Responds to a button3 event (press, release, or drag). On a drag, the
 * difference between the current and previous cursor location provides a
 * delta that controls the amount by which to translate in X and Y.
 * //from w w  w  . ja  va 2  s  .c  o m
 * @param mouseEvent
 *            the MouseEvent to respond to
 */
public void onButton3(MouseEvent mev) {
    if (subjectTransformGroup == null)
        return;

    int x = mev.getX();
    int y = mev.getY();

    if (mev.getID() == MouseEvent.MOUSE_PRESSED) {
        // Mouse button pressed: record position
        previousX = x;
        previousY = y;

        // Change to a "move" cursor
        if (parentComponent != null) {
            savedCursor = parentComponent.getCursor();
            parentComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        }
        return;
    }
    if (mev.getID() == MouseEvent.MOUSE_RELEASED) {
        // Mouse button released: do nothing

        // Switch the cursor back
        if (parentComponent != null)
            parentComponent.setCursor(savedCursor);
        return;
    }

    //
    // Mouse moved while button down: create a translation
    //
    // Compute the delta in X and Y from the previous
    // position. Use the delta to compute translation
    // distances with the mapping:
    //
    //   positive X mouse delta --> positive X-axis translation
    //   positive Y mouse delta --> negative Y-axis translation
    //
    // where positive X mouse movement is to the right, and
    // positive Y mouse movement is **down** the screen.
    //
    int deltaX = x - previousX;
    int deltaY = y - previousY;

    if (deltaX > UNUSUAL_XDELTA || deltaX < -UNUSUAL_XDELTA || deltaY > UNUSUAL_YDELTA
            || deltaY < -UNUSUAL_YDELTA) {
        // Deltas are too huge to be believable. Probably a glitch.
        // Don't record the new XY location, or do anything.
        return;
    }

    double xTranslationDistance = deltaX * XTranslationFactor;
    double yTranslationDistance = -deltaY * YTranslationFactor;

    //
    // Build transforms
    //
    translate.set(xTranslationDistance, yTranslationDistance, 0.0);
    transform1.set(translate);

    // Get and save the current transform
    subjectTransformGroup.getTransform(currentTransform);

    // Translate as needed
    currentTransform.mul(transform1);

    // Update the transform group
    subjectTransformGroup.setTransform(currentTransform);

    previousX = x;
    previousY = y;
}

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

/**
 * {@inheritDoc}//from   w w  w  . j a v a 2s.c om
 */
protected void processMouseEvent(MouseEvent e) {
    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
        selectFromEvent(e);
    } else if (e.getID() == MouseEvent.MOUSE_RELEASED) {
        if (_asKirkWouldSay_FIRE) {
            fireActionPerformed();
        }
        _asKirkWouldSay_FIRE = false;
    }
    super.processMouseEvent(e);
}

From source file:ExText.java

/**
 * Initialize the behavior.//ww  w . j  a  v a 2s.com
 */
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.//w  w  w  .j av a 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:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Simulates "Shuffle" selection./* w w  w .j a  v a 2s.  c  om*/
 */
public void pressShuffle() {
    final MouseEvent smevt = new MouseEvent(this, MouseEvent.MOUSE_RELEASED, 0, 1, 0, 0, 1, false);
    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            acShuffle.processEvent(smevt);
            return null;
        }
    });
}