home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / LinkArea.java < prev    next >
Text File  |  1997-07-30  |  3KB  |  94 lines

  1. // $Header: z:/admin/metro_examples/java/demo/ImageMap/rcs/LinkArea.java 1.1 1997/02/06 00:30:07 IPGIntel-2 Exp $ 
  2. /*
  3.  * @(#)LinkArea.java    1.6 96/12/06
  4.  *
  5.  * Copyright (c) 1994-1996 Sun Microsystems, Inc. All Rights Reserved.
  6.  *
  7.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  8.  * modify and redistribute this software in source and binary code form,
  9.  * provided that i) this copyright notice and license appear on all copies of
  10.  * the software; and ii) Licensee does not utilize the software in a manner
  11.  * which is disparaging to Sun.
  12.  *
  13.  * This software is provided "AS IS," without a warranty of any kind. ALL
  14.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  15.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  16.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  17.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  18.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  19.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  20.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  21.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  22.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  23.  * POSSIBILITY OF SUCH DAMAGES.
  24.  *
  25.  * This software is not designed or intended for use in on-line control of
  26.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  27.  * the design, construction, operation or maintenance of any nuclear
  28.  * facility. Licensee represents and warrants that it will not use or
  29.  * redistribute the Software for such purposes.
  30.  */
  31.  
  32. import java.awt.Graphics;
  33. import java.net.URL;
  34. import java.net.MalformedURLException;
  35.  
  36. /**
  37.  * The classic "Fetch a URL" ImageArea class.
  38.  * This class extends the basic ImageArea Class to fetch a URL when
  39.  * the user clicks in the area.
  40.  *
  41.  * @author     Jim Graham
  42.  * @version     1.6, 12/06/96
  43.  */
  44. class LinkArea extends ImageMapArea {
  45.     /** The URL to be fetched when the user clicks on this area. */
  46.     URL anchor;
  47.  
  48.     /**
  49.      * The argument string is the URL to be fetched.
  50.      */
  51.     public void handleArg(String arg) {
  52.     try {
  53.         anchor = new URL(parent.getDocumentBase(), arg);
  54.     } catch (MalformedURLException e) {
  55.         anchor = null;
  56.     }
  57.     }
  58.  
  59.     /**
  60.      * The isTerminal method indicates whether events should propagate
  61.      * to the areas underlying this one.
  62.      */
  63.     public boolean isTerminal() {
  64.     return true;
  65.     }
  66.  
  67.     /**
  68.      * The status message area is updated to show the destination URL.
  69.      */
  70.     public void enter() {
  71.     showStatus((anchor != null)
  72.            ? "Go To " + anchor.toExternalForm()
  73.            : null);
  74.     }
  75.  
  76.     /**
  77.      * The status message area is updated to show the destination URL.
  78.      */
  79.     public void exit() {
  80.     showStatus(null);
  81.     }
  82.  
  83.     /**
  84.      * The new URL is fetched when the user releases the mouse button
  85.      * only if they are still in the area.
  86.      */
  87.     public boolean lift(int x, int y) {
  88.     if (inside(x, y) && anchor != null) {
  89.         showDocument(anchor);
  90.     }
  91.     return true;
  92.     }
  93. }
  94.