Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public MainTableTooltip(DialogService dialogService, GuiPreferences preferences,
this.preferences = preferences;
this.preview = new PreviewViewer(dialogService, preferences, themeManager, taskExecutor);
this.tooltipContent.getChildren().addAll(fieldValueLabel, preview);
this.preview.setMinHeight(200);
}

public Tooltip createTooltip(BibDatabaseContext databaseContext, BibEntry entry, String fieldValue) {
Expand Down
20 changes: 20 additions & 0 deletions jabgui/src/main/java/org/jabref/gui/preview/PreviewViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.net.MalformedURLException;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;

import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.SimpleStringProperty;
Expand Down Expand Up @@ -52,6 +54,7 @@
public class PreviewViewer extends ScrollPane implements InvalidationListener {

private static final Logger LOGGER = LoggerFactory.getLogger(PreviewViewer.class);
AtomicBoolean widthSet = new AtomicBoolean(false);

Copy link
Member

Choose a reason for hiding this comment

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

Please keep the empty line as the thing which follow these multiple lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

// https://stackoverflow.com/questions/5669448/get-selected-texts-html-in-div/5670825#5670825
private static final String JS_GET_SELECTION_HTML_SCRIPT = """
Expand Down Expand Up @@ -125,6 +128,23 @@ private void configurePreviewView(ThemeManager themeManager) {
return;
}

Platform.runLater(() -> {
if (previewView.getEngine().executeScript("document.getElementById('content').scrollHeight") instanceof java.lang.Number heightVal) {
double actualHeight = (heightVal).doubleValue();
LOGGER.debug("Preview Height {}", actualHeight);
previewView.setPrefHeight(actualHeight + 4);
}

if (previewView.getEngine().executeScript("document.getElementById('content').scrollWidth") instanceof java.lang.Number widthVal && !widthSet.get()) {
double actualWidth = (widthVal).doubleValue();
double updatedWidth = actualWidth + 310;

LOGGER.debug("Preview Width {}", actualWidth);
previewView.setPrefWidth(Math.min(updatedWidth, 500));
widthSet.set(true);
}
});

// https://stackoverflow.com/questions/15555510/javafx-stop-opening-url-in-webview-open-in-browser-instead
NodeList anchorList = previewView.getEngine().getDocument().getElementsByTagName("a");
for (int i = 0; i < anchorList.getLength(); i++) {
Expand Down
Loading