package ei.engine.ui;

import java.util.ArrayList;

import ei.engine.scene.Entity;


public abstract class UiComponent {
	/** The list of listeners for this component */
	private ArrayList<UiListener> listeners;
	/** The name of the component */
	private String name;
	
	public UiComponent(String name){
		this.name = name;
		listeners = new ArrayList<UiListener>();
	}
	
	/**
	 * Add a listener to this component
	 * 
	 * @param l The listener to add
	 */
	public void addListener(UiListener l) {
		listeners.add(l);
	}
	
	/**
	 * Remove a listener from this component
	 * 
	 * @param l The listener to remove
	 */
	public void removeListener(UiListener l) {
		listeners.remove(l);
	}
	
	/**
	 * Casts a event to all the listeners
	 *
	 */
	protected void castEvent(){
		for (int i=0;i<listeners.size();i++) {
			listeners.get(i).ActionEvent(this);
		}
	}
	
	public void mousePos(int x, int y){
	}
	
	public void mouseDown(int x, int y, int event){
	}
	
	public void keyDown(int event){
	}
	
	public String getName(){
		return name;
	}
	
	public abstract Entity getNode();
}
