diff --git a/CHANGELOG.md b/CHANGELOG.md index cfbb06fed9a2..921fa8cbc537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,7 +48,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We changed connect timeouts for server requests to 30 seconds in general and 5 seconds for GROBID server (special) and improved user notifications on connection issues. [7026](https://github.com/JabRef/jabref/pull/7026) - We changed the order of the library tab context menu items. [#7171](https://github.com/JabRef/jabref/issues/7171) - We changed the way linked files are opened on Linux to use the native openFile method, compatible with confined packages. [7037](https://github.com/JabRef/jabref/pull/7037) -- We refined the entry preview to show the full names of authors and editors, to list the editor only if no author is present, have the year ealier. [#7083](https://github.com/JabRef/jabref/issues/7083) +- We refined the entry preview to show the full names of authors and editors, to list the editor only if no author is present, have the year earlier. [#7083](https://github.com/JabRef/jabref/issues/7083) +- We changed the resize behavior of table columns to change the width of the current column only. [#967](https://github.com/JabRef/jabref/issues/967) ### Fixed diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index d0e42e0221c5..1a4bbe78ccae 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -137,16 +137,14 @@ public MainTable(MainTableDataModel model, } } */ - mainTablePreferences.getColumnPreferences().getColumnSortOrder().forEach(columnModel -> + mainTablePreferences.getColumnPreferences().getColumnSortOrder().forEach(columnModel -> this.getColumns().stream() .map(column -> (MainTableColumn) column) .filter(column -> column.getModel().equals(columnModel)) .findFirst() .ifPresent(column -> this.getSortOrder().add(column))); - if (mainTablePreferences.getResizeColumnsToFit()) { - this.setColumnResizePolicy(new SmartConstrainedResizePolicy()); - } + this.setColumnResizePolicy(new SmartConstrainedResizePolicy()); this.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index 8ff3dd7efc9b..8b437d54c7c3 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -37,6 +37,7 @@ import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; import org.jabref.model.entry.field.SpecialField; +import org.jabref.model.entry.field.StandardField; import org.jabref.model.groups.AbstractGroup; import org.jabref.model.util.OptionalUtil; import org.jabref.preferences.PreferencesService; @@ -109,7 +110,16 @@ public MainTableColumnFactory(BibDatabaseContext database, default: case NORMALFIELD: if (!column.getQualifier().isBlank()) { - columns.add(createFieldColumn(column)); + TableColumn fieldColumn = createFieldColumn(column); + columns.add(fieldColumn); + if (column.getQualifier().equalsIgnoreCase(StandardField.YEAR.getName())) { + // We adjust the min width and the current width, but not the max width to allow the user to enlarge this field + // 75 is chosen, because of the optimal width of a four digit field + fieldColumn.setMinWidth(60); + fieldColumn.setPrefWidth(60); + } else { + fieldColumn.setMinWidth(ColumnPreferences.DEFAULT_COLUMN_WIDTH); + } } break; } @@ -125,7 +135,7 @@ public static void setExactWidth(TableColumn column, double width) { } /** - * Creates a column with a continous number + * Creates a column with a continuous number */ private TableColumn createIndexColumn(MainTableColumnModel columnModel) { TableColumn column = new MainTableColumn<>(columnModel); diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java index 0edf1dbde175..f7975c3b155e 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java @@ -124,6 +124,9 @@ public Type getType() { return typeProperty.getValue(); } + /** + * Returns the field name of the column (e.g., year) + */ public String getQualifier() { return qualifierProperty.getValue(); } diff --git a/src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java b/src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java index e6c543fb02fa..0c91356dc144 100644 --- a/src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java +++ b/src/main/java/org/jabref/gui/maintable/SmartConstrainedResizePolicy.java @@ -6,6 +6,7 @@ import java.util.List; import javafx.scene.control.ResizeFeaturesBase; +import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumnBase; import javafx.scene.control.TableView; import javafx.util.Callback; @@ -25,80 +26,37 @@ public class SmartConstrainedResizePolicy implements Callback table) { - double tableWidth = getContentWidth(table); - List> visibleLeafColumns = table.getVisibleLeafColumns(); - double totalWidth = visibleLeafColumns.stream().mapToDouble(TableColumnBase::getWidth).sum(); - - if (Math.abs(totalWidth - tableWidth) > 1) { - double totalPrefWidth = visibleLeafColumns.stream().mapToDouble(TableColumnBase::getPrefWidth).sum(); - if (totalPrefWidth > 0) { - for (TableColumnBase col : visibleLeafColumns) { - double share = col.getPrefWidth() / totalPrefWidth; - double newSize = tableWidth * share; - - // Just to make sure that we are staying under the total table width (due to rounding errors) - newSize -= 2; - - resize(col, newSize - col.getWidth()); - } - } - } - - return false; - } - - private void resize(TableColumnBase column, double delta) { - // We have to use reflection since TableUtil is not visible to us - try { - // TODO: reflective access, should be removed - Class clazz = Class.forName("javafx.scene.control.TableUtil"); - Method constrainedResize = clazz.getDeclaredMethod("resize", TableColumnBase.class, double.class); - constrainedResize.setAccessible(true); - constrainedResize.invoke(null, column, delta); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) { - LOGGER.error("Could not invoke resize in TableUtil", e); - } - } - private Boolean constrainedResize(TableView.ResizeFeatures prop) { TableView table = prop.getTable(); List> visibleLeafColumns = table.getVisibleLeafColumns(); - return constrainedResize(prop, - false, - getContentWidth(table) - 2, - visibleLeafColumns); - } - - private Boolean constrainedResize(TableView.ResizeFeatures prop, Boolean isFirstRun, Double contentWidth, List> visibleLeafColumns) { - // We have to use reflection since TableUtil is not visible to us - try { - // TODO: reflective access, should be removed - Class clazz = Class.forName("javafx.scene.control.TableUtil"); - Method constrainedResize = clazz.getDeclaredMethod("constrainedResize", ResizeFeaturesBase.class, Boolean.TYPE, Double.TYPE, List.class); - constrainedResize.setAccessible(true); - Object returnValue = constrainedResize.invoke(null, prop, isFirstRun, contentWidth, visibleLeafColumns); - return (Boolean) returnValue; - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) { - LOGGER.error("Could not invoke constrainedResize in TableUtil", e); - return false; + Double delta = prop.getDelta(); + TableColumn userChosenColumnToResize = prop.getColumn(); + + double oldWidth = userChosenColumnToResize.getWidth(); + double newWidth = oldWidth + delta; + prop.getColumn().getCo + if (delta < 0) { + double minWidth = userChosenColumnToResize.getMinWidth(); + LOGGER.trace("MinWidth {}", minWidth); + newWidth = Math.max(minWidth, oldWidth + delta); + } else { + double maxWidth = userChosenColumnToResize.getMaxWidth(); + LOGGER.trace("MaxWidth {}", maxWidth); + newWidth = Math.min(maxWidth, oldWidth + delta); } - } - - private Double getContentWidth(TableView table) { - try { - // TODO: reflective access, should be removed - Field privateStringField = TableView.class.getDeclaredField("contentWidth"); - privateStringField.setAccessible(true); - return (Double) privateStringField.get(table); - } catch (IllegalAccessException | NoSuchFieldException e) { - return 0d; + LOGGER.trace("Size: {} -> {}", oldWidth, newWidth); + if (oldWidth == newWidth) { + return false; } + userChosenColumnToResize.setPrefWidth(newWidth); + return true; } }