Search in sources :

Example 16 with ConnectionAnchor

use of org.eclipse.draw2d.ConnectionAnchor in project whole by wholeplatform.

the class SimpleEntityTreeFigure method paintConnections.

protected void paintConnections(Graphics graphics) {
    if (contents.isVisible()) {
        graphics.setForegroundColor(FigureConstants.relationsColor);
        int egdeXOffset = DrawUtils.SPACING - DrawUtils.EDGE_SPACING;
        ConnectionAnchor[] srcAnchors = getSourceAnchors();
        int i;
        int prevYSourceLocation = Integer.MAX_VALUE;
        for (i = 0; i < srcAnchors.length; i++) {
            IFigure contentPane = getContentPane(i);
            if (contentPane.isVisible()) {
                IFigure targetFigure = (IFigure) contentPane.getChildren().get(0);
                Point sourceLocation = srcAnchors[i].getLocation(null);
                Point targetLocation = null;
                if (targetFigure instanceof INodeFigure)
                    targetLocation = ((INodeFigure) targetFigure).getTargetAnchor(0).getLocation(null);
                else {
                    targetLocation = isRightToLeft() ? targetFigure.getBounds().getRight() : targetFigure.getBounds().getLeft();
                    targetFigure.translateToAbsolute(targetLocation);
                }
                translateToRelative(targetLocation);
                translateToRelative(sourceLocation);
                if (targetLocation.y > sourceLocation.y)
                    break;
                if (prevYSourceLocation >= targetLocation.y - 1)
                    egdeXOffset += DrawUtils.EDGE_SPACING;
                prevYSourceLocation = sourceLocation.y;
                DrawUtils.drawHorizontalEdge(graphics, sourceLocation, targetLocation, egdeXOffset);
            }
        }
        egdeXOffset = DrawUtils.SPACING - DrawUtils.EDGE_SPACING;
        prevYSourceLocation = Integer.MIN_VALUE;
        for (int j = srcAnchors.length - 1; j >= i; j--) {
            IFigure contentPane = getContentPane(j);
            if (contentPane.isVisible()) {
                IFigure targetFigure = (IFigure) contentPane.getChildren().get(0);
                Point sourceLocation = srcAnchors[j].getLocation(null);
                Point targetLocation = null;
                if (targetFigure instanceof INodeFigure)
                    targetLocation = ((INodeFigure) targetFigure).getTargetAnchor(0).getLocation(null);
                else {
                    targetLocation = isRightToLeft() ? targetFigure.getBounds().getRight() : targetFigure.getBounds().getLeft();
                    targetFigure.translateToAbsolute(targetLocation);
                }
                translateToRelative(targetLocation);
                translateToRelative(sourceLocation);
                if (prevYSourceLocation <= targetLocation.y + 1)
                    egdeXOffset += DrawUtils.EDGE_SPACING;
                prevYSourceLocation = sourceLocation.y;
                DrawUtils.drawHorizontalEdge(graphics, sourceLocation, targetLocation, egdeXOffset);
            }
        }
    }
}
Also used : ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) INodeFigure(org.whole.lang.ui.figures.INodeFigure) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

Example 17 with ConnectionAnchor

use of org.eclipse.draw2d.ConnectionAnchor in project whole by wholeplatform.

the class SimpleTableNodeWithBranchesFigure method paintConnections.

