@Override
  public void mouseDragged(MouseEvent e) {
    Canvas c = context.getTabbedPaneController().getCurrentTabContent();
    SelectionModel selectionModel = c.getSelectionModel();
    if (!selectionModel.prepareForMove()) {
      moved = false;
      return;
    }
    Point thisCoord = e.getPoint();
    int dx = thisCoord.x - previousPosition.x;
    int dy = thisCoord.y - previousPosition.y;
    if (selectionRec == null) {
      selectionRec = selectionModel.getSelectionBounds();
    }
    selectionRec.setRect(
        selectionRec.getX() + dx,
        selectionRec.getY() + dy,
        selectionRec.getWidth(),
        selectionRec.getHeight());
    c.setSelectionRectangleBounds(
        selectionRec.getX(),
        selectionRec.getY(),
        selectionRec.getWidth(),
        selectionRec.getHeight());

    c.setShowSelectionRectangle(true);

    c.repaint();
    previousPosition = (Point) thisCoord.clone();
    moved = true;
  }
  public void actionPerformed(ActionEvent e) {
    Canvas c = KrokiMockupToolApp.getInstance().getTabbedPaneController().getCurrentTabContent();
    if (c == null) {
      return;
    }
    VisibleClass visibleClass = c.getVisibleClass();
    SelectionModel selectionModel = c.getSelectionModel();

    for (VisibleElement visibleElement : selectionModel.getVisibleElementList()) {
      if (visibleElement instanceof ElementsGroup) {
        ((ElementsGroup) visibleElement).setGroupAlignment(GroupAlignment.right);
        ((Composite) visibleElement.getComponent())
            .getLayoutManager()
            .setAlign(LayoutManager.RIGHT);
        visibleElement.update();
      }
    }
    visibleClass.update();
    c.repaint();
  }
  @Override
  public void mouseReleased(MouseEvent e) {
    Canvas c = context.getTabbedPaneController().getCurrentTabContent();
    SelectionModel selectionModel = c.getSelectionModel();
    CommandManager commandManager = c.getCommandManager();
    if (moved && selectionRec != null) {
      Point thisCoord = e.getPoint();

      int dx = thisCoord.x - startPosition.x;
      int dy = thisCoord.y - startPosition.y;

      VisibleClass visibleClass = c.getVisibleClass();

      Point2D selPoint =
          selectionModel.getRelativePositionFor(selectionRec.getX(), selectionRec.getY());
      int sX = (int) selPoint.getX();
      int sY = (int) selPoint.getY();
      if (sX < 0) {
        dx = dx - sX;
      }
      if (sY < 0) {
        dy = dy - sY;
      }

      MoveCommand moveCommand = new MoveCommand(selectionModel.getVisibleElementList(), dx, dy);
      commandManager.addCommand(moveCommand);

      visibleClass.update();
      c.setShowSelectionRectangle(false);
      selectionRec = null;
      selectionModel.finishMove();
      moved = false;
    }
    c.repaint();
    context.goNext(State.SELECT_STATE);
  }