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

http://mt4j.googlecode.com/ · Java · 78 lines · 32 code · 11 blank · 35 comment · 5 complexity · ba335993a5a38482af020c695a0bbc43 MD5 · raw file

  1. /***********************************************************************
  2. * mt4j Copyright (c) 2008 - 2009 Christopher 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.arcballProcessor.ArcBallGestureEvent;
  24. /**
  25. * The Class DefaultArcballAction.
  26. *
  27. * @author Christopher Ruff
  28. */
  29. public class DefaultArcballAction implements IGestureEventListener {
  30. /** The target. */
  31. private IMTComponent3D target;
  32. /** The use custom target. */
  33. private boolean useCustomTarget;
  34. /**
  35. * Instantiates a new default arcball action.
  36. */
  37. public DefaultArcballAction(){
  38. this.useCustomTarget = false;
  39. }
  40. /**
  41. * Instantiates a new default arcball action.
  42. *
  43. * @param customTarget the target
  44. */
  45. public DefaultArcballAction(IMTComponent3D customTarget){
  46. this.target = customTarget;
  47. this.useCustomTarget = true;
  48. }
  49. /* (non-Javadoc)
  50. * @see org.mt4j.input.inputProcessors.IGestureEventListener#processGestureEvent(org.mt4j.input.inputProcessors.MTGestureEvent)
  51. */
  52. public boolean processGestureEvent(MTGestureEvent g) {
  53. ArcBallGestureEvent aEvt = (ArcBallGestureEvent)g;
  54. if (!useCustomTarget)
  55. target = aEvt.getTarget();
  56. if (target instanceof MTComponent){
  57. ((MTComponent)target).sendToFront();
  58. }
  59. if (aEvt.getId() == ArcBallGestureEvent.GESTURE_UPDATED){
  60. if (target instanceof MTComponent){
  61. MTComponent comp = (MTComponent)target;
  62. comp.transform(aEvt.getTransformationMatrix());
  63. }
  64. }
  65. return false;
  66. }
  67. }