/*
 * @(#)SaveOpenDemoFrame.java
 *
 * Copyright 2001 Thomas P. Hayes, All Rights Reserved.
 *
 * This software is the proprietary information of Thomas P. Hayes.
 * Use outside the CSPP 535 course taught by the author is subject
 * to license agreement.
 */

package saveopen.presentation;
import javax.swing.*;
import java.awt.event.*;

/**
 * Creates a frame and sets up a File menu with Save, Open, and Quit
 * methods.  Also provides a wrapper <code>addActionListener</code> method.
 */
public class SaveOpenDemoFrame extends JFrame {
    
    /** The menu item labelled "Save", used to serialize the
        target frame and write it to disk. */
    protected JMenuItem saveMenuItem;
    /** The menu item labelled "Open", used to read a frame 
        from a file and display it. */
    protected JMenuItem openMenuItem;
    /** The menu item labelled "Quit", used to make the program
        exit. */
    protected JMenuItem quitMenuItem;

    /**
     * Create a new frame, with a menu bar and panel taken
     * from within the apt.presentation package.  The window
     * is not automatically sized or displayed.
     */
    public SaveOpenDemoFrame() {
        JMenuBar mb = new JMenuBar();
        JMenu m = new JMenu("File");
        saveMenuItem = new JMenuItem("Save");
        saveMenuItem.setActionCommand("SODFSave");
        openMenuItem = new JMenuItem("Open");
        openMenuItem.setActionCommand("SODFOpen");
        quitMenuItem = new JMenuItem("Quit");
        quitMenuItem.setActionCommand("SODFQuit");
        m.add(openMenuItem);
        m.add(saveMenuItem);
        m.add(quitMenuItem);
        mb.add(m);
        setJMenuBar(mb);
    }

    /**
     * Wrapper method.  Registers an actionListener with the
     * 3 File menu items.
     */
    public void addActionListener(ActionListener listener) {
        saveMenuItem.addActionListener(listener);
        openMenuItem.addActionListener(listener);
        quitMenuItem.addActionListener(listener);
    }

    /**
     * For testing purposes only.  Creates an instance of the class
     * and quits when the window is closed.
     */
    public static void main(String[] args) {
        System.out.println("Test code for class apt.presentation.SaveOpenDemoFrame running...");
        JFrame f = new SaveOpenDemoFrame();
        f.pack();
        f.setVisible(true);
        f.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }});
    }
    
}





