package wedgi;

import java.awt.*;
import java.awt.event.*;
import java.io.*;

 /**
   * read for the Wedgie
   *
   * @author Owen Astrachan
   * @see ActionListener
   */
class ReadFileCommand implements ActionListener
{
    /**
      * construct a ReadFileCommand
      *
      * @param con the controller that actually performs the read
      * @param base AWT component used for displaying a wait cursor
      */
    public ReadFileCommand(Controller con,Component widget)
    {
        myController = con;
	myWidget = widget;
    }

    /**
      * performs the read action, sets a wait cursor,
      * asks the controller to read, and the resets the cursor
      */
    public void actionPerformed(ActionEvent ev)
    {
	String filename = getFilename();
	if (filename == null) return;

	myWidget.setCursor(
	    Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
	myController.load(filename);
	myWidget.setCursor(
	    Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));	
    }

    private String getFilename()
    {
	FileDialog fd = new
	    FileDialog(new Frame(), "Open File", FileDialog.LOAD);
	fd.show();

	if (fd.getFile() == null) return null;
	else  return fd.getDirectory() + fd.getFile();
    }

    private Controller myController;
    private Component  myWidget;
}
