}
Connector c1 = (Connector) connectors.get(0);
Connector c2 = (Connector) connectors.get(1);
ConnectionData data = new ConnectionData();
Point center1 = new Point(c1.getLeft() + c1.getWidth()/2, c1.getTop() + c1.getHeight()/2);
Point center2 = new Point(c2.getLeft() + c2.getWidth()/2, c2.getTop() + c2.getHeight()/2);
Point diff = new Point(center2.left - center1.left, center2.top - center1.top);
int leftSign = diff.left >= 0 ? -1 : 1;
int topSign = diff.top >= 0 ? -1 : 1;
//c1 vertical
int top = c1.getHeight()/2;
int left = diff.top != 0 ? top * diff.left / Math.abs(diff.top) : Integer.MAX_VALUE;
top *= -topSign;
if( Math.abs(left) > c1.getWidth()/2 ){
//c1 horizontal
left = c1.getWidth()/2;
top = diff.left != 0 ? left * diff.top / Math.abs(diff.left) : Integer.MAX_VALUE;
left *= -leftSign;
}
data.getPoints().add(new Point(center1.left + left, center1.top + top));
//c2 vertical
top = c2.getHeight()/2;
left = diff.top != 0 ? top * diff.left / Math.abs(diff.top) : Integer.MAX_VALUE;
top *= topSign;
left = -left;
if( Math.abs(left) > c2.getWidth()/2 ){
//c2 horizontal
left = c2.getWidth()/2;
top = diff.left != 0 ? left * diff.top / Math.abs(diff.left) : Integer.MAX_VALUE;
left *= leftSign;
top = -top;
}
data.getPoints().add(new Point(center2.left + left, center2.top + top));
return data;
}