package part1;

import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * An abstract class for the functionality shared amongst PlayerCommands.
 *
 *
 * @author $Author: cdent $
 *
 * @version $Revision: 1.2 $
 *
 */
public abstract class AbstractPlayerCommand implements PlayerCommand,
						       Cloneable,
						       ActionListener {

    private PlayerContext context;
    private boolean pressed = false;
    protected JButton button = new JButton();

    // subclasses must implement these methods
    public abstract void press();
    public abstract void init();

    public JButton getButton() {
	return button;
    }

    public void actionPerformed(ActionEvent e) {
	press();
    }
    
    protected void setText(String text) {
	button.setText(text);
    }

    public boolean isPressed() {
	return pressed;
    }

    public void falsify() {
	pressed = false;
    }
    
    public void truify() {
	pressed = true;
    }

    public void setContext(PlayerContext context) {
	this.context = context;
    }

    protected PlayerContext getContext() {
	return context;
    }

    public Object clone() {
	Object object = null;
	try {
	    object = super.clone();
	} catch (CloneNotSupportedException exception) {
	    System.err.println(" is not Cloneable");
	}
	return object;
    }

}
	
