/** Tell the connector to route itself between the
* current positions of the head and tail sites.
*/
public void route() {
TransformContext currentContext = getTransformContext();
Site headSite = getHeadSite();
Site tailSite = getTailSite();
Point2D headPt;
Point2D tailPt;
repaint();
// Get the transformed head and tail points. Sometimes
// people will call this before the connector is added
// to a container, so deal with it
if (currentContext != null) {
tailPt = tailSite.getPoint(currentContext);
headPt = headSite.getPoint(currentContext);
} else {
tailPt = tailSite.getPoint();
headPt = headSite.getPoint();
}
// Figure out the centers of the attached figures
Point2D tailCenter;
// Figure out the centers of the attached figures
Point2D headCenter;
if (tailSite.getFigure() != null) {
tailCenter = CanvasUtilities.getCenterPoint(tailSite.getFigure(),
currentContext);
} else {
tailCenter = tailPt;
}
if (headSite.getFigure() != null) {
headCenter = CanvasUtilities.getCenterPoint(headSite.getFigure(),
currentContext);
} else {
headCenter = headPt;
}
// Figure out the normal at the line ends.
double x = headCenter.getX() - tailCenter.getX();
double y = headCenter.getY() - tailCenter.getY();
double angle = Math.atan2(y, x);
// Tell the sites to adjust their positions
tailSite.setNormal(angle);
headSite.setNormal(angle - Math.PI);
// Recompute the head and tail points
if (currentContext != null) {
tailPt = tailSite.getPoint(currentContext);
headPt = headSite.getPoint(currentContext);
} else {
tailPt = tailSite.getPoint();
headPt = headSite.getPoint();
}
// Remember these points for the label
this._headPt = headPt;