home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 4.1 KB | 160 lines |
- package symantec.itools.awt;
-
-
- import java.net.URL;
- import java.awt.Event;
- import java.awt.Container;
- import java.applet.*;
-
-
- /**
- * Creates a text string that calls a URL address when clicked. An application
- * or applet can change the label text string, but a user cannot edit it.
- * <p>
- * Use LabelHTMLLink whenever you want to create ôhotö text, that links to a
- * URL address when clicked.
- * <p>
- * @version 1.0, Nov 26, 1996
- * @author Symantec
- */
- public class LabelHTMLLink
- extends LabelButton
- {
- /**
- * URL to show when the button is clicked.
- */
- protected URL url;
- /**
- * Applet context that shows the URL.
- */
- protected AppletContext context;
- /**
- * Frame specifier for showing a URL document in a browser or applet
- * viewer. It is interpreted as follows:
- * <UL>
- * <DT>"_self" show document in the current frame</DT>
- * <DT>"_parent" show document in the parent frame</DT>
- * <DT>"_top" show document in the topmost frame</DT>
- * <DT>"_blank" show document in a new unnamed toplevel window</DT>
- * <DT>all others show document in a new toplevel window with the given name</DT>
- * </UL>
- */
- protected String frame;
-
- /**
- * Constructs a default LabelHTMLLink.
- */
- public LabelHTMLLink()
- {
- frame = null;
- }
-
- /**
- * Returns the URL to show when the button is clicked.
- * @see #setURL
- */
- public URL getURL()
- {
- return url;
- }
-
- /**
- * Sets the URL to show when the button is clicked.
- * @param u the URL to show when the button is clicked
- * @see #getURL
- */
- public void setURL(URL u)
- {
- url = u;
- context = null;
- }
-
- /**
- * Sets the title displayed on the applet frame while showing
- * the URL.
- * @param f applet frame title
- * @see #getFrame
- */
- public void setFrame(String f)
- {
- frame = f;
- }
-
- /**
- * Returns the title that is displayed on the applet frame while showing
- * the URL.
- * @see #setFrame
- */
- public String getFrame()
- {
- return frame;
- }
-
- /**
- * Handles internal actions for this component.
- * This is a standard Java AWT method which usually gets called by the AWT
- * method handleEvent() in response to receiving an ACTION_EVENT event. In those
- * cases the o parameter contains the value in the event's arg field.
- *
- * @param event the event that caused this action
- * @param what the action
- * @return true if the action was handled
- * @see java.awt.Component#handleEvent
- */
- public boolean action(Event event, Object what)
- {
- if (context != null)
- {
- if (frame == null || frame.length() == 0)
- context.showDocument(url);
- else
- context.showDocument(url, frame);
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Ensures that this component is laid out properly, as needed.
- * This is a standard Java AWT method which gets called by the AWT to
- * make sure this component and its subcomponents have a valid layout.
- * If this component was made invalid with a call to invalidate(), then
- * it is laid out again.
- *
- * It is overridden here to locate the applet containing this component.
- *
- * @see java.awt.Component#invalidate
- */
- public void validate()
- {
- // On validation, try to find the containing applet. If we can find
- // it, we don't bother doing the link...
- Container c;
-
- c = getParent();
-
- while (c != null)
- {
- if (c instanceof Applet)
- {
- setAppletContext(((Applet) c).getAppletContext());
- break;
- }
-
- c = c.getParent();
- }
- }
-
- /**
- * Sets the applet context to use for showing the URL.
- * @param c the applet context
- */
- protected void setAppletContext(AppletContext c)
- {
- context = c;
- }
- }
-
-