package gradertool.view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

import gradertool.gradebook.NewClassDisplay;
import gradertool.gradebook.NewClassUI;

/****
 *
 * Class EditMenu is the "Edit" pulldown menu in the GraderToolUI prototype.
 * Anonymous instances of JMenuItem are defined for each item in the menu.
 *                                                                         <p>
 * This class serves as a good example for how items are added to a menu, and
 * how an item's "action listener" is given a simple prototype implementation.
 *                                                                         <p>
 * As explained in the Java Swing Tutorial, an action listener is implemented
 * in a method named "actionPerformed".  This method is specialized for all
 * clickable GUI components, such as menu items and buttons.  In a complete
 * implementation, action listeners perform actual computations, by calling
 * methods in companion computational classes.
 *                                                                         <p>
 * In a GUI prototype, action listeners don't do any real work.  Instead, they
 * do one of two things:
 *                                                                     <ol><li>
 * print a simple message to stdout, to indicate that a menu item or button has
 * been clicked on
 *                                                                         <li>
 * bring up another prototype GUI, such as a dialog or display window
 *                                                                        </ol>
 *                                                                         <p>
 * In the full implementation next quarter in 309, these simple prototype
 * actions will be replaced by calls to methods that do real work.
 *
 */
public class EditMenu extends JMenu {

    /**
     * Construct this by inserting each of its nine menu items into the
     * pulldown menu.  The items are New, Open, Close, Close All, Save, Save
     * As, Save All, Print, and Exit.  JSeparators are placed after the 'Close
     * All', 'Save All', and 'Print' items.
     */
    public EditMenu() {

        super("Edit");

        /*
         * Add each of the items to the menu, with separators in the
         * appropriate places (per the requirements).
         */
        addUndoItem();
        addRedoItem();
        addCutItem();
        addCopyItem();
        addPasteItem();
        addDeleteItem();
        addSelectAllItem();
        addFindItem();
    }

    /**
     * Add the 'Edit' menu item.  This and all other file menu items are created
     * using the following pattern:
     *                                                                    <pre>
     *     JMenu.add(new JMenuItem("<em>Item name</em>")).addActionListener(
     *         new ActionListener() {
     *             public void actionPerformed(ActionEvent e) {
     *                 <em>print a message to stdout, or bring up another GUI</em>
     *             }
     *         }
     *     );
     *                                                                   </pre>
     */
    protected void addUndoItem() {

        /*
         * Use the standard menu item pattern for the item.
         */
        add(new JMenuItem("Undo ...")).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Edit->Undo selected.");
                }
            }
        );
    }

    /**
     * Add the 'Redo ...' menu item.  It just prints a message.
     */
    protected void addRedoItem() {

        add(new JMenuItem("Redo ...")).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Edit->Redo selected.");
                }
            }
        );
    }

    /**
     * Add the 'Cut ...' menu item.  It just prints a message.
     */
    protected void addCutItem() {
        add(new JMenuItem("Cut")).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Edit->Cut selected.");
                }
            }
        );
    }

    /**
     * Add the 'Copy ...' menu item.  It just prints a message.
     */
    protected void addCopyItem() {
        add(new JMenuItem("Copy")).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Edit->Copy selected.");
                }
            }
        );
    }

    /**
     * Add the 'Paste ...' menu item.  It just prints a message.
     */
    protected void addPasteItem() {
        add(new JMenuItem("Paste")).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Edit->Paste selected.");
                }
            }
        );
    }

    /**
     * Add the 'Delete ...' menu item.  It just prints a message.
     */
    protected void addDeleteItem() {
        add(new JMenuItem("Delete")).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Edit->Delete selected.");
                }
            }
        );
    }

    /**
     * Add the 'Select All ...' menu item.  It just prints a message.
     */
    protected void addSelectAllItem() {
        add(new JMenuItem("Select All")).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Edit->Select All selected.");
                }
            }
        );
    }

    /**
     * Add the 'Find ...' menu item.  It just prints a message.
     */
    protected void addFindItem() {
        add(new JMenuItem("Find")).addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Edit->Find selected.");
                }
            }
        );
    }
}