Search in sources :

Example 11 with ConnectionAnchor

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);
}
Also used : ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

Example 12 with ConnectionAnchor

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;
}
Also used : ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) EditPart(org.eclipse.gef.EditPart) Iterator(java.util.Iterator) IFigure(org.eclipse.draw2d.IFigure) Figure(org.eclipse.draw2d.Figure) IFigure(org.eclipse.draw2d.IFigure)

Example 13 with ConnectionAnchor

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;
}
Also used : ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor)

Example 14 with ConnectionAnchor

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()]));
    }
}
Also used : ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) INodeFigure(org.whole.lang.ui.figures.INodeFigure) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

Example 15 with ConnectionAnchor

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;
}
Also used : ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) INodeFigure(org.whole.lang.ui.figures.INodeFigure) ArrayList(java.util.ArrayList) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

ConnectionAnchor (org.eclipse.draw2d.ConnectionAnchor)19 Point (org.eclipse.draw2d.geometry.Point)9 IFigure (org.eclipse.draw2d.IFigure)8 INodeFigure (org.whole.lang.ui.figures.INodeFigure)7 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 ArrayList (java.util.ArrayList)4 ConnectionCreateCommand (org.csstudio.opibuilder.commands.ConnectionCreateCommand)2 Iterator (java.util.Iterator)1 List (java.util.List)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 AnchorListener (org.eclipse.draw2d.AnchorListener)1 ChopboxAnchor (org.eclipse.draw2d.ChopboxAnchor)1 Figure (org.eclipse.draw2d.Figure)1 EditPart (org.eclipse.gef.EditPart)1 NodeEditPart (org.eclipse.gef.NodeEditPart)1 INodeConnector (org.talend.core.model.process.INodeConnector)1 ConnectionFigure (org.talend.designer.core.ui.editor.connections.ConnectionFigure)1 DummyConnectionFigure (org.talend.designer.core.ui.editor.connections.DummyConnectionFigure)1