private Map<Connection, BendConstraint> constraints = Maps.newHashMap();
@Override
public void route(final Connection connection) {
PointList points = connection.getPoints();
points.removeAllPoints();
Point startPoint = getStartPoint(connection);
connection.translateToRelative(startPoint);
points.addPoint(startPoint);
Point endPoint = getEndPoint(connection);
connection.translateToRelative(endPoint);
Object constraint = getConstraint(connection);
if (constraint instanceof BendConstraint) {
int dx = Integer.signum(endPoint.x - startPoint.x) * ILayoutConstants.connectionRadius();
int dy = Integer.signum(endPoint.y - startPoint.y) * ILayoutConstants.connectionRadius();
// can be simplified but becomes unreadable
if (((BendConstraint) constraint).isConvex()) {
if (((BendConstraint) constraint).isStart()) {
points.addPoint(startPoint.x - dx, startPoint.y + dy);
points.addPoint(startPoint.x - dx, endPoint.y - dy);
points.addPoint(startPoint.x , endPoint.y);
} else {
points.addPoint(endPoint.x, startPoint.y);
points.addPoint(endPoint.x + dx, startPoint.y + dy);
points.addPoint(endPoint.x + dx, endPoint.y - dy);
}
} else {
if (((BendConstraint) constraint).isStart()) {
points.addPoint(startPoint.x + dx, startPoint.y + dy);
points.addPoint(startPoint.x + dx, endPoint.y - dy);
points.addPoint(startPoint.x + 2 * dx, endPoint.y);
} else {
points.addPoint(endPoint.x - 2 * dx, startPoint.y);
points.addPoint(endPoint.x - dx, startPoint.y + dy);
points.addPoint(endPoint.x - dx, endPoint.y - dy);
}
}
}
points.addPoint(endPoint);
connection.setPoints(points);
}