/** The mouse was dragged - either draw a marquee or move some classes. */
  public void mouseDragged(MouseEvent evt) {
    if (isButtonOne(evt)) {
      if (marquee.isActive()) {
        Rectangle oldRect = marquee.getRectangle();
        marquee.move(evt.getX(), evt.getY());
        Rectangle newRect = (Rectangle) marquee.getRectangle().clone();
        if (oldRect != null) {
          newRect.add(oldRect);
        }
        newRect.width++;
        newRect.height++;
        graphEditor.repaint(newRect);
      } else if (rubberBand != null) {
        rubberBand.setEnd(evt.getX(), evt.getY());
        graphEditor.repaint();
      } else {
        if (!selection.isEmpty()) {
          int deltaX = snapToGrid(evt.getX() - dragStartX);
          int deltaY = snapToGrid(evt.getY() - dragStartY);

          if (resizing) {
            selection.resize(deltaX, deltaY);
          } else if (moving) {
            selection.move(deltaX, deltaY);
          }
        }
        graphEditor.repaint();
      }
    }
  }
  /** A key was pressed in the graph editor. */
  public void keyPressed(KeyEvent evt) {
    boolean handled = true; // assume for a start that we are handling the
    // key here

    if (isArrowKey(evt)) {
      if (evt.isControlDown()) { // resizing
        if (!resizing) startKeyboardResize();
        setKeyDelta(evt);
        selection.resize(keyDeltaX, keyDeltaY);
      } else if (evt.isShiftDown()) { // moving targets
        if (!moving) startKeyboardMove();
        setKeyDelta(evt);
        selection.move(keyDeltaX, keyDeltaY);
      } else { // navigate the diagram
        navigate(evt);
      }
    } else if (isPlusOrMinusKey(evt)) {
      resizeWithFixedRatio(evt);
    }

    // dependency selection
    else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP || evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
      selectDependency(evt);
    }

    // post context menu
    else if (evt.getKeyCode() == KeyEvent.VK_SPACE || evt.getKeyCode() == KeyEvent.VK_ENTER) {
      postMenu();
    }

    // 'A' (with any or no modifiers) selects all
    else if (evt.getKeyCode() == KeyEvent.VK_A) {
      selectAll();
    }

    // Escape removes selections
    else if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
      if (moving || resizing) {
        endMove();
      }
      clearSelection();
    } else {
      handled = false;
    }

    if (handled) evt.consume();

    graphEditor.repaint();
  }