3 import java.io.IOException;
4 import java.io.InputStream;
6 import java.text.DateFormat;
7 import java.text.ParseException;
8 import java.text.SimpleDateFormat;
9 import java.util.Properties;
10 import javax.swing.JFrame;
11 import javax.swing.JOptionPane;
13 import tim.prune.GpsPruner;
14 import tim.prune.I18nManager;
15 import tim.prune.browser.BrowserLauncher;
18 * Class to check the version of Prune
19 * and show an appropriate dialog
21 public abstract class CheckVersionScreen
24 * Show the check version dialog
25 * @param inParent parent frame
27 public static void show(JFrame inParent)
29 final String filePathStart = "http://activityworkshop.net/software/prune/prune_versioncheck_";
30 final String filePathEnd = ".txt";
31 String latestVer = null;
32 String nextVersion = null;
33 String releaseDate = null;
34 Properties props = new Properties();
37 // Load properties from the url on the server
38 InputStream inStream = new URL(filePathStart + GpsPruner.VERSION_NUMBER + filePathEnd).openStream();
41 // Extract the three fields we want, ignore others
42 latestVer = props.getProperty("prune.latestversion");
43 nextVersion = props.getProperty("prune.nextversion");
44 releaseDate = props.getProperty("prune.releasedate");
46 catch (IOException ioe) {
47 System.err.println(ioe.getClass().getName() + " - " + ioe.getMessage());
50 if (latestVer == null) {
51 // Couldn't get version number, show error message
52 JOptionPane.showMessageDialog(inParent, I18nManager.getText("dialog.checkversion.error"),
53 I18nManager.getText("dialog.checkversion.title"), JOptionPane.ERROR_MESSAGE);
55 else if (latestVer.equals(GpsPruner.VERSION_NUMBER))
57 // Version on the server is the same as this one
58 String displayMessage = I18nManager.getText("dialog.checkversion.uptodate");
59 if (nextVersion != null && !nextVersion.equals(""))
61 displayMessage += "\n\n" + nextVersion;
63 // Show information message that the current version is already running
64 JOptionPane.showMessageDialog(inParent, displayMessage,
65 I18nManager.getText("dialog.checkversion.title"), JOptionPane.INFORMATION_MESSAGE);
69 // A new version is available!
70 String displayMessage = I18nManager.getText("dialog.checkversion.newversion1") + " " + latestVer
71 + " " + I18nManager.getText("dialog.checkversion.newversion2");
74 if (releaseDate != null && !releaseDate.equals("")) {
75 displayMessage += "\n\n" + I18nManager.getText("dialog.checkversion.releasedate1") + " "
76 + DateFormat.getDateInstance(DateFormat.LONG).format(new SimpleDateFormat("y-M-d").parse(releaseDate))
77 + " " + I18nManager.getText("dialog.checkversion.releasedate2");
80 catch (ParseException pe) {
81 System.err.println("Oops, couldn't parse date: '" + releaseDate + "'");
83 displayMessage += "\n\n" + I18nManager.getText("dialog.checkversion.download");
85 // Show information message to download the new version
86 Object[] buttonTexts = {I18nManager.getText("button.showwebpage"), I18nManager.getText("button.cancel")};
87 if (JOptionPane.showOptionDialog(inParent, displayMessage,
88 I18nManager.getText("dialog.checkversion.title"), JOptionPane.YES_NO_OPTION,
89 JOptionPane.INFORMATION_MESSAGE, null, buttonTexts, buttonTexts[1])
90 == JOptionPane.YES_OPTION)
92 // User selected to launch home page
93 new BrowserLauncher().launchBrowser("http://activityworkshop.net/software/prune/download.html");