01: import java.awt.BasicStroke;
02: import java.awt.Graphics2D;
03: import java.awt.Shape;
04: import java.awt.geom.GeneralPath;
05: import java.awt.geom.Line2D;
06: import java.awt.geom.Point2D;
07: import java.awt.geom.Rectangle2D;
08:
09: /**
10: A class that supplies convenience implementations for
11: a number of methods in the Edge interface type.
12: */
13: public abstract class AbstractEdge implements Edge
14: {
15: public Object clone()
16: {
17: try
18: {
19: return super.clone();
20: }
21: catch (CloneNotSupportedException exception)
22: {
23: return null;
24: }
25: }
26:
27: public void connect(Node s, Node e)
28: {
29: start = s;
30: end = e;
31: }
32:
33: public Node getStart()
34: {
35: return start;
36: }
37:
38: public Node getEnd()
39: {
40: return end;
41: }
42:
43: public Rectangle2D getBounds(Graphics2D g2)
44: {
45: Line2D conn = getConnectionPoints();
46: Rectangle2D r = new Rectangle2D.Double();
47: r.setFrameFromDiagonal(conn.getX1(), conn.getY1(),
48: conn.getX2(), conn.getY2());
49: return r;
50: }
51:
52: public Line2D getConnectionPoints()
53: {
54: Rectangle2D startBounds = start.getBounds();
55: Rectangle2D endBounds = end.getBounds();
56: Point2D startCenter = new Point2D.Double(
57: startBounds.getCenterX(), startBounds.getCenterY());
58: Point2D endCenter = new Point2D.Double(
59: endBounds.getCenterX(), endBounds.getCenterY());
60: return new Line2D.Double(
61: start.getConnectionPoint(endCenter),
62: end.getConnectionPoint(startCenter));
63: }
64:
65: private Node start;
66: private Node end;
67: }