Changeset 12670 in josm
- Timestamp:
- 2017-08-27T00:45:21+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12665 r12670 210 210 } 211 211 212 /** 213 * Asks user to update its version of Java. 214 * @param updVersion target update version 215 * @param url download URL 216 * @param major true for a migration towards a major version of Java (8:9), false otherwise 217 * @param eolDate the EOL/expiration date 218 * @since 12270 219 */ 220 public static void askUpdateJava(String updVersion, String url, String eolDate, boolean major) { 221 ExtendedDialog ed = new ExtendedDialog( 222 Main.parent, 223 tr("Outdated Java version"), 224 tr("OK"), tr("Update Java"), tr("Cancel")); 225 // Check if the dialog has not already been permanently hidden by user 226 if (!ed.toggleEnable("askUpdateJava"+updVersion).toggleCheckState()) { 227 ed.setButtonIcons("ok", "java", "cancel").setCancelButton(3); 228 ed.setMinimumSize(new Dimension(480, 300)); 229 ed.setIcon(JOptionPane.WARNING_MESSAGE); 230 StringBuilder content = new StringBuilder(tr("You are running version {0} of Java.", 231 "<b>"+System.getProperty("java.version")+"</b>")).append("<br><br>"); 232 if ("Sun Microsystems Inc.".equals(System.getProperty("java.vendor")) && !platform.isOpenJDK()) { 233 content.append("<b>").append(tr("This version is no longer supported by {0} since {1} and is not recommended for use.", 234 "Oracle", eolDate)).append("</b><br><br>"); 235 } 236 content.append("<b>") 237 .append(major ? 238 tr("JOSM will soon stop working with this version; we highly recommend you to update to Java {0}.", updVersion) : 239 tr("You may face critical Java bugs; we highly recommend you to update to Java {0}.", updVersion)) 240 .append("</b><br><br>") 241 .append(tr("Would you like to update now ?")); 242 ed.setContent(content.toString()); 243 244 if (ed.showDialog().getValue() == 2) { 245 try { 246 platform.openUrl(url); 247 } catch (IOException e) { 248 Logging.warn(e); 249 } 250 } 251 } 252 } 253 212 254 @Override 213 255 protected List<InitializationTask> beforeInitializationTasks() { 214 256 return Arrays.asList( 215 257 new InitializationTask(tr("Starting file watcher"), fileWatcher::start), 216 new InitializationTask(tr("Executing platform startup hook"), platform ::startupHook),258 new InitializationTask(tr("Executing platform startup hook"), () -> platform.startupHook(MainApplication::askUpdateJava)), 217 259 new InitializationTask(tr("Building main menu"), this::initializeMainWindow), 218 260 new InitializationTask(tr("Updating user interface"), () -> { -
trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
r12620 r12670 2 2 package org.openstreetmap.josm.tools; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 6 import java.awt.Dimension;7 4 import java.awt.GraphicsEnvironment; 8 5 import java.io.BufferedReader; … … 20 17 import java.util.List; 21 18 22 import javax.swing.JOptionPane;23 24 19 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.gui.ExtendedDialog;26 20 import org.openstreetmap.josm.io.CertificateAmendment.CertAmend; 27 21 import org.openstreetmap.josm.tools.date.DateUtils; … … 61 55 * Reason: On OSX we need to register some callbacks with the 62 56 * OS, so we'll receive events from the system menu. 63 */ 64 default void startupHook() { 57 * @param callback Java expiration callback, providing GUI feedback 58 * @since 12270 (signature) 59 */ 60 default void startupHook(JavaExpirationCallback callback) { 65 61 // Do nothing 66 62 } … … 246 242 247 243 /** 248 * Asks user to update its version of Java. 249 * @param updVersion target update version 250 * @param url download URL 251 * @param major true for a migration towards a major version of Java (8:9), false otherwise 252 * @param eolDate the EOL/expiration date 244 * Called when an outdated version of Java is detected at startup. 245 * @since 12270 246 */ 247 @FunctionalInterface 248 public interface JavaExpirationCallback { 249 /** 250 * Asks user to update its version of Java. 251 * @param updVersion target update version 252 * @param url download URL 253 * @param major true for a migration towards a major version of Java (8:9), false otherwise 254 * @param eolDate the EOL/expiration date 255 */ 256 void askUpdateJava(String updVersion, String url, String eolDate, boolean major); 257 } 258 259 /** 260 * Checks if the running version of Java has expired, proposes to user to update it if needed. 261 * @param callback Java expiration callback 262 * @since 12270 (signature) 253 263 * @since 12219 254 264 */ 255 default void askUpdateJava(String updVersion, String url, String eolDate, boolean major) { 256 ExtendedDialog ed = new ExtendedDialog( 257 Main.parent, 258 tr("Outdated Java version"), 259 tr("OK"), tr("Update Java"), tr("Cancel")); 260 // Check if the dialog has not already been permanently hidden by user 261 if (!ed.toggleEnable("askUpdateJava"+updVersion).toggleCheckState()) { 262 ed.setButtonIcons("ok", "java", "cancel").setCancelButton(3); 263 ed.setMinimumSize(new Dimension(480, 300)); 264 ed.setIcon(JOptionPane.WARNING_MESSAGE); 265 StringBuilder content = new StringBuilder(tr("You are running version {0} of Java.", 266 "<b>"+System.getProperty("java.version")+"</b>")).append("<br><br>"); 267 if ("Sun Microsystems Inc.".equals(System.getProperty("java.vendor")) && !isOpenJDK()) { 268 content.append("<b>").append(tr("This version is no longer supported by {0} since {1} and is not recommended for use.", 269 "Oracle", eolDate)).append("</b><br><br>"); 270 } 271 content.append("<b>") 272 .append(major ? 273 tr("JOSM will soon stop working with this version; we highly recommend you to update to Java {0}.", updVersion) : 274 tr("You may face critical Java bugs; we highly recommend you to update to Java {0}.", updVersion)) 275 .append("</b><br><br>") 276 .append(tr("Would you like to update now ?")); 277 ed.setContent(content.toString()); 278 279 if (ed.showDialog().getValue() == 2) { 280 try { 281 openUrl(url); 282 } catch (IOException e) { 283 Logging.warn(e); 284 } 285 } 286 } 287 } 288 289 /** 290 * Checks if the running version of Java has expired, proposes to user to update it if needed. 291 * @since 12219 292 */ 293 default void checkExpiredJava() { 265 default void checkExpiredJava(JavaExpirationCallback callback) { 294 266 Date expiration = Utils.getJavaExpirationDate(); 295 267 if (expiration != null && expiration.before(new Date())) { 296 268 String version = Utils.getJavaLatestVersion(); 297 askUpdateJava(version != null ? version : "latest", 269 callback.askUpdateJava(version != null ? version : "latest", 298 270 Main.pref.get("java.update.url", "https://www.java.com/download"), 299 271 DateUtils.getDateFormat(DateFormat.MEDIUM).format(expiration), false); -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r12643 r12670 48 48 49 49 @Override 50 public void startupHook() { 50 public void startupHook(JavaExpirationCallback callback) { 51 51 // Here we register callbacks for the menu entries in the system menu and file opening through double-click 52 52 // http://openjdk.java.net/jeps/272 … … 79 79 Logging.warn("Failed to register with OSX: " + ex); 80 80 } 81 checkExpiredJava(); 81 checkExpiredJava(callback); 82 82 } 83 83 -
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r12620 r12670 183 183 184 184 @Override 185 public void startupHook() { 186 checkExpiredJava(); 185 public void startupHook(JavaExpirationCallback callback) { 186 checkExpiredJava(callback); 187 187 } 188 188 -
trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookOsxTest.java
r12620 r12670 37 37 @Test 38 38 public void testStartupHook() { 39 hook.startupHook(); 39 hook.startupHook((a,b,c,d) -> System.out.println("callback")); 40 40 } 41 41 -
trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java
r12620 r12670 44 44 @Test 45 45 public void testStartupHook() { 46 hook.startupHook(); 46 hook.startupHook((a,b,c,d) -> System.out.println("callback")); 47 47 } 48 48
Note:
See TracChangeset
for help on using the changeset viewer.