home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / windows / java / demo / imagemap / highlightarea.java < prev    next >
Encoding:
Java Source  |  1996-04-26  |  2.8 KB  |  93 lines

  1. /*
  2.  * @(#)HighlightArea.java    1.4 96/04/24  
  3.  *
  4.  * Copyright (c) 1994-1996 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.  * An area highlighting ImageArea class.
  38.  * This class extends the basic ImageArea Class to highlight an area of
  39.  * the base image when the mouse enters the area.
  40.  *
  41.  * @author     Jim Graham
  42.  * @version     1.4, 04/24/96
  43.  */
  44. class HighlightArea extends ImageMapArea {
  45.     int hlmode;
  46.     int hlpercent;
  47.  
  48.     /**
  49.      * The argument string is the highlight mode to be used.
  50.      */
  51.     public void handleArg(String arg) {
  52.     if (arg == null) {
  53.         hlmode = parent.hlmode;
  54.         hlpercent = parent.hlpercent;
  55.     } else {
  56.         if (arg.startsWith("darker")) {
  57.         hlmode = parent.DARKER;
  58.         arg = arg.substring("darker".length());
  59.         } else {
  60.         hlmode = parent.BRIGHTER;
  61.         if (arg.startsWith("brighter")) {
  62.             arg = arg.substring("brighter".length());
  63.         }
  64.         }
  65.         hlpercent = Integer.parseInt(arg);
  66.     }
  67.     }
  68.  
  69.     public void makeImages() {
  70.     setHighlight(parent.getHighlight(X, Y, W, H, hlmode, hlpercent));
  71.     }
  72.  
  73.     public void highlight(Graphics g) {
  74.     if (entered) {
  75.         g.drawImage(hlImage, X, Y, this);
  76.     }
  77.     }
  78.  
  79.     /**
  80.      * The area is repainted when the mouse enters.
  81.      */
  82.     public void enter() {
  83.     repaint();
  84.     }
  85.  
  86.     /**
  87.      * The area is repainted when the mouse leaves.
  88.      */
  89.     public void exit() {
  90.     repaint();
  91.     }
  92. }
  93.