Changeset 12670 in josm for trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
- Timestamp:
- 2017-08-27T00:45:21+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note:
See TracChangeset
for help on using the changeset viewer.