From 9199672c779e21fdd7dd4de50e08e31849857a84 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 28 Mar 2019 21:38:04 +0100 Subject: [PATCH 1/2] Convert AutoLinkFilesAction to JavaFX Fixes #4819. --- .../org/jabref/cli/ArgumentProcessor.java | 7 +- src/main/java/org/jabref/gui/JabRefFrame.java | 4 +- .../gui/actions/AutoLinkFilesAction.java | 52 ------ .../externalfiles/AutoLinkFilesAction.java | 68 +++++++ .../externalfiles/AutoSetFileLinksUtil.java | 66 +++++-- .../gui/externalfiles/AutoSetLinks.java | 172 ------------------ 6 files changed, 127 insertions(+), 242 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java create mode 100644 src/main/java/org/jabref/gui/externalfiles/AutoLinkFilesAction.java delete mode 100644 src/main/java/org/jabref/gui/externalfiles/AutoSetLinks.java diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index f97a582daab..56a4de65bde 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -13,7 +13,9 @@ import org.jabref.Globals; import org.jabref.JabRefException; -import org.jabref.gui.externalfiles.AutoSetLinks; +import org.jabref.gui.externalfiles.AutoSetFileLinksUtil; +import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.gui.undo.NamedCompound; import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.exporter.AtomicFileWriter; import org.jabref.logic.exporter.BibDatabaseWriter; @@ -496,7 +498,8 @@ private void automaticallySetFileLinks(List loaded) { for (ParserResult parserResult : loaded) { BibDatabase database = parserResult.getDatabase(); LOGGER.info(Localization.lang("Automatically setting file links")); - AutoSetLinks.autoSetLinks(database.getEntries(), parserResult.getDatabaseContext()); + AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(parserResult.getDatabaseContext(), Globals.prefs.getFilePreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance()); + util.linkAssociatedFiles(database.getEntries(), new NamedCompound("")); } } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 838f5d459f0..fed754d5f7a 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -56,7 +56,6 @@ import org.jabref.JabRefExecutorService; import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.Actions; -import org.jabref.gui.actions.AutoLinkFilesAction; import org.jabref.gui.actions.BibtexKeyPatternAction; import org.jabref.gui.actions.ConnectToSharedDatabaseCommand; import org.jabref.gui.actions.CopyFilesAction; @@ -88,6 +87,7 @@ import org.jabref.gui.exporter.ExportToClipboardAction; import org.jabref.gui.exporter.SaveAllAction; import org.jabref.gui.exporter.SaveDatabaseAction; +import org.jabref.gui.externalfiles.AutoLinkFilesAction; import org.jabref.gui.externalfiles.FindUnlinkedFilesAction; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.help.AboutAction; @@ -821,7 +821,7 @@ private MenuBar createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.SET_FILE_LINKS, new AutoLinkFilesAction()) + factory.createMenuItem(StandardActions.SET_FILE_LINKS, new AutoLinkFilesAction(this, prefs)) ); PushToApplicationButton pushToExternal = new PushToApplicationButton(this, pushApplications.getApplications()); diff --git a/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java b/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java deleted file mode 100644 index 7b77c9f59b4..00000000000 --- a/src/main/java/org/jabref/gui/actions/AutoLinkFilesAction.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.jabref.gui.actions; - -import java.util.List; - -import javax.swing.JDialog; -import javax.swing.JFrame; - -import org.jabref.JabRefExecutorService; -import org.jabref.JabRefGUI; -import org.jabref.gui.externalfiles.AutoSetLinks; -import org.jabref.gui.undo.NamedCompound; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.entry.BibEntry; - -/** - * This Action may only be used in a menu or button. - * Never in the entry editor. FileListEditor and EntryEditor have other ways to update the file links - */ -public class AutoLinkFilesAction extends SimpleCommand { - - public AutoLinkFilesAction() { - - } - - @Override - public void execute() { - List entries = JabRefGUI.getMainFrame().getCurrentBasePanel().getSelectedEntries(); - if (entries.isEmpty()) { - JabRefGUI.getMainFrame().getCurrentBasePanel() - .output(Localization.lang("This operation requires one or more entries to be selected.")); - return; - } - JDialog diag = new JDialog((JFrame) null, true); - final NamedCompound nc = new NamedCompound(Localization.lang("Automatically set file links")); - Runnable runnable = AutoSetLinks.autoSetLinks(entries, nc, null, - JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext(), e -> { - if (e.getID() > 0) { - // entry has been updated in Util.autoSetLinks, only treat nc and status message - if (nc.hasEdits()) { - nc.end(); - JabRefGUI.getMainFrame().getCurrentBasePanel().getUndoManager().addEdit(nc); - JabRefGUI.getMainFrame().getCurrentBasePanel().markBaseChanged(); - } - JabRefGUI.getMainFrame().output(Localization.lang("Finished automatically setting external links.")); - } else { - JabRefGUI.getMainFrame().output(Localization.lang("Finished automatically setting external links.") + " " - + Localization.lang("No files found.")); - } - } , diag); - JabRefExecutorService.INSTANCE.execute(runnable); - } -} diff --git a/src/main/java/org/jabref/gui/externalfiles/AutoLinkFilesAction.java b/src/main/java/org/jabref/gui/externalfiles/AutoLinkFilesAction.java new file mode 100644 index 00000000000..967243e840b --- /dev/null +++ b/src/main/java/org/jabref/gui/externalfiles/AutoLinkFilesAction.java @@ -0,0 +1,68 @@ +package org.jabref.gui.externalfiles; + +import java.util.List; + +import javafx.concurrent.Task; + +import org.jabref.gui.DialogService; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.actions.SimpleCommand; +import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.gui.undo.NamedCompound; +import org.jabref.logic.l10n.Localization; +import org.jabref.model.entry.BibEntry; +import org.jabref.preferences.JabRefPreferences; + +/** + * This Action may only be used in a menu or button. + * Never in the entry editor. FileListEditor and EntryEditor have other ways to update the file links + */ +public class AutoLinkFilesAction extends SimpleCommand { + + private final DialogService dialogService; + private final JabRefFrame frame; + private final JabRefPreferences preferences; + + public AutoLinkFilesAction(JabRefFrame frame, JabRefPreferences preferences) { + this.frame = frame; + this.dialogService = frame.getDialogService(); + this.preferences = preferences; + } + + @Override + public void execute() { + List entries = frame.getCurrentBasePanel().getSelectedEntries(); + if (entries.isEmpty()) { + dialogService.notify(Localization.lang("This operation requires one or more entries to be selected.")); + return; + } + + final NamedCompound nc = new NamedCompound(Localization.lang("Automatically set file links")); + AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(frame.getCurrentBasePanel().getBibDatabaseContext(), preferences.getFilePreferences(), preferences.getAutoLinkPreferences(), ExternalFileTypes.getInstance()); + Task> linkFilesTask = new Task>() { + @Override + protected List call() { + return util.linkAssociatedFiles(entries, nc); + } + + @Override + protected void succeeded() { + if (!getValue().isEmpty()) { + if (nc.hasEdits()) { + nc.end(); + frame.getCurrentBasePanel().getUndoManager().addEdit(nc); + } + dialogService.notify(Localization.lang("Finished automatically setting external links.")); + } else { + dialogService.notify(Localization.lang("Finished automatically setting external links.") + " " + Localization.lang("No files found.")); + } + } + }; + + dialogService.showProgressDialogAndWait( + Localization.lang("Automatically setting file links"), + Localization.lang("Searching for files"), + linkFilesTask + ); + } +} diff --git a/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java b/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java index f1f07088a16..284eba0f689 100644 --- a/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java +++ b/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java @@ -11,12 +11,17 @@ import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.externalfiletype.UnknownExternalFileType; +import org.jabref.gui.undo.NamedCompound; +import org.jabref.gui.undo.UndoableFieldChange; +import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.logic.util.io.AutoLinkPreferences; import org.jabref.logic.util.io.FileFinder; import org.jabref.logic.util.io.FileFinders; import org.jabref.logic.util.io.FileUtil; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.FileFieldWriter; import org.jabref.model.entry.LinkedFile; import org.jabref.model.metadata.FilePreferences; import org.jabref.model.util.FileHelper; @@ -26,7 +31,7 @@ public class AutoSetFileLinksUtil { - private static final Logger LOGGER = LoggerFactory.getLogger(AutoSetLinks.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AutoSetFileLinksUtil.class); private List directories; private AutoLinkPreferences autoLinkPreferences; private ExternalFileTypes externalFileTypes; @@ -35,12 +40,44 @@ public AutoSetFileLinksUtil(BibDatabaseContext databaseContext, FilePreferences this(databaseContext.getFileDirectoriesAsPaths(filePreferences), autoLinkPreferences, externalFileTypes); } - public AutoSetFileLinksUtil(List directories, AutoLinkPreferences autoLinkPreferences, ExternalFileTypes externalFileTypes) { + private AutoSetFileLinksUtil(List directories, AutoLinkPreferences autoLinkPreferences, ExternalFileTypes externalFileTypes) { this.directories = directories; this.autoLinkPreferences = autoLinkPreferences; this.externalFileTypes = externalFileTypes; } + public List linkAssociatedFiles(List entries, NamedCompound ce) { + List changedEntries = new ArrayList<>(); + for (BibEntry entry : entries) { + + List linkedFiles = new ArrayList<>(); + try { + linkedFiles = findAssociatedNotLinkedFiles(entry); + } catch (IOException e) { + LOGGER.error("Problem finding files", e); + } + + if (ce != null) { + for (LinkedFile linkedFile : linkedFiles) { + // store undo information + String newVal = FileFieldWriter.getStringRepresentation(linkedFile); + + String oldVal = entry.getField(FieldName.FILE).orElse(null); + + UndoableFieldChange fieldChange = new UndoableFieldChange(entry, FieldName.FILE, oldVal, newVal); + ce.addEdit(fieldChange); + + DefaultTaskExecutor.runInJavaFXThread(() -> { + entry.addFile(linkedFile); + }); + } + + changedEntries.add(entry); + } + } + return changedEntries; + } + public List findAssociatedNotLinkedFiles(BibEntry entry) throws IOException { List linkedFiles = new ArrayList<>(); @@ -53,22 +90,23 @@ public List findAssociatedNotLinkedFiles(BibEntry entry) throws IOEx // Collect the found files that are not yet linked for (Path foundFile : result) { boolean fileAlreadyLinked = entry.getFiles().stream() - .map(file -> file.findIn(directories)) - .anyMatch(file -> { - try { - return file.isPresent() && Files.isSameFile(file.get(), foundFile); - } catch (IOException e) { - LOGGER.error("Problem with isSameFile", e); - } - return false; - }); + .map(file -> file.findIn(directories)) + .anyMatch(file -> { + try { + return file.isPresent() && Files.isSameFile(file.get(), foundFile); + } catch (IOException e) { + LOGGER.error("Problem with isSameFile", e); + } + return false; + }); + if (!fileAlreadyLinked) { Optional type = FileHelper.getFileExtension(foundFile) - .map(externalFileTypes::getExternalFileTypeByExt) - .orElse(Optional.of(new UnknownExternalFileType(""))); + .map(externalFileTypes::getExternalFileTypeByExt) + .orElse(Optional.of(new UnknownExternalFileType(""))); String strType = type.isPresent() ? type.get().getName() : ""; - String relativeFilePath = FileUtil.relativize(foundFile, directories).toString(); + Path relativeFilePath = FileUtil.relativize(foundFile, directories); LinkedFile linkedFile = new LinkedFile("", relativeFilePath, strType); linkedFiles.add(linkedFile); } diff --git a/src/main/java/org/jabref/gui/externalfiles/AutoSetLinks.java b/src/main/java/org/jabref/gui/externalfiles/AutoSetLinks.java deleted file mode 100644 index d874493a98d..00000000000 --- a/src/main/java/org/jabref/gui/externalfiles/AutoSetLinks.java +++ /dev/null @@ -1,172 +0,0 @@ -package org.jabref.gui.externalfiles; - -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import javax.swing.BorderFactory; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JProgressBar; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; - -import org.jabref.Globals; -import org.jabref.gui.externalfiletype.ExternalFileType; -import org.jabref.gui.externalfiletype.ExternalFileTypes; -import org.jabref.gui.undo.NamedCompound; -import org.jabref.gui.undo.UndoableFieldChange; -import org.jabref.gui.util.DefaultTaskExecutor; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.FileFieldWriter; -import org.jabref.model.entry.LinkedFile; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class AutoSetLinks { - - private static final Logger LOGGER = LoggerFactory.getLogger(AutoSetLinks.class); - - private AutoSetLinks() { - } - - /** - * Shortcut method if links are set without using the GUI - * - * @param entries the entries for which links should be set - * @param databaseContext the database for which links are set - */ - public static void autoSetLinks(List entries, BibDatabaseContext databaseContext) { - autoSetLinks(entries, null, null, databaseContext, null, null); - } - - /** - * Automatically add links for this set of entries, based on the globally stored list of external file types. The - * entries are modified, and corresponding UndoEdit elements added to the NamedCompound given as argument. - * Furthermore, all entries which are modified are added to the Set of entries given as an argument. - *

