/**
 File:      WebKaiButton.java
 Author:    Angus McIntyre <angus@pobox.com>
 Date:      25.08.96
 Updated:   04.07.98
 
 Variant of KaiButton that takes a URL as an argument, and tells the parent
 browser to go to that URL when clicked.

    HISTORY
    -------
    
    11.06.99	Documented.
    04.07.98	Added test for non-null URL when updating status line.
    26.08.96    First release
    
    TO-DO
    -----
    
    Make cursors change on mouse entry/exit.
    
    LEGAL
    -----
    
    This software is free. It can be used and modified in any way you 
    choose, but it may not be sold, either separately or as part of a 
    collection without explicit prior permission from the author. The 
    author assumes no liability for any loss, damage or mental or 
    physical trauma you may incur through use of or inability to use 
    this software. This disclaimer must appear on any modified or 
    unmodified version of the software in which the name of the author
    also appears.
    
**/

/* ----------------------------------------------------------------------
 *                              IMPORTS
 * ---------------------------------------------------------------------- */

import java.applet.*;
import java.awt.*;
import java.util.*;
import java.net.*;

/**
 * A class of buttons that allow KaiButtons to be used on the Web. It stores
 * a URL and, when clicked, causes the containing browser to jump to that URL.
 */
 
public class WebKaiButton extends KaiButton {

    protected   URL         buttonURL;
    
    /**
     * Initializer; includes a URL argument to set up the URL for the button.
     */
     
    public  WebKaiButton(Image active,Image inactive,Image clicked,
                      int x, int y, int width, int height, URL url) {
        super(active,inactive,clicked,x,y,width,height);
        buttonURL = url;
    }

    /**
     * When the mouse enters the button, it should display the URL in the
     * browser's status bar (just like any other clickable object on the Web).
     */
     
    public  boolean mouseEnter(Event event, int x, int y) {
        super.mouseEnter(event,x,y);
        Container       container;
        AppletContext   context;
        
		//  Call the superclass method first, then retrieve the browser
		// object, and tell it to show the URL in its status line.
    
        container = getParent();
        context = ((Applet) container).getAppletContext();
        if (buttonURL != null)
        	context.showStatus(buttonURL.toString());
        return true;
    }
    
    /**
     * When the mouse goes up inside the button, jump to the relevant
     * URL. If there's no valid URL, print a helpful little error
     * message in the browser's status bar.
     */
       
    public  boolean mouseUp(Event event, int x, int y) {
        Container       container;
        AppletContext   context;
        
        super.mouseUp(event,x,y);
        container = getParent();
        context = ((Applet) container).getAppletContext();
        if (buttonURL != null)
            context.showDocument(buttonURL);
        else
            context.showStatus("No valid URL for this button - check 'url' parameter of applet.");
        return true;
    }
}

