home *** CD-ROM | disk | FTP | other *** search
/ Java Interactive Reference Guide / Java Interactive Reference Guide.iso / autorun / source.dir / 00090_15.txt < prev    next >
Encoding:
Text File  |  1980-01-11  |  3.0 KB  |  95 lines

  1. /*
  2.  * @(#)LinkArea.java    1.3 95/10/13  
  3.  *
  4.  * Copyright (c) 1994-1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
  8.  * without fee is hereby granted. 
  9.  * Please refer to the file http://java.sun.com/copy_trademarks.html
  10.  * for further important copyright and trademark information and to
  11.  * http://java.sun.com/licensing.html for further important licensing
  12.  * information for the Java (tm) Technology.
  13.  * 
  14.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  15.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  18.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  19.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  20.  * 
  21.  * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
  22.  * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
  23.  * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
  24.  * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
  25.  * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
  26.  * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
  27.  * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  SUN
  28.  * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
  29.  * HIGH RISK ACTIVITIES.
  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.3, 10/13/95
  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 boolean enter() {
  71.     showStatus((anchor != null)
  72.            ? "Go To " + anchor.toExternalForm()
  73.            : null);
  74.     return true;
  75.     }
  76.  
  77.     /**
  78.      * The status message area is updated to show the destination URL.
  79.      */
  80.     public void exit() {
  81.     showStatus(null);
  82.     }
  83.  
  84.     /**
  85.      * The new URL is fetched when the user releases the mouse button
  86.      * only if they are still in the area.
  87.      */
  88.     public boolean lift(int x, int y) {
  89.     if (inside(x, y) && anchor != null) {
  90.         showDocument(anchor);
  91.     }
  92.     return true;
  93.     }
  94. }
  95.