ImageMappublic class ImageMap extends Applet implements RunnableAn extensible ImageMap applet class.
The active areas on the image are controlled by ImageArea classes
that can be dynamically loaded over the net. |
Fields Summary |
---|
Image | baseImageThe unhighlighted image being mapped. | ImageMapArea[] | areasThe list of image area handling objects; | static final int | BRIGHTERThe primary highlight mode to be used. | static final int | DARKER | int | hlmode | int | hlpercentThe percentage of highlight to apply for the primary highlight mode. | MediaTracker | trackerThe MediaTracker for loading and constructing the various images. | Thread | aniThread | String | introTune | private boolean | fullrepaint | private static final long | UPDATERATE | int | pressX | int | pressY |
Methods Summary |
---|
void | addImage(java.awt.Image img)Add an image to the list of images to be tracked.
tracker.addImage(img, 1);
| void | checkSize()Check the size of this applet while the image is being loaded.
int w = baseImage.getWidth(this);
int h = baseImage.getHeight(this);
if (w > 0 && h > 0) {
resize(w, h);
synchronized(this) {
fullrepaint = true;
}
repaint(0, 0, w, h);
}
| java.awt.Image | getHighlight(int x, int y, int w, int h)Get a rectangular region of the baseImage highlighted according to
the primary highlight specification.
return getHighlight(x, y, w, h, hlmode, hlpercent);
| java.awt.Image | getHighlight(int x, int y, int w, int h, int mode, int percent)Get a rectangular region of the baseImage with a specific highlight.
return getHighlight(x, y, w, h, new HighlightFilter(mode == BRIGHTER,
percent));
| java.awt.Image | getHighlight(int x, int y, int w, int h, java.awt.image.ImageFilter filter)Get a rectangular region of the baseImage modified by an image filter.
ImageFilter cropfilter = new CropImageFilter(x, y, w, h);
ImageProducer prod = new FilteredImageSource(baseImage.getSource(),
cropfilter);
return makeImage(prod, filter, 0);
| public boolean | imageUpdate(java.awt.Image img, int infoflags, int x, int y, int width, int height)Handle updates from images being loaded.
if ((infoflags & (WIDTH | HEIGHT)) != 0) {
checkSize();
}
if ((infoflags & (SOMEBITS | FRAMEBITS | ALLBITS)) != 0) {
synchronized(this) {
fullrepaint = true;
}
repaint(((infoflags & (FRAMEBITS | ALLBITS)) != 0)
? 0 : UPDATERATE,
x, y, width, height);
}
return (infoflags & (ALLBITS | ERROR)) == 0;
| public void | init()Initialize the applet. Get attributes.
Initialize the ImageAreas.
Each ImageArea is a subclass of the class ImageArea, and is
specified with an attribute of the form:
areaN=ImageAreaClassName,arguments...
The ImageAreaClassName is parsed off and a new instance of that
class is created. The initializer for that class is passed a
reference to the applet and the remainder of the attribute
string, from which the class should retrieve any information it
needs about the area it controls and the actions it needs to
take within that area.
String s;
tracker = new MediaTracker(this);
parseHighlight(getParameter("highlight"));
introTune = getParameter("startsound");
baseImage = getImage(getDocumentBase(), getParameter("img"));
Vector areaVec = new Vector();
int num = 1;
while (true) {
ImageMapArea newArea;
s = getParameter("area"+num);
if (s == null) {
// Try rect for backwards compatibility.
s = getParameter("rect"+num);
if (s == null) {
break;
}
try {
newArea = new HighlightArea();
newArea.init(this, s);
areaVec.addElement(newArea);
String url = getParameter("href"+num);
if (url != null) {
s += "," + url;
newArea = new LinkArea();
newArea.init(this, s);
areaVec.addElement(newArea);
}
} catch (Exception e) {
System.out.println("error processing: "+s);
e.printStackTrace();
break;
}
} else {
try {
int classend = s.indexOf(",");
String name = s.substring(0, classend);
newArea = (ImageMapArea) Class.forName(name).newInstance();
s = s.substring(classend+1);
newArea.init(this, s);
areaVec.addElement(newArea);
} catch (Exception e) {
System.out.println("error processing: "+s);
e.printStackTrace();
break;
}
}
num++;
}
areas = new ImageMapArea[areaVec.size()];
areaVec.copyInto(areas);
checkSize();
| java.awt.Image | makeImage(java.awt.Image orig, java.awt.image.ImageFilter filter)Make a filtered image based on another image.
return makeImage(orig.getSource(), filter);
| java.awt.Image | makeImage(java.awt.image.ImageProducer prod, java.awt.image.ImageFilter filter)Make a filtered image based on another ImageProducer.
return makeImage(prod, filter,
(prod == baseImage.getSource()) ? 1 : 0);
| java.awt.Image | makeImage(java.awt.image.ImageProducer prod, java.awt.image.ImageFilter filter, int ID)Make a filtered image based on another ImageProducer.
Add it to the media tracker using the indicated ID.
Image filtered = createImage(new FilteredImageSource(prod, filter));
tracker.addImage(filtered, ID);
return filtered;
| public boolean | mouseDown(java.awt.Event evt, int x, int y)Inform all active ImageAreas of a mouse press.
pressX = x;
pressY = y;
for (int i = 0; i < areas.length; i++) {
if (areas[i].inside(x, y)) {
if (areas[i].press(x, y)) {
break;
}
}
}
return true;
| public boolean | mouseDrag(java.awt.Event evt, int x, int y)Inform all active ImageAreas of a mouse drag.
Only those areas that were inside the original mouseDown()
are informed of the mouseUp.
mouseMove(evt, x, y);
for (int i = 0; i < areas.length; i++) {
if (areas[i].inside(pressX, pressY)) {
if (areas[i].drag(x, y)) {
break;
}
}
}
return true;
| public boolean | mouseExit(java.awt.Event evt, int x, int y)Make sure that no ImageAreas are highlighted.
for (int i = 0; i < areas.length; i++) {
areas[i].checkExit();
}
return true;
| public boolean | mouseMove(java.awt.Event evt, int x, int y)Find the ImageAreas that the mouse is in.
boolean eaten = false;
for (int i = 0; i < areas.length; i++) {
if (!eaten && areas[i].inside(x, y)) {
eaten = areas[i].checkEnter(x, y);
} else {
areas[i].checkExit();
}
}
return true;
| public boolean | mouseUp(java.awt.Event evt, int x, int y)Inform all active ImageAreas of a mouse release.
Only those areas that were inside the original mouseDown()
are informed of the mouseUp.
for (int i = 0; i < areas.length; i++) {
if (areas[i].inside(pressX, pressY)) {
if (areas[i].lift(x, y)) {
break;
}
}
}
return true;
| public void | newStatus()Scan all areas looking for the topmost status string.
String msg = null;
for (int i = 0; i < areas.length; i++) {
msg = areas[i].getStatus(msg);
}
showStatus(msg);
| public void | paint(java.awt.Graphics g)Paint the image and all active highlights.
synchronized(this) {
fullrepaint = false;
}
if (baseImage == null) {
return;
}
g.drawImage(baseImage, 0, 0, this);
if (areas != null) {
for (int i = areas.length; --i >= 0; ) {
areas[i].highlight(g);
}
}
| void | parseHighlight(java.lang.String s)Parse a string representing the desired highlight to be applied.
if (s == null) {
return;
}
if (s.startsWith("brighter")) {
hlmode = BRIGHTER;
if (s.length() > "brighter".length()) {
hlpercent = Integer.parseInt(s.substring("brighter".length()));
}
} else if (s.startsWith("darker")) {
hlmode = DARKER;
if (s.length() > "darker".length()) {
hlpercent = Integer.parseInt(s.substring("darker".length()));
}
}
| public void | run()
Thread me = Thread.currentThread();
tracker.checkAll(true);
for (int i = areas.length; --i >= 0; ) {
areas[i].getMedia();
}
me.setPriority(Thread.MIN_PRIORITY);
while (aniThread == me) {
boolean animating = false;
for (int i = areas.length; --i >= 0; ) {
animating = areas[i].animate() || animating;
}
try {
synchronized(this) {
wait(animating ? 100 : 0);
}
} catch (InterruptedException e) {
break;
}
}
| public void | start()
if (introTune != null)
try {
play(new URL(getDocumentBase(), introTune));
} catch (MalformedURLException e) {}
if (aniThread == null) {
aniThread = new Thread(this);
aniThread.setName("ImageMap Animator");
aniThread.start();
}
| public synchronized void | startAnimation()
notify();
| public synchronized void | stop()
aniThread = null;
notify();
for (int i = 0; i < areas.length; i++) {
areas[i].exit();
}
| public void | update(java.awt.Graphics g)Update the active highlights on the image.
boolean full;
synchronized(this) {
full = fullrepaint;
}
if (full) {
paint(g);
return;
}
if (baseImage == null) {
return;
}
g.drawImage(baseImage, 0, 0, this);
if (areas == null) {
return;
}
// First unhighlight all of the deactivated areas
for (int i = areas.length; --i >= 0; ) {
areas[i].highlight(g);
}
|
|