use of javafx.scene.control.TableColumnBase in project jgnash by ccavanaugh.
the class TableViewManager method saveColumnWidths.
private void saveColumnWidths() {
JavaFXUtils.runLater(() -> {
if (preferenceKeyFactory.get() != null) {
final double[] columnWidths = tableView.getColumns().filtered(TableColumnBase::isVisible).stream().mapToDouble(value -> Math.floor(value.getWidth())).toArray();
final Preferences preferences = Preferences.userRoot().node(preferencesUserRoot + PREF_NODE_REG_WIDTH);
preferences.put(preferenceKeyFactory.get().get(), EncodeDecode.encodeDoubleArray(columnWidths));
}
});
}
use of javafx.scene.control.TableColumnBase in project jgnash by ccavanaugh.
the class TableViewManager method getCalculatedColumnWidth.
/**
* Determines the preferred width of the column including contents.
*
* @param column {@code TableColumn} to measure content
* @return preferred width
*/
private double getCalculatedColumnWidth(final TableColumnBase<S, ?> column) {
double maxWidth = 0;
/* Collect all the unique cell items and remove null*/
final Set<Object> cellItems = new HashSet<>();
for (int i = 0; i < tableView.getItems().size(); i++) {
cellItems.add(column.getCellData(i));
}
cellItems.remove(null);
if (cellItems.size() > 0) {
// don't try if there is no data or the stream function will throw an error
final OptionalDouble max = cellItems.parallelStream().filter(Objects::nonNull).mapToDouble(o -> {
final Format format = columnFormatFactory.get().call(column);
return JavaFXUtils.getDisplayedTextWidth(format != null ? format.format(o) : o.toString(), column.getStyle());
}).max();
maxWidth = max.isPresent() ? max.getAsDouble() : 0;
}
//noinspection SuspiciousMethodCalls
maxWidth = Math.max(maxWidth, Math.max(column.getMinWidth(), minimumColumnWidthFactory.get().call(tableView.getColumns().indexOf(column))));
// header text width
maxWidth = Math.max(maxWidth, JavaFXUtils.getDisplayedTextWidth(column.getText(), column.getStyle()) * BOLD_MULTIPLIER);
return Math.ceil(maxWidth + COLUMN_PADDING);
}
Aggregations