use JOptionPane for busy dialog
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 30 Jun 2008 21:34:42 +0000 (23:34 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Wed, 24 Dec 2008 00:53:28 +0000 (01:53 +0100)
src/de/todesbaum/jsite/gui/UpdateChecker.java

index 46b16c9..9f5ebf4 100644 (file)
 
 package de.todesbaum.jsite.gui;
 
+import java.awt.BorderLayout;
 import java.awt.event.ActionEvent;
 
 import javax.swing.AbstractAction;
 import javax.swing.Action;
-import javax.swing.JDialog;
+import javax.swing.JButton;
 import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.JProgressBar;
 
 import de.todesbaum.jsite.application.Freenet7Interface;
 import de.todesbaum.jsite.i18n.I18n;
+import de.todesbaum.jsite.i18n.I18nContainer;
 
 /**
  * Checks for newer versions of jSite.
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class UpdateChecker extends JDialog {
+public class UpdateChecker {
 
        /** The URL for update checks. */
        @SuppressWarnings("unused")
        private static final String UPDATE_KEY = "USK@e3myoFyp5avg6WYN16ImHri6J7Nj8980Fm~aQe4EX1U,QvbWT0ImE0TwLODTl7EoJx2NBnwDxTbLTE6zkB-eGPs,AQACAAE/jSite/0/currentVersion.txt";
 
+       /** The parent of the dialog. */
+       @SuppressWarnings("unused")
+       private final JFrame parent;
+
        /** The freenet interface. */
        @SuppressWarnings("unused")
        private final Freenet7Interface freenetInterface;
@@ -59,7 +68,7 @@ public class UpdateChecker extends JDialog {
         *            The freenet interface
         */
        public UpdateChecker(JFrame parent, Freenet7Interface freenetInterface) {
-               super(parent);
+               this.parent = parent;
                this.freenetInterface = freenetInterface;
                initActions();
        }
@@ -72,7 +81,7 @@ public class UpdateChecker extends JDialog {
         * Checks for updates, showing a dialog with an indeterminate progress bar.
         */
        public void checkForUpdates() {
-               /* TODO */
+               showBusyDialog();
        }
 
        //
@@ -95,14 +104,60 @@ public class UpdateChecker extends JDialog {
        }
 
        /**
+        * Shows a “please wait” dialog.
+        */
+       private void showBusyDialog() {
+               new Thread(new Runnable() {
+
+                       @SuppressWarnings("synthetic-access")
+                       public void run() {
+                               BusyPanel busyPanel = new BusyPanel();
+                               JButton cancelButton = new JButton(cancelAction);
+                               JOptionPane.showOptionDialog(parent, busyPanel, I18n.getMessage(""), 0, JOptionPane.INFORMATION_MESSAGE, null, new Object[] { cancelButton }, cancelButton);
+                       }
+               }).start();
+       }
+
+       /**
         * A panel that shows a busy progress bar and a “please wait” message.
         *
         * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
         */
-       @SuppressWarnings("unused")
        private class BusyPanel extends JPanel {
 
-               /* TODO */
+               /**
+                * Creates a new busy panel.
+                */
+               public BusyPanel() {
+                       super(new BorderLayout(12, 12));
+                       initComponents();
+               }
+
+               //
+               // PRIVATE METHODS
+               //
+
+               /**
+                * Initializes all components of this panel.
+                */
+               private void initComponents() {
+                       final JLabel label = new JLabel(I18n.getMessage("")); /* TODO */
+                       JProgressBar progressBar = new JProgressBar();
+                       progressBar.setIndeterminate(true);
+
+                       add(label, BorderLayout.PAGE_START);
+                       add(progressBar, BorderLayout.PAGE_END);
+
+                       I18nContainer.getInstance().registerRunnable(new Runnable() {
+
+                               /**
+                                * {@inheritDoc}
+                                */
+                               public void run() {
+                                       label.setText(I18n.getMessage("")); /* TODO */
+                               }
+                       });
+               }
 
        }