PageRenderTime 29ms CodeModel.GetById 14ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mt4j.googlecode.com/
Java | 137 lines | 62 code | 21 blank | 54 comment | 6 complexity | 9e2275aa0954ce33aa97c2b3dff51d31 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.DragEvent;
 25
 26
 27
 28/**
 29 * The Class DefaultDragAction.
 30 * @author Christopher Ruff
 31 */
 32public class DefaultDragAction implements IGestureEventListener,ICollisionAction  {
 33	
 34	/** The drag target. */
 35	private IMTComponent3D dragTarget;
 36	
 37	/** The use custom target. */
 38	private boolean useCustomTarget;
 39	
 40	/** The gesture aborted. */
 41	private boolean gestureAborted = false;
 42	
 43	/** The last event. */
 44	private MTGestureEvent lastEvent;
 45	
 46	/**
 47	 * Instantiates a new default drag action.
 48	 */
 49	public DefaultDragAction(){
 50		this.useCustomTarget = false;
 51	}
 52	
 53	/**
 54	 * Instantiates a new default drag action.
 55	 *
 56	 * @param dragTarget the drag target
 57	 */
 58	public DefaultDragAction(IMTComponent3D dragTarget){
 59		this.dragTarget = dragTarget;
 60		this.useCustomTarget = true;
 61	}
 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 DragEvent){
 69			DragEvent dragEvent = (DragEvent)g;
 70			lastEvent = dragEvent;
 71			
 72			if (!useCustomTarget)
 73				dragTarget = dragEvent.getTarget(); 
 74			
 75			switch (dragEvent.getId()) {
 76			case MTGestureEvent.GESTURE_STARTED:
 77			case MTGestureEvent.GESTURE_RESUMED:
 78				//Put target on top -> draw on top of others
 79				if (dragTarget instanceof MTComponent){
 80					MTComponent baseComp = (MTComponent)dragTarget;
 81					
 82					baseComp.sendToFront();
 83					
 84					/*
 85					//End all animations of the target
 86					Animation[] animations = AnimationManager.getInstance().getAnimationsForTarget(dragTarget);
 87					for (int i = 0; i < animations.length; i++) {
 88						Animation animation = animations[i];
 89						animation.stop();
 90					}
 91					*/
 92				}
 93				if(!gestureAborted)
 94				{ 	
 95					dragTarget.translateGlobal(dragEvent.getTranslationVect());
 96				}
 97				break;
 98			case MTGestureEvent.GESTURE_UPDATED:
 99				if(!gestureAborted)
100				{ 	
101					dragTarget.translateGlobal(dragEvent.getTranslationVect());
102				}
103				break;
104			case MTGestureEvent.GESTURE_CANCELED:
105				break;
106			case MTGestureEvent.GESTURE_ENDED:
107				break;
108			default:
109				break;
110			}
111		}
112		return false;
113	}
114
115
116	/* (non-Javadoc)
117	 * @see org.mt4j.input.inputProcessors.ICollisionAction#gestureAborted()
118	 */
119	public boolean gestureAborted() {
120		return this.gestureAborted;
121	}
122
123	/* (non-Javadoc)
124	 * @see org.mt4j.input.inputProcessors.ICollisionAction#getLastEvent()
125	 */
126	public MTGestureEvent getLastEvent() {
127		return this.lastEvent;
128	}
129
130	/* (non-Javadoc)
131	 * @see org.mt4j.input.inputProcessors.ICollisionAction#setGestureAborted(boolean)
132	 */
133	public void setGestureAborted(boolean aborted) {
134		this.gestureAborted = aborted;
135	}
136
137}