import java.awt.event.*;
import javax.swing.*;

/**
 * A "copy action" for an Editor.
 *
 * @author  Prof. David Bernstein, James Madison University
 */
public class CopyAction extends EditorAction
{
  private static final long serialVersionUID = 1L;

  /**
   * Explicit Value Constructor
   *
   * @param editor    The editor to copy from
   */
  public CopyAction(TextEditor editor)
  {
    super(editor, "Copy", new ImageIcon("copy.gif"));
    putValue(Action.SHORT_DESCRIPTION, "Copy the selected text");
  }

  /**
   * Handle actionPerformed messages.
   *
   * @param ae    The event that caused the message to be generated
   */
  public void actionPerformed(ActionEvent ae)
  {
    getEditor().copy();
  }

  /**
   * Set the enabled state of this Action based on whether
   * text is selected and whether the "clipboard" is populated.
   *
   * @param textIsSelected     true if there is text selected
   * @param textIsOnClipboard  true if the "clipboard" is populated
   */
  protected void setEnabled(boolean textIsSelected, boolean textIsOnClipboard)
  {
    setEnabled(textIsSelected);
  }
}
