PageRenderTime 17ms CodeModel.GetById 7ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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 ***********************************************************************/
 18package org.mt4j.input.gestureAction;
 19
 20import org.mt4j.components.MTComponent;
 21import org.mt4j.components.interfaces.IMTComponent3D;
 22import org.mt4j.input.inputProcessors.IGestureEventListener;
 23import org.mt4j.input.inputProcessors.MTGestureEvent;
 24import org.mt4j.input.inputProcessors.componentProcessors.dragProcessor.DragProcessor;
 25import org.mt4j.input.inputProcessors.componentProcessors.rotateProcessor.RotateEvent;
 26
 27
 28/**
 29 * The Class DefaultRotateAction.
 30 * 
 31 * @author Christopher Ruff
 32 */
 33public class DefaultRotateAction implements IGestureEventListener,ICollisionAction {
 34	
 35	/** The target. */
 36	private IMTComponent3D target;
 37	
 38	/** The use custom target. */
 39	private boolean useCustomTarget;
 40	
 41	/** The last event. */
 42	private MTGestureEvent lastEvent;
 43	
 44	/** The gesture aborted. */
 45	private boolean gestureAborted = false;
 46	
 47	/**
 48	 * Instantiates a new default rotate action.
 49	 */
 50	public DefaultRotateAction(){
 51		this.useCustomTarget = false;
 52	}
 53	
 54	/**
 55	 * Instantiates a new default rotate action.
 56	 * 
 57	 * @param customTarget the custom target
 58	 */
 59	public DefaultRotateAction(IMTComponent3D customTarget){
 60		this.target = customTarget;
 61		this.useCustomTarget = true;
 62	}
 63
 64	/* (non-Javadoc)
 65	 * @see org.mt4j.input.inputProcessors.IGestureEventListener#processGestureEvent(org.mt4j.input.inputProcessors.MTGestureEvent)
 66	 */
 67	public boolean processGestureEvent(MTGestureEvent g) {
 68		if (g instanceof RotateEvent){
 69			RotateEvent rotateEvent = (RotateEvent)g;
 70			lastEvent = rotateEvent;
 71			
 72			if (!useCustomTarget)
 73				target = rotateEvent.getTarget(); 
 74			
 75			switch (rotateEvent.getId()) {
 76			case MTGestureEvent.GESTURE_STARTED:
 77			case MTGestureEvent.GESTURE_RESUMED:
 78				if (target instanceof MTComponent){
 79					((MTComponent)target).sendToFront();
 80					/*
 81					Animation[] animations = AnimationManager.getInstance().getAnimationsForTarget(target);
 82					for (int i = 0; i < animations.length; i++) {
 83						Animation animation = animations[i];
 84						animation.stop();
 85					}
 86					*/
 87				}
 88				break;
 89			case MTGestureEvent.GESTURE_UPDATED:
 90				if(!gestureAborted())
 91				{
 92					target.rotateZGlobal(rotateEvent.getRotationPoint(), rotateEvent.getRotationDegrees());
 93					if (target.isGestureAllowed(DragProcessor.class))
 94						target.translateGlobal(rotateEvent.getTranslationVector());
 95				}
 96				break;
 97			case MTGestureEvent.GESTURE_CANCELED:
 98			case MTGestureEvent.GESTURE_ENDED:
 99				break;
100			default:
101				break;
102			}
103		}
104		return false;
105	}
106
107	/* (non-Javadoc)
108	 * @see org.mt4j.input.inputProcessors.ICollisionAction#gestureAborted()
109	 */
110	public boolean gestureAborted() {
111		return this.gestureAborted;
112	}
113
114	/* (non-Javadoc)
115	 * @see org.mt4j.input.inputProcessors.ICollisionAction#getLastEvent()
116	 */
117	public MTGestureEvent getLastEvent() {
118		return this.lastEvent;
119	}
120
121	/* (non-Javadoc)
122	 * @see org.mt4j.input.inputProcessors.ICollisionAction#setGestureAborted(boolean)
123	 */
124	public void setGestureAborted(boolean aborted) {
125		this.gestureAborted = aborted;
126	}
127}