01: import java.awt.*;
02: import java.awt.geom.*;
03: 
04: /**
05:    A class that assumes that an edge can yield its shape
06:    as a general path, and then takes advantage of the fact
07:    that containment testing can be done by fattening the
08:    general path.
09: */
10: abstract class GeneralPathEdge extends AbstractEdge
11: {  
12:    /**
13:       Returns the path that should be stroked to
14:       draw this edge. The path does not include
15:       arrow tips or labels.
16:       @return a path along the edge
17:    */
18:    public abstract GeneralPath getPath();
19: 
20:    public boolean contains(Point2D aPoint)
21:    {
22:       final double MAX_DIST = 3;
23: 
24:       // the end points may contain small nodes, so don't
25:       // match them
26:       Line2D conn = getConnectionPoints();
27:       if (aPoint.distance(conn.getP1()) <= MAX_DIST 
28:          || aPoint.distance(conn.getP2()) <= MAX_DIST)
29:          return false;
30: 
31:       GeneralPath p = getPath();
32:       BasicStroke fatStroke = new BasicStroke(
33:          (float)(2 * MAX_DIST));
34:       Shape fatPath = fatStroke.createStrokedShape(p);
35:       return fatPath.contains(aPoint);
36:    }
37: }