use of org.eclipse.draw2d.ConnectionAnchor in project webtools.sourceediting by eclipse.
the class XSDModelGroupRouter method getStartDirection.
protected Ray getStartDirection(Connection conn) {
ConnectionAnchor anchor = conn.getSourceAnchor();
Point p = getStartPoint(conn);
Rectangle rect;
if (anchor.getOwner() == null)
rect = new Rectangle(p.x - 1, p.y - 1, 2, 2);
else {
rect = conn.getSourceAnchor().getOwner().getBounds().getCopy();
conn.getSourceAnchor().getOwner().translateToAbsolute(rect);
}
return getDirection(rect, p);
}
use of org.eclipse.draw2d.ConnectionAnchor in project webtools.sourceediting by eclipse.
the class BaseTypeConnectingEditPart method getConnectionEditPart.
private EditPart getConnectionEditPart(int direction) {
// find the first connection that targets this editPart
// navigate backward along the connection (to the left) to find the source edit part
EditPart result = null;
for (Iterator i = getLayer(LayerConstants.CONNECTION_LAYER).getChildren().iterator(); i.hasNext(); ) {
Figure figure = (Figure) i.next();
if (figure instanceof TypeReferenceConnection) {
TypeReferenceConnection typeReferenceConnection = (TypeReferenceConnection) figure;
ConnectionAnchor thisAnchor = null;
if (direction == PositionConstants.EAST) {
thisAnchor = typeReferenceConnection.getSourceAnchor();
} else if (direction == PositionConstants.WEST) {
thisAnchor = typeReferenceConnection.getTargetAnchor();
}
if (thisAnchor != null && thisAnchor.getOwner() == getFigure()) {
ConnectionAnchor outAnchor = null;
if (direction == PositionConstants.EAST) {
outAnchor = typeReferenceConnection.getTargetAnchor();
} else if (direction == PositionConstants.WEST) {
outAnchor = typeReferenceConnection.getSourceAnchor();
}
if (outAnchor != null) {
IFigure sourceFigure = outAnchor.getOwner();
EditPart part = null;
while (part == null && sourceFigure != null) {
part = (EditPart) getViewer().getVisualPartMap().get(sourceFigure);
sourceFigure = sourceFigure.getParent();
}
result = part;
break;
}
}
}
}
return result;
}
use of org.eclipse.draw2d.ConnectionAnchor in project whole by wholeplatform.
the class NodeFigure method getClosestDistanceAnchor.
public static ConnectionAnchor getClosestDistanceAnchor(Point p, ConnectionAnchor[] anchors, DistanceMetric metric) {
ConnectionAnchor closestAnchor = null;
long min = Long.MAX_VALUE;
if (anchors != null)
for (int i = 0; i < anchors.length; i++) {
long d = metric.calculate(p, anchors[i].getLocation(p));
if (d < min) {
min = d;
closestAnchor = anchors[i];
}
}
return closestAnchor;
}
use of org.eclipse.draw2d.ConnectionAnchor in project whole by wholeplatform.
the class NodeWithCompositeBranchFigure method paintConnections.
@SuppressWarnings("unchecked")
protected void paintConnections(Graphics g) {
IFigure contentPane = getContentPane(getChildrenPaneIndex());
if (contentPane.isVisible()) {
// TODO test if needed
if (contentPane.getChildren().isEmpty())
return;
ConnectionAnchor[] srcAnchors = getSourceAnchors();
Point sourceLocation = srcAnchors[0].getLocation(null);
List<Point> targetLocations = new ArrayList<>();
for (IFigure targetFigure : (List<IFigure>) contentPane.getChildren()) {
if (targetFigure instanceof INodeFigure) {
INodeFigure targetNode = (INodeFigure) targetFigure;
for (int i = 0; i < targetNode.getTargetAnchorsSize(); i++) {
Point t = targetNode.getTargetAnchor(i).getLocation(sourceLocation);
translateToRelative(t);
targetLocations.add(t);
}
} else {
Point t = targetFigure.getBounds().getLeft();
targetFigure.translateToAbsolute(t);
translateToRelative(t);
targetLocations.add(t);
}
}
translateToRelative(sourceLocation);
g.setForegroundColor(FigureConstants.relationsColor);
DrawUtils.drawHorizontalTree(g, sourceLocation, DrawUtils.SPACING / 2 + 2, targetLocations.toArray(new Point[targetLocations.size()]));
}
}
use of org.eclipse.draw2d.ConnectionAnchor in project whole by wholeplatform.
the class XsiSimpleStructuralFigure method findTargetAnchors.
@SuppressWarnings("unchecked")
public static List<ConnectionAnchor> findTargetAnchors(IFigure figure) {
List<ConnectionAnchor> anchors = new ArrayList<ConnectionAnchor>();
List<IFigure> children = figure.getChildren();
for (int i = 0; i < children.size(); i++) {
IFigure child = children.get(i);
if (child instanceof INodeFigure) {
INodeFigure nodeFigure = (INodeFigure) child;
for (int j = 0, size = nodeFigure.getTargetAnchorsSize(); j < size; j++) anchors.add(nodeFigure.getTargetAnchor(j));
} else
anchors.addAll(findTargetAnchors(child));
}
return anchors;
}
Aggregations