Search in sources :

Example 1 with WakeupOnAWTEvent

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

the class MouseBehavior method initialize.

/*
     * Initializes the behavior.
     */
/**
 * <p>
 * initialize</p>
 */
public void initialize() {
    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);
    if (poster == null) {
        wakeupOn(mouseCriterion);
    } else {
        postCriterion = new WakeupOnBehaviorPost(poster, id);
        wakeupOn(postCriterion);
    }
    x = 0;
    y = 0;
    x_last = 0;
    y_last = 0;
}
Also used : WakeupOnAWTEvent(javax.media.j3d.WakeupOnAWTEvent) WakeupOr(javax.media.j3d.WakeupOr) WakeupOnBehaviorPost(javax.media.j3d.WakeupOnBehaviorPost)

Example 2 with WakeupOnAWTEvent

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

the class MouseRotate 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();
                // Drag and Button 1 down
                if ((id == MouseEvent.MOUSE_DRAGGED) && ((mevent.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK) && transformGroup != null) {
                    x = ((MouseEvent) event[i]).getX();
                    y = ((MouseEvent) event[i]).getY();
                    int dx = x - x_last;
                    int dy = y - y_last;
                    if (!reset) {
                        x_angle = dy * y_factor;
                        y_angle = dx * x_factor;
                        transformX.rotX(x_angle);
                        transformY.rotY(y_angle);
                        transformGroup.getTransform(currXform);
                        currXform.get(mat);
                        currXform.setTranslation(zero3d);
                        if (ViewerTG != null) {
                            ViewerTG.getTransform(VPTG_T3D);
                            VPTG_T3D.setTranslation(zero3d);
                            VPTG_T3D.invert();
                            currXform.mul(VPTG_T3D, currXform);
                        }
                        if (invert) {
                            currXform.mul(currXform, transformX);
                            currXform.mul(currXform, transformY);
                        } else {
                            currXform.mul(transformX, currXform);
                            currXform.mul(transformY, currXform);
                        }
                        if (ViewerTG != null) {
                            VPTG_T3D.invert();
                            currXform.mul(VPTG_T3D, currXform);
                        }
                        translation.set(mat.m03, mat.m13, mat.m23);
                        currXform.setTranslation(translation);
                        transformGroup.setTransform(currXform);
                        transformChanged(currXform);
                        if (callback != null) {
                            callback.transformChanged(MouseBehaviorCallback.TRANSLATE, currXform);
                        }
                    } else {
                        reset = false;
                    }
                    x_last = x;
                    y_last = y;
                } else 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 || postCriterion == null) {
        wakeupOn(mouseCriterion);
    } else {
        postId(doneID);
        wakeupOn(postCriterion);
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) AWTEvent(java.awt.AWTEvent) WakeupOnAWTEvent(javax.media.j3d.WakeupOnAWTEvent) WakeupOnAWTEvent(javax.media.j3d.WakeupOnAWTEvent) WakeupCriterion(javax.media.j3d.WakeupCriterion)

Example 3 with WakeupOnAWTEvent

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

the class PickMouseBehavior method initialize.

/**
 * <p>
 * initialize</p>
 */
public void initialize() {
    conditions = new WakeupCriterion[1];
    conditions[0] = new WakeupOnAWTEvent(Event.MOUSE_DOWN);
    wakeupCondition = new WakeupOr(conditions);
    wakeupOn(wakeupCondition);
}
Also used : WakeupOnAWTEvent(javax.media.j3d.WakeupOnAWTEvent) WakeupOr(javax.media.j3d.WakeupOr)

Example 4 with WakeupOnAWTEvent

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

the class PickMouseBehavior method processStimulus.

/**
 * {@inheritDoc}
 */
public void processStimulus(Enumeration criteria) {
    WakeupCriterion wakeup;
    AWTEvent[] evt = null;
    int xpos = 0, ypos = 0;
    while (criteria.hasMoreElements()) {
        wakeup = (WakeupCriterion) criteria.nextElement();
        if (wakeup instanceof WakeupOnAWTEvent) {
            evt = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
        }
    }
    if (evt[0] instanceof MouseEvent) {
        mevent = (MouseEvent) evt[0];
        processMouseEvent((MouseEvent) evt[0]);
        xpos = mevent.getPoint().x;
        ypos = mevent.getPoint().y;
    }
    if (buttonPress) {
        updateScene(xpos, ypos);
    }
    wakeupOn(wakeupCondition);
}
Also used : MouseEvent(java.awt.event.MouseEvent) AWTEvent(java.awt.AWTEvent) WakeupOnAWTEvent(javax.media.j3d.WakeupOnAWTEvent) WakeupOnAWTEvent(javax.media.j3d.WakeupOnAWTEvent) WakeupCriterion(javax.media.j3d.WakeupCriterion)

Example 5 with WakeupOnAWTEvent

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

the class GraphicsEvents method initialize.

/**
 * <p>
 * initialize</p>
 */
public void initialize() {
    WakeupCriterion[] behaviorPost = new WakeupCriterion[3];
    behaviorPost[0] = new WakeupOnBehaviorPost(systemRotate, BEHAVIORDONEPOST);
    behaviorPost[1] = new WakeupOnBehaviorPost(systemTranslate, BEHAVIORDONEPOST);
    behaviorPost[2] = new WakeupOnBehaviorPost(globalZoom, BEHAVIORDONEPOST);
    postCriterion = new WakeupOr(behaviorPost);
    WakeupCriterion[] awtCriterion = new WakeupCriterion[2];
    awtCriterion[0] = new WakeupOnAWTEvent(Event.MOUSE_DOWN);
    awtCriterion[1] = new WakeupOnAWTEvent(Event.MOUSE_UP);
    mouseCriterion = new WakeupOr(awtCriterion);
    wakeupOn(mouseCriterion);
}
Also used : WakeupOnAWTEvent(javax.media.j3d.WakeupOnAWTEvent) WakeupCriterion(javax.media.j3d.WakeupCriterion) WakeupOr(javax.media.j3d.WakeupOr) WakeupOnBehaviorPost(javax.media.j3d.WakeupOnBehaviorPost)

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