import java.awt.*;
import javax.swing.*;
import javax.swing.undo.*;

/**
 * An example that demonstrates undo/redo.
 *
 * @version 1.0
 * @author  Prof. David Bernstein, James Madison University
 */
public class Driver implements Runnable
{
    private UndoableEditSupport support;
    private YardMarker          ym;
    
    /**
     * The entry point of the application.
     *
     * @param args  The command line arguments (ignored)
     */
    public static void main(String[] args) throws Exception
    {
        Driver driver = new Driver();
        SwingUtilities.invokeAndWait(driver);


	// Make a change
	YardMarkerEdit edit = new YardMarkerEdit(driver.ym, 1, 10, "Own", 35);
	driver.support.postEdit(edit);


	// Sleep to give time to see the scoreboard
	// before the change
	try 
        {
	    Thread.sleep(5000);
	} 
        catch (InterruptedException ie) 
        {

	}

	// Make a change
	edit = new YardMarkerEdit(driver.ym, 2, 8, "Own", 37);
	driver.support.postEdit(edit);
    }
    
    /**
     * The code to run in the event dispatch thread.
     */
    public void run()
    {
	// Layout the frame
	JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	f.setSize(400,400);
	Container contentPane = f.getContentPane();

	contentPane.setLayout(new BorderLayout());
	contentPane.add(new JLabel("Bernstein Stadium"), BorderLayout.NORTH);

	ym = new YardMarker();
	contentPane.add(ym, BorderLayout.SOUTH);

	contentPane.add(new JLabel("Your ad here!"), BorderLayout.CENTER);

	JMenuBar menuBar  = new JMenuBar();
	JMenu editMenu = new JMenu("Edit");
	UndoRedoAction urAction = new UndoRedoAction();
	editMenu.add(urAction);
	menuBar.add(editMenu);

	f.setJMenuBar(menuBar);

	// Add undo/redo support
	support = new UndoableEditSupport();
	support.addUndoableEditListener(urAction);

	f.setVisible(true);
    }
}
