/**
  * Mouse pressed is called on mouse-down. Mouse released and mouse clicked are called on mouse-up.
  */
 @Override
 public void mousePressed(MouseEvent e) {
   // Zoom
   if (e.getButton() == MouseEvent.BUTTON1 && e.isMetaDown()) {
     selecting = true;
     selectionStart = gcodeRenderer.getMouseWorldLocation();
     selection.setStart(selectionStart);
   } else {
     animator.start();
   }
 }
 @Override
 public void mouseReleased(MouseEvent e) {
   // Finish selecting.
   if (selecting) {
     selecting = false;
     selectionEnd = gcodeRenderer.getMouseWorldLocation();
     gcodeRenderer.zoomToRegion(selectionStart, selectionEnd, 1.0);
     selection.clear();
     gcodeRenderer.forceRedraw();
   }
   animator.stop();
 }
  /** Mouse Motion Listener */
  @Override
  public void mouseDragged(java.awt.event.MouseEvent e) {
    // Don't rotate if we're making a selection.
    if (selecting) {
      gcodeRenderer.mouseMoved(new Point(e.getX(), e.getY()));
      selection.setEnd(gcodeRenderer.getMouseWorldLocation());
      gcodeRenderer.forceRedraw();
      return;
    }

    if (SwingUtilities.isLeftMouseButton(e)) {
      int x = e.getX();
      int y = e.getY();

      int panMouseButton = InputEvent.BUTTON2_MASK; // TODO: Make configurable

      if (e.isShiftDown() || e.getModifiers() == panMouseButton) {
        gcodeRenderer.mousePan(new Point(x, y));
      } else {
        gcodeRenderer.mouseRotate(new Point(x, y));
      }
    }
  }