private void calculateSelectedRect() {
        double startX = start.getX();
        double startY = start.getY();
        double endX = end.getX();
        double endY = end.getY();
        double swidth = endX - startX;
        double sheight = endY - startY;

        if (swidth > 0 && sheight > 0) {
            rect.setRect(startX, startY, swidth, sheight);
        } else if (swidth > 0 && sheight < 0) {
            rect.setRect(startX, endY, swidth, -sheight);
        } else if (swidth < 0 && sheight > 0) {
            rect.setRect(endX, startY, -swidth, sheight);
        } else if (swidth < 0 && sheight < 0) {
            rect.setRect(endX, endY, -swidth, -sheight);
        }
    }