PageRenderTime 42ms CodeModel.GetById 28ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/mt4j/input/inputData/AbstractCursorInputEvt.java

http://mt4j.googlecode.com/
Java | 232 lines | 74 code | 54 blank | 104 comment | 2 complexity | 0289f5825ca63ec267aff255d2df32d5 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.inputData;
 19
 20import org.mt4j.components.interfaces.IMTComponent3D;
 21import org.mt4j.input.inputSources.AbstractInputSource;
 22import org.mt4j.util.math.Vector3D;
 23
 24
 25/**
 26 * This event class is used for
 27 * input events that have position data associated with them. This applies
 28 * for mouse input, finger or fiducial input for example. Also associated
 29 * with this event is a InputMotion object, which contains information about the
 30 * input over time and is a container for all input events during this time.
 31 * 
 32 * @author Christopher Ruff
 33 */
 34public abstract class AbstractCursorInputEvt extends MTInputEvent {
 35	
 36//	public enum InputState{
 37//		INPUT_DETECTED,
 38//		INPUT_UPDATED,
 39//		INPUT_ENDED
 40//	}
 41	
 42	/** The Constant INPUT_DETECTED. 
 43	 * @deprecated use INPUT_STARTED instead 
 44	 * */
 45	public static final int INPUT_DETECTED = 0;
 46	
 47	public static final int INPUT_STARTED = 0;
 48	
 49	public static final int INPUT_UPDATED = 1;
 50	
 51	public static final int INPUT_ENDED = 2;
 52
 53	/** The position x. */
 54	private float positionX;
 55	
 56	/** The position y. */
 57	private float positionY;
 58	
 59	/** The id. */
 60	private int id;
 61	
 62	/** The associated cursor. */
 63	private InputCursor associatedCursor;
 64	
 65	/**
 66	 * Instantiates a new touch event.
 67	 * 
 68	 * @param source the source
 69	 * @param positionX the position x
 70	 * @param positionY the position y
 71	 * @param id the id
 72	 * @param c the m
 73	 */
 74	public AbstractCursorInputEvt(AbstractInputSource source, float positionX, float positionY, int id, InputCursor c) {
 75		super(source); 
 76		this.id = id;
 77		
 78		this.positionX = positionX;
 79		this.positionY = positionY;
 80		
 81		this.associatedCursor = c;
 82	}
 83	
 84	/**
 85	 * Instantiates a new touch event.
 86	 * 
 87	 * @param source the source
 88	 * @param positionX the position x
 89	 * @param positionY the position y
 90	 * @param id the id
 91	 * @param m the m
 92	 * @param target the target
 93	 */
 94	public AbstractCursorInputEvt(AbstractInputSource source, IMTComponent3D target, float positionX, float positionY, int id, InputCursor m) {
 95		super(source, target); 
 96		this.id = id;
 97		
 98		this.positionX = positionX;
 99		this.positionY = positionY;
100		
101		this.associatedCursor = m;
102	}
103	
104	
105	public void setId(int id){
106		this.id = id;
107	}
108	
109
110	
111	/**
112	 * Gets the cursor.
113	 * 
114	 * @return the cursor
115	 */
116	public InputCursor getCursor() {
117		return this.associatedCursor;
118	}
119
120
121	public void setCursor(InputCursor associatedcursor) {
122		this.associatedCursor = associatedcursor;
123	}
124		
125
126	/**
127	 * This method should be called before firing this event to the global input processors.
128	 * Here, the event is added to its cursor.
129	 */
130	@Override
131	public void onFired() {
132		super.onFired();
133		if (this.getCursor() != null){
134			this.getCursor().addEvent(this);
135		}else{
136//			System.out.println("couldnt add event to cursor - cursor null");
137		}
138	}
139
140	
141	/**
142	 * Gets the position x.
143	 * 
144	 * @return the position x
145	 * @deprecated use getScreenX()
146	 */
147	public float getPosX() {
148		return positionX;
149	}
150
151	
152	/**
153	 * Gets the position y.
154	 * 
155	 * @return the position y
156	 * @deprecated use getScreenY()
157	 */
158	public float getPosY() {
159		return positionY;
160	}
161	
162	public float getX(){
163		return this.positionX;
164	}
165	
166	public float getY(){
167		return this.positionY;
168	}
169	
170	
171	/**
172	 * Gets the position.
173	 *
174	 * @return the position
175	 */
176	public Vector3D getPosition(){
177		return new Vector3D(positionX, positionY, 0);
178	}
179	
180	
181	public void setScreenX(float positionX) {
182		this.positionX = positionX;
183	}
184
185	public void setScreenY(float positionY) {
186		this.positionY = positionY;
187	}
188
189	/**
190	 * Gets the id.
191	 * 
192	 * @return the id
193	 */
194	public int getId() {
195		return id;
196	}
197
198
199	/* (non-Javadoc)
200	 * @see java.lang.Object#toString()
201	 */
202	public String toString(){
203		return super.toString() + "; " + " PosX: " + positionX + " PosY: " + positionY + " InputSource: " + this.getSource(); 
204	}
205	
206	
207
208	@Override
209	abstract public Object clone() throws CloneNotSupportedException;
210	
211	
212	
213	/*
214	abstract public Inputcursor<? extends MTConcretePositionEvt> getcursor();
215
216	
217	abstract public float getPositionX();
218
219	abstract public float getPositionY();
220	
221	abstract public boolean isAddedTocursor();
222	
223	abstract public void setAddedTocursor(boolean addedTocursor);
224	*/
225	
226	
227	
228	
229
230    
231	
232}