Search in sources :

Example 6 with ConnectionAnchor

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

the class RBNodeFigure method paintConnections.

protected void paintConnections(Graphics graphics) {
    graphics.setForegroundColor(ColorConstants.black);
    ConnectionAnchor[] srcAnchors = getSourceAnchors();
    for (int i = 0; i < srcAnchors.length; i++) {
        IFigure contentPane = getContentPane(i + 1);
        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 = targetFigure.getBounds().getTop();
            targetFigure.translateToAbsolute(targetLocation);
        }
        translateToRelative(targetLocation);
        translateToRelative(sourceLocation);
        graphics.drawLine(sourceLocation, targetLocation);
    }
}
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 7 with ConnectionAnchor

use of org.eclipse.draw2d.ConnectionAnchor in project webtools.sourceediting by eclipse.

the class XSDModelGroupRouter method getEndDirection.

protected Ray getEndDirection(Connection conn) {
    ConnectionAnchor anchor = conn.getTargetAnchor();
    Point p = getEndPoint(conn);
    Rectangle rect;
    if (anchor.getOwner() == null)
        rect = new Rectangle(p.x - 1, p.y - 1, 2, 2);
    else {
        rect = conn.getTargetAnchor().getOwner().getBounds().getCopy();
        conn.getTargetAnchor().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 8 with ConnectionAnchor

use of org.eclipse.draw2d.ConnectionAnchor in project yamcs-studio by yamcs.

the class AbstractBaseEditPart method getClosestAnchorAt.

/**
 * Get the closest anchor to point p.
 *
 * @param p
 *            the reference point
 * @return the closest anchor to point p
 */
protected ConnectionAnchor getClosestAnchorAt(Point p) {
    if (anchorMap == null) {
        fillAnchorMap();
    }
    ConnectionAnchor closest = null;
    double min = Long.MAX_VALUE;
    for (var anchor : anchorMap.values()) {
        var p2 = anchor.getLocation(null);
        var d = p.getDistance(p2);
        if (d < min) {
            min = d;
            closest = anchor;
        }
    }
    return closest;
}
Also used : ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor)

Example 9 with ConnectionAnchor

use of org.eclipse.draw2d.ConnectionAnchor in project tdi-studio-se by Talend.

the class NodeFigure method setBounds.

@Override
public void setBounds(final Rectangle rect) {
    super.setBounds(rect);
    Point location = (new Point(rect.getCenter())).translate(new Point(-fig.getSize().width / 2, -(fig.getSize().height / 2)));
    Rectangle figBounds = new Rectangle(location, fig.getSize());
    this.fig.setBounds(figBounds);
    if (dummy) {
        if (sourceDummyMap != null) {
            if (targetConnection != null && sourceDummyMap.keySet().size() != 0) {
                for (final ConnectionFigure curConn : newSourceConnections) {
                    AnchorListener sourceListener = new AnchorListener() {

                        @Override
                        public void anchorMoved(ConnectionAnchor anchor) {
                            if (curConn != null) {
                                updateSource(curConn);
                            }
                        }
                    };
                    if (curConn.getTargetAnchor() != null && curConn.getTargetAnchor().getOwner() != null) {
                        sourceListeners.put(curConn, sourceListener);
                        curConn.getTargetAnchor().addAnchorListener(sourceListener);
                    }
                }
                newSourceConnections.clear();
                updateTarget();
                List<ConnectionFigure> toRemove = new ArrayList<ConnectionFigure>();
                for (ConnectionFigure curConn : sourceDummyMap.keySet()) {
                    ConnectionFigure connToRemove = updateSource(curConn);
                    if (connToRemove != null) {
                        toRemove.add(connToRemove);
                    }
                }
                sourceDummyMap.keySet().removeAll(toRemove);
            } else {
                INodeConnector mainNodeConnector = node.getConnectorFromType(EConnectionType.FLOW_MAIN);
                ConnectionFigure connection = new ConnectionFigure(mainNodeConnector.getConnectionProperty(EConnectionType.FLOW_MAIN), node);
                connection.setTargetDecoration(null);
                connection.setStart(new Point(figBounds.x, figBounds.y + figBounds.height / 2));
                connection.setEnd(new Point(figBounds.x + figBounds.width, figBounds.y + figBounds.height / 2));
            }
        }
    }
    if (!rect.getSize().equals(fig.getSize())) {
        lineBorder.setUseRectangle(true);
    } else {
        lineBorder.setUseRectangle(false);
    }
}
Also used : ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) ConnectionFigure(org.talend.designer.core.ui.editor.connections.ConnectionFigure) DummyConnectionFigure(org.talend.designer.core.ui.editor.connections.DummyConnectionFigure) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AnchorListener(org.eclipse.draw2d.AnchorListener) ArrayList(java.util.ArrayList) Point(org.eclipse.draw2d.geometry.Point) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 10 with ConnectionAnchor

use of org.eclipse.draw2d.ConnectionAnchor in project yamcs-studio by yamcs.

the class WidgetNodeEditPolicy method getConnectionCompleteCommand.

@Override
protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
    ConnectionCreateCommand cmd = (ConnectionCreateCommand) request.getStartCommand();
    cmd.setTarget(getWidgetEditPart().getWidgetModel());
    ConnectionAnchor anchor = getWidgetEditPart().getTargetConnectionAnchor(request);
    if (anchor == null)
        return null;
    cmd.setTargetTerminal(getWidgetEditPart().getTerminalNameFromAnchor(anchor));
    return cmd;
}
Also used : ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) ConnectionCreateCommand(org.csstudio.opibuilder.commands.ConnectionCreateCommand)

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