home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 9.4 KB | 325 lines |
- package symantec.itools.awt;
-
- import java.net.URL;
- import java.awt.Container;
- import java.applet.*;
- import java.beans.PropertyVetoException;
- import java.beans.PropertyChangeListener;
- import java.beans.VetoableChangeListener;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
-
- // 06/11/97 LAB Updated to Java 1.1.
- // 07/18/97 LAB Added add/removeNotify to handle event listener registration.
- // 07/29/97 CAR marked fields transient as needed
- // inner adaptor class implements java.io.Serializable
- // 08/18/97 CAR moved code to locate containing Applet into addNotify
- // 08/21/97 LAB Updated so when the mouse enters, the HTML link is displayed in the
- // status area of the browser/viewer. Added a check in the action event
- // handling code to look for a null url. Apparently context.showDocument()
- // would silently throw, causing the action event to be eaten if it was passed
- // a null url. Addresses Mac Bug #7436
-
- /**
- * Use this component to create an invisible rectangular button, usually within
- * an image, that displays the document at a given URL when clicked.
- * @version 1.1, June 11, 1997
- * @author Symantec
- */
- public class InvisibleHTMLLink extends InvisibleButton
- {
- /**
- * Constructs a default InvisibleHTMLLink.
- */
- public InvisibleHTMLLink()
- {
- frame = null;
- url = null;
- context = null;
- }
-
- /**
- * Sets the URL of the document to show when the button is clicked.
- * @param u the URL
- * @exception PropertyVetoException
- * if the specified property value is unacceptable
- * @see #getURL
- */
- public void setURL(URL u) throws PropertyVetoException
- {
- if(!symantec.itools.util.GeneralUtils.objectsEqual(url, u))
- {
- URL oldValue = url;
-
- vetos.fireVetoableChange("URL", oldValue, u);
- url = u;
- context = null;
- changes.firePropertyChange("URL", oldValue, u);
- }
- }
-
- /**
- * Returns the URL of the document to show when the button is clicked.
- * @see #setURL
- */
- public URL getURL()
- {
- return url;
- }
-
- /**
- * Sets the 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>
- * @param f the frame specifier
- * @see #getFrame
- * @see symantec.itools.util.GeneralUtils#frameTarget_self
- * @see symantec.itools.util.GeneralUtils#frameTarget_parent
- * @see symantec.itools.util.GeneralUtils#frameTarget_top
- * @see symantec.itools.util.GeneralUtils#frameTarget_blank
- * @exception PropertyVetoException
- * if the specified property value is unacceptable
- */
- public void setFrame(String f) throws PropertyVetoException
- {
- String oldValue = frame;
-
- vetos.fireVetoableChange("Frame", oldValue, f);
-
- frame = f;
-
- changes.firePropertyChange("Frame", oldValue, f);
- }
-
- /**
- * Gets the 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>
- * @return the frame specifier
- * @see #setFrame
- */
- public String getFrame()
- {
- return frame;
- }
-
- /**
- * Tells this component that it has been added to a container.
- * This is a standard Java AWT method which gets called by the AWT when
- * this component is added to a container. Typically, it is used to
- * create this component's peer.
- *
- * It has been overridden here to hook-up event listeners.
- *
- * @see #removeNotify
- */
- public synchronized void addNotify()
- {
- super.addNotify();
-
- //Hook up listeners
- if (action == null)
- {
- action = new Action();
- addActionListener(action);
- }
- if (mouse == null)
- {
- mouse = new Mouse();
- addMouseListener(mouse);
- }
-
- // On addNotify, try to find the containing applet.
- Container c = getParent();
- while (c != null)
- {
- if (c instanceof Applet)
- {
- setAppletContext(((Applet) c).getAppletContext());
- break;
- }
-
- c = c.getParent();
- }
- }
-
- /**
- * Tells this component that it is being removed from a container.
- * This is a standard Java AWT method which gets called by the AWT when
- * this component is removed from a container. Typically, it is used to
- * destroy the peers of this component and all its subcomponents.
- *
- * It has been overridden here to unhook event listeners.
- *
- * @see #addNotify
- */
- public synchronized void removeNotify()
- {
- //Unhook listeners
- if (action != null)
- {
- removeActionListener(action);
- action = null;
- }
- if (mouse != null)
- {
- removeMouseListener(mouse);
- mouse = null;
- }
-
- super.removeNotify();
- }
-
- /**
- * Adds a listener for all event changes.
- * @param PropertyChangeListener listener the listener to add.
- * @see #removePropertyChangeListener
- */
- public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
- {
- super.addPropertyChangeListener(listener);
- changes.addPropertyChangeListener(listener);
- }
-
- /**
- * Removes a listener for all event changes.
- * @param PropertyChangeListener listener the listener to remove.
- * @see #addPropertyChangeListener
- */
- public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
- {
- super.removePropertyChangeListener(listener);
- changes.removePropertyChangeListener(listener);
- }
-
- /**
- * Adds a vetoable listener for all event changes.
- * @param VetoableChangeListener listener the listener to add.
- * @see #removeVetoableChangeListener
- */
- public synchronized void addVetoableChangeListener(VetoableChangeListener listener)
- {
- super.addVetoableChangeListener(listener);
- vetos.addVetoableChangeListener(listener);
- }
-
- /**
- * Removes a vetoable listener for all event changes.
- * @param VetoableChangeListener listener the listener to remove.
- * @see #addVetoableChangeListener
- */
- public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)
- {
- super.removeVetoableChangeListener(listener);
- vetos.removeVetoableChangeListener(listener);
- }
-
- /**
- * This is the Mouse Event handling innerclass.
- */
- class Mouse extends java.awt.event.MouseAdapter
- {
- boolean statusChanged = false;
-
- /**
- * Handles Mouse Entered events
- * @param e the MouseEvent
- */
- public void mouseEntered(MouseEvent e)
- {
- if(context != null && url != null)
- {
- statusChanged = true;
- context.showStatus(url.toString());
- }
- }
-
- /**
- * Handles Mouse Exited events
- * @param e the MouseEvent
- */
- public void mouseExited(MouseEvent e)
- {
- if(context != null && statusChanged)
- {
- statusChanged = false;
- context.showStatus("");
- }
- }
- }
-
- /**
- * This is the Adjustment Event handling innerclass.
- */
- class Action implements java.awt.event.ActionListener, java.io.Serializable
- {
- /**
- * Handles Action events
- * @param e the ActionEvent
- */
- public void actionPerformed(ActionEvent e)
- {
- if (context != null && url != null)
- {
- if (frame == null || frame.length() == 0)
- context.showDocument(url);
- else
- context.showDocument(url, frame);
- }
- }
- }
-
- /**
- * Sets the applet context used to view documents.
- * @param c the new applet context
- */
- protected void setAppletContext(AppletContext c)
- {
- context = c;
- }
-
- /**
- * The URL of the document to show when the button is clicked.
- */
- protected URL url;
-
- /**
- * Applet context that shows the document.
- */
- transient 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;
-
- // Private members
- private Action action = null;
- private Mouse mouse = null;
- private symantec.itools.beans.VetoableChangeSupport vetos = new symantec.itools.beans.VetoableChangeSupport(this);
- private symantec.itools.beans.PropertyChangeSupport changes = new symantec.itools.beans.PropertyChangeSupport(this);
- }
-
-