home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / RollOverButton.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  25.1 KB  |  862 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.Dimension;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.MediaTracker;
  7. import java.awt.Toolkit;
  8. import java.net.URL;
  9. import java.net.MalformedURLException;
  10. import java.awt.Event;
  11. import java.awt.Container;
  12. import java.applet.*;
  13. import java.awt.Canvas;
  14. import symantec.itools.awt.TransparencyTrick;
  15. import symantec.itools.awt.TransparencyTrickUtils;
  16.  
  17. /**
  18.  * This is a button that allows three different states.  The standard state
  19.  * is when the button is not doing anything.  Durring this state you can specify
  20.  * null for the standard image, and the standard state will be transparent.  The 
  21.  * over state is when the mouse cursor is over the button.  This state also displays
  22.  * the LinkURL if it is not null.  The down state is when the mouse button is pressed
  23.  * down inside the button.  If there is a click in the button, it will attempt to go
  24.  * to the LinkURL, unless it is null.  This state also displays the LinkURL if it is
  25.  * not null.
  26.  * @version 1.0, Feb 4, 1997
  27.  * @author Symantec
  28.  */
  29.  
  30. //  Created and implemented by Levi Brown, Symantec Macintosh Internet Tools.
  31. //     02/04/97    LAB    Checked it in
  32.  
  33. public class RollOverButton extends java.awt.Canvas implements TransparencyTrick
  34. {
  35.     /**
  36.      * The image displayed when the button is not doing anything.
  37.      */
  38.     protected Image StandardImage;
  39.     /**
  40.      * The image displayed when the mouse is over the button.
  41.      */
  42.     protected Image OverImage;
  43.     /**
  44.      * The image displayed when the mouse is pressed down inside the button.
  45.      */
  46.     protected Image DownImage;
  47.     /**
  48.      * The file name of the image to use in default cases.
  49.      */
  50.     protected String StandardFileName;
  51.     /**
  52.      * The filename for the image to use when the mouse is over the button.
  53.      */
  54.     protected String OverFileName;
  55.     /**
  56.      * The filename for the image to use when the mouse is over the button and depressed.
  57.      */
  58.     protected String DownFileName;
  59.     /**
  60.      * Frame specifier for showing a URL document in a browser or applet 
  61.      * viewer. It is interpreted as follows:
  62.      * <UL>
  63.      * <DT>"_self"  show document in the current frame</DT>
  64.      * <DT>"_parent"    show document in the parent frame</DT>
  65.      * <DT>"_top"   show document in the topmost frame</DT>
  66.      * <DT>"_blank" show document in a new unnamed toplevel window</DT>
  67.      * <DT>all others   show document in a new toplevel window with the given name</DT>
  68.      * </UL>
  69.      */
  70.     protected String frame;
  71.     /**
  72.      * The URL for the image to use in defaullt cases.
  73.      */
  74.     protected URL StandardURL;
  75.     /**
  76.      * The URL for the image to use when the mouse is over the button.
  77.      */
  78.     protected URL OverURL;
  79.     /**
  80.      * The URL for the image to use when the mouse is over the button and depressed.
  81.      */
  82.     protected URL DownURL;
  83.     /**
  84.      * The URL that determines the link the button will go to on mouse up
  85.      */
  86.     protected URL LinkURL;
  87.     /**
  88.      * The flag indicating the image should be centered in the bounds of the 
  89.      * button. If true the image is centered. If false the image is drawn at
  90.      * 0,0 relative to the bounds of the button.
  91.      */
  92.     protected boolean isCenterMode;
  93.     /**
  94.      * Indicates the mouse is over the button.
  95.      */
  96.     protected boolean isMouseOver;
  97.     /**
  98.      * Indicates the frame should be cleared in between drawing 
  99.      * different button states.
  100.      */
  101.     protected boolean isClearFrame;
  102.     /**
  103.      * Indicates the mouse button is being pressed.
  104.      */
  105.     protected boolean isPressed;
  106.     /**
  107.      * Indicates the mouse is being dragged in the button.
  108.      */
  109.     protected boolean isMouseDrag;
  110.     /**
  111.      * The context used to display the document.
  112.      */
  113.     protected AppletContext context;
  114.     
  115.     /**
  116.      * Constructs a RollOverButton.
  117.      */
  118.     public RollOverButton()
  119.     {
  120.         StandardImage        = null;
  121.         OverImage            = null;
  122.         DownImage            = null;
  123.         StandardFileName    = null;
  124.         OverFileName        = null;
  125.         DownFileName        = null;
  126.         frame                = null;
  127.         StandardURL            = null;
  128.         OverURL                = null;
  129.         DownURL                = null;
  130.         LinkURL                = null;
  131.         isMouseOver            = false;
  132.         isClearFrame        = false;
  133.         isPressed            = false;
  134.         isMouseDrag            = false;
  135.     }
  136.  
  137.     /**
  138.      * Constructor allowing file name specifications for all three sates of the button.
  139.      * @param Standard the filename for the image to use in defaullt cases
  140.      * @param Over the filename for the image to use when the mouse is over the button
  141.      * @param Down the filename for the image to use when the mouse is over the button and depressed
  142.      */
  143.     public RollOverButton(String Standard, String Over, String Down)
  144.         throws MalformedURLException
  145.     {
  146.         this();
  147.         setStandardFileName(Standard);
  148.         setOverFileName(Over);
  149.         setDownFileName(Down);
  150.     }
  151.  
  152.     /**
  153.      * Constructor allowing URL specifications for all three sates of the button.
  154.      * @param Standard the URL for the image to use in defaullt cases
  155.      * @param Over the URL for the image to use when the mouse is over the button
  156.      * @param Down the URL for the image to use when the mouse is over the button and depressed
  157.      */
  158.     public RollOverButton(URL Standard, URL Over, URL Down)
  159.     {
  160.         this();
  161.         setStandardURL(Standard);
  162.         setOverURL(Over);
  163.         setDownURL(Down);
  164.     }
  165.  
  166.     /**
  167.      * Constructor allowing image specifications for all three sates of the button.
  168.      * @param Standard the image to use in defaullt cases
  169.      * @param Over the image to use when the mouse is over the button
  170.      * @param Down the image to use when the mouse is over the button and depressed
  171.      */
  172.     public RollOverButton(Image Standard, Image Over, Image Down)
  173.     {
  174.         this();
  175.         setStandardImage(Standard);
  176.         setOverImage(Over);
  177.         setDownImage(Down);
  178.     }
  179.  
  180.     /**
  181.      * Sets the file name of the image to use in default cases.
  182.      * @param str the file name to use for default cases
  183.      * @see #getStandardFileName
  184.      */
  185.     public void setStandardFileName(String str)
  186.         throws MalformedURLException
  187.     {
  188.         StandardFileName = str;
  189.         setFileNameHelper(StandardFileName);
  190.     }
  191.  
  192.     /**
  193.      * Gets the file name of the image to use in default cases.
  194.      * @return the file name being used for default cases
  195.      * @see #setStandardFileName
  196.      */
  197.     public String getStandardFileName()
  198.     {
  199.         return StandardFileName;
  200.     }
  201.  
  202.     /**
  203.      * Sets the file name of the image to use when the mouse is over the button.
  204.      * @param str the file name to use when the mouse is over the button
  205.      * @see #getOverFileName
  206.      */
  207.     public void setOverFileName(String str)
  208.         throws MalformedURLException
  209.     {
  210.         OverFileName = str;
  211.         setFileNameHelper(OverFileName);
  212.     }
  213.  
  214.     /**
  215.      * Gets the file name of the image to use when the mouse is over the button.
  216.      * @return str the file name used when the mouse is over the button
  217.      * @see #setOverFileName
  218.      */
  219.     public String getOverFileName()
  220.     {
  221.         return OverFileName;
  222.     }
  223.  
  224.     /**
  225.      * Sets the file name of the image to use when the mouse is down while in the button.
  226.      * @param str the file name to use when the mouse is down while in the button
  227.      * @see #getDownFileName
  228.      */
  229.     public void setDownFileName(String str)
  230.         throws MalformedURLException
  231.     {
  232.         DownFileName = str;
  233.         setFileNameHelper(DownFileName);
  234.     }
  235.  
  236.     /**
  237.      * Gets the file name of the image to use when the mouse is down while in the button.
  238.      * @return str the file name used when the mouse is down while in the button
  239.      * @see #setDownFileName
  240.      */
  241.     public String getDownFileName()
  242.     {
  243.         return DownFileName;
  244.     }
  245.  
  246.     /**
  247.      * A function used to consolidate shared code between the three file name setting functions.
  248.      * @param str the file name to set
  249.      */
  250.     protected void setFileNameHelper(String str)
  251.         throws MalformedURLException
  252.     {
  253.         try
  254.         {
  255.            setOverURL(new URL(str));
  256.         }
  257.         catch(MalformedURLException e)
  258.         {
  259.             //System.out.println("malformed URL");
  260.         }
  261.         repaint();
  262.     }
  263.     
  264.     /**
  265.      * Sets the URL of the image to use when in default states.
  266.      * @param aUrl the URL to use when in default states
  267.      * @see #getStandardURL
  268.      */
  269.     public void setStandardURL(URL aUrl)
  270.     {
  271.         StandardURL = aUrl;
  272.         StandardFileName = null;
  273.  
  274.         Image loadedImage = getToolkit().getImage(aUrl);
  275.         if (loadedImage != null) {
  276.             setStandardImage(loadedImage);
  277.             repaint();
  278.         }
  279.     }
  280.  
  281.     /**
  282.      * Gets the URL of the image used when in default states.
  283.      * @return the URL used when in default states
  284.      * @see #setStandardURL
  285.      */
  286.     public URL getStandardURL()
  287.     {
  288.         return StandardURL;
  289.     }
  290.  
  291.     /**
  292.      * Sets the URL of the image to use when the mouse is over the button.
  293.      * @param aUrl the URL to use when the mouse is over the button
  294.      * @see #getOverURL
  295.      */
  296.     public void setOverURL(URL aUrl)
  297.     {
  298.         OverURL = aUrl;
  299.         OverFileName = null;
  300.  
  301.         Image loadedImage = getToolkit().getImage(aUrl);
  302.         if (loadedImage != null) {
  303.             setOverImage(loadedImage);
  304.             repaint();
  305.         }
  306.     }
  307.  
  308.     /**
  309.      * Gets the URL of the image used when the mouse is over the button.
  310.      * @return the URL used when the mouse is over the button
  311.      * @see #setOverURL
  312.      */
  313.     public URL getOverURL()
  314.     {
  315.         return OverURL;
  316.     }
  317.  
  318.     /**
  319.      * Sets the URL of the image to use when the mouse is down while in the button.
  320.      * @param aUrl the URL to use when the mouse is down while in the button
  321.      * @see #getDownURL
  322.      */
  323.     public void setDownURL(URL aUrl)
  324.     {
  325.         DownURL = aUrl;
  326.         DownFileName = null;
  327.  
  328.         Image loadedImage = getToolkit().getImage(aUrl);
  329.         if (loadedImage != null) {
  330.             setDownImage(loadedImage);
  331.             repaint();
  332.         }
  333.     }
  334.  
  335.     /**
  336.      * Gets the URL of the image used when the mouse is down while in the button.
  337.      * @return the URL used when the mouse is down while in the button
  338.      * @see #setDownURL
  339.      */
  340.     public URL getDownURL()
  341.     {
  342.         return DownURL;
  343.     }
  344.         
  345.     /**
  346.      * Sets the image to use when in default states.
  347.      * @param img the Image to use when in default states
  348.      * @see #getStandardImage
  349.      */
  350.     public void setStandardImage(Image img)
  351.     {
  352.         StandardFileName = null;
  353.         StandardImage    = img;
  354.         setImageHelper(StandardImage);
  355.     }
  356.  
  357.     /**
  358.      * Gets the URL of the image used when in default states.
  359.      * @return the Image used when the in default states
  360.      * @see #setStandardImage
  361.      */
  362.     public Image getStandardImage()
  363.     {
  364.         return StandardImage;
  365.     }
  366.  
  367.     /**
  368.      * Sets the image to use when the mouse is over the button.
  369.      * @param img the Image to use when the mouse is over the button
  370.      * @see #getOverImage
  371.      */
  372.     public void setOverImage(Image img)
  373.     {
  374.         OverFileName = null;
  375.         OverImage    = img;
  376.         setImageHelper(OverImage);
  377.     }
  378.  
  379.     /**
  380.      * Gets the URL of the image used when the mouse is over the button.
  381.      * @return the Image used when the mouse is over the button
  382.      * @see #setOverImage
  383.      */
  384.     public Image getOverImage()
  385.     {
  386.         return OverImage;
  387.     }
  388.  
  389.     /**
  390.      * Sets the image to use when the mouse is down while in the button.
  391.      * @param img the Image to use when the mouse is down while in the button
  392.      * @see #getDownImage
  393.      */
  394.     public void setDownImage(Image img)
  395.     {
  396.         DownFileName = null;
  397.         DownImage    = img;
  398.         setImageHelper(DownImage);
  399.     }
  400.  
  401.     /**
  402.      * Gets the URL of the image used when the mouse is down while in the button.
  403.      * @return the Image used when the mouse is down while in the button
  404.      * @see #setDownImage
  405.      */
  406.     public Image getDownImage()
  407.     {
  408.         return DownImage;
  409.     }
  410.  
  411.     /**
  412.      * A function used to consolidate shared code between the three image setting functions.
  413.      * @param img the image to set
  414.      */
  415.     protected void setImageHelper(Image img)
  416.     {
  417.         if (img != null)
  418.         {
  419.             MediaTracker tracker;
  420.  
  421.             try
  422.             {
  423.                 tracker = new MediaTracker(this);
  424.                 tracker.addImage(img, 0);
  425.                 tracker.waitForID(0);
  426.             }
  427.             catch(InterruptedException e){}
  428.         }
  429.         else
  430.         {
  431.             repaint();
  432.         }    
  433.     }
  434.     
  435.     /**
  436.      * Sets the flag to erase before drawing a button state.
  437.      * @param b if true then clear the frame between the different states of the button
  438.      *                     if false then don't clear the frame
  439.      * @see #getClearFrame
  440.      */
  441.     public void setClearFrame(boolean b)
  442.     {
  443.         isClearFrame = b;
  444.     }
  445.     
  446.     /**
  447.      * Gets the flag that determines erasing before drawing a button state.
  448.      * @return if true then the frame will be cleared between the different states of the button,
  449.      *                    if false then the frame will not be cleared
  450.      * @see #setClearFrame
  451.      */
  452.     public boolean getClearFrame()
  453.     {
  454.         return isClearFrame;
  455.     }
  456.  
  457.     /**
  458.      * Sets the URL that determines the link the button will go to on mouse up.
  459.      * @param u the URL that determines the link the button will go to on mouse up
  460.      * @see #getURL
  461.      */
  462.     public void setURL(URL u)
  463.     {
  464.         LinkURL = u;
  465.         context = null;
  466.     }
  467.  
  468.     /**
  469.      * Gets the URL that determines the link the button will go to on mouse up.
  470.      * @return the URL that determines the link the button will go to on mouse up
  471.      * @see #setURL
  472.      */
  473.     public URL getURL()
  474.     {
  475.         return LinkURL;
  476.     }
  477.  
  478.  
  479.     /**
  480.      * Sets the document frame type/name specifier.
  481.      * @param f the new frame type/name specifier
  482.      * @see #getFrame
  483.      * @see #frame
  484.      */
  485.     public void setFrame(String f)
  486.     {
  487.         frame = f;
  488.     }
  489.  
  490.     /**
  491.      * Gets the document frame type/name specifier.
  492.      * @return the current frame type/name specifier
  493.      * @see #setFrame
  494.      * @see #frame
  495.      */
  496.     public String getFrame()
  497.     {
  498.         return frame;
  499.     }
  500.  
  501.     /**
  502.      * Sets the flag to center the image in the bounds of the button.
  503.      * @param b the new center mode. If true then center the image in the 
  504.      * bounds of the button, if false then draw the image at 0,0 relative to 
  505.      * the bounds of the button
  506.      * @see #getCenterMode
  507.      */
  508.     public void setCenterMode(boolean flag)
  509.     {
  510.         isCenterMode = flag;
  511.         invalidate();
  512.     }
  513.  
  514.     /**
  515.      * Gets the flag to center the image in the bounds of the button.
  516.      * @return the current center mode. If true then the image will be 
  517.      * centered in the bounds of the button, if false then the image will 
  518.      * be drawn at 0,0 relative to the bounds of the button.
  519.      * @see #setCenterMode
  520.      */
  521.     public boolean getCenterMode()
  522.     {
  523.         return isCenterMode;
  524.     }
  525.  
  526.     /**
  527.      * Sets the context used to view documents.
  528.      * @param c the new applet context
  529.      */
  530.     protected void setAppletContext(AppletContext c)
  531.     {
  532.         context = c;
  533.     }
  534.  
  535.     /**
  536.      * Paints this component using the given graphics context.
  537.      * This is a standard Java AWT method which typically gets called
  538.      * by the AWT to handle painting this component. It paints this component
  539.      * using the given graphics context. The graphics context clipping region
  540.      * is set to the bounding rectangle of this component and its <0,0>
  541.      * coordinate is this component's top-left corner.
  542.      * 
  543.      * @param g the graphics context used for painting
  544.      * @see java.awt.Component#repaint
  545.      * @see #update
  546.      */
  547.     public void paint(Graphics g)
  548.     {
  549.         Dimension dim = size();
  550.         
  551.         int x, y;
  552.         x = y = 0;
  553.         
  554.         if(isPressed && isMouseOver)
  555.         {
  556.              //Mouse Down Image
  557.             if(DownImage != null)
  558.             {
  559.                 if (isCenterMode)
  560.                 {
  561.                     x += (dim.width - DownImage.getWidth(this)) / 2;
  562.                     y += (dim.height - DownImage.getHeight(this)) / 2;
  563.                 }
  564.                 g.drawImage(DownImage, x, y, this);
  565.             }
  566.         }
  567.         else
  568.         {
  569.             //RollOver Image
  570.             if(isMouseOver && OverImage != null)
  571.             {
  572.                 if (isCenterMode)
  573.                 {
  574.                     x += (dim.width - OverImage.getWidth(this)) / 2;
  575.                     y += (dim.height - OverImage.getHeight(this)) / 2;
  576.                 }
  577.                 g.drawImage(OverImage, x, y, this);
  578.             }
  579.             //Standard Image
  580.             else
  581.             {
  582.                  if (StandardImage == null)
  583.                  {
  584.                      //Draw the standard state as "Transparent"
  585.                      TransparencyTrickUtils.paintComponentsBehind(this, g);
  586.                  }
  587.                  else
  588.                  {
  589.                     if (isCenterMode)
  590.                     {
  591.                         x += (dim.width - StandardImage.getWidth(this)) / 2;
  592.                         y += (dim.height - StandardImage.getHeight(this)) / 2;
  593.                     }
  594.                     g.drawImage(StandardImage, x, y, this);
  595.                 }
  596.             }
  597.         }
  598.     }
  599.  
  600.     /**
  601.      * Processes MOUSE_ENTER events.
  602.      * This is a standard Java AWT method which gets called by the AWT
  603.      * method handleEvent() in response to receiving a MOUSE_ENTER
  604.      * event. These events occur when the mouse first moves over this
  605.      * component.
  606.      * It keeps track of the mouse position relative to the button, and displays the URL Link.
  607.      * 
  608.      * @param e the event
  609.      * @param x the component-relative horizontal coordinate of the mouse
  610.      * @param y the component-relative vertical coordinate of the mouse
  611.      * 
  612.      * @return always true since the event was handled
  613.      * 
  614.      * @see #mouseExit
  615.      * @see java.awt.Component#handleEvent
  616.      */
  617.     public boolean mouseEnter(Event e, int x, int y)
  618.     {
  619.         isMouseOver = true;
  620.         //Display the LinkURL
  621.         if (context != null && LinkURL != null)
  622.         {
  623.             context.showStatus(LinkURL.toString());
  624.         } 
  625.         //Draw the button
  626.         repaint();
  627.     
  628.         return true;
  629.     }
  630.  
  631.     /**
  632.      * Processes MOUSE_EXIT events.
  633.      * This is a standard Java AWT method which gets called by the AWT
  634.      * method handleEvent() in response to receiving a MOUSE_EXIT
  635.      * event. These events occur when the mouse first leaves this 
  636.      * component.
  637.      * It keeps track of the mouse position relative to the button, 
  638.      * and erases the URL Link.
  639.      * 
  640.      * @param e the event
  641.      * @param x the component-relative horizontal coordinate of the mouse
  642.      * @param y the component-relative vertical coordinate of the mouse
  643.      * 
  644.      * @return always true since the event was handled
  645.      * 
  646.      * @see #mouseEnter
  647.      * @see java.awt.Component#handleEvent
  648.      */
  649.     public boolean mouseExit(Event e, int x, int y)
  650.     {
  651.         isMouseOver = false;
  652.         if (context != null && LinkURL != null)
  653.         {
  654.             context.showStatus("");
  655.         } 
  656.         //Draw the button in the standard state
  657.         repaint();
  658.     
  659.         return true;
  660.     }
  661.  
  662.     /**
  663.      * Processes MOUSE_DOWN events.
  664.      * This is a standard Java AWT method which gets called by the AWT
  665.      * method handleEvent() in response to receiving a MOUSE_DOWN
  666.      * event. These events occur when the mouse button is pressed while
  667.      * inside this component.
  668.      * It handles the mouse down event by setting the boolean isPressed.
  669.      * 
  670.      * @param e the event
  671.      * @param x the component-relative horizontal coordinate of the mouse
  672.      * @param y the component-relative vertical coordinate of the mouse
  673.      * 
  674.      * @return always true since the event was handled
  675.      * 
  676.      * @see #mouseUp
  677.      * @see java.awt.Component#handleEvent
  678.      */
  679.     public boolean mouseDown(Event e, int x, int y)
  680.     {
  681.         isPressed = true;
  682.         //Draw the button
  683.         repaint();
  684.     
  685.         return true;
  686.     }
  687.     
  688.     /**
  689.      * Processes MOUSE_UP events.
  690.      * This is a standard Java AWT method which gets called by the AWT
  691.      * method handleEvent() in response to receiving a MOUSE_UP
  692.      * event. These events occur when the mouse button is released while 
  693.      * inside this component.
  694.      * It handles the mouse up event by linking to the LinkURL if it is not null, sets the
  695.      * isPressed boolean, and posts an Action Event.
  696.      * 
  697.      * @param e the event
  698.      * @param x the component-relative horizontal coordinate of the mouse
  699.      * @param y the component-relative vertical coordinate of the mouse
  700.      * 
  701.      * @return always true since the event was handled
  702.      * 
  703.      * @see #mouseDown
  704.      * @see java.awt.Component#handleEvent
  705.      */
  706.     public boolean mouseUp(Event e, int x, int y)
  707.     {
  708.         if (isPressed)
  709.         {
  710.             isPressed = false;
  711.             //Draw the button in the over state.
  712.             repaint();
  713.             //Handle going to the LinkURL
  714.             if (context != null & LinkURL != null)
  715.             {
  716.                 if (frame == null || frame.length() == 0)
  717.                     context.showDocument(LinkURL);
  718.                 else
  719.                     context.showDocument(LinkURL, frame);
  720.             }        
  721.             postEvent(new Event(this, Event.ACTION_EVENT, null));
  722.         }
  723.     
  724.         return true;
  725.     }
  726.  
  727.     /**
  728.      * Processes MOUSE_DRAG events.
  729.      * This is a standard Java AWT method which gets called by the AWT
  730.      * method handleEvent() in response to receiving a MOUSE_DRAG
  731.      * event. These events occur when the mouse is moved around inside this
  732.      * component while the button is pressed.
  733.      * It keeps track of the state of the mouse button while the mouse 
  734.      * position is in the button.
  735.      * 
  736.      * @param e the event
  737.      * @param x the component-relative horizontal coordinate of the mouse
  738.      * @param y the component-relative vertical coordinate of the mouse
  739.      * 
  740.      * @return always true since the event was handled
  741.      * 
  742.      * @see #mouseMove
  743.      * @see java.awt.Component#handleEvent
  744.      */
  745.     public boolean mouseDrag(Event e, int x, int y)
  746.     {
  747.         isMouseDrag = true;
  748.         return true;
  749.     }
  750.     
  751.     /**
  752.      * Processes MOUSE_MOVE events.
  753.      * This is a standard Java AWT method which gets called by the AWT
  754.      * method handleEvent() in response to receiving a MOUSE_MOVE
  755.      * event. These events occur when the mouse is moved around inside this
  756.      * component while the button is NOT pressed.
  757.      * It keeps track of the state of the mouse button while the mouse 
  758.      * position is in the button.
  759.      * 
  760.      * @param e the event
  761.      * @param x the component-relative horizontal coordinate of the mouse
  762.      * @param y the component-relative vertical coordinate of the mouse
  763.      * 
  764.      * @return always true since the event was handled
  765.      * 
  766.      * @see #mouseDrag
  767.      * @see java.awt.Component#handleEvent
  768.      */
  769.     public boolean mouseMove(Event e, int x, int y)
  770.     {
  771.         isMouseDrag = false;
  772.         isPressed = false;
  773.         return true;
  774.     }
  775.     
  776.     /**
  777.      * Handles redrawing of this component on the screen.
  778.      * This is a standard Java AWT method which gets called by the Java
  779.      * AWT (repaint()) to handle repainting this component on the screen.
  780.      * The graphics context clipping region is set to the bounding rectangle
  781.      * of this component and its <0,0> coordinate is this component's 
  782.      * top-left corner.
  783.      * Typically this method paints the background color to clear the
  784.      * component's drawing space, sets graphics context to be the foreground
  785.      * color, and then calls paint() to draw the component.
  786.      *
  787.      * It is overridden here to add the clear frame feature to this button.
  788.      *
  789.      * @param g the graphics context
  790.      * @see java.awt.Component#repaint
  791.      * @see #paint
  792.      */
  793.     public void update(Graphics g)
  794.     {
  795.         if (isClearFrame)
  796.             super.update(g);
  797.         else
  798.             paint(g);
  799.     }
  800.  
  801.     /**
  802.      * Ensures that this component is laid out properly, as needed.
  803.      * This is a standard Java AWT method which gets called by the AWT to 
  804.      * make sure this component and its subcomponents have a valid layout.
  805.      * If this component was made invalid with a call to invalidate(), then 
  806.      * it is laid out again.
  807.      * 
  808.      * It is overridden here to locate the applet containing this component.
  809.      *
  810.      * @see java.awt.Component#invalidate
  811.      */
  812.     public void validate()
  813.     {
  814.         // On validation, try to find the containing applet.  If we can find
  815.         // it, we don't bother doing the link...
  816.         Container c;
  817.  
  818.         c = getParent();
  819.  
  820.         while (c != null)
  821.         {
  822.             if (c instanceof Applet)
  823.             {
  824.                 setAppletContext(((Applet) c).getAppletContext());
  825.                 break;
  826.             }
  827.  
  828.             c = c.getParent();
  829.         }
  830.     }
  831.     
  832.     /**
  833.      * Returns the recommended dimensions to properly display this component.
  834.      * This is a standard Java AWT method which gets called to determine
  835.      * the recommended size of this component. 
  836.      * In this case the recommended size is the minimum dimension needed to 
  837.      * encompass the three images that might be displayed.
  838.      *
  839.      * @see java.awt.Component#minimumSize
  840.      */
  841.     public Dimension preferredSize()
  842.     {
  843.         int iWidth, oWidth, dWidth, maxWidth, iHeight, oHeight, dHeight, maxHeight;
  844.         iWidth    = StandardImage    == null ? 0 : StandardImage.getWidth(this);
  845.         oWidth    = OverImage        == null ? 0 : OverImage.getWidth(this);            
  846.         dWidth    = DownImage        == null ? 0 : DownImage.getWidth(this);            
  847.         iHeight    = StandardImage    == null ? 0 : StandardImage.getHeight(this);
  848.         oHeight    = OverImage        == null ? 0 : OverImage.getHeight(this);
  849.         dHeight    = DownImage        == null ? 0 : DownImage.getHeight(this);
  850.         
  851.         maxWidth    = iWidth >= oWidth ? iWidth : oWidth;
  852.         maxWidth    = maxWidth >= dWidth ? maxWidth : dWidth;
  853.         maxHeight    = iHeight >= oHeight ? iHeight : oHeight;
  854.         maxHeight    = maxHeight >= dHeight ? maxHeight : dHeight;
  855.  
  856.         maxWidth    = maxWidth == 0 ? 10 : maxWidth;
  857.         maxHeight    = maxHeight == 0 ? 10 : maxHeight;
  858.         
  859.         return (new Dimension(maxWidth, maxHeight));
  860.     }
  861. }
  862.