@Override
 public void stopDragging(DrawingController controller, GraphicalRepresentation focusedGR) {
   if (beforePreviousSegment != null && beforePreviousSegment.overlap(currentSegment)) {
     getConnector()._simplifyLayoutOfCurrentPolylinByDeletingTwoPoints(index - 1);
   }
   if (afterNextSegment != null && afterNextSegment.overlap(currentSegment)) {
     getConnector()._simplifyLayoutOfCurrentPolylinByDeletingTwoPoints(index + 1);
   }
   super.stopDragging(controller, focusedGR);
 }
  private void retrieveInfos() {
    currentSegment = getArea();
    index = getPolylin().getSegmentIndex(currentSegment);
    if (index <= 0 || index >= getPolylin().getSegmentNb() - 1) {
      RectPolylinConnector.logger.warning(
          "Inconsistent data while managing adjustable segment in RectPolylinConnector "
              + getGraphicalRepresentation().getText()
              + " index="
              + index
              + " polylin.getSegmentNb()="
              + getPolylin().getSegmentNb());
      return;
    }
    previousSegment = getPolylin().getSegmentAt(index - 1);
    nextSegment = getPolylin().getSegmentAt(index + 1);
    if (currentSegment.getApproximatedOrientation() == null
        || previousSegment.getApproximatedOrientation() == null
        || nextSegment.getApproximatedOrientation() == null) {
      RectPolylinConnector.logger.warning(
          "Inconsistent data while managing adjustable segment in RectPolylinConnector");
      return;
    }
    if (index > 1) {
      beforePreviousSegment = getPolylin().getSegmentAt(index - 2);
    }
    if (index + 2 < getPolylin().getSegmentNb()) {
      afterNextSegment = getPolylin().getSegmentAt(index + 2);
    }
    currentOrientation = currentSegment.getApproximatedOrientation();
    previousOrientation = previousSegment.getApproximatedOrientation();
    nextOrientation = nextSegment.getApproximatedOrientation();

    if (currentOrientation.isHorizontal()) {
      if (previousOrientation == SimplifiedCardinalDirection.NORTH) {
        if (nextOrientation == SimplifiedCardinalDirection.NORTH) {
          draggingAuthorizedArea =
              new FGERectangle(previousSegment.getP1(), nextSegment.getP2(), Filling.FILLED);
        } else if (nextOrientation == SimplifiedCardinalDirection.SOUTH) {
          FGESegment limit;
          if (previousSegment.getP1().y > nextSegment.getP2().y) {
            limit =
                new FGESegment(
                    new FGEPoint(currentSegment.getP1().x, nextSegment.getP2().y),
                    new FGEPoint(currentSegment.getP2().x, nextSegment.getP2().y));
          } else {
            limit =
                new FGESegment(
                    new FGEPoint(currentSegment.getP1().x, previousSegment.getP1().y),
                    new FGEPoint(currentSegment.getP2().x, previousSegment.getP1().y));
          }
          draggingAuthorizedArea = new FGEHalfBand(limit, SimplifiedCardinalDirection.NORTH);
        }
      } else if (previousOrientation == SimplifiedCardinalDirection.SOUTH) {
        if (nextOrientation == SimplifiedCardinalDirection.SOUTH) {
          draggingAuthorizedArea =
              new FGERectangle(previousSegment.getP1(), nextSegment.getP2(), Filling.FILLED);
        } else if (nextOrientation == SimplifiedCardinalDirection.NORTH) {
          FGESegment limit;
          if (previousSegment.getP1().y < nextSegment.getP2().y) {
            limit =
                new FGESegment(
                    new FGEPoint(currentSegment.getP1().x, nextSegment.getP2().y),
                    new FGEPoint(currentSegment.getP2().x, nextSegment.getP2().y));
          } else {
            limit =
                new FGESegment(
                    new FGEPoint(currentSegment.getP1().x, previousSegment.getP1().y),
                    new FGEPoint(currentSegment.getP2().x, previousSegment.getP1().y));
          }
          draggingAuthorizedArea = new FGEHalfBand(limit, SimplifiedCardinalDirection.SOUTH);
        }
      }
    }
    if (currentOrientation.isVertical()) {
      if (previousOrientation == SimplifiedCardinalDirection.EAST) {
        if (nextOrientation == SimplifiedCardinalDirection.EAST) {
          draggingAuthorizedArea =
              new FGERectangle(previousSegment.getP1(), nextSegment.getP2(), Filling.FILLED);
        } else if (nextOrientation == SimplifiedCardinalDirection.WEST) {
          FGESegment limit;
          if (previousSegment.getP1().x < nextSegment.getP2().x) {
            limit =
                new FGESegment(
                    new FGEPoint(nextSegment.getP2().x, currentSegment.getP1().y),
                    new FGEPoint(nextSegment.getP2().x, currentSegment.getP2().y));
          } else {
            limit =
                new FGESegment(
                    new FGEPoint(previousSegment.getP1().x, currentSegment.getP1().y),
                    new FGEPoint(previousSegment.getP1().x, currentSegment.getP2().y));
          }
          draggingAuthorizedArea = new FGEHalfBand(limit, SimplifiedCardinalDirection.EAST);
        }
      } else if (previousOrientation == SimplifiedCardinalDirection.WEST) {
        if (nextOrientation == SimplifiedCardinalDirection.WEST) {
          draggingAuthorizedArea =
              new FGERectangle(previousSegment.getP1(), nextSegment.getP2(), Filling.FILLED);
        } else if (nextOrientation == SimplifiedCardinalDirection.EAST) {
          FGESegment limit;
          if (previousSegment.getP1().x > nextSegment.getP2().x) {
            limit =
                new FGESegment(
                    new FGEPoint(nextSegment.getP2().x, currentSegment.getP1().y),
                    new FGEPoint(nextSegment.getP2().x, currentSegment.getP2().y));
          } else {
            limit =
                new FGESegment(
                    new FGEPoint(previousSegment.getP1().x, currentSegment.getP1().y),
                    new FGEPoint(previousSegment.getP1().x, currentSegment.getP2().y));
          }
          draggingAuthorizedArea = new FGEHalfBand(limit, SimplifiedCardinalDirection.WEST);
        }
      }
    }

    if (draggingAuthorizedArea == null) {
      logger.warning("Inconsistent data while managing adjustable segment in RectPolylinConnector");
      return;
    }

    consistentData = true;
  }