PageRenderTime 28ms CodeModel.GetById 20ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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