Changeset 12219 in josm for trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
- Timestamp:
- 2017-05-20T19:06:29+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
r12217 r12219 2 2 package org.openstreetmap.josm.tools; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.Dimension; 4 7 import java.awt.GraphicsEnvironment; 5 8 import java.io.BufferedReader; … … 13 16 import java.security.cert.CertificateException; 14 17 import java.security.cert.X509Certificate; 18 import java.text.DateFormat; 19 import java.util.Date; 15 20 import java.util.List; 16 21 22 import javax.swing.JOptionPane; 23 24 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.gui.ExtendedDialog; 17 26 import org.openstreetmap.josm.io.CertificateAmendment.CertAmend; 27 import org.openstreetmap.josm.tools.date.DateUtils; 18 28 19 29 /** … … 224 234 */ 225 235 List<File> getDefaultProj4NadshiftDirectories(); 236 237 /** 238 * Determines if the JVM is OpenJDK-based. 239 * @return {@code true} if {@code java.home} contains "openjdk", {@code false} otherwise 240 * @since 12219 241 */ 242 default boolean isOpenJDK() { 243 String javaHome = System.getProperty("java.home"); 244 return javaHome != null && javaHome.contains("openjdk"); 245 } 246 247 /** 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 253 * @since 12219 254 */ 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 new String[]{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(new String[]{"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 Main.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() { 294 Date expiration = Utils.getJavaExpirationDate(); 295 if (expiration != null && expiration.before(new Date())) { 296 String version = Utils.getJavaLatestVersion(); 297 askUpdateJava(version != null ? version : "latest", 298 Main.pref.get("java.update.url", "https://www.java.com/download"), 299 DateUtils.getDateFormat(DateFormat.MEDIUM).format(expiration), false); 300 } 301 } 226 302 }
Note:
See TracChangeset
for help on using the changeset viewer.