Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into convertDubplicate…
Browse files Browse the repository at this point in the history
…tojavafx

* upstream/master:
  Fix not on FX thread exception
  Force javafx to run thread (#4604)
  Convert new version dialog to JavaFX (#4602)
  • Loading branch information
Siedlerchr committed Jan 24, 2019
2 parents fa62673 + c6a1fcb commit fc97929
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 82 deletions.
12 changes: 8 additions & 4 deletions src/main/java/org/jabref/FallbackExceptionHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref;

import org.jabref.gui.util.DefaultTaskExecutor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -17,9 +19,11 @@ public static void installExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable exception) {
LOGGER.error("Uncaught exception occurred in " + thread, exception);
JabRefGUI.getMainFrame()
.getDialogService()
.showErrorDialogAndWait(
exception.getLocalizedMessage(), exception);

DefaultTaskExecutor.runInJavaFXThread(() ->
JabRefGUI.getMainFrame()
.getDialogService()
.showErrorDialogAndWait("Uncaught exception occurred in " + thread, exception)
);
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/EntryTypeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.List;

import javafx.application.Platform;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
Expand Down Expand Up @@ -143,6 +144,7 @@ public void initialize() {
}
}

Platform.runLater(() -> idTextField.requestFocus());
}

public EntryType getChoice() {
Expand Down
113 changes: 36 additions & 77 deletions src/main/java/org/jabref/gui/help/NewVersionDialog.java
Original file line number Diff line number Diff line change
@@ -1,92 +1,51 @@
package org.jabref.gui.help;

import java.awt.Cursor;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.event.MouseInputAdapter;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;

import org.jabref.Globals;
import org.jabref.gui.JabRefDialog;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.util.BaseDialog;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.Version;
import org.jabref.preferences.VersionPreferences;

public class NewVersionDialog extends JabRefDialog {
public class NewVersionDialog extends BaseDialog<Void> {

public NewVersionDialog(Version currentVersion, Version latestVersion) {
super(NewVersionDialog.class);
setTitle(Localization.lang("New version available"));

JLabel lblTitle = new JLabel(Localization.lang("A new version of JabRef has been released."));
JLabel lblCurrentVersion = new JLabel(Localization.lang("Installed version") + ": " + currentVersion.getFullVersion());
JLabel lblLatestVersion = new JLabel(Localization.lang("Latest version") + ": " + latestVersion.getFullVersion());

String localization = Localization.lang("To see what is new view the changelog.");
JLabel lblMoreInformation = new JLabel("<HTML><a href=" + latestVersion.getChangelogUrl() + "'>" + localization + "</a></HTML>");
lblMoreInformation.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
lblMoreInformation.addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
JabRefDesktop.openBrowserShowPopup(latestVersion.getChangelogUrl());
this.setTitle(Localization.lang("New version available"));

ButtonType btnIgnoreUpdate = new ButtonType(Localization.lang("Ignore this update"), ButtonBar.ButtonData.CANCEL_CLOSE);
ButtonType btnDownloadUpdate = new ButtonType(Localization.lang("Download update"), ButtonBar.ButtonData.APPLY);
ButtonType btnRemindMeLater = new ButtonType(Localization.lang("Remind me later"), ButtonBar.ButtonData.CANCEL_CLOSE);
this.getDialogPane().getButtonTypes().addAll(btnIgnoreUpdate, btnDownloadUpdate, btnRemindMeLater);
this.setResultConverter(button -> {
if (button == btnIgnoreUpdate) {
Globals.prefs.storeVersionPreferences(new VersionPreferences(latestVersion));
} else if (button == btnDownloadUpdate) {
JabRefDesktop.openBrowserShowPopup(Version.JABREF_DOWNLOAD_URL);
}
return null;
});

JButton btnIgnoreUpdate = new JButton(Localization.lang("Ignore this update"));
btnIgnoreUpdate.addActionListener(e -> {
Globals.prefs.storeVersionPreferences(new VersionPreferences(latestVersion));
dispose();
});

JButton btnDownloadUpdate = new JButton(Localization.lang("Download update"));
btnDownloadUpdate.addActionListener(e -> {
JabRefDesktop.openBrowserShowPopup(Version.JABREF_DOWNLOAD_URL);
dispose();
});

JButton btnRemindMeLater = new JButton(Localization.lang("Remind me later"));
btnRemindMeLater.addActionListener(e -> dispose());

JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridheight = 1;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(2, 5, 5, 2);

c.gridx = c.gridy = 0;
c.gridwidth = 3;
panel.add(lblTitle, c);

c.gridy = 1;
panel.add(lblCurrentVersion, c);

c.gridy = 2;
panel.add(lblLatestVersion, c);

c.gridy = 3;
panel.add(lblMoreInformation, c);

c.gridy = 4;
c.gridx = 0;
c.gridwidth = 1;
panel.add(btnDownloadUpdate, c);

c.gridx = 1;
panel.add(btnIgnoreUpdate, c);

c.gridx = 2;
panel.add(btnRemindMeLater, c);

add(panel);
pack();
setVisible(true);
Button defaultButton = (Button) this.getDialogPane().lookupButton(btnDownloadUpdate);
defaultButton.setDefaultButton(true);

Hyperlink lblMoreInformation = new Hyperlink(Localization.lang("To see what is new view the changelog."));
lblMoreInformation.setOnAction(event ->
JabRefDesktop.openBrowserShowPopup(latestVersion.getChangelogUrl())
);

VBox container = new VBox(
new Label(Localization.lang("A new version of JabRef has been released.")),
new Label(Localization.lang("Installed version") + ": " + currentVersion.getFullVersion()),
new Label(Localization.lang("Latest version") + ": " + latestVersion.getFullVersion()),
lblMoreInformation
);
getDialogPane().setContent(container);
getDialogPane().setPrefWidth(450);
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/help/VersionWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void showUpdateInfo(Optional<Version> newerVersion, boolean manualExecut
}
} else {
// notify the user about a newer version
new NewVersionDialog(installedVersion, newerVersion.get());
new NewVersionDialog(installedVersion, newerVersion.get()).showAndWait();
}
}
}

0 comments on commit fc97929

Please sign in to comment.