/extensions/org/mt4jx/input/gestureAction/CollisionDragAction.java

http://mt4j.googlecode.com/ · Java · 74 lines · 51 code · 14 blank · 9 comment · 5 complexity · bf08b4dd48a60abc783717231f90ec85 MD5 · raw file

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