public ControlPoint getControlPoint(Location x) {

    if (controlPoints != null) {
      for (ControlPoint cp : controlPoints) if (cp.getType() == x) return cp;
    }
    return null;
  }
  public void controlPointMoveDrag(
      ControlPoint cp, RenderingProperties rp, Point2D.Double[] delta, Point2D.Double p) {

    switch (type) {
      case TEXT:
        Line2D.Double point = (Line2D.Double) baseShape;
        point.x1 = p.x;
        point.y1 = p.y;
        point.x2 = p.x;
        point.y2 = p.y;
        break;

      case LINE:
        Line2D.Double l = (Line2D.Double) baseShape;
        if (cp.id == 0) {
          l.x1 = p.x;
          l.y1 = p.y;
        } else {
          l.x2 = p.x;
          l.y2 = p.y;
        }
        break;
      case ARROW:
        Point2D.Double[] pArray = computeArrowCoordinates((GeneralPath) baseShape);
        baseShape =
            (cp.id == 0)
                ? createArrowLine(p.x, p.y, pArray[1].x, pArray[1].y)
                : createArrowLine(pArray[0].x, pArray[0].y, p.x, p.y);
        break;
      case ELLIPSE:
      case BOX:
        Polygon2D poly = (Polygon2D) baseShape;

        switch (cp.id) {

            // Need to update the other control points! Unfortunately, not straightforward because
            // of
            // the differences between the image space and the viewport space and the fact that we
            // want to preserve
            // the 90 degree angle between the points (objects may be rotated at various angles).
            // The delta contribution
            // in X/Y is passed in for a given point, and must be added to the corresponding polygon
            // corners.

          case 0:
            poly.xpoints[0] += delta[0].x;
            poly.ypoints[0] += delta[0].y;
            poly.xpoints[1] += delta[0].x;
            poly.ypoints[1] += delta[0].y;
            controlPoints.get(1).updateXY(poly.xpoints[1], poly.ypoints[1]);
            controlPoints.get(7).updateXY(poly.xpoints[0], poly.ypoints[0]);
            controlPoints
                .get(2)
                .updateXY(
                    (poly.xpoints[1] + poly.xpoints[2]) / 2,
                    (poly.ypoints[1] + poly.ypoints[2]) / 2);
            controlPoints
                .get(6)
                .updateXY(
                    (poly.xpoints[3] + poly.xpoints[0]) / 2,
                    (poly.ypoints[3] + poly.ypoints[0]) / 2);
            break;
          case 1:
            poly.xpoints[0] += delta[1].x;
            poly.ypoints[0] += delta[1].y;
            poly.xpoints[1] += (delta[1].x + delta[2].x);
            poly.ypoints[1] += (delta[1].y + delta[2].y);
            poly.xpoints[2] += delta[2].x;
            poly.ypoints[2] += delta[2].y;
            for (ControlPoint points : controlPoints) points.setVisible(false);
            controlPoints.get(7).updateXY(poly.xpoints[0], poly.ypoints[0]);
            controlPoints.get(1).updateXY(poly.xpoints[1], poly.ypoints[1]);
            controlPoints.get(3).updateXY(poly.xpoints[2], poly.ypoints[2]);
            controlPoints
                .get(0)
                .updateXY(
                    (poly.xpoints[0] + poly.xpoints[1]) / 2,
                    (poly.ypoints[0] + poly.ypoints[1]) / 2);
            controlPoints
                .get(2)
                .updateXY(
                    (poly.xpoints[1] + poly.xpoints[2]) / 2,
                    (poly.ypoints[1] + poly.ypoints[2]) / 2);
            controlPoints
                .get(4)
                .updateXY(
                    (poly.xpoints[2] + poly.xpoints[3]) / 2,
                    (poly.ypoints[2] + poly.ypoints[3]) / 2);
            controlPoints
                .get(6)
                .updateXY(
                    (poly.xpoints[3] + poly.xpoints[0]) / 2,
                    (poly.ypoints[3] + poly.ypoints[0]) / 2);
            for (ControlPoint points : controlPoints) points.setVisible(true);
            break;
          case 2:
            poly.xpoints[1] += delta[0].x;
            poly.ypoints[1] += delta[0].y;
            poly.xpoints[2] += delta[0].x;
            poly.ypoints[2] += delta[0].y;
            controlPoints.get(1).updateXY(poly.xpoints[1], poly.ypoints[1]);
            controlPoints.get(3).updateXY(poly.xpoints[2], poly.ypoints[2]);
            controlPoints
                .get(0)
                .updateXY(
                    (poly.xpoints[0] + poly.xpoints[1]) / 2,
                    (poly.ypoints[0] + poly.ypoints[1]) / 2);
            controlPoints
                .get(4)
                .updateXY(
                    (poly.xpoints[2] + poly.xpoints[3]) / 2,
                    (poly.ypoints[2] + poly.ypoints[3]) / 2);
            break;
          case 3:
            poly.xpoints[3] += delta[1].x;
            poly.ypoints[3] += delta[1].y;
            poly.xpoints[2] += (delta[1].x + delta[2].x);
            poly.ypoints[2] += (delta[1].y + delta[2].y);
            poly.xpoints[1] += delta[2].x;
            poly.ypoints[1] += delta[2].y;
            for (ControlPoint points : controlPoints) points.setVisible(false);
            controlPoints.get(5).updateXY(poly.xpoints[3], poly.ypoints[3]);
            controlPoints.get(1).updateXY(poly.xpoints[1], poly.ypoints[1]);
            controlPoints.get(3).updateXY(poly.xpoints[2], poly.ypoints[2]);
            controlPoints
                .get(0)
                .updateXY(
                    (poly.xpoints[0] + poly.xpoints[1]) / 2,
                    (poly.ypoints[0] + poly.ypoints[1]) / 2);
            controlPoints
                .get(2)
                .updateXY(
                    (poly.xpoints[1] + poly.xpoints[2]) / 2,
                    (poly.ypoints[1] + poly.ypoints[2]) / 2);
            controlPoints
                .get(4)
                .updateXY(
                    (poly.xpoints[2] + poly.xpoints[3]) / 2,
                    (poly.ypoints[2] + poly.ypoints[3]) / 2);
            controlPoints
                .get(6)
                .updateXY(
                    (poly.xpoints[3] + poly.xpoints[0]) / 2,
                    (poly.ypoints[3] + poly.ypoints[0]) / 2);
            for (ControlPoint points : controlPoints) points.setVisible(true);
            break;
          case 4:
            poly.xpoints[2] += delta[0].x;
            poly.ypoints[2] += delta[0].y;
            poly.xpoints[3] += delta[0].x;
            poly.ypoints[3] += delta[0].y;
            controlPoints.get(3).updateXY(poly.xpoints[2], poly.ypoints[2]);
            controlPoints.get(5).updateXY(poly.xpoints[3], poly.ypoints[3]);
            controlPoints
                .get(2)
                .updateXY(
                    (poly.xpoints[1] + poly.xpoints[2]) / 2,
                    (poly.ypoints[1] + poly.ypoints[2]) / 2);
            controlPoints
                .get(6)
                .updateXY(
                    (poly.xpoints[3] + poly.xpoints[0]) / 2,
                    (poly.ypoints[3] + poly.ypoints[0]) / 2);
            break;
          case 5:
            poly.xpoints[2] += delta[1].x;
            poly.ypoints[2] += delta[1].y;
            poly.xpoints[3] += (delta[1].x + delta[2].x);
            poly.ypoints[3] += (delta[1].y + delta[2].y);
            poly.xpoints[0] += delta[2].x;
            poly.ypoints[0] += delta[2].y;
            for (ControlPoint points : controlPoints) points.setVisible(false);
            controlPoints.get(5).updateXY(poly.xpoints[3], poly.ypoints[3]);
            controlPoints.get(7).updateXY(poly.xpoints[0], poly.ypoints[0]);
            controlPoints.get(3).updateXY(poly.xpoints[2], poly.ypoints[2]);
            controlPoints
                .get(0)
                .updateXY(
                    (poly.xpoints[0] + poly.xpoints[1]) / 2,
                    (poly.ypoints[0] + poly.ypoints[1]) / 2);
            controlPoints
                .get(2)
                .updateXY(
                    (poly.xpoints[1] + poly.xpoints[2]) / 2,
                    (poly.ypoints[1] + poly.ypoints[2]) / 2);
            controlPoints
                .get(4)
                .updateXY(
                    (poly.xpoints[2] + poly.xpoints[3]) / 2,
                    (poly.ypoints[2] + poly.ypoints[3]) / 2);
            controlPoints
                .get(6)
                .updateXY(
                    (poly.xpoints[3] + poly.xpoints[0]) / 2,
                    (poly.ypoints[3] + poly.ypoints[0]) / 2);
            for (ControlPoint points : controlPoints) points.setVisible(true);
            break;
          case 6:
            poly.xpoints[0] += delta[0].x;
            poly.ypoints[0] += delta[0].y;
            poly.xpoints[3] += delta[0].x;
            poly.ypoints[3] += delta[0].y;
            controlPoints.get(7).updateXY(poly.xpoints[0], poly.ypoints[0]);
            controlPoints.get(5).updateXY(poly.xpoints[3], poly.ypoints[3]);
            controlPoints
                .get(0)
                .updateXY(
                    (poly.xpoints[0] + poly.xpoints[1]) / 2,
                    (poly.ypoints[0] + poly.ypoints[1]) / 2);
            controlPoints
                .get(4)
                .updateXY(
                    (poly.xpoints[2] + poly.xpoints[3]) / 2,
                    (poly.ypoints[2] + poly.ypoints[3]) / 2);
            break;
          case 7:
            poly.xpoints[1] += delta[1].x;
            poly.ypoints[1] += delta[1].y;
            poly.xpoints[0] += (delta[1].x + delta[2].x);
            poly.ypoints[0] += (delta[1].y + delta[2].y);
            poly.xpoints[3] += delta[2].x;
            poly.ypoints[3] += delta[2].y;
            for (ControlPoint points : controlPoints) points.setVisible(false);
            controlPoints.get(7).updateXY(poly.xpoints[0], poly.ypoints[0]);
            controlPoints.get(1).updateXY(poly.xpoints[1], poly.ypoints[1]);
            controlPoints.get(5).updateXY(poly.xpoints[3], poly.ypoints[3]);
            controlPoints
                .get(0)
                .updateXY(
                    (poly.xpoints[0] + poly.xpoints[1]) / 2,
                    (poly.ypoints[0] + poly.ypoints[1]) / 2);
            controlPoints
                .get(2)
                .updateXY(
                    (poly.xpoints[1] + poly.xpoints[2]) / 2,
                    (poly.ypoints[1] + poly.ypoints[2]) / 2);
            controlPoints
                .get(4)
                .updateXY(
                    (poly.xpoints[2] + poly.xpoints[3]) / 2,
                    (poly.ypoints[2] + poly.ypoints[3]) / 2);
            controlPoints
                .get(6)
                .updateXY(
                    (poly.xpoints[3] + poly.xpoints[0]) / 2,
                    (poly.ypoints[3] + poly.ypoints[0]) / 2);
            for (ControlPoint points : controlPoints) points.setVisible(true);
            break;
        }
        break;
      case POLYGON:
        break;
      case POLYLINE:
        {
          Polygon2D polyline = (Polygon2D) baseShape;
          polyline.xpoints[cp.id] = p.x;
          polyline.ypoints[cp.id] = p.y;
        }
        break;
      case CURVE:
        {
          FourPointCurve fpc = (FourPointCurve) baseShape;
          ArrayList<Point2D.Double> pList = fpc.getControlPoints();
          Point2D.Double p2d = pList.get(cp.id);
          p2d.x = p.x;
          p2d.y = p.y;
          fpc.update();
        }
        break;
      default:
        break;
    }
  }