|
I have a class that extends mouseBehavior. I think all is
working fine, but I need remove the behavior of the view when the user press the
second button of the mouse.
I have tried different ways but it doesnt work. Can you
help me?
Im very very lost so give me an idea,
please!!
Thanks in advance.
// Code of the my Zoom mouse Behavior
import java.awt.*;
import java.awt.event.*; import java.util.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.behaviors.mouse.*; import j3dui.utils.*;
import j3dui.utils.app.*; public class ZoomPtoVista extends
MouseBehavior
{ double z_factor = .04; Vector3d translation = new Vector3d(); private MouseBehaviorCallback callback
= null;
protected PanelCentral universe; //class that contans canvas3d and the virtual universe Canvas3D display;
ZoomPtoVista(PanelCentral univ, AppView
view,TransformGroup tView)
{ super (tView); display = view.getDisplay(); tView.getTransform (currXform); transformGroup.setTransform (currXform); universe= univ; } public void initialize() { super.initialize (); } /** * Return the z-axis movement multipler. **/ public double getFactor() { return z_factor; } public void processStimulus (Enumeration criteria)
{ WakeupCriterion wakeup; AWTEvent[] events; MouseEvent evt; while (criteria.hasMoreElements())
{ wakeup = (WakeupCriterion) criteria.nextElement(); if (wakeup instanceof WakeupOnAWTEvent)
{ events = ((WakeupOnAWTEvent)wakeup).getAWTEvent(); if (events.length > 0) { evt = (MouseEvent) events[events.length-1]; if
(evt.getSource()==display)
doProcess(evt); } } else if (wakeup instanceof WakeupOnBehaviorPost) { while (true) { // access to the queue must be synchronized synchronized (mouseq) { if (mouseq.isEmpty()) break; evt = (MouseEvent)mouseq.remove(0); // consolodate MOUSE_DRAG events while ((evt.getID() == MouseEvent.MOUSE_DRAGGED) && !mouseq.isEmpty() &&(((MouseEvent)mouseq.get(0)).getID() ==MouseEvent.MOUSE_DRAGGED)) { evt = (MouseEvent)mouseq.remove(0); } } doProcess(evt); } } }
wakeupOn (mouseCriterion); } void doProcess(MouseEvent evt) { int id; int dx, dy; processMouseEvent(evt);
if (((buttonPress)&&((flags & MANUAL_WAKEUP) == 0)) ||((wakeUp)&&((flags & MANUAL_WAKEUP) != 0))) { id = evt.getID(); if ((id == MouseEvent.MOUSE_DRAGGED) &&!evt.isAltDown() && !evt.isMetaDown()) { x = evt.getX(); y = evt.getY(); dx = x - x_last; dy = y - y_last; if (!reset) { transformGroup.getTransform(currXform); translation.z = dy*z_factor; transformX.set(translation); if (invert) { currXform.mul(currXform, transformX); } else { currXform.mul(transformX, currXform); } transformGroup.setTransform(currXform); transformChanged( currXform ); if (callback!=null) callback.transformChanged( MouseBehaviorCallback.ZOOM,currXform ); } else { reset = false; } x_last = x; y_last = y; } else if (id == MouseEvent.MOUSE_PRESSED) { // I have to put the code
to remove the behavior here!!!!!!
if (evt.getModifiers() == evt.BUTTON3_MASK) universe.desactivaComportamiento(); x_last =
evt.getX();
y_last = evt.getY(); } } } /**
* Users can overload this method which is called every time * the Behavior updates the transform * * Default implementation does nothing */ public void transformChanged( Transform3D transform ) { } /**
* The transformChanged method in the callback class will * be called every time the transform is updated */ public void setupCallback( MouseBehaviorCallback callback ) { this.callback = callback; } } -------------------------------------------------- PiXoTo mail: [EMAIL PROTECTED] msn: [EMAIL PROTECTED] web: http://www.pixoto.com -------------------------------------------------- |
