org.eclipse.draw2d.AbstractRouter Java Examples

The following examples show how to use org.eclipse.draw2d.AbstractRouter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BPMNShapeFactory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private PolylineConnection createConnectorFigure(Edge bonitaEdge) {
    Bounds sourceLocation = getBPMNShapeBounds(modelExporter.getEObjectID(bonitaEdge.getSource()));
    Bounds targetLocation = getBPMNShapeBounds(modelExporter.getEObjectID(bonitaEdge.getTarget()));

    PolylineConnection conn = new PolylineConnection();
    AbstractRouter router = new CustomRectilinearRouter();
    conn.setConnectionRouter(router);
    final List<RelativeBendpoint> pointList = ((RelativeBendpoints) bonitaEdge.getBendpoints()).getPoints();
    List<org.eclipse.draw2d.RelativeBendpoint> figureConstraint = new ArrayList<>();
    for (int i = 0; i < pointList.size(); i++) {
        RelativeBendpoint relativeBendpoint = (RelativeBendpoint) pointList.get(i);
        IFigure sourceFigure = new Figure();
        sourceFigure.setBounds(toRectangle(sourceLocation));
        IFigure targetFigure = new Figure();
        targetFigure.setBounds(toRectangle(targetLocation));
        conn.setSourceAnchor(new CustomAnchor(sourceFigure));
        conn.setTargetAnchor(new CustomAnchor(targetFigure));
        org.eclipse.draw2d.RelativeBendpoint rbp = new org.eclipse.draw2d.RelativeBendpoint(conn);
        rbp.setRelativeDimensions(
                new Dimension(relativeBendpoint.getSourceX(), relativeBendpoint.getSourceY()),
                new Dimension(relativeBendpoint.getTargetX(), relativeBendpoint.getTargetY()));
        if (pointList.size() == 1) {
            rbp.setWeight(0.5f);
        } else {
            rbp.setWeight(i / ((float) pointList.size() - 1));
        }
        figureConstraint.add(rbp);
    }
    conn.setRoutingConstraint(figureConstraint);
    router.route(conn);
    return conn;
}