Map<AnchorLocation, BoundaryAnchor> targetBoundaryAnchors = getBoundaryAnchors(target);
if (connection instanceof FreeFormConnectionImpl) {
EList<Point> bendpoints = ((FreeFormConnectionImpl) connection).getBendpoints();
if (bendpoints.size() > 0) {
FixPointAnchor sourceAnchor = getCorrectAnchor(sourceBoundaryAnchors, bendpoints.get(0));
FixPointAnchor targetAnchor = getCorrectAnchor(targetBoundaryAnchors,
bendpoints.get(bendpoints.size() - 1));
return new Tuple<FixPointAnchor, FixPointAnchor>(sourceAnchor, targetAnchor);
}
}
BoundaryAnchor sourceTop = sourceBoundaryAnchors.get(AnchorLocation.TOP);
BoundaryAnchor sourceBottom = sourceBoundaryAnchors.get(AnchorLocation.BOTTOM);
BoundaryAnchor sourceLeft = sourceBoundaryAnchors.get(AnchorLocation.LEFT);
BoundaryAnchor sourceRight = sourceBoundaryAnchors.get(AnchorLocation.RIGHT);
BoundaryAnchor targetBottom = targetBoundaryAnchors.get(AnchorLocation.BOTTOM);
BoundaryAnchor targetTop = targetBoundaryAnchors.get(AnchorLocation.TOP);
BoundaryAnchor targetRight = targetBoundaryAnchors.get(AnchorLocation.RIGHT);
BoundaryAnchor targetLeft = targetBoundaryAnchors.get(AnchorLocation.LEFT);
boolean sLower = sourceTop.location.getY() > targetBottom.location.getY();
boolean sHigher = sourceBottom.location.getY() < targetTop.location.getY();
boolean sRight = sourceLeft.location.getX() > targetRight.location.getX();
boolean sLeft = sourceRight.location.getX() < targetLeft.location.getX();
if (sLower) {
if (!sLeft && !sRight) {
return new Tuple<FixPointAnchor, FixPointAnchor>(sourceTop.anchor, targetBottom.anchor);
} else if (sLeft) {
FixPointAnchor fromTopAnchor = getCorrectAnchor(targetBoundaryAnchors,
peService.getLocationRelativeToDiagram(sourceTop.anchor));
FixPointAnchor fromRightAnchor = getCorrectAnchor(targetBoundaryAnchors,
peService.getLocationRelativeToDiagram(sourceRight.anchor));
double topLength = getLength(peService.getLocationRelativeToDiagram(fromTopAnchor),
peService.getLocationRelativeToDiagram(sourceTop.anchor));
double rightLength = getLength(peService.getLocationRelativeToDiagram(fromRightAnchor),
peService.getLocationRelativeToDiagram(sourceRight.anchor));
if (topLength < rightLength) {
return new Tuple<FixPointAnchor, FixPointAnchor>(sourceTop.anchor, fromTopAnchor);
} else {
return new Tuple<FixPointAnchor, FixPointAnchor>(sourceRight.anchor, fromRightAnchor);
}
} else {
FixPointAnchor fromTopAnchor = getCorrectAnchor(targetBoundaryAnchors,
peService.getLocationRelativeToDiagram(sourceTop.anchor));
FixPointAnchor fromLeftAnchor = getCorrectAnchor(targetBoundaryAnchors,
peService.getLocationRelativeToDiagram(sourceLeft.anchor));
double topLength = getLength(peService.getLocationRelativeToDiagram(fromTopAnchor),
peService.getLocationRelativeToDiagram(sourceTop.anchor));
double leftLength = getLength(peService.getLocationRelativeToDiagram(fromLeftAnchor),
peService.getLocationRelativeToDiagram(sourceLeft.anchor));
if (topLength < leftLength) {
return new Tuple<FixPointAnchor, FixPointAnchor>(sourceTop.anchor, fromTopAnchor);
} else {
return new Tuple<FixPointAnchor, FixPointAnchor>(sourceLeft.anchor, fromLeftAnchor);
}
}
}
if (sHigher) {
if (!sLeft && !sRight) {
return new Tuple<FixPointAnchor, FixPointAnchor>(sourceBottom.anchor, targetTop.anchor);
} else if (sLeft) {
FixPointAnchor fromBottomAnchor = getCorrectAnchor(targetBoundaryAnchors,
peService.getLocationRelativeToDiagram(sourceBottom.anchor));
FixPointAnchor fromRightAnchor = getCorrectAnchor(targetBoundaryAnchors,
peService.getLocationRelativeToDiagram(sourceRight.anchor));
double bottomLength = getLength(peService.getLocationRelativeToDiagram(fromBottomAnchor),
peService.getLocationRelativeToDiagram(sourceBottom.anchor));
double rightLength = getLength(peService.getLocationRelativeToDiagram(fromRightAnchor),
peService.getLocationRelativeToDiagram(sourceRight.anchor));
if (bottomLength < rightLength) {
return new Tuple<FixPointAnchor, FixPointAnchor>(sourceBottom.anchor, fromBottomAnchor);
} else {
return new Tuple<FixPointAnchor, FixPointAnchor>(sourceRight.anchor, fromRightAnchor);
}
} else {
FixPointAnchor fromBottomAnchor = getCorrectAnchor(targetBoundaryAnchors,
peService.getLocationRelativeToDiagram(sourceBottom.anchor));
FixPointAnchor fromLeftAnchor = getCorrectAnchor(targetBoundaryAnchors,
peService.getLocationRelativeToDiagram(sourceLeft.anchor));
double bottomLength = getLength(peService.getLocationRelativeToDiagram(fromBottomAnchor),
peService.getLocationRelativeToDiagram(sourceBottom.anchor));
double leftLength = getLength(peService.getLocationRelativeToDiagram(fromLeftAnchor),