@Override
  public void mouseUp(int i, int j, MouseEvent e) {
    if (currentHandle != null) {
      currentHandle.stopInteraction(i, j, e, view);
      currentHandle = null;
      return;
    }

    if (selMode) {
      selMode = false;
      view.setSelectionRubberBand(null);
      view.repaint();
    }

    if (e.isShiftDown() && e.getX() == originalX && e.getY() == originalY) {
      for (Figure f : view.getModel().getFigures()) {
        if (f.contains(originalX, originalY)) {
          if (view.getSelection().contains(f) && f != lastSelectedFigure) {
            view.removeFromSelection(f);
          }
          view.repaint();
          break;
        }
      }
    }
  }
  @Override
  public void mouseDrag(int i, int j, java.awt.event.MouseEvent e) {
    if (currentHandle != null) {
      currentHandle.dragInteraction(i, j, e, view);
      return;
    }

    if (selMode) {
      sx1 = e.getX();
      sy1 = e.getY();
      Set<Figure> sel = new HashSet<Figure>();
      Rectangle selRectangle =
          new Rectangle(min(sx0, sx1), min(sy0, sy1), abs(sx1 - sx0), abs(sy1 - sy0));

      for (Figure f : view.getModel().getFigures()) {
        if (contains(selRectangle, f.getBounds())) {
          sel.add(f);
        }
      }
      view.setSelectionRubberBand(selRectangle);
      view.clearSelection();
      for (Figure f : sel) {
        view.addToSelection(f);
      }
      view.repaint();
      return;
    }

    int k = i - tempX;
    int l = j - tempY;

    for (Figure f : view.getSelection()) {
      f.move(k, l);
      view.getModel().getDrawCommandHandler().addCommand(new MoveCommand(f, k, l));
    }

    tempX = i;
    tempY = j;
    view.repaint();
  }