public CellGrid(Map<Point, Component> mapComps) {
        mapRows = new HashMap<>(25);
        mapCols = new HashMap<>(25);
        for (Map.Entry<Point, Component> entry : mapComps.entrySet()) {
            int row = entry.getKey().y;
            int col = entry.getKey().x;
            List<Cell> rows = mapRows.get(row);
            List<Cell> cols = mapCols.get(col);
            if (rows == null) {
                rows = new ArrayList<>(25);
                mapRows.put(row, rows);
            }
            if (cols == null) {
                cols = new ArrayList<>(25);
                mapCols.put(col, cols);
            }
            Cell cell = new Cell(entry.getKey(), entry.getValue());
            rows.add(cell);
            cols.add(cell);
        }

        int rowCount = mapRows.size();
        int colCount = mapCols.size();

        cellWidth = 0;
        cellHeight = 0;

        for (List<Cell> comps : mapRows.values()) {
            for (Cell cell : comps) {
                Component comp = cell.getComponent();
                cellWidth = Math.max(cellWidth, comp.getPreferredSize().width);
                cellHeight = Math.max(cellHeight, comp.getPreferredSize().height);
            }
        }

        int cellSize = Math.max(cellHeight, cellWidth);

        prefSize = new Dimension(cellSize * colCount, cellSize * rowCount);
    }