BaseGridData implements GridData { double calculateInitWidth(GridColumn<?> column, OptionalDouble optionalCurrentWidth) { if (!GridColumn.ColumnWidthMode.isAuto(column)) { return column.getWidth(); } GridWidthMetadata gridWidthMetadata = new GridWidthMetadata(optionalCurrentWidth); int visibleWidth = getVisibleWidth(); double calculatedWidth; if (gridWidthMetadata.numberOfAutoColumn < 2) { calculatedWidth = visibleWidth - gridWidthMetadata.fixedWidth; } else { calculatedWidth = (visibleWidth - gridWidthMetadata.fixedWidth) / (gridWidthMetadata.numberOfAutoColumn - 1); } return Math.max(calculatedWidth, column.getMinimumWidth()); } BaseGridData();  BaseGridData(final boolean isMerged); @Override List<GridColumn<?>> getColumns(); @Override int getColumnCount(); @Override void appendColumn(final GridColumn<?> column); @Override void insertColumn(final int index,
                             final GridColumn<?> column); @Override void deleteColumn(final GridColumn<?> column); @Override void moveColumnTo(final int index,
                             final GridColumn<?> column); @Override void moveColumnsTo(final int index,
                              final List<GridColumn<?>> columns); @Override List<GridRow> getRows(); @Override GridRow getRow(final int rowIndex); @Override void appendRow(final GridRow row); @Override void insertRow(final int rowIndex,
                          final GridRow row); @Override Range deleteRow(final int rowIndex); @Override void moveRowTo(final int index,
                          final GridRow row); @Override void moveRowsTo(final int index,
                           final List<GridRow> rows); @Override int getRowCount(); @Override int getHeaderRowCount(); @Override void setHeaderRowCount(final int headerRowCount); @Override GridCell<?> getCell(final int rowIndex,
                               final int columnIndex); @Override SelectedCell getSelectedCellsOrigin(); @Override List<SelectedCell> getSelectedCells(); @Override List<SelectedCell> getSelectedHeaderCells(); @Override void clearSelections(); @Override void updateColumn(final int index,
                             final GridColumn<?> column); @Override boolean isMerged(); @Override void setMerged(final boolean isMerged); @Override boolean isRowDraggingEnabled(); @Override void setRowDraggingEnabled(final boolean enabled); @Override boolean isColumnDraggingEnabled(); @Override void setColumnDraggingEnabled(final boolean enabled); @Override Range setCell(final int rowIndex,
                         final int columnIndex,
                         final Supplier<GridCell<?>> cellSupplier); @Override @SuppressWarnings("unchecked") Range setCellValue(final int rowIndex,
                              final int columnIndex,
                              final GridCellValue<?> value); @Override Range deleteCell(final int rowIndex,
                            final int columnIndex); @Override Range selectCell(final int rowIndex,
                            final int columnIndex); @Override Range selectCells(final int rowIndex,
                             final int columnIndex,
                             final int width,
                             final int height); @Override Range selectHeaderCell(final int headerRowIndex,
                                  final int headerColumnIndex); @Override void collapseCell(final int rowIndex,
                             final int columnIndex); @Override void expandCell(final int rowIndex,
                           final int columnIndex); @Override boolean refreshWidth(); @Override boolean refreshWidth(double currentWidth); @Override boolean setVisibleSizeAndRefresh(int width, int height); @Override int getVisibleWidth(); @Override int getVisibleHeight();  }
@Test public void calculateInitWidth() { BaseGridData data = spy(baseGridData); double originalWidth = 100; BaseGridColumn<String> column = new BaseGridColumn<>(header, columnRenderer, originalWidth); column.setColumnWidthMode(GridColumn.ColumnWidthMode.FIXED); data.appendColumn(column); assertEquals(originalWidth, data.calculateInitWidth(column, OptionalDouble.empty()), 0.1); data.setVisibleSizeAndRefresh(500, 0); BaseGridColumn<String> column1 = new BaseGridColumn<>(header, columnRenderer, originalWidth); column1.setColumnWidthMode(GridColumn.ColumnWidthMode.AUTO); data.appendColumn(column1); assertEquals(data.getVisibleWidth() - originalWidth, data.calculateInitWidth(column1, OptionalDouble.empty()), 0.1); BaseGridColumn<String> column2 = new BaseGridColumn<>(header, columnRenderer, originalWidth); column2.setColumnWidthMode(GridColumn.ColumnWidthMode.AUTO); data.appendColumn(column2); BaseGridColumn<String> column3 = new BaseGridColumn<>(header, columnRenderer, originalWidth); column3.setColumnWidthMode(GridColumn.ColumnWidthMode.AUTO); data.appendColumn(column3); assertEquals(((data.getVisibleWidth() - originalWidth) / 2), data.calculateInitWidth(column2, OptionalDouble.empty()), 0.1); BaseGridColumn<String> column4 = new BaseGridColumn<>(header, columnRenderer, originalWidth); column4.setColumnWidthMode(GridColumn.ColumnWidthMode.AUTO); double minWidth = originalWidth * 10; column4.setMinimumWidth(minWidth); data.appendColumn(column4); assertEquals(minWidth, column4.getWidth(), 0.1); }