@Override
  public void mouseMoved(MouseEvent mouse) {
    // if an insertion mode is activated. Draw temp node for the user.
    if (machineMode.isSelected()) {
      if (!(cursorNode instanceof Machine))
        cursorNode =
            new Machine(
                "",
                cap(mouse.getX() - 10, 70, getWidth() - 90),
                cap(mouse.getY() - 10, 120, getHeight() - 90));

      cursorNode.x = cap(mouse.getX() - 10, 70, getWidth() - 90);
      cursorNode.y = cap(mouse.getY() - 10, 120, getHeight() - 90);
    } else if (primaryMode.isSelected()) {
      if (!(cursorNode instanceof Primary))
        cursorNode =
            new Primary(
                "",
                cap(mouse.getX() - 10, 70, getWidth() - 90),
                cap(mouse.getY() - 10, 120, getHeight() - 90));

      cursorNode.x = cap(mouse.getX() - 10, 70, getWidth() - 90);
      cursorNode.y = cap(mouse.getY() - 10, 120, getHeight() - 90);

    } else {
      cursorNode = null;
    }

    repaint();
  }
 @Override
 public void mouseDragged(MouseEvent mouse) {
   if (visualizeButton.isSelected()) return;
   if (selectedNode != null) {
     selectedNode.x = cap(mouse.getX() - offX, 70, getWidth() - 100);
     selectedNode.y = cap(mouse.getY() - offY, 160, getHeight() - 120);
   }
   repaint();
 }