01: package net.xoetrope.swing;
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-2003</p>
14: */
15: public class XImageMap extends XHotspotImage {
16: protected boolean drawHotspots;
17: protected Vector linePoints;
18:
19: public XImageMap() {
20: linePoints = new Vector();
21: }
22:
23: public void addPoint(Point pt) {
24: linePoints.addElement(pt);
25: }
26:
27: public void addPoint(int x, int y) {
28: linePoints.addElement(new Point(x, y));
29: }
30:
31: public void paintComponent(Graphics g) {
32: Enumeration e = linePoints.elements();
33: g.setColor(Color.red);
34: Point startPt = null;
35: if (e.hasMoreElements())
36: startPt = (Point) e.nextElement();
37: while (e.hasMoreElements()) {
38: Point endPt = (Point) e.nextElement();
39: g.drawLine(startPt.x, startPt.y, endPt.x, endPt.y);
40: g.drawLine(startPt.x - 1, startPt.y - 1, endPt.x - 1,
41: endPt.y - 1);
42: g.drawLine(startPt.x + 1, startPt.y + 1, endPt.x + 1,
43: endPt.y + 1);
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: startPt = endPt;
49: }
50:
51: if (drawHotspots) {
52: int numHotspots = hotspots.size();
53: g.setColor(Color.darkGray);
54: for (int i = 0; i < numHotspots; i++) {
55: Polygon poly = (Polygon) hotspots.elementAt(i);
56: g.drawPolygon(poly);
57: }
58: }
59: }
60:
61: /**
62: * Set the flag controlling rendering of the hotspots. When turned on a line
63: * is drawn to show the edges of the hotspots
64: * @param draw true to render the hotspots
65: */
66: public void setDrawHotspots(boolean draw) {
67: drawHotspots = draw;
68: }
69:
70: /**
71: * Get the flag controlling rendering of the hotspots.
72: * @return true if the hotspots are rendered
73: */
74: public boolean getDarHotspots() {
75: return drawHotspots;
76: }
77: }
|