home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1998 February
/
VPR9802A.ISO
/
APP_DEMO
/
VC
/
SOURCE.BIN
/
RollOverButton.java
< prev
next >
Wrap
Text File
|
1997-10-27
|
36KB
|
1,252 lines
package symantec.itools.awt;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.net.URL;
import java.net.MalformedURLException;
import java.awt.Event;
import java.awt.Component;
import java.awt.Container;
import java.applet.*;
import java.beans.PropertyVetoException;
import java.beans.PropertyChangeListener;
import java.beans.VetoableChangeListener;
import java.awt.AWTEventMulticaster;
import java.awt.AWTEvent;
import java.awt.event.MouseEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
// Created and implemented by Levi Brown, Symantec Macintosh Internet Tools.
// 02/04/97 LAB Checked it in
// 05/31/97 LAB Updated to Java 1.1
// 07/14/97 LAB Added add/removeNotify for event listener registration.
// Removed use of TransparencyTrick and made Lightweight.
// Updated version.
// 07/28/97 CAR fixed typo in setStandardFileName and in setDownFileName
// marked fields transient as needed
// implemented readObject for use during deserialization
// 08/28/97 CAR "erases" images when setters for images are set to null
/**
* This is a button that allows three different states and
* displays the document with a given URL when clicked.
* Each button state has its own associated image. Each image is specified
* by providing the file name or the URL of the file containing the image.
* The document to show is specified by providing the "LinkURL" of that
* document.
* <p>
* The "standard" state is when the mouse is not over the button.
* If the standard image is null, the button will be transparent when in the
* standard state, otherwise the specified image will be displayed.
* <p>
* The "over" state is when the mouse cursor is over the button.
* This state also displays the LinkURL if it is not null.
* <p>
* The "down" state is when the mouse button is pressed inside the button.
* When there is a MOUSE_UP in the button, it will attempt to show the document
* at the LinkURL unless it is null. This state also displays the
* LinkURL if it is not null.
* <p>
*
* @version 1.1, July 14, 1997
* @author Symantec
*/
public class RollOverButton extends Component
{
/**
* Constructs a default RollOverButton.
* It has no associated images nor a LinkURL.
*/
public RollOverButton()
{
standardImage = null;
overImage = null;
downImage = null;
standardFileName = null;
overFileName = null;
downFileName = null;
frame = null;
standardURL = null;
overURL = null;
downURL = null;
linkURL = null;
isMouseOver = false;
isClearFrame = false;
isPressed = false;
isMouseDrag = false;
isCenterMode = true;
}
/**
* Constructs a RollOverButton with an image file name given for each
* button state.
* @param Standard the file name of the image to use while the mouse is not over the button
* @param Over the file name of the image to use while the mouse is over the button
* @param Down the file name of the image to use while the mouse is over the button and pressed
* @exception MalformedURLException if a URL cannot be created from any of file names
*/
public RollOverButton(String standard, String over, String down) throws MalformedURLException
{
this();
try
{
setStandardFileName(standard);
setOverFileName(over);
setDownFileName(down);
}
catch(PropertyVetoException e){}
}
/**
* Constructs a RollOverButton with an image file URL given for each
* button state.
* @param Standard the URL of the image to use while the mouse is not over the button
* @param Over the URL of the image to use while the mouse is over the button
* @param Down the URL of the image to use while the mouse is over the button and pressed
*/
public RollOverButton(URL standard, URL over, URL down)
{
this();
try
{
setStandardURL(standard);
setOverURL(over);
setDownURL(down);
}
catch(PropertyVetoException e){}
catch(MalformedURLException e){}
}
/**
* Constructs a RollOverButton with an image given for each button state.
* @param Standard the image to use while the mouse is not over the button
* @param Over the image to use while the mouse is over the button
* @param Down the image to use while the mouse is over the button and pressed
*/
public RollOverButton(Image standard, Image over, Image down)
{
this();
try
{
setStandardImage(standard);
setOverImage(over);
setDownImage(down);
}
catch(PropertyVetoException e){}
}
/**
* Sets the file name of the image to display while the mouse is not over
* the button.
* @param str the image file name
* @exception MalformedURLException if a URL cannot be created from the file name
* @see #getStandardFileName
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setStandardFileName(String str) throws MalformedURLException, PropertyVetoException
{
if(standardFileName != str && (standardFileName == null || !standardFileName.equals(str)))
{
String oldValue = standardFileName;
vetos.fireVetoableChange("StandardFileName", oldValue, str);
standardFileName = str;
if(standardFileName == null)
{
setStandardURL(null);
}
else
{
setStandardURL(new URL(standardFileName));
}
setStandardURL(new URL(standardFileName));
changes.firePropertyChange("StandardFileName", oldValue, str);
}
}
/**
* Gets the file name of the image to display while the mouse is not over
* the button.
* @return the image file name
* @see #setStandardFileName
*/
public String getStandardFileName()
{
return standardFileName;
}
/**
* Sets the file name of the image to display while the mouse is over
* the button.
* @param str the image file name
* @exception MalformedURLException if a URL cannot be created from the file name
* @see #getOverFileName
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setOverFileName(String str) throws MalformedURLException, PropertyVetoException
{
if(overFileName != str && (overFileName == null || !overFileName.equals(str)))
{
String oldValue = overFileName;
vetos.fireVetoableChange("OverFileName", oldValue, str);
overFileName = str;
if(overFileName == null)
{
setOverURL(null);
}
else
{
setOverURL(new URL(overFileName));
}
changes.firePropertyChange("OverFileName", oldValue, str);
}
}
/**
* Gets the file name of the image to display while the mouse is over
* the button.
* @return the image file name
* @see #setOverFileName
*/
public String getOverFileName()
{
return overFileName;
}
/**
* Sets the file name of the image to display while the button is being pressed.
* @param str the image file name
* @exception MalformedURLException if a URL cannot be created from the file name
* @see #getDownFileName
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setDownFileName(String str) throws MalformedURLException, PropertyVetoException
{
if(downFileName != str && (downFileName == null || !downFileName.equals(str)))
{
String oldValue = downFileName;
vetos.fireVetoableChange("DownFileName", oldValue, str);
downFileName = str;
if(downFileName == null)
{
setDownURL(null);
}
else
{
setDownURL(new URL(downFileName));
}
changes.firePropertyChange("DownFileName", oldValue, str);
}
}
/**
* Gets the file name of the image to display while the button is being
* pressed.
* @return the image file name
* @see #setDownFileName
*/
public String getDownFileName()
{
return downFileName;
}
/**
* Sets the URL of the image to display while the mouse is not over
* the button.
* @param aURL the image URL
* @see #getStandardURL
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @exception MalformedURLException
* if the given URL is bad
*/
public void setStandardURL(URL aUrl) throws MalformedURLException, PropertyVetoException
{
if(standardURL == null || !standardURL.equals(aUrl))
{
URL oldValue = standardURL;
vetos.fireVetoableChange("StandardURL", oldValue, aUrl);
standardURL = aUrl;
standardFileName = null;
Image loadedImage = null;
if (aUrl != null)
loadedImage= getToolkit().getImage(aUrl);
setStandardImage(loadedImage);
repaint();
changes.firePropertyChange("StandardURL", oldValue, aUrl);
}
}
/**
* Gets the URL of the image to display while the mouse is not over
* the button.
* @return the image URL
* @see #setStandardURL
*/
public URL getStandardURL()
{
return standardURL;
}
/**
* Sets the URL of the image to display while the mouse is over
* the button.
* @param aURL the image URL
* @see #getOverURL
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @exception MalformedURLException
* if the given URL is bad
*/
public void setOverURL(URL aUrl) throws MalformedURLException, PropertyVetoException
{
if(overURL == null || !overURL.equals(aUrl))
{
URL oldValue = overURL;
vetos.fireVetoableChange("OverURL", oldValue, aUrl);
overURL = aUrl;
Image loadedImage = null;
if (aUrl != null)
loadedImage = getToolkit().getImage(aUrl);
setOverImage(loadedImage);
repaint();
changes.firePropertyChange("OverURL", oldValue, aUrl);
}
}
/**
* Gets the URL of the image to display while the mouse is over
* the button.
* @return the image URL
* @see #setOverURL
*/
public URL getOverURL()
{
return overURL;
}
/**
* Sets the URL of the image to display while the button is being pressed.
* @param aURL the image URL
* @see #getDownURL
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @exception MalformedURLException
* if the given URL is bad
*/
public void setDownURL(URL aUrl) throws MalformedURLException, PropertyVetoException
{
if(downURL == null || !downURL.equals(aUrl))
{
URL oldValue = downURL;
vetos.fireVetoableChange("DownURL", oldValue, aUrl);
downURL = aUrl;
Image loadedImage = null;
if (aUrl != null)
loadedImage = getToolkit().getImage(aUrl);
setDownImage(loadedImage);
repaint();
changes.firePropertyChange("DownURL", oldValue, aUrl);
}
}
/**
* Gets the URL of the image to display while the button is being pressed.
* @return the image URL
* @see #setDownURL
*/
public URL getDownURL()
{
return downURL;
}
/**
* Sets the image to display while the mouse is not over the button.
* @param img the image
* @see #getStandardImage
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setStandardImage(Image img) throws PropertyVetoException
{
if(standardImage == null || !standardImage.equals(img))
{
Image oldValue = standardImage;
vetos.fireVetoableChange("StandardImage", oldValue, img);
standardImage = img;
setImageHelper(standardImage);
changes.firePropertyChange("StandardImage", oldValue, img);
}
}
/**
* Gets the image displayed while the mouse is not over the button.
* @return the image
* @see #setStandardImage
*/
public Image getStandardImage()
{
return standardImage;
}
/**
* Sets the image to display while the mouse is over the button.
* @param img the image
* @see #getOverImage
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setOverImage(Image img) throws PropertyVetoException
{
if(overImage == null || !overImage.equals(img))
{
Image oldValue = overImage;
vetos.fireVetoableChange("OverImage", oldValue, img);
overImage = img;
setImageHelper(overImage);
changes.firePropertyChange("OverImage", oldValue, img);
}
}
/**
* Gets the image displayed while the mouse is over the button.
* @return the image
* @see #setOverImage
*/
public Image getOverImage()
{
return overImage;
}
/**
* Sets the image to display while the button is being pressed.
* @param img the image
* @see #getDownImage
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setDownImage(Image img) throws PropertyVetoException
{
if(downImage == null || !downImage.equals(img))
{
Image oldValue = downImage;
vetos.fireVetoableChange("DownImage", oldValue, img);
downImage = img;
setImageHelper(downImage);
changes.firePropertyChange("DownImage", oldValue, img);
}
}
/**
* Gets the image displayed while the button is being pressed.
* @return the image
* @see #setDownImage
*/
public Image getDownImage()
{
return downImage;
}
/**
* Sets the flag to erase the background before drawing the button.
* Not erasing the background often results in a faster, more flicker-free
* update.
* @param b if true clear the background before painting, if false then don't
* @see #isClearFrame
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setClearFrame(boolean b) throws PropertyVetoException
{
Boolean oldValue = new Boolean(isClearFrame);
Boolean newValue = new Boolean(b);
vetos.fireVetoableChange("ClearFrame", oldValue, newValue);
isClearFrame = b;
changes.firePropertyChange("ClearFrame", oldValue, newValue);
}
/**
* Gets the flag that determines if the background should be erased before
* the button is drawn.
* @return true if the background will be cleared before painting the button,
* false if it will not be cleared
* @see #setClearFrame
*/
public boolean isClearFrame()
{
return isClearFrame;
}
/**
* @deprecated
* @see #isClearFrame
*/
public boolean getClearFrame()
{
return isClearFrame();
}
/**
* Sets the URL of the document to display on mouse up.
* @param u the URL of the document to display
* @see #getURL
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setURL(URL aUrl) throws PropertyVetoException
{
if(linkURL == null || !linkURL.equals(aUrl))
{
URL oldValue = linkURL;
vetos.fireVetoableChange("URL", oldValue, aUrl);
linkURL = aUrl;
context = null;
changes.firePropertyChange("URL", oldValue, aUrl);
}
}
/**
* Gets the URL of the document to display on mouse up.
* @return the URL of the document to display
* @see #setURL
*/
public URL getURL()
{
return linkURL;
}
/**
* 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 new frame specifier
* @see #getFrame
* @see #frame
* @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 current frame specifier
* @see #setFrame
* @see #frame
*/
public String getFrame()
{
return frame;
}
/**
* Sets the flag to center the image within the bounds of the button.
* @param flag true to center the image within the button,
* false to draw the image at 0,0 relative to the button
* @see #isCenterMode
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setCenterMode(boolean flag) throws PropertyVetoException
{
if(isCenterMode != flag)
{
Boolean oldValue = new Boolean(isCenterMode);
Boolean newValue = new Boolean(flag);
vetos.fireVetoableChange("CenterMode", oldValue, newValue);
isCenterMode = flag;
invalidate();
changes.firePropertyChange("CenterMode", oldValue, newValue);
}
}
/**
* Gets the flag that determines whether to center the image within the
* bounds of the button.
* @return true if the image will be centered within the button,
* false if the image will be drawn at 0,0 relative to the button.
* @see #setCenterMode
*/
public boolean isCenterMode()
{
return isCenterMode;
}
/**
* @deprecated
* @see #isCenterMode
*/
public boolean getCenterMode()
{
return isCenterMode();
}
/**
* Paints this component using the given graphics context.
* This is a standard Java AWT method which typically gets called
* by the AWT to handle painting this component. It paints this component
* using the given graphics context. The graphics context clipping region
* is set to the bounding rectangle of this component and its [0,0]
* coordinate is this component's top-left corner.
*
* @param g the graphics context used for painting
* @see java.awt.Component#repaint
* @see #update
*/
public void paint(Graphics g)
{
Dimension dim = size();
int x, y;
x = y = 0;
if(isPressed)
{
if(isMouseOver)
{
//Mouse Down Image
if(downImage != null)
{
if (isCenterMode)
{
x += (dim.width - downImage.getWidth(this)) / 2;
y += (dim.height - downImage.getHeight(this)) / 2;
}
g.drawImage(downImage, x, y, this);
}
}
else
{
//RollOver Image
if(overImage != null)
{
if (isCenterMode)
{
x += (dim.width - overImage.getWidth(this)) / 2;
y += (dim.height - overImage.getHeight(this)) / 2;
}
g.drawImage(overImage, x, y, this);
}
}
}
else
{
//RollOver Image
if(isMouseOver && overImage != null)
{
if (isCenterMode)
{
x += (dim.width - overImage.getWidth(this)) / 2;
y += (dim.height - overImage.getHeight(this)) / 2;
}
g.drawImage(overImage, x, y, this);
}
//Standard Image
else
{
if (standardImage == null)
{
//Draw the standard state as "Transparent"
}
else
{
if (isCenterMode)
{
x += (dim.width - standardImage.getWidth(this)) / 2;
y += (dim.height - standardImage.getHeight(this)) / 2;
}
g.drawImage(standardImage, x, y, this);
}
}
}
}
/**
* Handles redrawing of this component on the screen.
* This is a standard Java AWT method which gets called by the Java
* AWT (repaint()) to handle repainting this component on the screen.
* The graphics context clipping region is set to the bounding rectangle
* of this component and its [0,0] coordinate is this component's
* top-left corner.
* Typically this method paints the background color to clear the
* component's drawing space, sets graphics context to be the foreground
* color, and then calls paint() to draw the component.
*
* It is overridden here to add the clear frame feature to this button.
*
* @param g the graphics context
* @see java.awt.Component#repaint
* @see #paint
*/
public void update(Graphics g)
{
if (isClearFrame)
super.update(g);
else
paint(g);
}
/**
* 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 (mouse == null)
{
mouse = new Mouse();
addMouseListener(mouse);
}
if (mouseMotion == null)
{
mouseMotion = new MouseMtn();
addMouseMotionListener(mouseMotion);
}
}
/**
* 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 (mouse != null)
{
removeMouseListener(mouse);
mouse = null;
}
if (mouseMotion != null)
{
removeMouseMotionListener(mouseMotion);
mouseMotion = null;
}
super.removeNotify();
}
/**
* 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();
}
}
/**
* Returns the recommended dimensions to properly display this component.
* This is a standard Java AWT method which gets called to determine
* the recommended size of this component.
* In this case the recommended size is the minimum dimension needed to
* encompass the three images that might be displayed.
*
* @see #getMinimumSize
*/
public Dimension getPreferredSize()
{
int iWidth, oWidth, dWidth, maxWidth, iHeight, oHeight, dHeight, maxHeight;
iWidth = standardImage == null ? 0 : standardImage.getWidth(this);
oWidth = overImage == null ? 0 : overImage.getWidth(this);
dWidth = downImage == null ? 0 : downImage.getWidth(this);
iHeight = standardImage == null ? 0 : standardImage.getHeight(this);
oHeight = overImage == null ? 0 : overImage.getHeight(this);
dHeight = downImage == null ? 0 : downImage.getHeight(this);
maxWidth = iWidth >= oWidth ? iWidth : oWidth;
maxWidth = maxWidth >= dWidth ? maxWidth : dWidth;
maxHeight = iHeight >= oHeight ? iHeight : oHeight;
maxHeight = maxHeight >= dHeight ? maxHeight : dHeight;
maxWidth = maxWidth == 0 ? 10 : maxWidth;
maxHeight = maxHeight == 0 ? 10 : maxHeight;
return (new Dimension(maxWidth, maxHeight));
}
/**
* Returns the minimum dimensions to properly display this component.
* This is a standard Java AWT method which gets called to determine
* the minimum size of this component.
* In this case the minimum size simply returns the results of
* a call to getPreferedSize().
*
* @see #getPreferredSize
*/
public Dimension getMinimumSize()
{
return getPreferredSize();
}
/**
* @deprecated
* @see #getPreferredSize
*/
public Dimension preferredSize()
{
return getPreferredSize();
}
/**
* Sets the command name of the action event fired by this button.
* @param command The name of the action event command fired by this button
* @exception PropertyVetoException
* if the specified property value is unacceptable
*/
public void setActionCommand(String command) throws PropertyVetoException
{
String oldValue = actionCommand;
vetos.fireVetoableChange("ActionCommand", oldValue, command);
actionCommand = command;
changes.firePropertyChange("ActionCommand", oldValue, command);
}
/**
* @returns the command name of the action event fired by this button.
*/
public String getActionCommand()
{
return actionCommand;
}
/**
* Adds the specified action listener to receive action events
* from this button.
* @param l the action listener
*/
public void addActionListener(ActionListener l)
{
actionListener = AWTEventMulticaster.add(actionListener, l);
}
/**
* Removes the specified action listener so it no longer receives
* action events from this button.
* @param l the action listener
*/
public void removeActionListener(ActionListener l)
{
actionListener = AWTEventMulticaster.remove(actionListener, l);
}
/**
* Fire an action event to the listeners
*/
public void sourceActionEvent()
{
if (actionListener != null)
actionListener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand));
}
/**
* Adds a listener for all event changes.
* @param listener the listener to add.
* @see #removePropertyChangeListener
*/
public void addPropertyChangeListener(PropertyChangeListener listener)
{
changes.addPropertyChangeListener(listener);
}
/**
* Removes a listener for all event changes.
* @param listener the listener to remove.
* @see #addPropertyChangeListener
*/
public void removePropertyChangeListener(PropertyChangeListener listener)
{
changes.removePropertyChangeListener(listener);
}
/**
* Adds a vetoable listener for all event changes.
* @param listener the listener to add.
* @see #removeVetoableChangeListener
*/
public void addVetoableChangeListener(VetoableChangeListener listener)
{
vetos.addVetoableChangeListener(listener);
}
/**
* Removes a vetoable listener for all event changes.
* @param listener the listener to remove.
* @see #addVetoableChangeListener
*/
public void removeVetoableChangeListener(VetoableChangeListener listener)
{
vetos.removeVetoableChangeListener(listener);
}
/**
* This is the Mouse Event handling innerclass.
*/
class Mouse extends java.awt.event.MouseAdapter implements java.io.Serializable
{
/**
* Handles the Mouse Pressed events
* @param e the MouseEvent
* @see #mouseReleased
*/
public void mousePressed(MouseEvent e)
{
isPressed = true;
//Draw the button
repaint();
}
/**
* Handles the Mouse Released events
* @param e the MouseEvent
* @see #mousePressed
*/
public void mouseReleased(MouseEvent e)
{
if (isPressed)
{
isPressed = false;
//Draw the button.
repaint();
//If the mouse released occured over the button, goto the link, and fire an event.
if(isMouseOver)
{
//Handle going to the linkURL
if (context != null & linkURL != null)
{
if (frame == null || frame.length() == 0)
context.showDocument(linkURL);
else
context.showDocument(linkURL, frame);
}
sourceActionEvent();
}
}
}
/**
* Handles the Mouse Entered events
* @param e the MouseEvent
* @see #mouseExited
*/
public void mouseEntered(MouseEvent e)
{
isMouseOver = true;
//Display the linkURL
if (context != null && linkURL != null)
{
context.showStatus(linkURL.toString());
}
//Draw the button
repaint();
}
/**
* Handles the Mouse Exited events
* @param e the MouseEvent
* @see #mouseEntered
*/
public void mouseExited(MouseEvent e)
{
isMouseOver = false;
if (context != null && linkURL != null)
{
context.showStatus("");
}
//Draw the button in the standard state
repaint();
}
}
/**
* This is the MouseMotion Event handling innerclass.
*/
class MouseMtn implements java.awt.event.MouseMotionListener, java.io.Serializable
{
/**
* Handles the Mouse Moved events
* @param e the MouseEvent
* @see #mouseDragged
*/
public void mouseMoved(MouseEvent e)
{
isMouseDrag = false;
isPressed = false;
}
/**
* Handles the Mouse Dragged events
* @param e the MouseEvent
* @see #mouseMoved
*/
public void mouseDragged(MouseEvent e)
{
isMouseDrag = true;
}
}
/**
* A function used to consolidate shared code between the three image setting functions.
* @param img the image to set
*/
protected void setImageHelper(Image img)
{
if (img != null)
{
MediaTracker tracker;
try
{
tracker = new MediaTracker(this);
tracker.addImage(img, 0);
tracker.waitForID(0);
}
catch(InterruptedException e){}
}
else
{
repaint();
}
}
/**
* Sets the applet context used to view documents.
* @param c the new applet context
*/
protected void setAppletContext(AppletContext c)
{
context = c;
}
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
in.defaultReadObject();
if(standardURL != null) {
standardImage = getToolkit().getImage(standardURL);
if (standardImage != null)
{
setImageHelper(standardImage);
repaint();
}
}
if (overURL != null) {
overImage = getToolkit().getImage(overURL);
if (overImage != null)
{
setImageHelper(overImage);
repaint();
}
}
if (downURL != null) {
downImage = getToolkit().getImage(downURL);
if (downImage != null)
{
setImageHelper(downImage);
repaint();
}
}
}
/**
* The image displayed while the mouse is not over the button.
* If this is null, the button will be invisible in this state.
*/
transient protected Image standardImage;
/**
* The image displayed while the mouse is over the button.
* If this is null, the StandardImage will be used.
* If that is null, the button will be invisible in this state.
*/
transient protected Image overImage;
/**
* The image displayed while the mouse is pressed down inside the button.
* If this is null, no drawing takes place.
*/
transient protected Image downImage;
/**
* The file name of the image to display while the mouse is not over the button.
*/
protected String standardFileName;
/**
* The file name of the image to display while the mouse is over the button.
*/
protected String overFileName;
/**
* The file name of the image to display while the mouse is over the button and pressed.
*/
protected String downFileName;
/**
* 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>
*/
protected String frame;
/**
* The URL of the image to use in while the mouse is not over the button.
*/
protected URL standardURL;
/**
* The URL of the image to use while the mouse is over the button.
*/
protected URL overURL;
/**
* The URL of the image to use while the mouse is over the button and pressed.
*/
protected URL downURL;
/**
* The URL of the document to show after the button has been pressed.
*/
protected URL linkURL;
/**
* If true the image will be centered within the bounds of the
* button. If false the image is drawn at
* 0,0 relative to the bounds of the button.
*/
protected boolean isCenterMode;
/**
* True if the mouse is over the button.
*/
transient protected boolean isMouseOver;
/**
* If true the frame is cleared in between drawing
* different button states.
*/
protected boolean isClearFrame;
/**
* True if the mouse button is being pressed.
*/
transient protected boolean isPressed;
/**
* True if the mouse is being dragged in the button.
*/
transient protected boolean isMouseDrag;
/**
* The applet context that shows the document.
*/
transient protected AppletContext context;
String actionCommand;
ActionListener actionListener = null;
private Mouse mouse = null;
private MouseMtn mouseMotion = 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);
}