2 * jSite-remote - UpdateChecker.java -
3 * Copyright © 2008 David Roden
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.
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.
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.
20 package de.todesbaum.jsite.gui;
22 import java.awt.BorderLayout;
23 import java.awt.event.ActionEvent;
24 import java.io.IOException;
25 import java.text.MessageFormat;
27 import javax.swing.AbstractAction;
28 import javax.swing.Action;
29 import javax.swing.JButton;
30 import javax.swing.JDialog;
31 import javax.swing.JFrame;
32 import javax.swing.JLabel;
33 import javax.swing.JOptionPane;
34 import javax.swing.JPanel;
35 import javax.swing.JProgressBar;
37 import de.todesbaum.jsite.application.Freenet7Interface;
38 import de.todesbaum.jsite.i18n.I18n;
39 import de.todesbaum.jsite.i18n.I18nContainer;
40 import de.todesbaum.util.freenet.fcp2.Connection;
43 * Checks for newer versions of jSite.
45 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
47 public class UpdateChecker {
49 /** The URL for update checks. */
50 @SuppressWarnings("unused")
51 private static final String UPDATE_KEY = "USK@e3myoFyp5avg6WYN16ImHri6J7Nj8980Fm~aQe4EX1U,QvbWT0ImE0TwLODTl7EoJx2NBnwDxTbLTE6zkB-eGPs,AQACAAE/jSite/0/currentVersion.txt";
53 /** Object used for synchronization. */
54 private final Object syncObject = new Object();
56 /** The parent of the dialog. */
57 private final JFrame parent;
59 /** The freenet interface. */
60 private final Freenet7Interface freenetInterface;
62 /** The cancel action. */
63 private Action cancelAction;
65 /** Whether the busy dialog has been cancelled. */
66 private boolean cancelled;
69 * Creates a new update checker that uses the given frame as its parent and
70 * communications via the given freenet interface.
73 * The parent of the dialog
74 * @param freenetInterface
75 * The freenet interface
77 public UpdateChecker(JFrame parent, Freenet7Interface freenetInterface) {
79 this.freenetInterface = freenetInterface;
89 * Checks for updates, showing a dialog with an indeterminate progress bar.
91 public void checkForUpdates() {
92 JDialog busyDialog = showBusyDialog();
93 Connection connection = freenetInterface.getConnection("jSite-update-check");
95 if (!connection.connect()) {
96 busyDialog.setVisible(false);
97 JOptionPane.showMessageDialog(parent, I18n.getMessage(""), I18n.getMessage(""), JOptionPane.ERROR_MESSAGE);
100 } catch (IOException ioe1) {
101 busyDialog.setVisible(false);
102 JOptionPane.showMessageDialog(parent, MessageFormat.format(I18n.getMessage(""), ioe1.getMessage()), I18n.getMessage(""), JOptionPane.ERROR_MESSAGE);
104 connection.disconnect();
113 * Initializes all actions.
115 private void initActions() {
116 cancelAction = new AbstractAction(I18n.getMessage("")) {
121 @SuppressWarnings("synthetic-access")
122 public void actionPerformed(ActionEvent actionEvent) {
123 synchronized (syncObject) {
131 * Shows a “please wait” dialog.
135 private JDialog showBusyDialog() {
136 BusyPanel busyPanel = new BusyPanel();
137 JButton cancelButton = new JButton(cancelAction);
138 JOptionPane optionPane = new JOptionPane(busyPanel, JOptionPane.INFORMATION_MESSAGE, 0, null, new Object[] { cancelButton });
139 final JDialog busyDialog = optionPane.createDialog(parent, I18n.getMessage(""));
140 new Thread(new Runnable() {
146 busyDialog.setVisible(true);
153 * A panel that shows a busy progress bar and a “please wait” message.
155 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
157 private class BusyPanel extends JPanel {
160 * Creates a new busy panel.
163 super(new BorderLayout(12, 12));
172 * Initializes all components of this panel.
174 private void initComponents() {
175 final JLabel label = new JLabel(I18n.getMessage("")); /* TODO */
176 JProgressBar progressBar = new JProgressBar();
177 progressBar.setIndeterminate(true);
179 add(label, BorderLayout.PAGE_START);
180 add(progressBar, BorderLayout.PAGE_END);
182 I18nContainer.getInstance().registerRunnable(new Runnable() {
188 label.setText(I18n.getMessage("")); /* TODO */