From 57fb5f659df9804e6f8d531bcbe554de331c7f12 Mon Sep 17 00:00:00 2001 From: mulla028 Date: Thu, 5 Dec 2024 18:24:02 -0500 Subject: [PATCH] WebView and CheckBox added, onMarkdownToggle() method implemented to handle checkbox changes --- .../summary/SummaryShowingComponent.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/java/org/jabref/gui/ai/components/summary/SummaryShowingComponent.java b/src/main/java/org/jabref/gui/ai/components/summary/SummaryShowingComponent.java index 3cb04347d11..456e5253650 100644 --- a/src/main/java/org/jabref/gui/ai/components/summary/SummaryShowingComponent.java +++ b/src/main/java/org/jabref/gui/ai/components/summary/SummaryShowingComponent.java @@ -6,24 +6,31 @@ import java.util.Locale; import javafx.fxml.FXML; +import javafx.scene.control.CheckBox; import javafx.scene.control.TextArea; import javafx.scene.layout.VBox; import javafx.scene.text.Text; +import javafx.scene.web.WebView; import org.jabref.logic.ai.summarization.Summary; +import org.jabref.logic.layout.format.MarkdownFormatter; import com.airhacks.afterburner.views.ViewLoader; public class SummaryShowingComponent extends VBox { @FXML private TextArea summaryTextArea; @FXML private Text summaryInfoText; + @FXML private WebView markdownWebView; + @FXML private CheckBox markdownCheckbox; private final Summary summary; private final Runnable regenerateCallback; + private final MarkdownFormatter markdownFormatter; public SummaryShowingComponent(Summary summary, Runnable regenerateCallback) { this.summary = summary; this.regenerateCallback = regenerateCallback; + this.markdownFormatter = new MarkdownFormatter(); ViewLoader.view(this) .root(this) @@ -33,6 +40,8 @@ public SummaryShowingComponent(Summary summary, Runnable regenerateCallback) { @FXML private void initialize() { summaryTextArea.setText(summary.content()); + markdownWebView.setVisible(false); + markdownWebView.setManaged(false); String newInfo = summaryInfoText .getText() @@ -46,6 +55,29 @@ private static String formatTimestamp(LocalDateTime timestamp) { return timestamp.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.getDefault())); } + @FXML + private void onMarkdownToggle() { + if (markdownCheckbox.isSelected()) { + String htmlContent = markdownFormatter.format(summaryTextArea.getText()); + markdownWebView.getEngine().loadContent(htmlContent); + + markdownWebView.setPrefHeight(summaryTextArea.getPrefHeight()); + markdownWebView.setPrefWidth(summaryTextArea.getPrefWidth()); + + markdownWebView.setVisible(true); + markdownWebView.setManaged(true); + + summaryTextArea.setVisible(false); + summaryTextArea.setManaged(false); + } else { + summaryTextArea.setVisible(true); + summaryTextArea.setManaged(true); + + markdownWebView.setVisible(false); + markdownWebView.setManaged(false); + } + } + @FXML private void onRegenerateButtonClick() { regenerateCallback.run();