@Override
  protected void paintControls(Graphics2D g, ShapeCreationPanel scp) {
    g = (Graphics2D) g.create();

    Rectangle2D r = new Rectangle2D.Float();
    Ellipse2D e = new Ellipse2D.Float();
    Line2D line = new Line2D.Float();
    double z = ((double) scp.getHandleSize()) / 2.0;

    AffineTransform tx = scp.getTransform();

    try {
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(Color.black);
      g.setStroke(new BasicStroke(1));

      CubicPath[] paths = getCubicPaths(scp);
      Selection selection = scp.getSelectionModel().getSelection();
      Selection indication = scp.getSelectionModel().getIndication();
      for (int shapeIndex = 0; shapeIndex < paths.length; shapeIndex++) {
        if (scp.getHandlesActive().supports(scp, shapeIndex)) {
          CubicPath path = paths[shapeIndex];

          if (path != null && path.isEmpty() == false) {
            for (int nodeIndex = 0; nodeIndex < path.getNodeCount(); nodeIndex++) {
              Point2D nodePoint = path.getNode(nodeIndex, null);
              nodePoint = tx.transform(nodePoint, null);

              Point2D p = path.getPrevControlForNode(nodeIndex, null);

              if (p != null) {
                p = tx.transform(p, null);

                g.setColor(Color.lightGray);
                line.setLine(nodePoint, p);
                g.draw(line);

                e.setFrame(p.getX() - z, p.getY() - z, 2 * z, 2 * z);

                if (selection.getShapeIndex() == shapeIndex
                    && selection.getNodeIndex() == nodeIndex
                    && Handle.PREVIOUS_CONTROL.equals(selection.getHandle())) {
                  g.setColor(Color.black);
                } else if (indication.getShapeIndex() == shapeIndex
                    && indication.getNodeIndex() == nodeIndex
                    && Handle.PREVIOUS_CONTROL.equals(indication.getHandle())) {
                  g.setColor(Color.gray);
                } else {
                  g.setColor(Color.white);
                }
                g.fill(e);
                g.setColor(Color.black);
                g.draw(e);
              }

              p = path.getNextControlForNode(nodeIndex, null);
              if (p != null) {
                p = tx.transform(p, null);

                g.setColor(Color.lightGray);
                line.setLine(nodePoint, p);
                g.draw(line);

                e.setFrame(p.getX() - z, p.getY() - z, 2 * z, 2 * z);

                if (selection.getShapeIndex() == shapeIndex
                    && selection.getNodeIndex() == nodeIndex
                    && Handle.NEXT_CONTROL.equals(selection.getHandle())) {
                  g.setColor(Color.black);
                } else if (indication.getShapeIndex() == shapeIndex
                    && indication.getNodeIndex() == nodeIndex
                    && Handle.NEXT_CONTROL.equals(indication.getHandle())) {
                } else {
                  g.setColor(Color.white);
                }
                g.fill(e);
                g.setColor(Color.black);
                g.draw(e);
              }

              r.setFrame(nodePoint.getX() - z, nodePoint.getY() - z, 2 * z, 2 * z);

              if (selection.getShapeIndex() == shapeIndex
                  && selection.getNodeIndex() == nodeIndex
                  && Handle.PRIMARY.equals(selection.getHandle())) {
                g.setColor(Color.black);
              } else if (indication.getShapeIndex() == shapeIndex
                  && indication.getNodeIndex() == nodeIndex
                  && Handle.PRIMARY.equals(indication.getHandle())) {
                g.setColor(Color.gray);
              } else {
                g.setColor(Color.white);
              }
              g.fill(r);
              g.setColor(Color.black);
              g.draw(r);
            }
          }
        }
      }
    } finally {
      g.dispose();
    }
  }
        @Override
        public void mouseDragged(MouseEvent e) {
          try {
            if (e.getClickCount() > 1) return;

            ShapeCreationPanel scp = (ShapeCreationPanel) e.getComponent();
            boolean isCreating = ShapeCreationPanel.MODE_CREATE.equals(scp.getMode());
            CubicPath[] paths = getCubicPaths(scp);
            int i = scp.getSelectionModel().getSelection().getShapeIndex();
            CubicPath path = i == -1 ? null : paths[i];

            Point2D p = new Point2D.Double(e.getX(), e.getY());
            try {
              scp.getTransform().createInverse().transform(p, p);
            } catch (NoninvertibleTransformException e2) {
              throw new RuntimeException(e2);
            }
            float x = (float) p.getX();
            float y = (float) p.getY();
            boolean replacePath = true;

            if (isCreating) {
              int nodeIndex = path.getNodeCount() - 1;
              float dx = x - clickX;
              float dy = y - clickY;
              path.setPrevControlForNode(nodeIndex, clickX - dx, clickY - dy);
            } else {
              Selection s = scp.getSelectionModel().getSelection();
              int nodeIndex = s.getNodeIndex();
              if (nodeIndex != -1) {
                if (Handle.PREVIOUS_CONTROL.equals(s.getHandle())) {
                  path.setPrevControlForNode(nodeIndex, new Point2D.Double(x, y));
                  if (Constraint.ANGLE_ONLY.equals(getConstraint(scp))) {
                    path.setNextControlForNodeFromPrev(nodeIndex, false);
                  } else if (Constraint.ANGLE_AND_DISTANCE.equals(getConstraint(scp))) {
                    path.setNextControlForNodeFromPrev(nodeIndex, true);
                  }
                } else if (Handle.PRIMARY.equals(s.getHandle())) {
                  path.setNode(nodeIndex, new Point2D.Double(x, y), true);
                } else { // next control:
                  path.setNextControlForNode(nodeIndex, new Point2D.Double(x, y));
                  if (Constraint.ANGLE_ONLY.equals(getConstraint(scp))) {
                    path.setPrevControlForNodeFromNext(nodeIndex, false);
                  } else if (Constraint.ANGLE_AND_DISTANCE.equals(getConstraint(scp))) {
                    path.setPrevControlForNodeFromNext(nodeIndex, true);
                  }
                }
              } else {
                float dx = e.getX() - lastUntransformedX;
                float dy = e.getY() - lastUntransformedY;
                nudge(scp, dx, dy);
                replacePath = false;
              }
            }

            if (i >= 0 && replacePath) {
              changingDataModel.add(Thread.currentThread());
              try {
                scp.getDataModel().setShape(i, path);
              } finally {
                changingDataModel.remove(Thread.currentThread());
              }
            }
          } finally {
            lastUntransformedX = e.getX();
            lastUntransformedY = e.getY();
          }
        }