/*
    URL-clickable horizontal scrolling text applet.

    Parameters (see also Scroller):
        URL             the URL to jump to when the applet is clicked
                            by a mouse
            def: none - if none supplied or invalid, it's just a scrolling
                text applet
        TARGET          for frames, etc.
            def: "_top"

    Copyright 1998 by E. A. Graham, Jr.
    Free to use or modify.
 */

import java.awt.*;
import java.applet.*;
import java.net.URL;
import java.net.MalformedURLException;

public class HrefScroller extends Scroller {
    String  urlName;
    String  urlTarget;
    URL     nextURL = null;

    public void init() {
        super.init();

        urlName = ReadText("URL");
        if (urlName != null) {
            int x = urlName.indexOf(',');
            if (x > 0) {
                urlTarget = urlName.substring(x+1);
                urlName = urlName.substring(0,x);
            }
            else {
                urlTarget = "_top";     // just to make sure we jump out of frames
            }
            try {
                if (urlName.indexOf("http://") < 0) {
                    nextURL = new URL(getDocumentBase(),urlName);
                }
                else {
                    nextURL = new URL(urlName);
                }
            }
            catch (MalformedURLException e) {};
        }
        borderWidth = Math.abs(borderWidth);
    }

    public boolean mouseDown(Event e,int x, int y) {
        borderWidth = -borderWidth;
        return true;
    }
    public boolean mouseUp(Event e,int x, int y) {
        borderWidth = -borderWidth;
        if (nextURL !=null) {
            getAppletContext().showDocument(nextURL,urlTarget);
        }
        return true;
    }
    public boolean mouseEnter(Event e,int x,int y) {
        if (nextURL != null) showStatus("Link to " + urlName);
        return true;
    }
    public boolean mouseExit(Event e,int x,int y){
        showStatus("");
        return true;
    }
}
