IseBehavior.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
17 package com.generalrobotix.ui.view.tdview;
18 
19 import java.awt.AWTEvent;
20 import java.awt.event.*;
21 import java.util.Enumeration;
22 import java.util.Vector;
23 
24 import javax.media.j3d.*;
25 import javax.vecmath.*;
26 
28 
33 class IseBehavior extends Behavior {
34  //--------------------------------------------------------------------
35  // インスタンス変数
36  private BehaviorHandler handler_;
37  private WakeupCondition wakeupCondition_;
38  private BehaviorInfo info_;
39  private boolean isDragging_;
40 
41  private Vector<Grx3DViewClickListener> listeners_ = new Vector<Grx3DViewClickListener>();
42 
43  //--------------------------------------------------------------------
44  // コンストラクタ
45  public IseBehavior(BehaviorHandler handler/*, GrxHandView v*/) {
46  handler_ = handler;
47  setSchedulingBounds(
48  new BoundingSphere(new Point3d(), Double.POSITIVE_INFINITY)
49  );
50  }
51 
52  //--------------------------------------------------------------------
53  // 公開メソッド
54  public void initialize() {
55  wakeupCondition_ = new WakeupOr(
56  new WakeupCriterion[] {
57  new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED)
58  }
59  );
60  wakeupOn(wakeupCondition_);
61  }
62 
63  public void setBehaviorInfo(BehaviorInfo info) {
64  info_ = info;
65  }
66 
67  public BehaviorInfo getBehaviorInfo() { return info_; }
68 
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);
77  }
78  } else if (wakeup instanceof WakeupOnElapsedTime) {
79  if(!handler_.processTimerOperation(info_))
80  wakeupCondition_ = new WakeupOr(
81  new WakeupCriterion[] {
82  new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED)
83  }
84  );
85  }
86  }
87 
88  wakeupOn(wakeupCondition_);
89 
90  }
91 
92  private synchronized void _processMouseEvent(MouseEvent evt) {
93  //System.out.println("IseBehavior: processMouseEvent()");
94  switch (evt.getID()) {
95  case MouseEvent.MOUSE_PRESSED:
96  //改造中
97  //v_.addPoint( evt.getPoint().x, evt.getPoint().y );
98  for( Grx3DViewClickListener l : listeners_ )
99  if( l != null )
100  l.run( evt.getPoint().x, evt.getPoint().y );
101 
102  //PickingInfo info = _makePickingInfo(evt);
103  handler_.processPicking(evt, info_);
104  wakeupCondition_ = new WakeupOr(
105  new WakeupCriterion[] {
106  new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED),
107  new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED)
108  }
109  );
110  break;
111  case MouseEvent.MOUSE_RELEASED:
112  info_.setTimerEnabled(false);
113  handler_.processReleased(evt, info_);
114  isDragging_ = false;
115  wakeupCondition_ = new WakeupOr(
116  new WakeupCriterion[] {
117  new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED)
118  }
119  );;
120  break;
121  case MouseEvent.MOUSE_DRAGGED:
122  if (isDragging_) {
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)
130  }
131  );
132  }
133  } else {
134  isDragging_ = true;
135  handler_.processStartDrag(evt, info_);
136  }
137  break;
138  }
139  }
140 
141  public void addClickListener( Grx3DViewClickListener listener ){
142  listeners_.add( listener );
143  }
144 
145  public void removeClickListener( Grx3DViewClickListener listener ){
146  listeners_.remove( listener );
147  }
148 }
149 
#define null
our own NULL pointer
Definition: IceTypes.h:57
backing_store_ptr info
Definition: jmemsys.h:181


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:04