HotSpot.java

See also Intro.java, HotSpot_readme

package tiongson.expo;

import java.net.URL;
import java.awt.*;
import java.applet.Applet;

/** HotSpot.class
 *  I grant anyone a royalty-free license
 *  to use this applet or source code for non-commercial 
 *  use ONLY.
 *  
 *  This copyright must be included in any copies of this code.
 * 
 *  All other rigths reserved. Copyright phillip r. tiongson, 1997.
 *  
 *  In other words, if you aren't making money from selling this code
 *  it is fine to use it. If you are making money, please give me some.
 *  thanks, if you want to use it, contact me, 
 *  phillip tiongson, at sdallas@mit.edu.
 *
 *  @author   Phillip R. Tiongson
 *  @version  1.0
 */
class HotSpot extends Object {
			
	boolean absolute = false;
	boolean newBrowser = false;
	boolean sound = false;
	int x = 0;
	int y = 0;
	Rectangle rect = null;
	Polygon poly = null;
	URL href = null;
	Image image = null;
	long startTime = 0;
	int seed = 0;

	boolean on = false;

	public HotSpot(boolean abs, boolean newB, boolean sound, 
		URL href, Image image, int x, int y, Polygon poly) {
		
		super();
		
		this.absolute = abs;
		this.newBrowser = newB;
		this.sound = sound;
		this.href = href;
		this.image = image;
		this.x = x;
		this.y = y;
		this.poly = poly;

		startTime = System.currentTimeMillis();
		seed = Intro.RandomInt(3000);

		// System.out.println(this.toString());
		
	}

	public HotSpot(boolean abs, boolean newB, boolean sound, 
		URL href, Image image, int x, int y, Rectangle rect) {

		super();
		
		this.absolute = abs;
		this.newBrowser = newB;
		this.sound = sound;
		this.href = href;
		this.image = image;
		this.x = x;
		this.y = y;
		this.rect = rect;
		
		//System.out.println(this.toString());
	}
	
	public String toString() {
		
		return ("hotspot: abs:"+absolute+" newB:"+newBrowser+" sound:"+sound+
				" href:"+href+" image:"+image+" x:"+x+" y:"+y+ " rect:"+rect+
				" poly:"+poly);
			
	}
	
	public void paint(Graphics g, int offX, int offY, boolean debug) {
	
		if (debug) {
			g.setColor(Color.red);
			
			
			if (poly != null) {
	
				
				int number = poly.npoints;
				int[] localX = new int[number];
				int[] localY = new int[number];
				
				for(int i = 0; i < number; i++) {
					localX[i] = poly.xpoints[i] + offX;
					localY[i] = poly.ypoints[i] + offY;
				}
				
				g.fillPolygon(localX, localY, number);
				
			} 
		
			if (rect != null) {
				g.fillRect(rect.x+offX, rect.y+offY, rect.width, rect.height);		
			}
		}
			
		if ((image != null) && (on)) {
			if (!absolute) {
				offX += (int) (20*Math.sin(((startTime-System.currentTimeMillis())*Math.PI)/(5200.0+seed)));
				offY += (int) (15*Math.sin(((startTime-System.currentTimeMillis())*Math.PI)/(6000.0+seed)));
			}
			g.drawImage(image, x+offX, y+offY, null);
		}
			
	} //paint
	
	public boolean inside(int x, int y) {
	
		//System.out.println("checking inside "+href);
		
		if (poly != null) return poly.inside(x,y);
		if (rect != null) return rect.inside(x,y);
		
		return false;
		
	} // inside
	
	public void openHREF(Applet app) {
	
		if (href == null) return;
	
		if (sound) {
			app.play(href);
			return; 
		}
		
		
		if (newBrowser) {
			java.applet.AppletContext nac = app.getAppletContext();
			nac.showDocument(href, "_top");
		} else {
			java.applet.AppletContext nac = app.getAppletContext();
			nac.showDocument(href); 
		}
		
		return;	
		
	} // openHREF

	public void show() {
		on = true;
	}
	
	public void hide() {
		on = false;	
	}
	
}