package programming101.calculator;

import java.awt.Button;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


/**
	* Basic calculator button class.
  * This class is abstract and cannot be instantiated.  It must be subclassed 
  * to implement the following abstract method(s):
  * <UL>
  * <LI><CODE>actionPerformed</CODE> - called when the appropriate
  * button is pushed
  * </UL>
	*
	* @author © 1998 Peter T. Sander
	* @version 1.2 (7/04/98)
	* @since 13/03/98
	*/

public abstract class CalculatorButton extends Button
		implements ActionListener {
	// visible attributes
	private int width = 24;
	private int height = 24;
	private Calculator calculator;
	// other variables
	// protected access since they're meant to be inherited
	protected double cumulator;
	protected String entryField;
	protected CalculatorButton lastButton;
	
	/**
		* Constructor.
		*
		* @param tag button label
		*/
	public CalculatorButton(String tag, Calculator calculator) {
		super(tag);
		this.calculator = calculator;
		getCalculatorData();
		addActionListener(this);
	}
	
	/**
		* Getter method for calculator attributes.  Stores results in appropriate
		* button object variables.
		*/
	protected final void getCalculatorData() {
		cumulator = calculator.getCumulator();
		entryField = calculator.getEntryField();
		lastButton = calculator.getLastButton();
	}
	
	/**
		* Setter method for calculator attributes.  Stores results in appropriate
		* calculator object variables.
		*
		* @param cumulator cumulative value for the calculator
		* @param entryField last value entered, also value to display
		* @param lastButton last button pushed
		*/
	protected final void setCalculatorData(double cumulator, String entryField,
									CalculatorButton lastButton) {
		calculator.setCumulator(cumulator);
		calculator.setEntryField(entryField);
		calculator.setLastButton(lastButton);
	}
	
	/**
		* Setter method for button size attributes.
		*
		* @param width width of button
		* @param height height of buttn
		*/
	public final void setSize(int width, int height) {
		this.width = width;
		this.height = height;
		super.setSize(width, height);
	}

	/**
		* Getter method for button size attributes.
		*
		* @return dimensions of the button
		*/
	public final Dimension getPreferredSize() {
		return new Dimension(width, height);
	}
	
	/**
		* Called when the appropriate button is pushed.
		*
		* @param ae info about button which perpetrated the event 
		*/
	public abstract void actionPerformed(ActionEvent ae);
}
