/* Author: Jeff Dalton <J.Dalton@ed.ac.uk>
 * Updated: Tue Jul 17 14:50:43 2001 by Jeff Dalton
 * Copyright: (c) 2001, AIAI, University of Edinburgh
 */

package ix.itest;

import javax.swing.*;

import java.awt.event.*;

import ix.util.*;

/**
 * The main frame of the I-TEST user interface.
 */
class ItestFrame extends JFrame implements ActionListener {

    JMenu testMenu = new JMenu("Test", true); // tear-off "Test" menu

    /**
     * Creates the frame and adds its menu bar.
     */
    ItestFrame(String title) {
	super(title);
	setJMenuBar(makeMenuBar());
    }

    /**
     * Adds a test by adding a menu item to the "Test" menu.
     */
    void addTest(String text, ActionListener listener) {
	JMenuItem item = new JMenuItem(text);
	item.addActionListener(listener);
	testMenu.add(item);
    }


    /**
     * Creates the menu bar
     */
    protected JMenuBar makeMenuBar() {
	JMenuBar bar = new JMenuBar();

	JMenu fileMenu = new JMenu("File");
	bar.add(fileMenu);
	fileMenu.add(makeMenuItem("Exit"));

	bar.add(Box.createHorizontalGlue()); // let later items move right

	bar.add(testMenu);

	return bar;
    }

    // /\/: Must find a better way to do this rather than have
    // this method everywhere.
    protected JMenuItem makeMenuItem(String text) {
	JMenuItem item = new JMenuItem(text);
	item.addActionListener(this);
	return item;
    }


    /**
     * Action interpreter
     */
    public void actionPerformed(ActionEvent e) {
	String command = e.getActionCommand();
	Debug.noteln("I-TEST action:", command);
	if (command.equals("Exit")) {
	    System.exit(0);
	}
	else
	    Debug.noteln("Nothing to do for", command);
    }

}

