import java.util.Hashtable;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;

/**
  Management for all of Mozart's actions.
  This class is a Hashtable that contains all of the
  application's actions. Included in this list will 
  be the actions for MozartDocuments (HTMLDocuments).
  The constants that this class define are there to make
  it easier to remember what the strings really are.
  <br><br><a href="../source/MozartActions.java">View Source File</a>
*/
public class MozartActions extends Hashtable {
  private Mozart mozart;

  /**
    Initializes the hashtable by creating new actions
    and <i>put</i>ing them into it. Also creates actions
    contained in the HTMLEditor and adds them also.
  */
  public MozartActions(Mozart mozart) {
    this.mozart = mozart;

    // Actions for the file menu
    put(FileMenu.New, new FileNewAction(mozart));
    put(FileMenu.Open, new FileOpenAction(mozart));
    put(FileMenu.OpenLocation, new OpenLocationAction(mozart));
    put(FileMenu.Close, new FileCloseAction(mozart));
    put(FileMenu.Quit, new QuitAction(mozart));

    Action action;

    // Actions for the edit menu
    action = new DefaultEditorKit.CutAction();
    action.putValue(Action.NAME, "Cut");
    action.putValue(Action.SMALL_ICON, new ImageIcon("images/cut.gif"));
    put(EditMenu.Cut, action);

    action = new DefaultEditorKit.CopyAction();
    action.putValue(Action.NAME, "Copy");
    action.putValue(Action.SMALL_ICON, new ImageIcon("images/copy.gif"));
    put(EditMenu.Copy, action);

    action = new DefaultEditorKit.PasteAction();
    action.putValue(Action.NAME, "Paste");
    action.putValue(Action.SMALL_ICON, new ImageIcon("images/paste.gif"));
    put(EditMenu.Paste, action);

    MozartUndoManager undoManager = mozart.getUndoManager();
    put(EditMenu.Undo, undoManager.getUndoAction());
    put(EditMenu.Redo, undoManager.getRedoAction());

    // Add Document actions
    action = new StyledEditorKit.BoldAction();
    action.putValue(Action.NAME, "Bold");
    put(FormatMenu.Bold, action);
    
    action = new StyledEditorKit.ItalicAction();
    action.putValue(Action.NAME, "Italic");
    put(FormatMenu.Italic, action);

    action = new StyledEditorKit.UnderlineAction();
    action.putValue(Action.NAME, "Underline");
    put(FormatMenu.Underline, action);
  }
  
  /**
    This method returns an action from the hashtable
    with a specific name.
  */
  public Action getAction(String name) {
    return (Action) get(name);
  }
}

