home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / Cdrom / Main / HotSpot.java < prev    next >
Encoding:
Java Source  |  2017-09-21  |  3.5 KB  |  165 lines

  1. package tiongson.expo;
  2.  
  3. import java.net.URL;
  4. import java.awt.*;
  5. import java.applet.Applet;
  6.  
  7. /** HotSpot.class
  8.  *  I grant anyone a royalty-free license
  9.  *  to use this applet or source code for non-commercial 
  10.  *  use ONLY.
  11.  *  
  12.  *  This copyright must be included in any copies of this code.
  13.  * 
  14.  *  All other rigths reserved. Copyright phillip r. tiongson, 1997.
  15.  *  
  16.  *  In other words, if you aren't making money from selling this code
  17.  *  it is fine to use it. If you are making money, please give me some.
  18.  *  thanks, if you want to use it, contact me, 
  19.  *  phillip tiongson, at sdallas@mit.edu.
  20.  *
  21.  *  @author   Phillip R. Tiongson
  22.  *  @version  1.0
  23.  */
  24. class HotSpot extends Object {
  25.             
  26.     boolean absolute = false;
  27.     boolean newBrowser = false;
  28.     boolean sound = false;
  29.     int x = 0;
  30.     int y = 0;
  31.     Rectangle rect = null;
  32.     Polygon poly = null;
  33.     URL href = null;
  34.     Image image = null;
  35.     long startTime = 0;
  36.     int seed = 0;
  37.  
  38.     boolean on = false;
  39.  
  40.     public HotSpot(boolean abs, boolean newB, boolean sound, 
  41.         URL href, Image image, int x, int y, Polygon poly) {
  42.         
  43.         super();
  44.         
  45.         this.absolute = abs;
  46.         this.newBrowser = newB;
  47.         this.sound = sound;
  48.         this.href = href;
  49.         this.image = image;
  50.         this.x = x;
  51.         this.y = y;
  52.         this.poly = poly;
  53.  
  54.         startTime = System.currentTimeMillis();
  55.         seed = Intro.RandomInt(3000);
  56.  
  57.         // System.out.println(this.toString());
  58.         
  59.     }
  60.  
  61.     public HotSpot(boolean abs, boolean newB, boolean sound, 
  62.         URL href, Image image, int x, int y, Rectangle rect) {
  63.  
  64.         super();
  65.         
  66.         this.absolute = abs;
  67.         this.newBrowser = newB;
  68.         this.sound = sound;
  69.         this.href = href;
  70.         this.image = image;
  71.         this.x = x;
  72.         this.y = y;
  73.         this.rect = rect;
  74.         
  75.         //System.out.println(this.toString());
  76.     }
  77.     
  78.     public String toString() {
  79.         
  80.         return ("hotspot: abs:"+absolute+" newB:"+newBrowser+" sound:"+sound+
  81.                 " href:"+href+" image:"+image+" x:"+x+" y:"+y+ " rect:"+rect+
  82.                 " poly:"+poly);
  83.             
  84.     }
  85.     
  86.     public void paint(Graphics g, int offX, int offY, boolean debug) {
  87.     
  88.         if (debug) {
  89.             g.setColor(Color.red);
  90.             
  91.             
  92.             if (poly != null) {
  93.     
  94.                 
  95.                 int number = poly.npoints;
  96.                 int[] localX = new int[number];
  97.                 int[] localY = new int[number];
  98.                 
  99.                 for(int i = 0; i < number; i++) {
  100.                     localX[i] = poly.xpoints[i] + offX;
  101.                     localY[i] = poly.ypoints[i] + offY;
  102.                 }
  103.                 
  104.                 g.fillPolygon(localX, localY, number);
  105.                 
  106.             } 
  107.         
  108.             if (rect != null) {
  109.                 g.fillRect(rect.x+offX, rect.y+offY, rect.width, rect.height);        
  110.             }
  111.         }
  112.             
  113.         if ((image != null) && (on)) {
  114.             if (!absolute) {
  115.                 offX += (int) (20*Math.sin(((startTime-System.currentTimeMillis())*Math.PI)/(5200.0+seed)));
  116.                 offY += (int) (15*Math.sin(((startTime-System.currentTimeMillis())*Math.PI)/(6000.0+seed)));
  117.             }
  118.             g.drawImage(image, x+offX, y+offY, null);
  119.         }
  120.             
  121.     } //paint
  122.     
  123.     public boolean inside(int x, int y) {
  124.     
  125.         //System.out.println("checking inside "+href);
  126.         
  127.         if (poly != null) return poly.inside(x,y);
  128.         if (rect != null) return rect.inside(x,y);
  129.         
  130.         return false;
  131.         
  132.     } // inside
  133.     
  134.     public void openHREF(Applet app) {
  135.     
  136.         if (href == null) return;
  137.     
  138.         if (sound) {
  139.             app.play(href);
  140.             return; 
  141.         }
  142.         
  143.         
  144.         if (newBrowser) {
  145.             java.applet.AppletContext nac = app.getAppletContext();
  146.             nac.showDocument(href, "_top");
  147.         } else {
  148.             java.applet.AppletContext nac = app.getAppletContext();
  149.             nac.showDocument(href); 
  150.         }
  151.         
  152.         return;    
  153.         
  154.     } // openHREF
  155.  
  156.     public void show() {
  157.         on = true;
  158.     }
  159.     
  160.     public void hide() {
  161.         on = false;    
  162.     }
  163.     
  164. }
  165.