use JOptionPane for busy dialog
[jSite.git] / src / de / todesbaum / jsite / gui / UpdateChecker.java
1 /*
2  * jSite-remote - UpdateChecker.java -
3  * Copyright © 2008 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package de.todesbaum.jsite.gui;
21
22 import java.awt.BorderLayout;
23 import java.awt.event.ActionEvent;
24
25 import javax.swing.AbstractAction;
26 import javax.swing.Action;
27 import javax.swing.JButton;
28 import javax.swing.JFrame;
29 import javax.swing.JLabel;
30 import javax.swing.JOptionPane;
31 import javax.swing.JPanel;
32 import javax.swing.JProgressBar;
33
34 import de.todesbaum.jsite.application.Freenet7Interface;
35 import de.todesbaum.jsite.i18n.I18n;
36 import de.todesbaum.jsite.i18n.I18nContainer;
37
38 /**
39  * Checks for newer versions of jSite.
40  *
41  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
42  */
43 public class UpdateChecker {
44
45         /** The URL for update checks. */
46         @SuppressWarnings("unused")
47         private static final String UPDATE_KEY = "USK@e3myoFyp5avg6WYN16ImHri6J7Nj8980Fm~aQe4EX1U,QvbWT0ImE0TwLODTl7EoJx2NBnwDxTbLTE6zkB-eGPs,AQACAAE/jSite/0/currentVersion.txt";
48
49         /** The parent of the dialog. */
50         @SuppressWarnings("unused")
51         private final JFrame parent;
52
53         /** The freenet interface. */
54         @SuppressWarnings("unused")
55         private final Freenet7Interface freenetInterface;
56
57         /** The cancel action. */
58         @SuppressWarnings("unused")
59         private Action cancelAction;
60
61         /**
62          * Creates a new update checker that uses the given frame as its parent and
63          * communications via the given freenet interface.
64          *
65          * @param parent
66          *            The parent of the dialog
67          * @param freenetInterface
68          *            The freenet interface
69          */
70         public UpdateChecker(JFrame parent, Freenet7Interface freenetInterface) {
71                 this.parent = parent;
72                 this.freenetInterface = freenetInterface;
73                 initActions();
74         }
75
76         //
77         // ACTIONS
78         //
79
80         /**
81          * Checks for updates, showing a dialog with an indeterminate progress bar.
82          */
83         public void checkForUpdates() {
84                 showBusyDialog();
85         }
86
87         //
88         // PRIVATE METHODS
89         //
90
91         /**
92          * Initializes all actions.
93          */
94         private void initActions() {
95                 cancelAction = new AbstractAction(I18n.getMessage("")) {
96
97                         /**
98                          * {@inheritDoc}
99                          */
100                         public void actionPerformed(ActionEvent actionEvent) {
101                                 /* TODO */
102                         }
103                 };
104         }
105
106         /**
107          * Shows a “please wait” dialog.
108          */
109         private void showBusyDialog() {
110                 new Thread(new Runnable() {
111
112                         @SuppressWarnings("synthetic-access")
113                         public void run() {
114                                 BusyPanel busyPanel = new BusyPanel();
115                                 JButton cancelButton = new JButton(cancelAction);
116                                 JOptionPane.showOptionDialog(parent, busyPanel, I18n.getMessage(""), 0, JOptionPane.INFORMATION_MESSAGE, null, new Object[] { cancelButton }, cancelButton);
117                         }
118                 }).start();
119         }
120
121         /**
122          * A panel that shows a busy progress bar and a “please wait” message.
123          *
124          * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
125          */
126         private class BusyPanel extends JPanel {
127
128                 /**
129                  * Creates a new busy panel.
130                  */
131                 public BusyPanel() {
132                         super(new BorderLayout(12, 12));
133                         initComponents();
134                 }
135
136                 //
137                 // PRIVATE METHODS
138                 //
139
140                 /**
141                  * Initializes all components of this panel.
142                  */
143                 private void initComponents() {
144                         final JLabel label = new JLabel(I18n.getMessage("")); /* TODO */
145                         JProgressBar progressBar = new JProgressBar();
146                         progressBar.setIndeterminate(true);
147
148                         add(label, BorderLayout.PAGE_START);
149                         add(progressBar, BorderLayout.PAGE_END);
150
151                         I18nContainer.getInstance().registerRunnable(new Runnable() {
152
153                                 /**
154                                  * {@inheritDoc}
155                                  */
156                                 public void run() {
157                                         label.setText(I18n.getMessage("")); /* TODO */
158                                 }
159                         });
160                 }
161
162         }
163
164 }