/extensions/org/mt4jx/input/gestureAction/CollisionDragAction.java
Java | 74 lines | 51 code | 14 blank | 9 comment | 5 complexity | bf08b4dd48a60abc783717231f90ec85 MD5 | raw file
1package org.mt4jx.input.gestureAction; 2 3import org.mt4j.components.MTComponent; 4import org.mt4j.components.interfaces.IMTComponent3D; 5import org.mt4j.input.inputProcessors.IGestureEventListener; 6import org.mt4j.input.inputProcessors.MTGestureEvent; 7import org.mt4j.input.inputProcessors.componentProcessors.dragProcessor.DragEvent; 8 9public class CollisionDragAction implements IGestureEventListener { 10 11 private IMTComponent3D dragTarget; 12 private boolean useCustomTarget; 13 private boolean gestureAborted = false; 14 15 public CollisionDragAction(){ 16 this.useCustomTarget = false; 17 } 18 19 public CollisionDragAction(IMTComponent3D dragTarget){ 20 this.dragTarget = dragTarget; 21 this.useCustomTarget = true; 22 } 23 24 public boolean processGestureEvent(MTGestureEvent ge) { 25 26 if (ge instanceof DragEvent){ 27 DragEvent dragEvent = (DragEvent)ge; 28 29 if (!useCustomTarget) 30 dragTarget = dragEvent.getTarget(); 31 32 switch (dragEvent.getId()) { 33 case MTGestureEvent.GESTURE_STARTED: 34 //Put target on top -> draw on top of others 35 if (dragTarget instanceof MTComponent){ 36 MTComponent baseComp = (MTComponent)dragTarget; 37 38 baseComp.sendToFront(); 39 40 /* 41 //End all animations of the target 42 Animation[] animations = AnimationManager.getInstance().getAnimationsForTarget(dragTarget); 43 for (int i = 0; i < animations.length; i++) { 44 Animation animation = animations[i]; 45 animation.stop(); 46 } 47 */ 48 } 49 dragTarget.translateGlobal(dragEvent.getTranslationVect()); 50 break; 51 case MTGestureEvent.GESTURE_UPDATED: 52 if(!isGestureAborted()) 53 { 54 dragTarget.translateGlobal(dragEvent.getTranslationVect()); 55 } 56 break; 57 case MTGestureEvent.GESTURE_ENDED: 58 break; 59 default: 60 break; 61 } 62 } 63 return false; 64 } 65 66 public void setGestureAborted(boolean gestureAborted) { 67 this.gestureAborted = gestureAborted; 68 } 69 70 public boolean isGestureAborted() { 71 return gestureAborted; 72 } 73} 74