Index: /trunk/src/org/openstreetmap/josm/gui/MainApplication.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/MainApplication.java (revision 12669)
+++ /trunk/src/org/openstreetmap/josm/gui/MainApplication.java (revision 12670)
@@ -210,9 +210,51 @@
}
+ /**
+ * Asks user to update its version of Java.
+ * @param updVersion target update version
+ * @param url download URL
+ * @param major true for a migration towards a major version of Java (8:9), false otherwise
+ * @param eolDate the EOL/expiration date
+ * @since 12270
+ */
+ public static void askUpdateJava(String updVersion, String url, String eolDate, boolean major) {
+ ExtendedDialog ed = new ExtendedDialog(
+ Main.parent,
+ tr("Outdated Java version"),
+ tr("OK"), tr("Update Java"), tr("Cancel"));
+ // Check if the dialog has not already been permanently hidden by user
+ if (!ed.toggleEnable("askUpdateJava"+updVersion).toggleCheckState()) {
+ ed.setButtonIcons("ok", "java", "cancel").setCancelButton(3);
+ ed.setMinimumSize(new Dimension(480, 300));
+ ed.setIcon(JOptionPane.WARNING_MESSAGE);
+ StringBuilder content = new StringBuilder(tr("You are running version {0} of Java.",
+ ""+System.getProperty("java.version")+"")).append("
");
+ if ("Sun Microsystems Inc.".equals(System.getProperty("java.vendor")) && !platform.isOpenJDK()) {
+ content.append("").append(tr("This version is no longer supported by {0} since {1} and is not recommended for use.",
+ "Oracle", eolDate)).append("
");
+ }
+ content.append("")
+ .append(major ?
+ tr("JOSM will soon stop working with this version; we highly recommend you to update to Java {0}.", updVersion) :
+ tr("You may face critical Java bugs; we highly recommend you to update to Java {0}.", updVersion))
+ .append("
")
+ .append(tr("Would you like to update now ?"));
+ ed.setContent(content.toString());
+
+ if (ed.showDialog().getValue() == 2) {
+ try {
+ platform.openUrl(url);
+ } catch (IOException e) {
+ Logging.warn(e);
+ }
+ }
+ }
+ }
+
@Override
protected List beforeInitializationTasks() {
return Arrays.asList(
new InitializationTask(tr("Starting file watcher"), fileWatcher::start),
- new InitializationTask(tr("Executing platform startup hook"), platform::startupHook),
+ new InitializationTask(tr("Executing platform startup hook"), () -> platform.startupHook(MainApplication::askUpdateJava)),
new InitializationTask(tr("Building main menu"), this::initializeMainWindow),
new InitializationTask(tr("Updating user interface"), () -> {
Index: /trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/tools/PlatformHook.java (revision 12669)
+++ /trunk/src/org/openstreetmap/josm/tools/PlatformHook.java (revision 12670)
@@ -2,7 +2,4 @@
package org.openstreetmap.josm.tools;
-import static org.openstreetmap.josm.tools.I18n.tr;
-
-import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.io.BufferedReader;
@@ -20,8 +17,5 @@
import java.util.List;
-import javax.swing.JOptionPane;
-
import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.gui.ExtendedDialog;
import org.openstreetmap.josm.io.CertificateAmendment.CertAmend;
import org.openstreetmap.josm.tools.date.DateUtils;
@@ -61,6 +55,8 @@
* Reason: On OSX we need to register some callbacks with the
* OS, so we'll receive events from the system menu.
- */
- default void startupHook() {
+ * @param callback Java expiration callback, providing GUI feedback
+ * @since 12270 (signature)
+ */
+ default void startupHook(JavaExpirationCallback callback) {
// Do nothing
}
@@ -246,54 +242,30 @@
/**
- * Asks user to update its version of Java.
- * @param updVersion target update version
- * @param url download URL
- * @param major true for a migration towards a major version of Java (8:9), false otherwise
- * @param eolDate the EOL/expiration date
+ * Called when an outdated version of Java is detected at startup.
+ * @since 12270
+ */
+ @FunctionalInterface
+ public interface JavaExpirationCallback {
+ /**
+ * Asks user to update its version of Java.
+ * @param updVersion target update version
+ * @param url download URL
+ * @param major true for a migration towards a major version of Java (8:9), false otherwise
+ * @param eolDate the EOL/expiration date
+ */
+ void askUpdateJava(String updVersion, String url, String eolDate, boolean major);
+ }
+
+ /**
+ * Checks if the running version of Java has expired, proposes to user to update it if needed.
+ * @param callback Java expiration callback
+ * @since 12270 (signature)
* @since 12219
*/
- default void askUpdateJava(String updVersion, String url, String eolDate, boolean major) {
- ExtendedDialog ed = new ExtendedDialog(
- Main.parent,
- tr("Outdated Java version"),
- tr("OK"), tr("Update Java"), tr("Cancel"));
- // Check if the dialog has not already been permanently hidden by user
- if (!ed.toggleEnable("askUpdateJava"+updVersion).toggleCheckState()) {
- ed.setButtonIcons("ok", "java", "cancel").setCancelButton(3);
- ed.setMinimumSize(new Dimension(480, 300));
- ed.setIcon(JOptionPane.WARNING_MESSAGE);
- StringBuilder content = new StringBuilder(tr("You are running version {0} of Java.",
- ""+System.getProperty("java.version")+"")).append("
");
- if ("Sun Microsystems Inc.".equals(System.getProperty("java.vendor")) && !isOpenJDK()) {
- content.append("").append(tr("This version is no longer supported by {0} since {1} and is not recommended for use.",
- "Oracle", eolDate)).append("
");
- }
- content.append("")
- .append(major ?
- tr("JOSM will soon stop working with this version; we highly recommend you to update to Java {0}.", updVersion) :
- tr("You may face critical Java bugs; we highly recommend you to update to Java {0}.", updVersion))
- .append("
")
- .append(tr("Would you like to update now ?"));
- ed.setContent(content.toString());
-
- if (ed.showDialog().getValue() == 2) {
- try {
- openUrl(url);
- } catch (IOException e) {
- Logging.warn(e);
- }
- }
- }
- }
-
- /**
- * Checks if the running version of Java has expired, proposes to user to update it if needed.
- * @since 12219
- */
- default void checkExpiredJava() {
+ default void checkExpiredJava(JavaExpirationCallback callback) {
Date expiration = Utils.getJavaExpirationDate();
if (expiration != null && expiration.before(new Date())) {
String version = Utils.getJavaLatestVersion();
- askUpdateJava(version != null ? version : "latest",
+ callback.askUpdateJava(version != null ? version : "latest",
Main.pref.get("java.update.url", "https://www.java.com/download"),
DateUtils.getDateFormat(DateFormat.MEDIUM).format(expiration), false);
Index: /trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java (revision 12669)
+++ /trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java (revision 12670)
@@ -48,5 +48,5 @@
@Override
- public void startupHook() {
+ public void startupHook(JavaExpirationCallback callback) {
// Here we register callbacks for the menu entries in the system menu and file opening through double-click
// http://openjdk.java.net/jeps/272
@@ -79,5 +79,5 @@
Logging.warn("Failed to register with OSX: " + ex);
}
- checkExpiredJava();
+ checkExpiredJava(callback);
}
Index: /trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java (revision 12669)
+++ /trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java (revision 12670)
@@ -183,6 +183,6 @@
@Override
- public void startupHook() {
- checkExpiredJava();
+ public void startupHook(JavaExpirationCallback callback) {
+ checkExpiredJava(callback);
}
Index: /trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookOsxTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookOsxTest.java (revision 12669)
+++ /trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookOsxTest.java (revision 12670)
@@ -37,5 +37,5 @@
@Test
public void testStartupHook() {
- hook.startupHook();
+ hook.startupHook((a,b,c,d) -> System.out.println("callback"));
}
Index: /trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java (revision 12669)
+++ /trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java (revision 12670)
@@ -44,5 +44,5 @@
@Test
public void testStartupHook() {
- hook.startupHook();
+ hook.startupHook((a,b,c,d) -> System.out.println("callback"));
}