package extensions.awt;
import java.awt.*;

/**
 * Delegate TextField action event.
 *
 * @see java.awt.TextField
 * @see extensions.awt.ActionProtocol
 * @version 1.0.2
 * @author John Webster Small
 */
public class TextFieldAction
  extends TextField
  implements ActionProtocol
{
  private ActionProtocol ap;

  /** Construct a TextFieldAction (i.e. a TextField) with
    * the action to be performed when user presses <ENTER>
    * in this TextField. The action is performed automatically
    * only if this TextFieldAction appears within an
    * FrameExtended or DialogExtended window.
    * @param ap action to be performed, i.e. run()
    * @see extensions.awt.FrameExtended
    * @see extensions.awt.DialogExtended
    * @see extensions.awt.ActionProtocol
    * @see extensions.awt.MenuItemAction
    */
  public TextFieldAction(ActionProtocol ap)
  {
    super();
    this.ap = ap;
  }

  /** Construct a TextFieldAction (i.e. a TextField) with
    * the action to be performed when user presses <ENTER>
    * in this TextField. The action is performed automatically
    * only if this TextFieldAction appears within an
    * FrameExtended or DialogExtended window.
    * @param cols number of columns of visible text
    * @param ap action to be performed, i.e. run()
    */
  public TextFieldAction(int cols, ActionProtocol ap)
  {
    super(cols);
    this.ap = ap;
  }

  /** Construct a TextFieldAction (i.e. a TextField) with
    * the action to be performed when user presses <ENTER>
    * in this TextField. The action is performed automatically
    * only if this TextFieldAction appears within an
    * FrameExtended or DialogExtended window.
    * @param text contexts
    * @param ap action to be performed, i.e. run()
    */
  public TextFieldAction(String text, ActionProtocol ap)
  {
    super(text);
    this.ap = ap;
  }

  /** Construct a TextFieldAction (i.e. a TextField) with
    * the action to be performed when user presses <ENTER>
    * in this TextField. The action is performed automatically
    * only if this TextFieldAction appears within an
    * FrameExtended or DialogExtended window.
    * @param text contexts
    * @param cols number of columns of visible text
    * @param ap action to be performed, i.e. run()
    */
  public TextFieldAction(String text, int cols, ActionProtocol ap)
  {
    super(text,cols);
    this.ap = ap;
  }

  /** Forward the pressed <ENTER> action event on to
    * the action for further processing by the application
    * model rather than the GUI. This method is called
    * automatically by FrameExtended and DialogExtended.
    * @param forward the component forwarding action event
    * @param evt the event that caused the action
    * @param what the action
    * @see extensions.awt.ActionProtocol
    * @see extensions.awt.FrameExtended#handleEvent
    * @see extensions.awt.DialogExtended#handleEvent
    */
  public final void action(Component forward, Event evt, Object what)
  {
    if (ap != null)
      ap.action(forward,evt,what);
  }
}
