private void adjustHandles(List<Point> oldWaypoints, List<Point> newWaypoints) {
    if (oldWaypoints.size() != newWaypoints.size()) {
      // re-assign segment index and segment parameter
      // System.out.println("Before: " + oldWaypoints.size() +
      // " waypoints");
      // System.out.println("After: " + newWaypoints.size() +
      // " waypoints");
      List<FXCircleSegmentHandlePart> parts =
          PartUtils.filterParts(
              PartUtils.getAnchoreds(getHost().getAnchorages().keySet()),
              FXCircleSegmentHandlePart.class);
      Collections.<FXCircleSegmentHandlePart>sort(parts);
      // System.out.println("Found " + parts.size() +
      // " FXSelectionHandleParts");
      Iterator<FXCircleSegmentHandlePart> it = parts.iterator();
      FXCircleSegmentHandlePart part = null;
      for (int i = 0; i <= newWaypoints.size(); i++) {
        // param 0
        part = it.next();
        // System.out.println("Reassigned index " +
        // part.getSegmentIndex() + " - " + part.getSegmentParameter() +
        // " to " + i + " - " + 0.0);
        setSegmentIndex(part, i);
        setSegmentParameter(part, 0.0);

        // skip mid point handles around newly created waypoints
        if (createdSegmentIndex < 0
            || part.getSegmentIndex() != createdSegmentIndex - 1
                && part.getSegmentIndex() != createdSegmentIndex) {
          // param 0.5
          part = it.next();
          // System.out.println("Reassigned index " +
          // part.getSegmentIndex() + " - " +
          // part.getSegmentParameter() + " to " + i + " - " + 0.5);
          setSegmentIndex(part, i);
          setSegmentParameter(part, 0.5);
        }
      }
      // param 1
      part = it.next();
      // System.out.println("Reassigned index " + part.getSegmentIndex() +
      // " - " + part.getSegmentParameter() + " to " +
      // (newWaypoints.size()) + " - " + 1.0);
      setSegmentIndex(part, newWaypoints.size());
      setSegmentParameter(part, 1.0);

      // not used -> could be removed (and re-added)
      while (it.hasNext()) {
        part = it.next();
        // System.out.println("Reassigned index " +
        // part.getSegmentIndex() + " - " + part.getSegmentParameter() +
        // " to " + -1 + " - " + 1.0);
        // hide (but do not remove from root part and anchorage yet
        // (this will be initiated upon commit)
        setSegmentIndex(part, -1);
      }
    }
  }
  @Override
  public void press(MouseEvent e) {
    createdSegmentIndex = -1;
    FXCircleSegmentHandlePart hp = getHost();
    IVisualPart<Node, ? extends Node> anchorage =
        getHost().getAnchorages().keySet().iterator().next();

    disableRefreshVisuals(anchorage);
    init(getBendPolicy(anchorage));

    if (hp.getSegmentParameter() == 0.5) {
      // create new way point
      getBendPolicy(anchorage)
          .createAndSelectSegmentPoint(
              hp.getSegmentIndex(), new Point(e.getSceneX(), e.getSceneY()));

      // find other segment handle parts
      List<FXCircleSegmentHandlePart> parts =
          PartUtils.filterParts(
              PartUtils.getAnchoreds(getHost().getAnchorages().keySet()),
              FXCircleSegmentHandlePart.class);

      // sort parts by segment index and parameter
      Collections.<FXCircleSegmentHandlePart>sort(parts);

      // increment segment index of succeeding parts
      for (FXCircleSegmentHandlePart p : parts) {
        if (p.getSegmentIndex() > hp.getSegmentIndex()
            || (p.getSegmentIndex() == hp.getSegmentIndex() && p.getSegmentParameter() == 1)) {
          p.setSegmentIndex(p.getSegmentIndex() + 1);
        }
      }

      // adjust index and parameter of this segment handle part
      hp.setSegmentIndex(hp.getSegmentIndex() + 1);
      hp.setSegmentParameter(0);
      createdSegmentIndex = hp.getSegmentIndex();
    } else {
      // select existing way point
      getBendPolicy(anchorage)
          .selectSegmentPoint(
              hp.getSegmentIndex(),
              hp.getSegmentParameter(),
              new Point(e.getSceneX(), e.getSceneY()));
    }
  }
 private void setSegmentIndex(FXCircleSegmentHandlePart part, int value) {
   if (part.getSegmentIndex() != value) {
     part.setSegmentIndex(value);
   }
 }