// Copyright 1996, Marimba Inc. All Rights Reserved.


// @(#)URLButtonWidget.java, 1.12, 12/20/96





package marimba.gui;





import java.awt.*;





import marimba.persist.*;


import marimba.util.*;





/**


 * A simple url button widget.


 *


 * @author	Sami Shaio


 * @version 	1.12, 12/20/96


 */


public class URLButtonWidget extends CommandButtonWidget {


    final static String defaultURL = "http://www.marimba.com/";





    /**


     * The URL that this button points to.


     * @see #getURL


     * @see #setURL


     */


    public String  url = defaultURL;





    /**


     * Get the properties of this widget.


     */


    public void getProperties(PropertyList list) {


	super.getProperties(list);


	list.setString("url", url, defaultURL);


    }





    /**


     * Set the properties of this widget.


     */


    public void setProperties(PropertyList list) {


	super.setProperties(list);


	url = list.getString("url", defaultURL);


    }





    /**


     * Get the value of the URL.


     * @see #URL


     */


    public String getURL() {


	return url;


    }





    /**


     * Set the URL.


     * @see #URL


     */


    public void setURL(String url) {


	this.url = url;


    }





    /**


     * The button was pressed, an action event is posted with


     * as argument true or false, depending on whether the


     * showURL succeeded or failed.


     */


    public void action() {


	super.action();


	Presentation p = getPresentation();


	if (p == null || url == null || url.length() == 0 ||


			!Environment.showURL(p.getURL(url))) {


	    // FAILED


	    postEvent(new Event(this, Event.ACTION_EVENT, new Boolean(false)));


	} else {


	    // SUCCEEDED


	    postEvent(new Event(this, Event.ACTION_EVENT, new Boolean(true)));


	}


    }





    /**


     * Debugging.


     */


    public void paramString(StringBuffer buf) {


	super.paramString(buf);


	if (url != null) {


	    buf.append(",url=");


	    buf.append(url);


	}


    }


}


