diff options
Diffstat (limited to 'src')
4 files changed, 133 insertions, 14 deletions
diff --git a/src/classes/share/javax/media/j3d/BehaviorStructure.java b/src/classes/share/javax/media/j3d/BehaviorStructure.java index f03d9c9..93609c7 100644 --- a/src/classes/share/javax/media/j3d/BehaviorStructure.java +++ b/src/classes/share/javax/media/j3d/BehaviorStructure.java @@ -437,6 +437,7 @@ class BehaviorStructure extends J3dStructure { boolean keyEnable = false; boolean mouseMotionEnable = false; boolean mouseEnable = false; + boolean mouseWheelEnable = false; WakeupOnAWTEvent awtCond; int awtId; long eventMask; @@ -460,8 +461,16 @@ class BehaviorStructure extends J3dStructure { if ((awtId == MouseEvent.MOUSE_DRAGGED) || (awtId == MouseEvent.MOUSE_MOVED)) { mouseMotionEnable = true; - } else { + } + else if ((awtId == MouseEvent.MOUSE_ENTERED) || + (awtId == MouseEvent.MOUSE_EXITED) || + (awtId == MouseEvent.MOUSE_CLICKED) || + (awtId == MouseEvent.MOUSE_PRESSED) || + (awtId == MouseEvent.MOUSE_RELEASED) ) { mouseEnable = true; + } + else if (awtId == MouseEvent.MOUSE_WHEEL) { + mouseWheelEnable = true; } } else { if ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0) { @@ -470,6 +479,9 @@ class BehaviorStructure extends J3dStructure { if ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0) { mouseMotionEnable = true; } + if ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0) { + mouseWheelEnable = true; + } } } @@ -482,6 +494,10 @@ class BehaviorStructure extends J3dStructure { incTimestamp = true; universe.disableKeyEvents(); } + if (!mouseWheelEnable && universe.enableMouseWheel) { + incTimestamp = true; + universe.disableMouseWheelEvents(); + } if (!mouseMotionEnable && universe.enableMouseMotion) { incTimestamp = true; universe.disableMouseMotionEvents(); @@ -684,6 +700,10 @@ class BehaviorStructure extends J3dStructure { (awtCond.EventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0) { awtCond.addAWTEvent(evt); } + else if ((id == MouseEvent.MOUSE_WHEEL) && + (awtCond.EventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0) { + awtCond.addAWTEvent(evt); + } } } } diff --git a/src/classes/share/javax/media/j3d/EventCatcher.java b/src/classes/share/javax/media/j3d/EventCatcher.java index 5fb9d39..9540b05 100644 --- a/src/classes/share/javax/media/j3d/EventCatcher.java +++ b/src/classes/share/javax/media/j3d/EventCatcher.java @@ -22,22 +22,23 @@ import java.awt.event.*; * 1.1 event model. Most events are sent to the canvas for processing. */ class EventCatcher extends Object implements ComponentListener, FocusListener, - KeyListener, MouseListener, MouseMotionListener, WindowListener { + KeyListener, MouseListener, MouseMotionListener, MouseWheelListener, WindowListener { // The canvas associated with this event catcher - Canvas3D canvas; + private Canvas3D canvas; static final boolean DEBUG = false; - boolean stopped = false; + private boolean stopped = false; /** * flags for event listeners */ - boolean componentEvents = false; - boolean focusEvents = false; - boolean keyEvents = false; - boolean mouseEvents = false; - boolean mouseMotionEvents = false; - boolean mouseListenerAdded = false; + private boolean componentEvents = false; + private boolean focusEvents = false; + private boolean keyEvents = false; + private boolean mouseEvents = false; + private boolean mouseMotionEvents = false; + private boolean mouseWheelEvents = false; + private boolean mouseListenerAdded = false; EventCatcher(Canvas3D c) { canvas = c; @@ -146,6 +147,21 @@ class EventCatcher extends Object implements ComponentListener, FocusListener, } } + void enableMouseWheelEvents() { + if (!mouseWheelEvents) { + canvas.addMouseWheelListener(this); + mouseWheelEvents = true; + } + } + + + void disableMouseWheelEvents() { + if (mouseWheelEvents) { + canvas.removeMouseWheelListener(this); + mouseWheelEvents = false; + } + } + public void componentResized(ComponentEvent e) { if (e.getSource() == canvas) { @@ -270,7 +286,7 @@ class EventCatcher extends Object implements ComponentListener, FocusListener, } public void mouseExited(MouseEvent e) { - if (mouseEvents) + if (mouseEvents) canvas.sendEventToBehaviorScheduler(e); if (DEBUG) { System.out.println(e); @@ -294,6 +310,8 @@ class EventCatcher extends Object implements ComponentListener, FocusListener, } public void mouseDragged(MouseEvent e) { + // Note : We don't have to test for mouseMotionEvent here because + // this routine will never be called unless mouseMotionEvent is enabled. canvas.sendEventToBehaviorScheduler(e); if (DEBUG) { System.out.println(e); @@ -301,11 +319,23 @@ class EventCatcher extends Object implements ComponentListener, FocusListener, } public void mouseMoved(MouseEvent e) { + // Note : We don't have to test for mouseMotionEvent here because + // this routine will never be called unless mouseMotionEvent is enabled. canvas.sendEventToBehaviorScheduler(e); if (DEBUG) { System.out.println(e); } } + + public void mouseWheelMoved(MouseWheelEvent e) { + // Note : We don't have to test for mouseWheelEvent here because + // this routine will never be called unless mouseWheelEvent is enabled. + canvas.sendEventToBehaviorScheduler(e); + if (DEBUG) { + System.out.println(e); + } + } + public void windowActivated(WindowEvent e) { windowOpened(e); @@ -381,8 +411,10 @@ class EventCatcher extends Object implements ComponentListener, FocusListener, componentEvents = false; mouseEvents = false; mouseMotionEvents = false; - mouseListenerAdded = false; + mouseWheelEvents = false; + mouseListenerAdded = false; stopped = false; } + } diff --git a/src/classes/share/javax/media/j3d/VirtualUniverse.java b/src/classes/share/javax/media/j3d/VirtualUniverse.java index 26a34db..64a0b4a 100644 --- a/src/classes/share/javax/media/j3d/VirtualUniverse.java +++ b/src/classes/share/javax/media/j3d/VirtualUniverse.java @@ -137,6 +137,7 @@ public class VirtualUniverse extends Object { boolean enableKey = false; boolean enableMouse = false; boolean enableMouseMotion = false; + boolean enableMouseWheel = false; // Keep track of how many active View use this universe int activeViewCount = 0; @@ -623,6 +624,10 @@ public class VirtualUniverse extends Object { if (enableMouseMotion) { enableMouseMotionEvents(); } + if (enableMouseWheel) { + enableMouseWheelEvents(); + } + } void enableComponentEvents() { @@ -860,6 +865,58 @@ public class VirtualUniverse extends Object { } } + void disableMouseWheelEvents() { + Enumeration cvs; + Canvas3D cv; + View views[]; + ViewPlatformRetained vp; + Object[] vps = getViewPlatformList(); + + enableMouseWheel = false; + + if (vps != null) { + for (int i=0; i<vps.length; i++) { + vp =(ViewPlatformRetained)vps[i]; + views = vp.getViewList(); + for (int j=views.length-1; j>=0; j--) { + cvs = views[j].getAllCanvas3Ds(); + while(cvs.hasMoreElements()) { + cv = (Canvas3D) cvs.nextElement(); + // offscreen canvas does not have event catcher + if (cv.eventCatcher != null) + cv.eventCatcher.disableMouseWheelEvents(); + } + } + } + } + } + + void enableMouseWheelEvents() { + Enumeration cvs; + Canvas3D cv; + View views[]; + ViewPlatformRetained vp; + Object[] vps = getViewPlatformList(); + + enableMouseWheel = true; + + if (vps != null) { + for (int i=0; i<vps.length; i++) { + vp =(ViewPlatformRetained)vps[i]; + views = vp.getViewList(); + for (int j=views.length-1; j>=0; j--) { + cvs = views[j].getAllCanvas3Ds(); + while(cvs.hasMoreElements()) { + cv = (Canvas3D) cvs.nextElement(); + // offscreen canvas does not have event catcher + if (cv.eventCatcher != null) + cv.eventCatcher.enableMouseWheelEvents(); + } + } + } + } + } + /** * Sets the "current" view (during view activation) for this virtual * universe. diff --git a/src/classes/share/javax/media/j3d/WakeupOnAWTEvent.java b/src/classes/share/javax/media/j3d/WakeupOnAWTEvent.java index 8c81612..497c29a 100644 --- a/src/classes/share/javax/media/j3d/WakeupOnAWTEvent.java +++ b/src/classes/share/javax/media/j3d/WakeupOnAWTEvent.java @@ -108,7 +108,6 @@ public final class WakeupOnAWTEvent extends WakeupCriterion { * set every time the condition met. */ void resetBehaviorCondition(BehaviorStructure bs) { - if (enableAWTEventTS != bs.awtEventTimestamp) { if ((AwtId >= ComponentEvent.COMPONENT_FIRST && AwtId <= ComponentEvent.COMPONENT_LAST) || @@ -128,7 +127,15 @@ public final class WakeupOnAWTEvent extends WakeupCriterion { if ((AwtId == MouseEvent.MOUSE_DRAGGED) || (AwtId == MouseEvent.MOUSE_MOVED)) { behav.universe.enableMouseMotionEvents(); - } else { + } + else if (AwtId == MouseEvent.MOUSE_WHEEL) { + behav.universe.enableMouseWheelEvents(); + } + else if (AwtId == MouseEvent.MOUSE_CLICKED || + AwtId == MouseEvent.MOUSE_ENTERED || + AwtId == MouseEvent.MOUSE_EXITED || + AwtId == MouseEvent.MOUSE_PRESSED || + AwtId == MouseEvent.MOUSE_RELEASED) { behav.universe.enableMouseEvents(); } } else { @@ -138,6 +145,9 @@ public final class WakeupOnAWTEvent extends WakeupCriterion { if ((EventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0) { behav.universe.enableMouseMotionEvents(); } + if ((EventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0) { + behav.universe.enableMouseWheelEvents(); + } } enableAWTEventTS = bs.awtEventTimestamp; } |