Search in sources :

Example 1 with BendpointRequest

use of org.eclipse.gef.requests.BendpointRequest in project knime-core by knime.

the class WorkflowConnectionBendpointTracker method updateSourceRequest.

/**
 * {@inheritDoc}
 */
@Override
protected void updateSourceRequest() {
    BendpointRequest request = (BendpointRequest) getSourceRequest();
    // get the currently dragging bendpoint
    Point dragPoint = getLocation();
    WorkflowEditor.adaptZoom(m_zoomManager, dragPoint, false);
    // get the two points next to the dragging bendpoint from the
    // list of all points of the connection
    PointList pList = ((Connection) request.getSource().getFigure()).getPoints();
    Point[] neighbourPoints = getNeighbourPoints(dragPoint, pList);
    // if the neighbours could not be determined to not apply snapping
    if (neighbourPoints == null) {
        request.setLocation(getLocation());
        return;
    }
    double xCorrection = 0.0;
    // check the drag point for all 4 vertical / horizontal lines
    // to snap to those lines
    double diff1 = Math.abs(dragPoint.x - neighbourPoints[0].x);
    if (diff1 < THRESHOLD) {
        xCorrection = diff1;
    }
    double diff2 = Math.abs(dragPoint.x - neighbourPoints[1].x);
    if ((diff2 < THRESHOLD) && (diff2 < diff1)) {
        // always apply the smaller correction
        xCorrection = diff2;
    }
    double yCorrection = 0.0;
    diff1 = Math.abs(dragPoint.y - neighbourPoints[0].y);
    if (diff1 < THRESHOLD) {
        yCorrection = diff1;
    }
    diff2 = Math.abs(dragPoint.y - neighbourPoints[1].y);
    if ((diff2 < THRESHOLD) && (diff2 < diff1)) {
        // always apply the smaller correction
        yCorrection = diff2;
    }
    request.setLocation(getLocation().translate((int) xCorrection, (int) yCorrection));
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) BendpointRequest(org.eclipse.gef.requests.BendpointRequest) Connection(org.eclipse.draw2d.Connection) Point(org.eclipse.draw2d.geometry.Point)

Example 2 with BendpointRequest

use of org.eclipse.gef.requests.BendpointRequest in project archi by archimatetool.

the class ExtendedConnectionBendpointTracker method updateSourceRequest.

@Override
protected void updateSourceRequest() {
    // snap-to-grid patch
    Point pt = getLocation();
    // Check whether snap enabled and whether user is holding down modifier key
    if (isSnapToGridEnabled() && !getCurrentInput().isModKeyDown(MODIFIER_NO_SNAPPING)) {
        setNearestSnapPoint(pt, getSnapGridSize());
    }
    BendpointRequest request = (BendpointRequest) getSourceRequest();
    request.setLocation(pt);
}
Also used : BendpointRequest(org.eclipse.gef.requests.BendpointRequest) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

Point (org.eclipse.draw2d.geometry.Point)2 BendpointRequest (org.eclipse.gef.requests.BendpointRequest)2 Connection (org.eclipse.draw2d.Connection)1 PointList (org.eclipse.draw2d.geometry.PointList)1