]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/CheckVersionScreen.java
Version 6, October 2008
[GpsPrune.git] / tim / prune / gui / CheckVersionScreen.java
1 package tim.prune.gui;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.net.URL;
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;
12
13 import tim.prune.GpsPruner;
14 import tim.prune.I18nManager;
15 import tim.prune.browser.BrowserLauncher;
16
17 /**
18  * Class to check the version of Prune
19  * and show an appropriate dialog
20  */
21 public abstract class CheckVersionScreen
22 {
23         /**
24          * Show the check version dialog
25          * @param inParent parent frame
26          */
27         public static void show(JFrame inParent)
28         {
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();
35                 try
36                 {
37                         // Load properties from the url on the server
38                         InputStream inStream = new URL(filePathStart + GpsPruner.VERSION_NUMBER + filePathEnd).openStream();
39                         props.load(inStream);
40
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");
45                 }
46                 catch (IOException ioe) {
47                         System.err.println(ioe.getClass().getName() + " - " + ioe.getMessage());
48                 }
49
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);
54                 }
55                 else if (latestVer.equals(GpsPruner.VERSION_NUMBER))
56                 {
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(""))
60                         {
61                                 displayMessage += "\n\n" + nextVersion;
62                         }
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);
66                 }
67                 else
68                 {
69                         // A new version is available!
70                         String displayMessage = I18nManager.getText("dialog.checkversion.newversion1") + " " + latestVer
71                                 + " " + I18nManager.getText("dialog.checkversion.newversion2");
72                         try
73                         {
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");
78                                 }
79                         }
80                         catch (ParseException pe) {
81                                 System.err.println("Oops, couldn't parse date: '" + releaseDate + "'");
82                         }
83                         displayMessage += "\n\n" + I18nManager.getText("dialog.checkversion.download");
84
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)
91                         {
92                                 // User selected to launch home page
93                                 new BrowserLauncher().launchBrowser("http://activityworkshop.net/software/prune/download.html");
94                         }
95                 }
96         }
97 }