/src/org/mt4j/input/gestureAction/DefaultRotateAction.java

http://mt4j.googlecode.com/ · Java · 127 lines · 59 code · 15 blank · 53 comment · 6 complexity · d10c0f3eb32fb9cb83c3d1b04799589b MD5 · raw file

  1. /***********************************************************************
  2. * mt4j Copyright (c) 2008 - 2009, C.Ruff, Fraunhofer-Gesellschaft All rights reserved.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. ***********************************************************************/
  18. package org.mt4j.input.gestureAction;
  19. import org.mt4j.components.MTComponent;
  20. import org.mt4j.components.interfaces.IMTComponent3D;
  21. import org.mt4j.input.inputProcessors.IGestureEventListener;
  22. import org.mt4j.input.inputProcessors.MTGestureEvent;
  23. import org.mt4j.input.inputProcessors.componentProcessors.dragProcessor.DragProcessor;
  24. import org.mt4j.input.inputProcessors.componentProcessors.rotateProcessor.RotateEvent;
  25. /**
  26. * The Class DefaultRotateAction.
  27. *
  28. * @author Christopher Ruff
  29. */
  30. public class DefaultRotateAction implements IGestureEventListener,ICollisionAction {
  31. /** The target. */
  32. private IMTComponent3D target;
  33. /** The use custom target. */
  34. private boolean useCustomTarget;
  35. /** The last event. */
  36. private MTGestureEvent lastEvent;
  37. /** The gesture aborted. */
  38. private boolean gestureAborted = false;
  39. /**
  40. * Instantiates a new default rotate action.
  41. */
  42. public DefaultRotateAction(){
  43. this.useCustomTarget = false;
  44. }
  45. /**
  46. * Instantiates a new default rotate action.
  47. *
  48. * @param customTarget the custom target
  49. */
  50. public DefaultRotateAction(IMTComponent3D customTarget){
  51. this.target = customTarget;
  52. this.useCustomTarget = true;
  53. }
  54. /* (non-Javadoc)
  55. * @see org.mt4j.input.inputProcessors.IGestureEventListener#processGestureEvent(org.mt4j.input.inputProcessors.MTGestureEvent)
  56. */
  57. public boolean processGestureEvent(MTGestureEvent g) {
  58. if (g instanceof RotateEvent){
  59. RotateEvent rotateEvent = (RotateEvent)g;
  60. lastEvent = rotateEvent;
  61. if (!useCustomTarget)
  62. target = rotateEvent.getTarget();
  63. switch (rotateEvent.getId()) {
  64. case MTGestureEvent.GESTURE_STARTED:
  65. case MTGestureEvent.GESTURE_RESUMED:
  66. if (target instanceof MTComponent){
  67. ((MTComponent)target).sendToFront();
  68. /*
  69. Animation[] animations = AnimationManager.getInstance().getAnimationsForTarget(target);
  70. for (int i = 0; i < animations.length; i++) {
  71. Animation animation = animations[i];
  72. animation.stop();
  73. }
  74. */
  75. }
  76. break;
  77. case MTGestureEvent.GESTURE_UPDATED:
  78. if(!gestureAborted())
  79. {
  80. target.rotateZGlobal(rotateEvent.getRotationPoint(), rotateEvent.getRotationDegrees());
  81. if (target.isGestureAllowed(DragProcessor.class))
  82. target.translateGlobal(rotateEvent.getTranslationVector());
  83. }
  84. break;
  85. case MTGestureEvent.GESTURE_CANCELED:
  86. case MTGestureEvent.GESTURE_ENDED:
  87. break;
  88. default:
  89. break;
  90. }
  91. }
  92. return false;
  93. }
  94. /* (non-Javadoc)
  95. * @see org.mt4j.input.inputProcessors.ICollisionAction#gestureAborted()
  96. */
  97. public boolean gestureAborted() {
  98. return this.gestureAborted;
  99. }
  100. /* (non-Javadoc)
  101. * @see org.mt4j.input.inputProcessors.ICollisionAction#getLastEvent()
  102. */
  103. public MTGestureEvent getLastEvent() {
  104. return this.lastEvent;
  105. }
  106. /* (non-Javadoc)
  107. * @see org.mt4j.input.inputProcessors.ICollisionAction#setGestureAborted(boolean)
  108. */
  109. public void setGestureAborted(boolean aborted) {
  110. this.gestureAborted = aborted;
  111. }
  112. }