Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert AutoLinkFilesAction to JavaFX #4822

Merged
merged 2 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Copy link
Member

Choose a reason for hiding this comment

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

I think this dialog is superflous as JabRef won't even start with java9 cause of the class/module visibility

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) {
Expand Down
20 changes: 4 additions & 16 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -1251,17 +1250,6 @@ private boolean isExistURLorDOI(List<BibEntry> 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);
}
Expand Down Expand Up @@ -1440,15 +1428,15 @@ 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() {
GUIGlobals.setFont(GUIGlobals.currentFont.getSize() + 1);
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() {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void performAction(BasePanel basePanel, ParserResult parserResult) {

migration.performMigration(parserResult);
List<BibEntry> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BibEntry> conflicts) {
Expand All @@ -25,15 +23,15 @@ public boolean askUserForMerge(List<BibEntry> 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")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void fetchAndMerge(BibEntry entry, List<String> 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 -> {
Expand Down