- * The entries' bibtex keys must have been set - entries lacking key are ignored. The operation is done in a new - * thread, which is returned for the caller to wait for if needed. - * - * @param entries A collection of BibEntry objects to find links for. - * @param ce A NamedCompound to add UndoEdit elements to. - * @param changedEntries MODIFIED, optional. A Set of BibEntry objects to which all modified entries is added. - - * @param databaseContext The database providing the relevant file directory, if any. - * @param callback An ActionListener that is notified (on the event dispatch thread) when the search is finished. - * The ActionEvent has id=0 if no new links were added, and id=1 if one or more links were added. This - * parameter can be null, which means that no callback will be notified. - * @param diag An instantiated modal JDialog which will be used to display the progress of the automatically setting. This - * parameter can be null, which means that no progress update will be shown. - * @return the thread performing the automatically setting - */ - public static Runnable autoSetLinks(final List entries, final NamedCompound ce, - final Set changedEntries, - final BibDatabaseContext databaseContext, final ActionListener callback, final JDialog diag) { - final Collection types = ExternalFileTypes.getInstance().getExternalFileTypeSelection(); - if (diag != null) { - final JProgressBar prog = new JProgressBar(SwingConstants.HORIZONTAL, 0, types.size() - 1); - final JLabel label = new JLabel(Localization.lang("Searching for files")); - prog.setIndeterminate(true); - prog.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - diag.setTitle(Localization.lang("Automatically setting file links")); - diag.getContentPane().add(prog, BorderLayout.CENTER); - diag.getContentPane().add(label, BorderLayout.SOUTH); - - diag.pack(); - diag.setLocationRelativeTo(diag.getParent()); - } - - Runnable r = () -> { - boolean foundAny = false; - AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(databaseContext, Globals.prefs.getFilePreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance()); - - for (BibEntry entry : entries) { - - List linkedFiles = new ArrayList<>(); - try { - linkedFiles = util.findAssociatedNotLinkedFiles(entry); - } catch (IOException e) { - LOGGER.error("Problem finding files", e); - } - - if (ce != null) { - for (LinkedFile linkedFile : linkedFiles) { - // store undo information - String newVal = FileFieldWriter.getStringRepresentation(linkedFile); - - String oldVal = entry.getField(FieldName.FILE).orElse(null); - - UndoableFieldChange fieldChange = new UndoableFieldChange(entry, FieldName.FILE, oldVal, newVal); - ce.addEdit(fieldChange); - - DefaultTaskExecutor.runInJavaFXThread(() -> { - entry.addFile(linkedFile); - }); - foundAny = true; - } - - if (changedEntries != null) { - changedEntries.add(entry); - } - } - - } - - final int id = foundAny ? 1 : 0; - SwingUtilities.invokeLater(() -> { - - if (diag != null) { - diag.dispose(); - } - if (callback != null) { - callback.actionPerformed(new ActionEvent(AutoSetLinks.class, id, "")); - } - - }); - - }; - - SwingUtilities.invokeLater(() -> { - // show dialog which will be hidden when the task is done - if (diag != null) { - diag.setVisible(true); - } - }); - - return r; - } - - /** - * Automatically add links for this entry to the table model given as an argument, based on the globally stored list - * of external file types. The entry itself is not modified. The entry's bibtex key must have been set. - * - * @param entry The BibEntry to find links for. - - * @param databaseContext The database providing the relevant file directory, if any. - * @param callback An ActionListener that is notified (on the event dispatch thread) when the search is finished. - * The ActionEvent has id=0 if no new links were added, and id=1 if one or more links were added. This - * parameter can be null, which means that no callback will be notified. The passed ActionEvent is - * constructed with (this, id, ""), where id is 1 if something has been done and 0 if nothing has been - * done. - * @param diag An instantiated modal JDialog which will be used to display the progress of the automatically setting. This - * parameter can be null, which means that no progress update will be shown. - * @return the runnable able to perform the automatically setting - */ - public static Runnable autoSetLinks(final BibEntry entry, - final BibDatabaseContext databaseContext, final ActionListener callback, final JDialog diag) { - return autoSetLinks(Collections.singletonList(entry), null, null, databaseContext, callback, - diag); - } - -} From 2b1631501ec836518a48d9cf890e0ae3952715ac Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 28 Mar 2019 22:01:17 +0100 Subject: [PATCH 2/2] Convert a few more dialogs to JavaFX --- src/main/java/org/jabref/JabRefMain.java | 12 ++++---- src/main/java/org/jabref/gui/JabRefFrame.java | 20 +++---------- .../importer/ParserResultWarningDialog.java | 17 +---------- .../actions/MergeReviewIntoCommentAction.java | 2 +- ...geReviewIntoCommentConfirmationDialog.java | 28 +++++++++---------- .../gui/mergeentries/FetchAndMergeEntry.java | 2 +- 6 files changed, 26 insertions(+), 55 deletions(-) diff --git a/src/main/java/org/jabref/JabRefMain.java b/src/main/java/org/jabref/JabRefMain.java index 66e624a002d..7c6f3d78f49 100644 --- a/src/main/java/org/jabref/JabRefMain.java +++ b/src/main/java/org/jabref/JabRefMain.java @@ -2,14 +2,13 @@ import java.net.Authenticator; -import javax.swing.JFrame; -import javax.swing.JOptionPane; - import javafx.application.Application; import javafx.application.Platform; +import javafx.scene.control.Alert; import javafx.stage.Stage; import org.jabref.cli.ArgumentProcessor; +import org.jabref.gui.FXDialog; import org.jabref.gui.remote.JabRefMessageHandler; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.l10n.Localization; @@ -119,9 +118,10 @@ private static void ensureCorrectJavaVersion() { versionError.append("\n"); versionError.append(Localization.lang("Note that currently, JabRef does not run with Java 9.")); } - final JFrame frame = new JFrame(); - JOptionPane.showMessageDialog(null, versionError, Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); - frame.dispose(); + + FXDialog alert = new FXDialog(Alert.AlertType.ERROR, Localization.lang("Error"), true); + alert.setHeaderText(null); + alert.setContentText(versionError.toString()); // We exit on Java 9 error since this will definitely not work if (java9Fail) { diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index fed754d5f7a..74d5ba16cf5 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -113,7 +113,6 @@ import org.jabref.logic.autosaveandbackup.BackupManager; import org.jabref.logic.importer.IdFetcher; import org.jabref.logic.importer.OpenDatabase; -import org.jabref.logic.importer.OutputPrinter; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.l10n.Localization; @@ -148,7 +147,7 @@ /** * The main window of the application. */ -public class JabRefFrame extends BorderPane implements OutputPrinter { +public class JabRefFrame extends BorderPane { // Frame titles. public static final String FRAME_TITLE = "JabRef"; @@ -1251,17 +1250,6 @@ private boolean isExistURLorDOI(List selectEntryList) { return false; } - @Override - public void showMessage(String message, String title, int msgType) { - JOptionPane.showMessageDialog(null, message, title, msgType); - } - - @Override - public void setStatus(String s) { - output(s); - } - - @Override public void showMessage(String message) { JOptionPane.showMessageDialog(null, message); } @@ -1440,7 +1428,7 @@ private void setDefaultTableFontSize() { for (BasePanel basePanel : getBasePanelList()) { basePanel.updateTableFont(); } - setStatus(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize()))); + dialogService.notify(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize()))); } private void increaseTableFontSize() { @@ -1448,7 +1436,7 @@ private void increaseTableFontSize() { for (BasePanel basePanel : getBasePanelList()) { basePanel.updateTableFont(); } - setStatus(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize()))); + dialogService.notify(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize()))); } private void decreaseTableFontSize() { @@ -1460,7 +1448,7 @@ private void decreaseTableFontSize() { for (BasePanel basePanel : getBasePanelList()) { basePanel.updateTableFont(); } - setStatus(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize()))); + dialogService.notify(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize()))); } private class CloseDatabaseAction extends SimpleCommand { diff --git a/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java b/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java index 45dbf2fc9e7..827f88f51de 100644 --- a/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java +++ b/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java @@ -1,13 +1,8 @@ package org.jabref.gui.importer; -import java.awt.Dimension; import java.util.List; import java.util.Objects; -import javax.swing.JOptionPane; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; - import org.jabref.gui.JabRefFrame; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.l10n.Localization; @@ -71,17 +66,7 @@ public static void showParserResultWarningDialog(final ParserResult parserResult dialogTitle = Localization.lang("Warnings") + " (" + parserResult.getFile().get().getName() + ")"; } - // Create JTextArea with JScrollPane - final JTextArea textArea = new JTextArea(dialogContent.toString()); - final JScrollPane scrollPane = new JScrollPane(textArea) { - - @Override - public Dimension getPreferredSize() { - return new Dimension(800, Math.min(Math.max(100, warnings.size() * 15), 400)); // Guess a suitable height between 100 and 400 - } - }; - // Show dialog - JOptionPane.showMessageDialog(null, scrollPane, dialogTitle, JOptionPane.WARNING_MESSAGE); + jabRefFrame.getDialogService().showWarningDialogAndWait(dialogTitle, dialogContent.toString()); } } diff --git a/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java b/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java index 2a76c406f62..3196f1c46aa 100644 --- a/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java @@ -20,7 +20,7 @@ public void performAction(BasePanel basePanel, ParserResult parserResult) { migration.performMigration(parserResult); List conflicts = MergeReviewIntoCommentMigration.collectConflicts(parserResult); - if (!conflicts.isEmpty() && new MergeReviewIntoCommentConfirmationDialog(basePanel).askUserForMerge(conflicts)) { + if (!conflicts.isEmpty() && new MergeReviewIntoCommentConfirmationDialog(basePanel.frame().getDialogService()).askUserForMerge(conflicts)) { migration.performConflictingMigration(parserResult); } } diff --git a/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentConfirmationDialog.java b/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentConfirmationDialog.java index 2f789560771..74889ba5462 100644 --- a/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentConfirmationDialog.java +++ b/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentConfirmationDialog.java @@ -4,18 +4,16 @@ import java.util.Optional; import java.util.stream.Collectors; -import javax.swing.JOptionPane; - -import org.jabref.gui.BasePanel; +import org.jabref.gui.DialogService; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; public class MergeReviewIntoCommentConfirmationDialog { - private final BasePanel panel; + private final DialogService dialogService; - public MergeReviewIntoCommentConfirmationDialog(BasePanel panel) { - this.panel = panel; + public MergeReviewIntoCommentConfirmationDialog(DialogService dialogService) { + this.dialogService = dialogService; } public boolean askUserForMerge(List conflicts) { @@ -25,15 +23,15 @@ public boolean askUserForMerge(List conflicts) { .map(Optional::get) .collect(Collectors.joining(",\n")); - String[] options = {Localization.lang("Merge fields")}; - int answer = JOptionPane.showOptionDialog( - null, - bibKeys + " " + - Localization.lang("has/have both a 'Comment' and a 'Review' field.") + "\n" + - Localization.lang("Since the 'Review' field was deprecated in JabRef 4.2, these two fields are about to be merged into the 'Comment' field.") + "\n" + - Localization.lang("The conflicting fields of these entries will be merged into the 'Comment' field."), - Localization.lang("Review Field Migration"), JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); + String content = bibKeys + " " + + Localization.lang("has/have both a 'Comment' and a 'Review' field.") + "\n" + + Localization.lang("Since the 'Review' field was deprecated in JabRef 4.2, these two fields are about to be merged into the 'Comment' field.") + "\n" + + Localization.lang("The conflicting fields of these entries will be merged into the 'Comment' field."); - return 0 == answer; + return dialogService.showConfirmationDialogAndWait( + Localization.lang("Review Field Migration"), + content, + Localization.lang("Merge fields") + ); } } diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index cd7be54acc3..ff87b3ddf2c 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -65,7 +65,7 @@ public void fetchAndMerge(BibEntry entry, List fields) { if (fetchedEntry.isPresent()) { showMergeDialog(entry, fetchedEntry.get(), fetcher.get()); } else { - panel.frame().setStatus(Localization.lang("Cannot get info based on given %0: %1", type, fieldContent.get())); + dialogService.notify(Localization.lang("Cannot get info based on given %0: %1", type, fieldContent.get())); } }) .onFailure(exception -> {