use of org.talend.commons.ui.gmf.draw2d.LineSeg in project tdi-studio-se by Talend.
the class NodeAnchor method getLocationForMultipleConnections.
public Point getLocationForMultipleConnections(int connectionId) {
if ((sourceLocation.y >= targetLocation.y) && ((sourceLocation.y + sourceRect.height) <= (targetLocation.y + targetRect.height))) {
targetRect = new Rectangle(new Point(targetLocation.x, sourceLocation.y), new Dimension(targetRect.width, sourceRect.height));
} else if ((sourceLocation.x >= targetLocation.x) && ((sourceLocation.x + sourceRect.width) <= (targetLocation.x + targetRect.width))) {
targetRect = new Rectangle(new Point(sourceLocation.x, targetLocation.y), new Dimension(sourceRect.width, sourceRect.height));
}
// will calculate the numerator and denominator for the function to place the points.
// example: 1/2; 3/4; 1/4; 5/8; 3/8; 7/8; 1/8; 9/16; 7/16; 11/16; 5/16; 13/16; 3/16...
int num = 1;
int numPair = 1;
int numImpair = 1;
int denom = 2;
for (int i = 1; i < connectionId + 1; i++) {
if ((i % 2) == 0) {
// pair
if ((numPair + 2) > denom) {
denom = denom * 2;
numPair = (denom / 2) + 1;
numImpair = numPair;
} else {
numPair += 2;
}
num = numPair;
} else {
// impair
numImpair -= 2;
if (numImpair > 0) {
num = numImpair;
}
}
}
LineSeg lineSource, lineTarget;
if ((sourceLocation.x < targetRect.getCenter().x) && (targetRect.getCenter().x < (sourceLocation.x + sourceRect.width))) {
lineSource = new LineSeg(sourceRect.getLeft(), sourceRect.getRight());
lineTarget = new LineSeg(targetRect.getLeft(), targetRect.getRight());
} else {
lineSource = new LineSeg(sourceRect.getTop(), sourceRect.getBottom());
lineTarget = new LineSeg(targetRect.getTop(), targetRect.getBottom());
}
Double length = (lineSource.length() * num / denom);
Point pointSource = new Point();
lineSource.pointOn(length.longValue(), KeyPoint.ORIGIN, pointSource);
length = (lineTarget.length() * num / denom);
Point pointTarget = new Point();
lineTarget.pointOn(length.longValue(), KeyPoint.ORIGIN, pointTarget);
if ((sourceLocation.y < pointTarget.y) && (pointTarget.y < (sourceLocation.y + sourceRect.height))) {
// contains
pointSource.y = pointTarget.y;
}
if ((sourceLocation.x < pointTarget.x) && (pointTarget.x < (sourceLocation.x + sourceRect.width))) {
// contains
pointSource.x = pointTarget.x;
}
return calculateLocationFromRef(pointSource, pointTarget);
}
use of org.talend.commons.ui.gmf.draw2d.LineSeg in project tdi-studio-se by Talend.
the class NodeAnchor method calculateLocationFromRef.
/**
* DOC nrousseau Comment method "calculateLocationFromRef".
*
* @param sourceRect
* @param targetRect
* @param sourcePoint
* @param targetPoint
*/
private Point calculateLocationFromRef(Point sourcePoint, Point targetPoint) {
LineSeg lineSourceToTarget = new LineSeg(sourcePoint, targetPoint);
List<LineSeg> lineList = new ArrayList<LineSeg>();
if (!isTargetAnchor) {
lineList.add(new LineSeg(sourceRect.getTopLeft(), sourceRect.getTopRight()));
lineList.add(new LineSeg(sourceRect.getTopLeft(), sourceRect.getBottomLeft()));
lineList.add(new LineSeg(sourceRect.getTopRight(), sourceRect.getBottomRight()));
lineList.add(new LineSeg(sourceRect.getBottomLeft(), sourceRect.getBottomRight()));
} else {
lineList.add(new LineSeg(targetRect.getTopLeft(), targetRect.getTopRight()));
lineList.add(new LineSeg(targetRect.getTopLeft(), targetRect.getBottomLeft()));
lineList.add(new LineSeg(targetRect.getTopRight(), targetRect.getBottomRight()));
lineList.add(new LineSeg(targetRect.getBottomLeft(), targetRect.getBottomRight()));
}
int tolerance = 0;
Point inter = null;
while (inter == null && (tolerance < 10)) {
for (LineSeg line : lineList) {
inter = lineSourceToTarget.intersect(line, tolerance);
if (inter != null) {
return inter;
}
}
tolerance++;
}
return super.getLocation(getReferencePoint());
}
Aggregations