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

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

    /**
      * 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;

	myComponent.setCursor(
	    Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
	
	myController.load(filename);

	myComponent.setCursor(
	    Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));	
    }

    private String getFilename()
    {
	String s = (String) JOptionPane.showInputDialog(myComponent,
           "Enter URL",
           "Wedgi/URL",
           JOptionPane.QUESTION_MESSAGE,
           null,null,null);

	return s;
    }

    private Controller myController;
    private Component  myComponent;
}
