import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 * This is an action listener that will start a new thread instead
 * of blocking the EventQueue ("freezing" the GUI).
 * 
 * Use this wherever you have to poll the oswaldInterface
 * 
 * @author goskab
 *
 */
public abstract class ThreadedActionListener extends Thread implements ActionListener, Cloneable {
	ThreadedActionListener thread = null;
	/**
	 * Don't touch this method, it starts up the proper thread
	 */
	public void actionPerformed(ActionEvent arg0) {
		try {
			//check if our thread is dead, we only want one running at once
			if ((thread != null && !thread.isAlive()) || thread == null) {
				//clone the current object, and start that :)
				thread = (ThreadedActionListener)this.clone();
				thread.start();
			}
		}
		catch (Exception e) {
			System.out.println("Exception thrown while cloning. This shouldn't happen");
		}
	}
	
	/**
	 * Your normal "actionPerformed" code goes in this method
	 */
	public abstract void run();

}
