17 package com.generalrobotix.ui.view.tdview;
19 import java.awt.event.*;
20 import javax.media.j3d.TransformGroup;
22 import org.eclipse.swt.widgets.Display;
29 class IseBehaviorHandler
implements BehaviorHandler {
34 private static final ObjectRotationHandler
35 OBJECT_ROTATION_HANDLER =
new ObjectRotationHandler();
36 private static final ObjectTranslationHandler
37 OBJECT_TRANSLATION_HANDLER =
new ObjectTranslationHandler();
38 private static final JointRotationHandler
39 JOINT_ROTATION_HANDLER =
new JointRotationHandler();
40 private static final ObjectFittingHandler
41 OBJECT_FITTING_HANDLER =
new ObjectFittingHandler();
42 private static final InvKinemaHandler
43 INV_KINEMA_HANDLER =
new InvKinemaHandler();
46 private static final WalkViewHandler
47 WALK_VIEW_HANDLER =
new WalkViewHandler();
48 private static final RoomViewHandler
49 ROOM_VIEW_HANDLER =
new RoomViewHandler();
51 public static final String
52 BUTTON_MODE_ROTATION =
"button_mode_rotation";
53 public static final String
54 BUTTON_MODE_TRANSLATION =
"button_mode_translation";
55 public static final String BUTTON_MODE_ZOOM =
"button_mode_zoom";
56 public static final String CTRL_PRESSED =
"ctrl_pressed";
57 public static final String ALT_PRESSED =
"alt_pressed";
59 private static final int TIMER_MODE_OFF = 0;
60 private static final int TIMER_MODE_OPERATION = 1;
61 private static final int TIMER_MODE_VIEW = 2;
65 private ViewHandler viewHandler_;
66 private OperationHandler operationHandler_;
67 private BehaviorHandler indicator_;
68 private int timerMode_;
69 private BehaviorManager bManager_;
73 public IseBehaviorHandler(BehaviorManager bManager) {
74 viewHandler_ = ROOM_VIEW_HANDLER;
75 ROOM_VIEW_HANDLER.setParallelMode(
false);
81 public void setViewIndicator(BehaviorHandler handler) {
85 public void setViewMode(
int mode) {
87 case BehaviorManager.WALK_VIEW_MODE:
88 viewHandler_ = WALK_VIEW_HANDLER;
90 case BehaviorManager.ROOM_VIEW_MODE:
91 viewHandler_ = ROOM_VIEW_HANDLER;
92 ROOM_VIEW_HANDLER.setParallelMode(
false);
94 case BehaviorManager.PARALLEL_VIEW_MODE:
95 viewHandler_ = ROOM_VIEW_HANDLER;
96 ROOM_VIEW_HANDLER.setParallelMode(
true);
101 public void setViewHandlerMode(String str) {
102 WALK_VIEW_HANDLER.setMode(str);
103 ROOM_VIEW_HANDLER.setMode(str);
106 public void setOperationMode(
int mode) {
108 case BehaviorManager.OPERATION_MODE_NONE:
109 if (operationHandler_ !=
null) {
110 operationHandler_.disableHandler();
112 operationHandler_ =
null;
114 case BehaviorManager.OBJECT_ROTATION_MODE:
115 if (operationHandler_ !=
null) {
116 operationHandler_.disableHandler();
118 operationHandler_ = OBJECT_ROTATION_HANDLER;
120 case BehaviorManager.OBJECT_TRANSLATION_MODE:
121 if (operationHandler_ !=
null) {
122 operationHandler_.disableHandler();
124 operationHandler_ = OBJECT_TRANSLATION_HANDLER;
126 case BehaviorManager.JOINT_ROTATION_MODE:
127 if (operationHandler_ !=
null) {
128 operationHandler_.disableHandler();
130 operationHandler_ = JOINT_ROTATION_HANDLER;
132 case BehaviorManager.FITTING_FROM_MODE:
133 if (operationHandler_ !=
null &&
134 operationHandler_ != OBJECT_FITTING_HANDLER
136 operationHandler_.disableHandler();
138 operationHandler_ = OBJECT_FITTING_HANDLER;
139 OBJECT_FITTING_HANDLER.setFittingMode(
140 ObjectFittingHandler.FITTING_FROM
143 case BehaviorManager.FITTING_TO_MODE:
144 if (operationHandler_ !=
null &&
145 operationHandler_ != OBJECT_FITTING_HANDLER
147 operationHandler_.disableHandler();
149 operationHandler_ = OBJECT_FITTING_HANDLER;
150 OBJECT_FITTING_HANDLER.setFittingMode(
151 ObjectFittingHandler.FITTING_TO
154 case BehaviorManager.INV_KINEMA_FROM_MODE:
155 if (operationHandler_ !=
null &&
156 operationHandler_ != INV_KINEMA_HANDLER
158 operationHandler_.disableHandler();
160 operationHandler_ = INV_KINEMA_HANDLER;
161 INV_KINEMA_HANDLER.setInvKinemaMode(InvKinemaHandler.FROM_MODE);
163 case BehaviorManager.INV_KINEMA_TRANSLATION_MODE:
164 if (operationHandler_ !=
null &&
165 operationHandler_ != INV_KINEMA_HANDLER
167 operationHandler_.disableHandler();
169 operationHandler_ = INV_KINEMA_HANDLER;
170 INV_KINEMA_HANDLER.setInvKinemaMode(
171 InvKinemaHandler.TRANSLATION_MODE
174 case BehaviorManager.INV_KINEMA_ROTATION_MODE:
175 if (operationHandler_ !=
null &&
176 operationHandler_ != INV_KINEMA_HANDLER
178 operationHandler_.disableHandler();
180 operationHandler_ = INV_KINEMA_HANDLER;
181 INV_KINEMA_HANDLER.setInvKinemaMode(
182 InvKinemaHandler.ROTATION_MODE
188 public void setInvKinemaResolver(InvKinemaResolver resolver) {
189 INV_KINEMA_HANDLER.setInvKinemaResolver(resolver);
192 private boolean ret_;
193 public boolean fit(
final BehaviorInfo
info) {
194 if (operationHandler_ == OBJECT_FITTING_HANDLER) {
197 ret_ = OBJECT_FITTING_HANDLER.fit(info);
206 public void setPickTarget(TransformGroup tg, BehaviorInfo info) {
207 if (operationHandler_ !=
null) {
208 operationHandler_.setPickTarget(tg, info);
214 public void processPicking(
final MouseEvent evt,
final BehaviorInfo info) {
215 if (!evt.isAltDown() && !evt.isMetaDown()) {
216 if (operationHandler_ !=
null) {
219 operationHandler_.processPicking(evt, info);
225 if (!evt.isConsumed()) {
226 viewHandler_.processPicking(evt, info);
227 indicator_.processPicking(evt, info);
231 public void processStartDrag(
final MouseEvent evt,
final BehaviorInfo info) {
232 int mode = TIMER_MODE_OFF;
233 timerMode_ = TIMER_MODE_OFF;
235 if (!evt.isAltDown() && !evt.isMetaDown()) {
236 if (operationHandler_ !=
null) {
239 operationHandler_.processStartDrag(evt, info);
242 mode = TIMER_MODE_OPERATION;
246 if (!evt.isConsumed()) {
247 viewHandler_.processStartDrag(evt, info);
248 mode = TIMER_MODE_VIEW;
251 if (info.isTimerEnabled()) {
257 if (!evt.isAltDown() && !evt.isMetaDown()) {
258 if (operationHandler_ !=
null) {
261 operationHandler_.processDragOperation(evt, info);
267 if (!evt.isConsumed()) {
268 viewHandler_.processDragOperation(evt, info);
272 public void processReleased(
final MouseEvent evt,
final BehaviorInfo info) {
273 if (!evt.isAltDown() && !evt.isMetaDown()) {
274 if (operationHandler_ !=
null) {
277 operationHandler_.processReleased(evt, info);
283 if (!evt.isConsumed()) {
284 viewHandler_.processReleased(evt, info);
285 indicator_.processReleased(evt, info);
290 switch (timerMode_) {
293 case TIMER_MODE_OPERATION:
294 if(operationHandler_ instanceof InvKinemaHandler)
295 if(!bManager_.initDynamicsSimulator())
299 operationHandler_.processTimerOperation(info);
303 case TIMER_MODE_VIEW:
304 viewHandler_.processTimerOperation(info);
310 private boolean syncExec(Runnable r){
311 Display display = Display.getDefault();
312 if ( display!=
null && !display.isDisposed()){
313 display.syncExec( r );
#define null
our own NULL pointer
void processReleased(MouseEvent evt, BehaviorInfo info)
void processStartDrag(MouseEvent evt, BehaviorInfo info)
void processDragOperation(MouseEvent evt, BehaviorInfo info)
void processPicking(MouseEvent evt, BehaviorInfo info)
boolean processTimerOperation(BehaviorInfo info)