protected void paintConnections(Graphics g) {
    g.setForegroundColor(FigureConstants.relationsColor);
    int egdeXOffset = DrawUtils.SPACING - DrawUtils.EDGE_SPACING;
    ConnectionAnchor[] srcAnchors = getSourceAnchors();
    int i, j, pi = 0;
    int prevYSourceLocation = Integer.MAX_VALUE;
    for (i = 0, pi = 0; i < srcAnchors.length; i++, pi++) {
        while (featuresStyling[pi].isEmbedded()) pi++;
        IFigure contentPane = getContentPane(typePaneShift + pi);
        if (contentPane.isVisible()) {
            // TODO test if needed
            if (contentPane.getChildren().isEmpty())
                return;
            Point sourceLocation = srcAnchors[i].getLocation(null);
            int yMax = 0;
            IFigure targetFigure = (IFigure) contentPane.getChildren().get(0);
            List<Point> targetLocations = new ArrayList<>();
            if (targetFigure instanceof INodeFigure) {
                INodeFigure targetNode = (INodeFigure) targetFigure;
                for (int ti = 0; ti < targetNode.getTargetAnchorsSize(); ti++) {
                    Point t = targetNode.getTargetAnchor(ti).getLocation(sourceLocation);
                    translateToRelative(t);
                    targetLocations.add(t);
                    yMax = Math.max(yMax, t.y);
                }
            } else {
                Point t = targetFigure.getBounds().getLeft();
                targetFigure.translateToAbsolute(t);
                translateToRelative(t);
                targetLocations.add(t);
                yMax = Math.max(yMax, t.y);
            }
            translateToRelative(sourceLocation);
            if (yMax > sourceLocation.y)
                break;
            if (prevYSourceLocation >= yMax - 1)
                egdeXOffset += DrawUtils.EDGE_SPACING;
            prevYSourceLocation = sourceLocation.y;
            DrawUtils.drawHorizontalTree(g, sourceLocation, egdeXOffset, targetLocations.toArray(new Point[targetLocations.size()]));
        }
    }
    egdeXOffset = DrawUtils.SPACING - DrawUtils.EDGE_SPACING;
    prevYSourceLocation = Integer.MIN_VALUE;
    for (j = srcAnchors.length - 1, pi = featuresStyling.length - 1; j >= i; j--, pi--) {
        while (featuresStyling[pi].isEmbedded()) pi--;
        IFigure contentPane = getContentPane(typePaneShift + pi);
        if (contentPane.isVisible()) {
            // TODO test if needed
            if (contentPane.getChildren().isEmpty())
                return;
            Point sourceLocation = srcAnchors[j].getLocation(null);
            int yMax = 0;
            IFigure targetFigure = (IFigure) contentPane.getChildren().get(0);
            List<Point> targetLocations = new ArrayList<>();
            if (targetFigure instanceof INodeFigure) {
                INodeFigure targetNode = (INodeFigure) targetFigure;
                for (int ti = 0; ti < targetNode.getTargetAnchorsSize(); ti++) {
                    Point t = targetNode.getTargetAnchor(ti).getLocation(sourceLocation);
                    translateToRelative(t);
                    targetLocations.add(t);
                    yMax = Math.max(yMax, t.y);
                }
            } else {
                Point t = targetFigure.getBounds().getLeft();
                targetFigure.translateToAbsolute(t);
                translateToRelative(t);
                targetLocations.add(t);
                yMax = Math.max(yMax, t.y);
            }
            translateToRelative(sourceLocation);
            if (prevYSourceLocation <= yMax + 1)
                egdeXOffset += DrawUtils.EDGE_SPACING;
            prevYSourceLocation = sourceLocation.y;
            DrawUtils.drawHorizontalTree(g, sourceLocation, egdeXOffset, targetLocations.toArray(new Point[targetLocations.size()]));
        }
    }
}
Also used : ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) INodeFigure(org.whole.lang.ui.figures.INodeFigure) ArrayList(java.util.ArrayList) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

Example 18 with ConnectionAnchor

use of org.eclipse.draw2d.ConnectionAnchor in project archi by archimatetool.

the class ConnectionEndpointEditPolicy method showConnectionMoveFeedback.

/**
 * Shows or updates connection move feedback. Called whenever a show
 * feedback request is received for reconnection.
 *
 * @param request
 *            the reconnect request
 */
protected void showConnectionMoveFeedback(ReconnectRequest request) {
    NodeEditPart node = null;
    if (request.getTarget() instanceof NodeEditPart)
        node = (NodeEditPart) request.getTarget();
    if (originalAnchor == null) {
        if (request.isMovingStartAnchor())
            originalAnchor = getConnection().getSourceAnchor();
        else
            originalAnchor = getConnection().getTargetAnchor();
    }
    ConnectionAnchor anchor = null;
    if (node != null) {
        if (request.isMovingStartAnchor())
            anchor = node.getSourceConnectionAnchor(request);
        else
            anchor = node.getTargetConnectionAnchor(request);
    }
    FeedbackHelper helper = getFeedbackHelper(request);
    helper.update(anchor, request.getLocation());
}
Also used : NodeEditPart(org.eclipse.gef.NodeEditPart) ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor)

Example 19 with ConnectionAnchor

use of org.eclipse.draw2d.ConnectionAnchor in project xtext-eclipse by eclipse.

the class Connection method createAnchors.

private void createAnchors(CrossPoint source, CrossPoint target) {
    ConnectionAnchor sourceAnchor = new Anchor(source);
    ConnectionAnchor targetAnchor = new Anchor(target);
    setSourceAnchor(sourceAnchor);
    setTargetAnchor(targetAnchor);
}
Also used : ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) ChopboxAnchor(org.eclipse.draw2d.ChopboxAnchor)

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