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 edition for the update check URL. */
50 private static final int UPDATE_EDITION = 2;
52 /** The URL for update checks. */
53 @SuppressWarnings("unused")
54 private static final String UPDATE_KEY = "USK@e3myoFyp5avg6WYN16ImHri6J7Nj8980Fm~aQe4EX1U,QvbWT0ImE0TwLODTl7EoJx2NBnwDxTbLTE6zkB-eGPs,AQACAAE/jSite/" + UPDATE_EDITION + "/jSite.properties";
56 /** Object used for synchronization. */
57 private final Object syncObject = new Object();
59 /** The parent of the dialog. */
60 private final JFrame parent;
62 /** The freenet interface. */
63 private final Freenet7Interface freenetInterface;
65 /** The cancel action. */
66 private Action cancelAction;
68 /** Whether the busy dialog has been cancelled. */
69 private boolean cancelled;
72 * Creates a new update checker that uses the given frame as its parent and
73 * communications via the given freenet interface.
76 * The parent of the dialog
77 * @param freenetInterface
78 * The freenet interface
80 public UpdateChecker(JFrame parent, Freenet7Interface freenetInterface) {
82 this.freenetInterface = freenetInterface;
92 * Checks for updates, showing a dialog with an indeterminate progress bar.
94 public void checkForUpdates() {
95 JDialog busyDialog = showBusyDialog();
96 Connection connection = freenetInterface.getConnection("jSite-update-check");
98 if (!connection.connect()) {
99 busyDialog.setVisible(false);
100 JOptionPane.showMessageDialog(parent, I18n.getMessage(""), I18n.getMessage(""), JOptionPane.ERROR_MESSAGE);
103 } catch (IOException ioe1) {
104 busyDialog.setVisible(false);
105 JOptionPane.showMessageDialog(parent, MessageFormat.format(I18n.getMessage(""), ioe1.getMessage()), I18n.getMessage(""), JOptionPane.ERROR_MESSAGE);
107 connection.disconnect();
116 * Initializes all actions.
118 private void initActions() {
119 cancelAction = new AbstractAction(I18n.getMessage("")) {
124 @SuppressWarnings("synthetic-access")
125 public void actionPerformed(ActionEvent actionEvent) {
126 synchronized (syncObject) {
134 * Shows a “please wait” dialog.
138 private JDialog showBusyDialog() {
139 BusyPanel busyPanel = new BusyPanel();
140 JButton cancelButton = new JButton(cancelAction);
141 JOptionPane optionPane = new JOptionPane(busyPanel, JOptionPane.INFORMATION_MESSAGE, 0, null, new Object[] { cancelButton });
142 final JDialog busyDialog = optionPane.createDialog(parent, I18n.getMessage(""));
143 new Thread(new Runnable() {
149 busyDialog.setVisible(true);
156 * A panel that shows a busy progress bar and a “please wait” message.
158 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
160 private class BusyPanel extends JPanel {
163 * Creates a new busy panel.
166 super(new BorderLayout(12, 12));
175 * Initializes all components of this panel.
177 private void initComponents() {
178 final JLabel label = new JLabel(I18n.getMessage("")); /* TODO */
179 JProgressBar progressBar = new JProgressBar();
180 progressBar.setIndeterminate(true);
182 add(label, BorderLayout.PAGE_START);
183 add(progressBar, BorderLayout.PAGE_END);
185 I18nContainer.getInstance().registerRunnable(new Runnable() {
191 label.setText(I18n.getMessage("")); /* TODO */