import java.beans.*;
import java.net.*;


public class URLEditor extends PropertyEditorSupport {

  protected URL u;
  
  public Object getValue() {

    try {
      return new URL(u.toString());
    }
    catch (MalformedURLException e) {
      return null;
    }

  }

  public void setValue(Object o) {

    try {
      URL u = (URL) o;
      this.u = new URL(u.toString());
    }
    catch (MalformedURLException e) {

    }

  }

  public String getAsText() {

    return u.toString();
    
  }

  public void setAsText(String s) throws IllegalArgumentException {

    try {
      this.u = new URL(s);
      firePropertyChange();
    }
    catch (MalformedURLException e) {
      throw new IllegalArgumentException(s + " is not a valid URL");
    }

  }

}