/**
   * Connects the figure to the new target. If there is no new target the connection reverts to its
   * original one.
   */
  public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) {
    Connector target = findConnectionTarget(x, y, view.drawing());
    if (target == null) {
      target = fOriginalTarget;
    }

    setPoint(x, y);
    connect(target);
    getConnection().updateConnection();

    Connector oldConnector =
        ((ChangeConnectionHandle.UndoActivity) getUndoActivity()).getOldConnector();
    // there has been no change so there is nothing to undo
    if ((oldConnector == null)
        || (target() == null)
        || (oldConnector.owner() == target().owner())) {
      setUndoActivity(null);
    } else {
      getUndoActivity().setAffectedFigures(new SingleFigureEnumerator(getConnection()));
    }

    if (getTargetFigure() != null) {
      getTargetFigure().connectorVisibility(false);
      setTargetFigure(null);
    }
  }