FileDocCategorySizeDatePackage
ImageMapArea.javaAPI DocSun JDK 1.5.0 Example11708Sat Jan 08 15:09:02 GMT 2005None

ImageMapArea

public class ImageMapArea extends Object implements ImageObserver
The base ImageArea class. This class performs the basic functions that most ImageArea classes will need and delegates specific actions to the subclasses.
author
Jim Graham
version
1.17, 07/26/04

Fields Summary
ImageMap
parent
The applet parent that contains this ImageArea.
int
X
The X location of the area (if rectangular).
int
Y
The Y location of the area (if rectangular).
int
W
The size().width of the area (if rectangular).
int
H
The size().height of the area (if rectangular).
boolean
entered
This flag indicates whether the user was in this area during the last scan of mouse locations.
boolean
active
This flag indicates whether the area is currently highlighted.
Image
hlImage
This is the default highlight image if no special effects are needed to draw the highlighted image. It is created by the default "makeImages()" method.
String
status
This is the status string requested by this area. Only the status string from the topmost area which has requested one will be displayed.
Constructors Summary
Methods Summary
public booleananimate()
This method is called every animation cycle if there are any active animating areas.

return
true if this area requires further animation notifications

	return false;
    
public booleancheckEnter(int x, int y)
The checkEnter method is called when the mouse is inside the region to see if the area needs to have its enter method called. The default implementation simply checks if the entered flag is set and only calls enter if it is false.

	if (!entered) {
	    entered = true;
	    enter(x, y);
	}
	return isTerminal();
    
public voidcheckExit()
The checkExit method is called when the mouse is outside the region to see if the area needs to have its exit method called. The default implementation simply checks if the entered flag is set and only calls exit if it is true.

	if (entered) {
	    entered = false;
	    exit();
	}
    
public booleandrag(int x, int y)
The drag method is called when the user moves the mouse while the button is pressed. Only those ImageAreas that were informed of a press will be informed of the corresponding mouse movements.

return
true if this ImageMapArea wants to prevent any underlying areas from seeing the drag

	return isTerminal();
    
public voiddrawImage(java.awt.Graphics g, java.awt.Image img, int imgx, int imgy, int x, int y, int w, int h)
This utility method draws a rectangular subset of a highlight image.

	Graphics ng = g.create();
	try {
	    ng.clipRect(x, y, w, h);
	    ng.drawImage(img, imgx, imgy, this);
	} finally {
	    ng.dispose();
	}
    
public voidenter(int x, int y)
The enter method is called when the mouse enters the region. The location is supplied, but the standard implementation is to call the overloaded method with no arguments.

	enter();
    
public voidenter()
The overloaded enter method is called when the mouse enters the region. This method can be overridden if the ImageArea does not need to know where the mouse entered.

    
public voidexit()
The exit method is called when the mouse leaves the region.

    
public java.lang.StringgetAppletInfo()

    return "Title: ImageArea \nAuthor: Jim Graham \nThis class performs the basic functions that most ImageArea classes will need and delegates specific actions to the subclasses.";
  
public voidgetMedia()
This method loads any additional media that the ImageMapArea may need for its animations.

    
public java.lang.StringgetStatus(java.lang.String prevmsg)
This utility method returns the status string this area wants to put into the status bar. If no previous area (higher in the stacking order) has yet returned a status message, prevmsg will be null and this area will then return its own message, otherwise it will leave the present message alone.

	return (prevmsg == null) ? status : prevmsg;
    
public voidhandleArg(java.lang.String s)
This method handles the remainder of the argument string after the standard initializer has parsed off the 4 rectangular parameters. If the subclass does not override this method, the remainder will be ignored.

    
public voidhighlight(java.awt.Graphics g)
This method highlights the specified area when the user enters it with his mouse. The standard highlight method is to replace the indicated rectangular area of the image with the primary highlighted image.

    
public booleanimageUpdate(java.awt.Image img, int infoflags, int x, int y, int width, int height)
This method handles the updates from drawing the images.

	if (img == hlImage) {
	    return parent.imageUpdate(img, infoflags, x + X, y + Y,
				      width, height);
	} else {
	    return (infoflags & (ALLBITS | ERROR)) == 0;
	}
    
public voidinit(ImageMap parent, java.lang.String args)
Initialize this ImageArea as called from the applet. If the subclass does not override this initializer, then it will perform the basic functions of setting the parent applet and parsing out 4 numbers from the argument string which specify a rectangular region for the ImageArea to act on. The remainder of the argument string is passed to the handleArg() method for more specific handling by the subclass.


                                                                            
          
	this.parent = parent;
	StringTokenizer st = new StringTokenizer(args, ", ");
	X = Integer.parseInt(st.nextToken());
	Y = Integer.parseInt(st.nextToken());
	W = Integer.parseInt(st.nextToken());
	H = Integer.parseInt(st.nextToken());
	if (st.hasMoreTokens()) {
	    handleArg(st.nextToken(","));
	} else {
	    handleArg(null);
	}
	makeImages();
    
public booleaninside(int x, int y)
This method tests to see if a point is inside this ImageArea. The standard method assumes a rectangular area as parsed by the standard initializer. If a more complex area is required then this method will have to be overridden by the subclass.

	return (x >= X && x < (X + W) && y >= Y && y < (Y + H));
    
public booleanisTerminal()
The isTerminal method controls whether events propagate to the areas which lie beneath this one.

return
true if the events should be propagated to the underlying areas.

	return false;
    
public booleanlift(int x, int y)
The lift method is called when the user releases the mouse button. The location is supplied, but the standard implementation is to call the overloaded method with no arguments. Only those ImageAreas that were informed of a press will be informed of the corresponding release.

return
true if this ImageMapArea wants to prevent any underlying areas from seeing the lift

	return lift();
    
public booleanlift()
The overloaded lift method is called when the user releases the mouse button. This method can be overridden if the ImageArea does not need to know the location of the release.

return
true if this ImageMapArea wants to prevent any underlying areas from seeing the lift

	return isTerminal();
    
public voidmakeImages()
This method handles the construction of the various images used to highlight this particular ImageArea when the user interacts with it.

	setHighlight(parent.getHighlight(X, Y, W, H));
    
public booleanpress(int x, int y)
The press method is called when the user presses the mouse button inside the ImageArea. The location is supplied, but the standard implementation is to call the overloaded method with no arguments.

return
true if this ImageMapArea wants to prevent any underlying areas from seeing the press

	return press();
    
public booleanpress()
The overloaded press method is called when the user presses the mouse button inside the ImageArea. This method can be overridden if the ImageArea does not need to know the location of the press.

return
true if this ImageMapArea wants to prevent any underlying areas from seeing the press

	return isTerminal();
    
public voidrepaint()
The repaint method causes the area to be repainted at the next opportunity.

	parent.repaint(0, X, Y, W, H);
    
public voidsetHighlight(java.awt.Image img)
This method sets the image to be used to render the ImageArea when it is highlighted.

	hlImage = img;
    
public voidshowDocument(java.net.URL u)
This utility method tells the browser to visit a URL.

	parent.getAppletContext().showDocument(u);
    
public voidshowStatus(java.lang.String msg)
This utility method records a string to be shown in the status bar.

	status = msg;
	parent.newStatus();