Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8207957: TableSkinUtils should not contain actual code implementation #6

Closed
wants to merge 14 commits into from
Closed
Expand Up @@ -165,7 +165,11 @@ public NestedTableColumnHeader(final TableColumnBase tc) {
if (me.getClickCount() == 2 && me.isPrimaryButtonDown()) {
// the user wants to resize the column such that its
// width is equal to the widest element in the column
header.resizeColumnToFitContent(column, -1);
TableHeaderRow tableHeader = header.getTableHeaderRow();
TableColumnHeader columnHeader = tableHeader.getColumnHeaderFor(column);
if(columnHeader != null){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after if and before {.

columnHeader.resizeColumnToFitContent(-1);
}
} else {
// rather than refer to the rect variable, we just grab
// it from the source to prevent a small memory leak.
Expand Down
Expand Up @@ -533,7 +533,7 @@ private void updateScene() {
if (getTableColumn() == null || getTableColumn().getWidth() != DEFAULT_COLUMN_WIDTH || getScene() == null) {
return;
}
doColumnAutoSize(getTableColumn(), n);
doColumnAutoSize(n);
autoSizeComplete = true;
}
}
Expand Down Expand Up @@ -585,25 +585,27 @@ private void initUI() {
}
}

private void doColumnAutoSize(TableColumnBase<?,?> column, int cellsToMeasure) {
double prefWidth = column.getPrefWidth();
private void doColumnAutoSize(int cellsToMeasure) {
double prefWidth = getTableColumn().getPrefWidth();

// if the prefWidth has been set, we do _not_ autosize columns
if (prefWidth == DEFAULT_COLUMN_WIDTH) {
resizeColumnToFitContent(column, cellsToMeasure);
resizeColumnToFitContent(cellsToMeasure);
}
}

/**
* Resizes the given column based on the preferred width of all items contained in it. This can be potentially very
* expensive if the number of rows is large. Subclass can either call this method or override it (no need to call
* {@code super()}) to provide their custom algorithm.
* Resizes this {@code TableColumnHeader}'s column based on content of header and content of cells. This
* implementation measures the preferred width of the header, the preferred width of the first {@code maxRow} cells
* and sizes the column to the maximum width of all measured values. Subclass can either call this method or
* override it (no need to call {@code super()}) to provide their custom implementation (exclude headers, exclude
* null content, use min).
*
* @param tc the column to resize
* @param maxRows the number of rows considered when resizing. If -1 is given, all rows are considered.
* @since 12
* @since 14
kevinrushforth marked this conversation as resolved.
Show resolved Hide resolved
*/
protected void resizeColumnToFitContent(TableColumnBase<?, ?> tc, int maxRows) {
protected void resizeColumnToFitContent(int maxRows) {
TableColumnBase<?, ?> tc = getTableColumn();
if (!tc.isResizable()) return;

Object control = this.getTableSkin().getSkinnable();
Expand Down Expand Up @@ -672,7 +674,10 @@ private <T,S> void resizeColumnToFitContent(TableView<T> tv, TableColumn<T, S> t

int size = tc.getColumns().size();
if (size > 0) {
resizeColumnToFitContent(tc.getColumns().get(size - 1), maxRows);
TableColumnHeader columnHeader = getTableHeaderRow().getColumnHeaderFor(tc.getColumns().get(size - 1));
if (columnHeader != null) {
columnHeader.resizeColumnToFitContent(maxRows);
}
return;
}

Expand Down Expand Up @@ -751,7 +756,10 @@ private <T,S> void resizeColumnToFitContent(TreeTableView<T> ttv, TreeTableColum

int size = tc.getColumns().size();
if (size > 0) {
resizeColumnToFitContent(tc.getColumns().get(size - 1), maxRows);
TableColumnHeader columnHeader = getTableHeaderRow().getColumnHeaderFor(tc.getColumns().get(size - 1));
if (columnHeader != null) {
columnHeader.resizeColumnToFitContent(maxRows);
}
return;
}

Expand Down
Expand Up @@ -140,7 +140,7 @@ public MyTableColumnHeader(final TableColumnBase tc) {
}

public void resizeCol() {
resizeColumnToFitContent(getTableColumn(), -1);
resizeColumnToFitContent(-1);
}
}
}