1 package tim.prune.function;
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.JOptionPane;
13 import tim.prune.GenericFunction;
14 import tim.prune.GpsPrune;
15 import tim.prune.I18nManager;
16 import tim.prune.function.browser.BrowserLauncher;
19 * Class to check the version of GpsPrune
20 * and show an appropriate dialog
22 public class CheckVersionScreen extends GenericFunction
26 * @param inApp app object
28 public CheckVersionScreen(App inApp)
36 public String getNameKey() {
37 return "function.checkversion";
41 * Show the check version dialog
45 final String filePathStart = "http://activityworkshop.net/software/gpsprune/gpsprune_versioncheck_";
46 final String filePathEnd = ".txt";
47 String latestVer = null;
48 String nextVersion = null;
49 String releaseDate = null;
50 Properties props = new Properties();
53 // Load properties from the url on the server
54 InputStream inStream = new URL(filePathStart + GpsPrune.VERSION_NUMBER + filePathEnd).openStream();
57 // Extract the three fields we want, ignore others
58 latestVer = props.getProperty("prune.latestversion");
59 nextVersion = props.getProperty("prune.nextversion");
60 releaseDate = props.getProperty("prune.releasedate");
62 catch (IOException ioe) {
63 System.err.println(ioe.getClass().getName() + " - " + ioe.getMessage());
66 if (latestVer == null) {
67 // Couldn't get version number, show error message
68 JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("dialog.checkversion.error"),
69 I18nManager.getText(getNameKey()), JOptionPane.ERROR_MESSAGE);
71 else if (latestVer.equals(GpsPrune.VERSION_NUMBER))
73 // Version on the server is the same as this one
74 String displayMessage = I18nManager.getText("dialog.checkversion.uptodate");
75 if (nextVersion != null && !nextVersion.equals(""))
77 displayMessage += "\n\n" + nextVersion;
79 // Show information message that the current version is already running
80 JOptionPane.showMessageDialog(_parentFrame, displayMessage,
81 I18nManager.getText(getNameKey()), JOptionPane.INFORMATION_MESSAGE);
85 // A new version is available!
86 String displayMessage = I18nManager.getText("dialog.checkversion.newversion1") + " " + latestVer
87 + " " + I18nManager.getText("dialog.checkversion.newversion2");
90 if (releaseDate != null && !releaseDate.equals("")) {
91 displayMessage += "\n\n" + I18nManager.getText("dialog.checkversion.releasedate1") + " "
92 + DateFormat.getDateInstance(DateFormat.LONG).format(new SimpleDateFormat("y-M-d").parse(releaseDate))
93 + " " + I18nManager.getText("dialog.checkversion.releasedate2");
96 catch (ParseException pe) {
97 System.err.println("Oops, couldn't parse date: '" + releaseDate + "'");
99 displayMessage += "\n\n" + I18nManager.getText("dialog.checkversion.download");
101 // Show information message to download the new version
102 Object[] buttonTexts = {I18nManager.getText("button.showwebpage"), I18nManager.getText("button.cancel")};
103 if (JOptionPane.showOptionDialog(_parentFrame, displayMessage,
104 I18nManager.getText(getNameKey()), JOptionPane.YES_NO_OPTION,
105 JOptionPane.INFORMATION_MESSAGE, null, buttonTexts, buttonTexts[1])
106 == JOptionPane.YES_OPTION)
108 // User selected to launch home page
109 BrowserLauncher.launchBrowser("http://activityworkshop.net/software/gpsprune/download.html");