01: package net.xoetrope.awt;
02:
03: import java.util.Enumeration;
04: import java.util.Vector;
05:
06: import java.awt.Color;
07: import java.awt.Graphics;
08: import java.awt.Point;
09: import java.awt.Polygon;
10:
11: /**
12: * <p>Description: </p>
13: * <p>Copyright (c) Xoetrope Ltd., 1998-2004<br>
14: * License: see license.txt
15: * $Revision: 1.5 $
16: */
17: public class XImageMap extends XHotspotImage {
18: protected Vector linePoints;
19: protected boolean drawHotspots;
20:
21: public XImageMap() {
22: linePoints = new Vector();
23: drawHotspots = false;
24: }
25:
26: public void addPoint(Point pt) {
27: linePoints.addElement(pt);
28: }
29:
30: public void addPoint(int x, int y) {
31: linePoints.addElement(new Point(x, y));
32: }
33:
34: public void paint(Graphics g) {
35: super .paint(g);
36: Enumeration e = linePoints.elements();
37: g.setColor(Color.red);
38: Point startPt = null;
39: if (e.hasMoreElements())
40: startPt = (Point) e.nextElement();
41: while (e.hasMoreElements()) {
42: Point endPt = (Point) e.nextElement();
43: g.drawLine(startPt.x, startPt.y, endPt.x, endPt.y);
44: g.drawLine(startPt.x - 1, startPt.y - 1, endPt.x - 1,
45: endPt.y - 1);
46: g.drawLine(startPt.x + 1, startPt.y + 1, endPt.x + 1,
47: endPt.y + 1);
48: g.drawLine(startPt.x + 1, startPt.y - 1, endPt.x + 1,
49: endPt.y - 1);
50: g.drawLine(startPt.x - 1, startPt.y + 1, endPt.x - 1,
51: endPt.y + 1);
52: startPt = endPt;
53: }
54:
55: if (drawHotspots) {
56: int numHotspots = hotspots.size();
57: g.setColor(Color.darkGray);
58: for (int i = 0; i < numHotspots; i++) {
59: Polygon poly = (Polygon) hotspots.elementAt(i);
60: g.drawPolygon(poly);
61: }
62: }
63: }
64:
65: /**
66: * Set the flag controlling rendering of the hotspots. When turned on a line
67: * is drawn to show the edges of the hotspots
68: * @param draw true to render the hotspots
69: */
70: public void setDrawHotspots(boolean draw) {
71: drawHotspots = draw;
72: }
73:
74: /**
75: * Get the flag controlling rendering of the hotspots.
76: * @return true if the hotspots are rendered
77: */
78: public boolean getDarHotspots() {
79: return drawHotspots;
80: }
81: }
|