    01: import java.awt.*;
    02: import java.awt.geom.*;
    03:
    04: /**
    05:    A class that supplies convenience implementations for
    06:    a number of methods in the Edge interface type.
    07: */
    08: public abstract class AbstractEdge implements Edge
    09: {
    10:    public Object clone()
    11:    {
    12:       try
    13:       {
    14:          return super.clone();
    15:       }
    16:       catch (CloneNotSupportedException exception)
    17:       {
    18:          return null;
    19:       }
    20:    }
    21:
    22:    public void connect(Node s, Node e)
    23:    {
    24:       start = s;
    25:       end = e;
    26:    }
    27:
    28:    public Node getStart()
    29:    {
    30:       return start;
    31:    }
    32:
    33:    public Node getEnd()
    34:    {
    35:       return end;
    36:    }
    37:
    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:    }
    46:
    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:    }
    59:
    60:    private Node start;
    61:    private Node end;
    62: }