PageRenderTime 45ms CodeModel.GetById 36ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mt4j.googlecode.com/
Java | 128 lines | 35 code | 21 blank | 72 comment | 2 complexity | 422d8d6901518a03de4c467a983a722c 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 java.util.Collection;
 21import java.util.HashMap;
 22import java.util.Map;
 23
 24
 25
 26/**
 27 * This class is basically a centralized wrapper for a HashMap acting as a store
 28 * for active inputs.
 29 * cursors are added when a new Touch is registered. cursors should be put in the map by
 30 * using their cursor-ID. When the cursor has ended they have to be removed again.
 31 * 
 32 * @author Christopher Ruff
 33 */
 34public class ActiveCursorPool {
 35	
 36	/** The cursor pool. */
 37	private static ActiveCursorPool cursorPool;
 38	
 39	/** The cursors map. */
 40	private Map<Long, InputCursor> cursorMap;
 41	
 42	/**
 43	 * Instantiates a new cursor pool.
 44	 */
 45	private ActiveCursorPool(){
 46		cursorMap = new HashMap<Long, InputCursor>();
 47//		cursorMap = new WeakHashMap<Long, InputCursor>();
 48	}
 49	
 50	/**
 51	 * Gets the single instance of cursorPool.
 52	 * 
 53	 * @return single instance of cursorPool
 54	 */
 55	public static ActiveCursorPool getInstance(){
 56		if (cursorPool == null){
 57			cursorPool = new ActiveCursorPool();
 58			return cursorPool;
 59		}else{
 60			return cursorPool;
 61		}
 62	}
 63
 64	
 65	/**
 66	 * Put cursor. The id is assumed to be the cursors ID.
 67	 * 
 68	 * @param cursorID the cursor id
 69	 * @param m the m
 70	 */ //TODO automate because id = cursorID?
 71	public void putActiveCursor(long cursorID, InputCursor m){
 72		cursorMap.put(cursorID, m);
 73	}
 74	
 75	
 76	/**
 77	 * Gets the cursor by id.
 78	 * 
 79	 * @param ID the iD
 80	 * 
 81	 * @return the cursor by id
 82	 */
 83	public InputCursor getActiveCursorByID(long ID){
 84		return cursorMap.get(ID);
 85	}
 86	
 87	public InputCursor[] getActiveCursors(){
 88		Collection<InputCursor> values = cursorMap.values();
 89		return values.toArray(new InputCursor[values.size()]);
 90		/*
 91		Set<Long> keys = cursorsMap.keySet();
 92		for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
 93			Long long1 = (Long) iterator.next();
 94			Inputcursor cursor = cursorsMap.get(long1);
 95			MTCursorInputEvt lastEvt = cursor.getLastEvent();
 96			MTCursorInputEvt copy = (MTCursorInputEvt) lastEvt.clone();
 97			copy.setId(MTCursorInputEvt.INPUT_ENDED);
 98			
 99		}
100		return null;
101		*/
102	}
103	
104	
105	/**
106	 * Removes the cursor.
107	 * 
108	 * @param ID the iD
109	 * @return the input cursor
110	 */
111	public InputCursor removeCursor(long ID){
112		return cursorMap.remove(ID);
113	}
114	
115	/**
116	 * Gets the active cursor count.
117	 * 
118	 * @return the active cursor count
119	 */
120	public long getActiveCursorCount(){
121		return cursorMap.size();
122	}
123	
124	
125	
126
127	
128}