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 new version dialog to JavaFX #4602

Merged
merged 1 commit into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
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();
}
}
}