IseBehavior.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00017 package com.generalrobotix.ui.view.tdview;
00018 
00019 import java.awt.AWTEvent;
00020 import java.awt.event.*;
00021 import java.util.Enumeration;
00022 import java.util.Vector;
00023 
00024 import javax.media.j3d.*;
00025 import javax.vecmath.*;
00026 
00027 import com.generalrobotix.ui.util.Grx3DViewClickListener;
00028 
00033 class IseBehavior extends Behavior {
00034     //--------------------------------------------------------------------
00035     // インスタンス変数
00036     private BehaviorHandler handler_;
00037     private WakeupCondition wakeupCondition_;
00038     private BehaviorInfo info_;
00039     private boolean isDragging_;
00040 
00041     private Vector<Grx3DViewClickListener> listeners_ = new Vector<Grx3DViewClickListener>();
00042 
00043     //--------------------------------------------------------------------
00044     // コンストラクタ
00045     public IseBehavior(BehaviorHandler handler/*, GrxHandView v*/) {
00046         handler_ = handler;
00047         setSchedulingBounds(
00048             new BoundingSphere(new Point3d(), Double.POSITIVE_INFINITY)
00049         );
00050     }
00051 
00052     //--------------------------------------------------------------------
00053     // 公開メソッド
00054     public void initialize() {
00055         wakeupCondition_ = new WakeupOr(
00056                 new WakeupCriterion[] {
00057                         new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED)
00058                     }
00059                 );
00060         wakeupOn(wakeupCondition_);
00061     }
00062 
00063     public void setBehaviorInfo(BehaviorInfo info) {
00064         info_ = info;
00065     }
00066 
00067     public BehaviorInfo getBehaviorInfo() { return info_; }
00068 
00069     public void processStimulus(Enumeration criteria) {
00070         while (criteria.hasMoreElements()) {
00071             WakeupCriterion wakeup = (WakeupCriterion)criteria.nextElement();
00072             if (wakeup instanceof WakeupOnAWTEvent) {
00073                 AWTEvent[] event = ((WakeupOnAWTEvent)wakeup).getAWTEvent();
00074                 if (event[0] instanceof MouseEvent) {
00075                     MouseEvent mouseEvent = (MouseEvent)event[0];
00076                     _processMouseEvent(mouseEvent);
00077                 }
00078             } else if (wakeup instanceof WakeupOnElapsedTime) {
00079                 if(!handler_.processTimerOperation(info_))
00080                         wakeupCondition_ = new WakeupOr(
00081                             new WakeupCriterion[] {
00082                                     new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED)
00083                                 }
00084                             );
00085             }
00086         }
00087 
00088         wakeupOn(wakeupCondition_);
00089 
00090     }
00091 
00092     private synchronized void _processMouseEvent(MouseEvent evt) {
00093         //System.out.println("IseBehavior: processMouseEvent()");
00094         switch (evt.getID()) {
00095         case MouseEvent.MOUSE_PRESSED:
00096                         //改造中
00097                         //v_.addPoint( evt.getPoint().x, evt.getPoint().y );
00098                 for( Grx3DViewClickListener l : listeners_ )
00099                         if( l != null )
00100                                 l.run( evt.getPoint().x, evt.getPoint().y );
00101 
00102             //PickingInfo info = _makePickingInfo(evt);
00103             handler_.processPicking(evt, info_);
00104             wakeupCondition_ = new WakeupOr(
00105                     new WakeupCriterion[] {
00106                             new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED),
00107                             new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED)
00108                         }
00109                     );
00110             break;
00111         case MouseEvent.MOUSE_RELEASED:
00112             info_.setTimerEnabled(false);
00113             handler_.processReleased(evt, info_);
00114             isDragging_ = false;
00115             wakeupCondition_ = new WakeupOr(
00116                     new WakeupCriterion[] {
00117                             new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED)
00118                         }
00119                     );;
00120             break;
00121         case MouseEvent.MOUSE_DRAGGED:
00122             if (isDragging_) {
00123                 handler_.processDragOperation(evt, info_);
00124                 if (info_.isTimerEnabled()) {
00125                     wakeupCondition_ = new WakeupOr(
00126                             new WakeupCriterion[] {
00127                                     new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED),
00128                                     new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED),
00129                                     new WakeupOnElapsedTime(10)
00130                                 }
00131                             );
00132                 }
00133             } else {
00134                 isDragging_ = true;
00135                 handler_.processStartDrag(evt, info_);
00136             }
00137             break;
00138         }
00139     }
00140 
00141         public void addClickListener( Grx3DViewClickListener listener ){
00142                 listeners_.add( listener );
00143         }
00144 
00145         public void removeClickListener( Grx3DViewClickListener listener ){
00146                 listeners_.remove( listener );
00147         }
00148 }
00149 


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:17