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