17 package com.generalrobotix.ui.view.tdview;
19 import java.awt.AWTEvent;
20 import java.awt.event.*;
21 import java.util.Enumeration;
22 import java.util.Vector;
24 import javax.media.j3d.*;
25 import javax.vecmath.*;
33 class IseBehavior
extends Behavior {
36 private BehaviorHandler handler_;
37 private WakeupCondition wakeupCondition_;
38 private BehaviorInfo info_;
39 private boolean isDragging_;
41 private Vector<Grx3DViewClickListener> listeners_ =
new Vector<Grx3DViewClickListener>();
45 public IseBehavior(BehaviorHandler handler) {
48 new BoundingSphere(
new Point3d(), Double.POSITIVE_INFINITY)
54 public void initialize() {
55 wakeupCondition_ =
new WakeupOr(
56 new WakeupCriterion[] {
57 new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED)
60 wakeupOn(wakeupCondition_);
63 public void setBehaviorInfo(BehaviorInfo
info) {
67 public BehaviorInfo getBehaviorInfo() {
return info_; }
69 public void processStimulus(Enumeration criteria) {
70 while (criteria.hasMoreElements()) {
71 WakeupCriterion wakeup = (WakeupCriterion)criteria.nextElement();
72 if (wakeup instanceof WakeupOnAWTEvent) {
73 AWTEvent[]
event = ((WakeupOnAWTEvent)wakeup).getAWTEvent();
74 if (event[0] instanceof MouseEvent) {
75 MouseEvent mouseEvent = (MouseEvent)event[0];
76 _processMouseEvent(mouseEvent);
78 }
else if (wakeup instanceof WakeupOnElapsedTime) {
79 if(!handler_.processTimerOperation(info_))
80 wakeupCondition_ =
new WakeupOr(
81 new WakeupCriterion[] {
82 new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED)
88 wakeupOn(wakeupCondition_);
92 private synchronized void _processMouseEvent(MouseEvent evt) {
94 switch (evt.getID()) {
95 case MouseEvent.MOUSE_PRESSED:
98 for( Grx3DViewClickListener l : listeners_ )
100 l.run( evt.getPoint().x, evt.getPoint().y );
103 handler_.processPicking(evt, info_);
104 wakeupCondition_ =
new WakeupOr(
105 new WakeupCriterion[] {
106 new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED),
107 new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED)
111 case MouseEvent.MOUSE_RELEASED:
112 info_.setTimerEnabled(
false);
113 handler_.processReleased(evt, info_);
115 wakeupCondition_ =
new WakeupOr(
116 new WakeupCriterion[] {
117 new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED)
121 case MouseEvent.MOUSE_DRAGGED:
123 handler_.processDragOperation(evt, info_);
124 if (info_.isTimerEnabled()) {
125 wakeupCondition_ =
new WakeupOr(
126 new WakeupCriterion[] {
127 new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED),
128 new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED),
129 new WakeupOnElapsedTime(10)
135 handler_.processStartDrag(evt, info_);
141 public void addClickListener( Grx3DViewClickListener listener ){
142 listeners_.add( listener );
145 public void removeClickListener( Grx3DViewClickListener listener ){
146 listeners_.remove( listener );
#define null
our own NULL pointer