//Copyright (c) 1997 The Open Group
//
//Permission to use, copy, modify, and distribute this software and its documentation for
//any purpose and without fee is hereby granted, provided that the above copyright notice
//appears in all copies and that both the copyright notice and this permission notice
//appear in supporting documentation, and that the name of ("TOG") or The Open Group not
//be used in advertising or publicity pertaining to distribution of the software without
//specific, written prior permission.
//
//THE OPEN GROUP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
//IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
//SHALL TOG BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
//WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
//NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
//PERFORMANCE OF THIS SOFTWARE. 

package com.jxml.quick.editors;

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

/** 
 * URL Property Editor
 * <p>Quick 1.1
 */
public class URLEditor extends PropertyEditorSupport {

    public String getJavaInitializationString() 
    {
	return "\"" + getValue() + "\"";
    }

    public void setAsText(String text) throws java.lang.IllegalArgumentException 
    {
        try
        {
	    URL url=new URL(text);
	    String host=url.getHost();
	    if (host.equals("self"))
	    {
		url=new URL(
			url.getProtocol(),
			InetAddress.getLocalHost().getHostName(),
			url.getPort(),
			url.getFile());
	    }
            setValue(url);
        } catch (Exception e)
        {
            throw new IllegalArgumentException(e.getMessage());
        }
    }

}
