Search in sources :

Example 1 with TableColumnBase

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));
        }
    });
}
Also used : Format(java.text.Format) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OptionalDouble(java.util.OptionalDouble) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) EncodeDecode(jgnash.util.EncodeDecode) HashSet(java.util.HashSet) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) ObjectProperty(javafx.beans.property.ObjectProperty) NotNull(jgnash.util.NotNull) Set(java.util.Set) Logger(java.util.logging.Logger) Preferences(java.util.prefs.Preferences) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) TableColumnBase(javafx.scene.control.TableColumnBase) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) Preferences(java.util.prefs.Preferences)

Example 2 with TableColumnBase

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);
}
Also used : Format(java.text.Format) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OptionalDouble(java.util.OptionalDouble) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) EncodeDecode(jgnash.util.EncodeDecode) HashSet(java.util.HashSet) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) ObjectProperty(javafx.beans.property.ObjectProperty) NotNull(jgnash.util.NotNull) Set(java.util.Set) Logger(java.util.logging.Logger) Preferences(java.util.prefs.Preferences) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) TableColumnBase(javafx.scene.control.TableColumnBase) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) Format(java.text.Format) Objects(java.util.Objects) OptionalDouble(java.util.OptionalDouble) HashSet(java.util.HashSet)

Aggregations

Format (java.text.Format)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Objects (java.util.Objects)2 OptionalDouble (java.util.OptionalDouble)2 Set (java.util.Set)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Supplier (java.util.function.Supplier)2 Level (java.util.logging.Level)2 Logger (java.util.logging.Logger)2 Preferences (java.util.prefs.Preferences)2 BooleanProperty (javafx.beans.property.BooleanProperty)2 ObjectProperty (javafx.beans.property.ObjectProperty)2 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 ChangeListener (javafx.beans.value.ChangeListener)2