//
// keycoderecorder.js
//
// Copyright 2008-2009 Palm, Inc. All rights reserved.
//
KeycodeRecorder = Class.create({
	initialize: function(keys) {
		// Obtain a copy of the interested keys.
		this.pool = new Hash();
	},
	
	watchForKeycode: function(code) {
		//Mojo.Log.info("Watching for key: " + code);
		if (!this.isARecordableKeycode(code)) {
			// Only create a new keycode entry if
			// one doesn't already exist and thus
			// avoid overwritting the original.
			this.pool.set(code, false);
		}
	},
	
	stopWatchingForKeycode: function(code) {
		this.pool.unset(code);
	},
	
	isARecordableKeycode: function(code) {
		var res = this.pool.get(code);
		return (res !== undefined);
	},
	
	addRecord: function(code) {
		if (this.isARecordableKeycode(code)) {
			this.pool.set(code, true);
		}
	},
	
	removeRecord: function(code) {
		if (this.isARecordableKeycode(code)) {
			this.pool.set(code, false);
		}
	},
	
	hasRecordOfKeycode: function(code) {
		
		return (this.pool.get(code) ? true : false);
	},
	
	clearAllRecords : function(code) {
		
		this.pool.each(function(pair){this.pool.set(pair.key, false);}.bind(this));		
	}
});
