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