From 76be88965c9c7af4969f1b1a961e8823b849ad47 Mon Sep 17 00:00:00 2001 From: Sebastian Balzer Date: Sun, 3 Mar 2024 14:18:26 +0100 Subject: [PATCH 1/5] Add ability to zoom using Ctrl + Scroll in PDF Viewer --- .../gui/documentviewer/DocumentViewerControl.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java b/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java index 75709e4f28b..a28c33ea98d 100644 --- a/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java +++ b/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java @@ -14,6 +14,7 @@ import javafx.scene.control.ProgressIndicator; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.input.ScrollEvent; import javafx.scene.layout.StackPane; import javafx.scene.shape.Rectangle; import javafx.util.Duration; @@ -76,6 +77,16 @@ public void show(DocumentViewModel document) { flow.estimatedScrollYProperty().addListener((observable, oldValue, newValue) -> scrollY.setValue(newValue)); scrollY.addListener((observable, oldValue, newValue) -> flow.estimatedScrollYProperty().setValue((double) newValue)); flow.totalLengthEstimateProperty().addListener((observable, oldValue, newValue) -> scrollYMax.setValue(newValue)); + flow.addEventFilter(ScrollEvent.SCROLL, (ScrollEvent event) -> { + if (event.isControlDown()) { + event.consume(); + if (event.getDeltaY() > 0) { + changePageWidth(100); + } else { + changePageWidth(-100); + } + } + }); } private void updateCurrentPage(ObservableList visiblePages) { @@ -91,7 +102,8 @@ private void updateCurrentPage(ObservableList visiblePages) // Successful hit inMiddleOfViewport = Optional.of(hit.getCell()); } - } catch (NoSuchElementException exception) { + } catch ( + NoSuchElementException exception) { // Sometimes throws exception if no page is found -> ignore } From 4e609de1d3d6f6468d0f464827804bac438285af Mon Sep 17 00:00:00 2001 From: Sebastian Balzer Date: Sun, 3 Mar 2024 15:55:52 +0100 Subject: [PATCH 2/5] Limit zoom-out to ~1 page Observed problems with infinite zoom-out: - Occasional display errors (e.g. no text displayed for certain pages) - No content can be seen if zoomed out too far, might be unclear to user what happened and that zooming in will fix problem --- .../gui/documentviewer/DocumentViewerControl.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java b/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java index a28c33ea98d..c2a74f9253f 100644 --- a/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java +++ b/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java @@ -140,7 +140,16 @@ private void updateSizeOfDisplayedPages() { public void changePageWidth(int delta) { // Assuming the current page is A4 (or has same aspect ratio) - setPageWidth(desiredPageDimension.getWidth(Math.sqrt(2)) + delta); + int newWidth = desiredPageDimension.getWidth(Math.sqrt(2)) + delta; + // Limit zoom out to ~1 page due to occasional display errors when zooming out further + int minWidth = (int) (flow.getHeight() / 2 * Math.sqrt(2)); + if (newWidth < minWidth) { + if (newWidth - delta == minWidth) { // Attempting to zoom out when already at minWidth + return; + } + newWidth = minWidth; + } + setPageWidth(newWidth); } /** From a16e25032b496b307f6ef7da884fae178b8511ef Mon Sep 17 00:00:00 2001 From: Sebastian Balzer Date: Sun, 3 Mar 2024 16:01:32 +0100 Subject: [PATCH 3/5] Updated CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9c3b0c1f44..c6d73621744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We added the possibility to redownload files that had been present but are no longer in the specified location. [#10848](https://github.com/JabRef/jabref/issues/10848) - We added the citation key pattern `[camelN]`. Equivalent to the first N words of the `[camel]` pattern. - We added ability to export in CFF (Citation File Format) [#10661](https://github.com/JabRef/jabref/issues/10661). +- We added the ability to zoom in and out in the document viewer using Ctrl + Scroll. ### Changed From 2a710e7fcd0e8bdc4795e65df753ae871cf06e9d Mon Sep 17 00:00:00 2001 From: Sebastian Balzer <120449829+cardionaut@users.noreply.github.com> Date: Mon, 4 Mar 2024 09:56:33 +0100 Subject: [PATCH 4/5] Remove catch newline from formatter --- .../org/jabref/gui/documentviewer/DocumentViewerControl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java b/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java index c2a74f9253f..03b46392267 100644 --- a/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java +++ b/src/main/java/org/jabref/gui/documentviewer/DocumentViewerControl.java @@ -102,8 +102,7 @@ private void updateCurrentPage(ObservableList visiblePages) // Successful hit inMiddleOfViewport = Optional.of(hit.getCell()); } - } catch ( - NoSuchElementException exception) { + } catch (NoSuchElementException exception) { // Sometimes throws exception if no page is found -> ignore } From 2723e78de5c4dfe0962996d96b0340bbd10b521a Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 4 Mar 2024 11:25:47 +0100 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aee7fc805a7..172492abf17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We added the possibility to redownload files that had been present but are no longer in the specified location. [#10848](https://github.com/JabRef/jabref/issues/10848) - We added the citation key pattern `[camelN]`. Equivalent to the first N words of the `[camel]` pattern. - We added ability to export in CFF (Citation File Format) [#10661](https://github.com/JabRef/jabref/issues/10661). -- We added the ability to zoom in and out in the document viewer using Ctrl + Scroll. +- We added the ability to zoom in and out in the document viewer using Ctrl + Scroll. [#10964](https://github.com/JabRef/jabref/pull/10964) ### Changed