OSDN Git Service

Updated copyright year(s) for release 1.2.
[sudokuki/sudokuki.git] / src / classes / net / jankenpoi / sudokuki / ui / swing / CheckUpdateAction.java
1 /*\r
2  * Sudokuki - essential sudoku game\r
3  * Copyright (C) 2007-2013 Sylvain Vedrenne\r
4  *\r
5  * This program is free software: you can redistribute it and/or modify\r
6  * it under the terms of the GNU General Public License as published by\r
7  * the Free Software Foundation, either version 3 of the License, or\r
8  * (at your option) any later version.\r
9  * \r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  * \r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
17  */\r
18 package net.jankenpoi.sudokuki.ui.swing;\r
19 \r
20 import java.awt.event.ActionEvent;\r
21 \r
22 import javax.swing.AbstractAction;\r
23 import javax.swing.Action;\r
24 import javax.swing.JFrame;\r
25 import javax.swing.JOptionPane;\r
26 import static net.jankenpoi.i18n.I18n._;\r
27 \r
28 @SuppressWarnings("serial")\r
29 public class CheckUpdateAction extends AbstractAction {\r
30 \r
31         private Action openUpdateSiteAction;\r
32 \r
33         private JFrame frame;\r
34 \r
35         public CheckUpdateAction(JFrame frame, Action openUpdateSiteAction) {\r
36                 this.frame = frame;\r
37                 this.openUpdateSiteAction = openUpdateSiteAction;\r
38                 performSilentCheck();\r
39         }\r
40 \r
41         @Override\r
42         public void actionPerformed(ActionEvent e) {\r
43                 CheckUpdateDialog dlg = new CheckUpdateDialog(frame, this);\r
44                 dlg.setVisible(true);\r
45                 int upToDateStatus = dlg.getResult();\r
46                 if (upToDateStatus == 0) {\r
47                         JOptionPane.showMessageDialog(frame, "<html>"\r
48                                         + "<table border=\"0\">" + "<tr>"\r
49                                         + _("This version of Sudokuki is up-to-date.") + "</tr>"\r
50                                         + "</html>", "Sudokuki", JOptionPane.PLAIN_MESSAGE);\r
51                 } else if (upToDateStatus == 1) {\r
52                         openUpdateSiteAction.setEnabled(true);\r
53                         NewVersionFoundDialog nvDlg = new NewVersionFoundDialog(frame);\r
54                         nvDlg.setVisible(true);\r
55                 } else if (upToDateStatus == -1) {\r
56                         JOptionPane.showMessageDialog(frame, "<html>"\r
57                                         + "<table border=\"0\">" + "<tr>"\r
58                                         + _("Unable to retrieve update information.<br/><br/>Please check on the following website<br/>if a new version of Sudokuki is available:<br/><br/>")\r
59                                         + "http://sourceforge.net/projects/sudokuki/files/sudokuki"\r
60                                         + "</tr>" + "</html>", "Sudokuki",\r
61                                         JOptionPane.WARNING_MESSAGE);\r
62                 } else {\r
63                         /*\r
64                          * CheckUpdateAction.actionPerformed() CANCELLED");\r
65                          */\r
66                 }\r
67         }\r
68 \r
69         public void performSilentCheck() {\r
70                 CheckUpdateDialog dlg = new CheckUpdateDialog(frame, this);\r
71                 dlg.setVisible(false);\r
72                 // Here I'm supposing that the SwingWorker created by the\r
73                 // CheckUpdateDialog will live on and from its done() method will notify\r
74                 // this CheckUpdateAction when ready.\r
75         }\r
76 \r
77         void notifyNewVersionFound() {\r
78         openUpdateSiteAction.setEnabled(true);\r
79         }\r
80 \r
81 }\r