package wedgi;

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

/**
  * get the name of a URL from the user
  *
  */
public class URLDialog extends Dialog
{
    public URLDialog (Frame f)
    {
	super(f, "URL loader",true);   // make the dialog modal
	setSize(200,100);
	myString = null;
	myText = new TextField(100);
	add(BorderLayout.NORTH,myText);
	Panel buttonPanel = new Panel();
	Button ok = new Button("OK");
	Button cancel = new Button("cancel");
	buttonPanel.add(ok);
	buttonPanel.add(cancel);
	add(BorderLayout.SOUTH,buttonPanel);
	
	ActionListener okAction = new ProcessOk();
	ok.addActionListener(okAction);
	myText.addActionListener(okAction);
	cancel.addActionListener(
	    new ActionListener()
	    {
		public void actionPerformed(ActionEvent e)
		{
		    myString = null;
		    URLDialog.this.setVisible(false);
		}
	    });
    }

    public String getURL()
    {
	return myString;
    }

    private String myString;
    private TextField myText;

    class ProcessOk implements ActionListener
    {
	public void actionPerformed(ActionEvent e)
	{
	    myString = myText.getText();
	    URLDialog.this.setVisible(false);
	}
    }
}
