Search in sources :

Example 11 with WakeupOnAWTEvent

use of javax.media.j3d.WakeupOnAWTEvent in project ffx by mjschnie.

the class MouseTranslate method processStimulus.

/**
 * {@inheritDoc}
 */
public void processStimulus(Enumeration criteria) {
    while (criteria.hasMoreElements()) {
        WakeupCriterion wakeup = (WakeupCriterion) criteria.nextElement();
        if (wakeup instanceof WakeupOnAWTEvent) {
            AWTEvent[] event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
            for (int i = 0; i < event.length; i++) {
                MouseEvent mevent = (MouseEvent) event[i];
                processMouseEvent(mevent);
                int id = event[i].getID();
                int mod = mevent.getModifiersEx();
                boolean rightButton = ((mod & mouseButton) == mouseButton);
                if (!rightButton) {
                    rightButton = ((mod & MouseEvent.SHIFT_DOWN_MASK) == MouseEvent.SHIFT_DOWN_MASK);
                }
                if ((id == MouseEvent.MOUSE_DRAGGED) && rightButton && transformGroup != null) {
                    x = ((MouseEvent) event[i]).getX();
                    y = ((MouseEvent) event[i]).getY();
                    int dx = x - x_last;
                    int dy = y - y_last;
                    if ((!reset) && ((Math.abs(dy) < 50) && (Math.abs(dx) < 50))) {
                        transformGroup.getTransform(currXform);
                        Transform3D VPTG_T3D = new Transform3D();
                        ViewerTG.getTransform(VPTG_T3D);
                        VPTG_T3D.setTranslation(zero3d);
                        VPTG_T3D.invert();
                        currXform.mul(VPTG_T3D, currXform);
                        translation.x = dx * x_factor;
                        translation.y = -dy * y_factor;
                        transformX.set(translation);
                        if (invert) {
                            currXform.mul(currXform, transformX);
                        } else {
                            currXform.mul(transformX, currXform);
                        }
                        VPTG_T3D.invert();
                        currXform.mul(VPTG_T3D, currXform);
                        transformGroup.setTransform(currXform);
                        transformChanged(currXform);
                        if (callback != null) {
                            callback.transformChanged(MouseBehaviorCallback.TRANSLATE, currXform);
                        }
                    } else {
                        reset = false;
                    }
                    x_last = x;
                    y_last = y;
                }
                if (id == MouseEvent.MOUSE_PRESSED) {
                    x_last = ((MouseEvent) event[i]).getX();
                    y_last = ((MouseEvent) event[i]).getY();
                } else if (id == MouseEvent.MOUSE_RELEASED) {
                    setTransformGroup(null);
                }
            }
        }
    }
    if (transformGroup != null) {
        wakeupOn(mouseCriterion);
    } else {
        mouseButton = MouseEvent.BUTTON3_DOWN_MASK;
        postId(doneID);
        wakeupOn(postCriterion);
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) Transform3D(javax.media.j3d.Transform3D) AWTEvent(java.awt.AWTEvent) WakeupOnAWTEvent(javax.media.j3d.WakeupOnAWTEvent) WakeupOnAWTEvent(javax.media.j3d.WakeupOnAWTEvent) WakeupCriterion(javax.media.j3d.WakeupCriterion)

Aggregations

WakeupOnAWTEvent (javax.media.j3d.WakeupOnAWTEvent)11 WakeupCriterion (javax.media.j3d.WakeupCriterion)9 AWTEvent (java.awt.AWTEvent)8 MouseEvent (java.awt.event.MouseEvent)7 WakeupOr (javax.media.j3d.WakeupOr)3 Transform3D (javax.media.j3d.Transform3D)2 WakeupOnBehaviorPost (javax.media.j3d.WakeupOnBehaviorPost)2 LeftButtonMode (ffx.ui.GraphicsCanvas.LeftButtonMode)1 Matrix4d (javax.vecmath.Matrix4d)1 Vector3d (javax.vecmath.Vector3d)1 Vector3f (javax.vecmath.Vector3f)1