Throw exception instead of simply returning in case the lockfile override is not...
[jSite.git] / src / de / todesbaum / jsite / main / Main.java
index b00e020..b04473d 100644 (file)
@@ -52,6 +52,7 @@ import de.todesbaum.jsite.gui.NodeManagerPage;
 import de.todesbaum.jsite.gui.ProjectFilesPage;
 import de.todesbaum.jsite.gui.ProjectInsertPage;
 import de.todesbaum.jsite.gui.ProjectPage;
+import de.todesbaum.jsite.gui.UpdateChecker;
 import de.todesbaum.jsite.i18n.I18n;
 import de.todesbaum.jsite.i18n.I18nContainer;
 import de.todesbaum.util.image.IconLoader;
@@ -61,7 +62,7 @@ import de.todesbaum.util.swing.WizardListener;
 
 /**
  * The main class that ties together everything.
- * 
+ *
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  */
 public class Main implements ActionListener, ListSelectionListener, WizardListener, NodeManagerListener {
@@ -75,12 +76,15 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
        /** The freenet interface. */
        private Freenet7Interface freenetInterface = new Freenet7Interface();
 
+       /** The update checker. */
+       private final UpdateChecker updateChecker;
+
        /** The jSite icon. */
        private Icon jSiteIcon;
 
        /**
         * Enumeration for all possible pages.
-        * 
+        *
         * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
         */
        private static enum PageType {
@@ -108,6 +112,9 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
        /** The “manage nodes” action. */
        private Action manageNodeAction;
 
+       /** The “check for updates” action. */
+       private Action checkForUpdatesAction;
+
        /** The “about jSite” action. */
        private Action aboutAction;
 
@@ -132,7 +139,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
 
        /**
         * Creates a new core with the given configuration from the given file.
-        * 
+        *
         * @param configFilename
         *            The name of the configuration file
         */
@@ -145,8 +152,11 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
                Locale.setDefault(configuration.getLocale());
                I18n.setLocale(configuration.getLocale());
                if (!configuration.createLockFile()) {
-                       JOptionPane.showMessageDialog(null, I18n.getMessage("jsite.main.already-running"), null, JOptionPane.ERROR_MESSAGE);
-                       return;
+                       int option = JOptionPane.showOptionDialog(null, I18n.getMessage("jsite.main.already-running"), "", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { I18n.getMessage("jsite.main.already-running.override"), I18n.getMessage("jsite.wizard.quit") }, I18n.getMessage("jsite.wizard.quit"));
+                       if (option != 0) {
+                               throw new IllegalStateException("Lockfile override not active, refusing start.");
+                       }
+                       configuration.removeLockfileOnExit();
                }
                wizard = new TWizard();
                createActions();
@@ -158,6 +168,8 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
                jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
                wizard.setIcon(jSiteIcon);
 
+               updateChecker = new UpdateChecker(wizard, freenetInterface);
+
                initPages();
                showPage(PageType.PAGE_PROJECTS);
        }
@@ -184,6 +196,16 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
                                wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
                        }
                };
+               checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       @SuppressWarnings("synthetic-access")
+                       public void actionPerformed(ActionEvent actionEvent) {
+                               updateChecker.checkForUpdates();
+                       }
+               };
                aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
 
                        @SuppressWarnings("synthetic-access")
@@ -204,7 +226,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
 
        /**
         * Creates the menu bar.
-        * 
+        *
         * @return The menu bar
         */
        private JMenuBar createMenuBar() {
@@ -234,6 +256,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
 
                final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
                menuBar.add(helpMenu);
+               helpMenu.add(checkForUpdatesAction);
                helpMenu.add(aboutAction);
 
                I18nContainer.getInstance().registerRunnable(new Runnable() {
@@ -282,7 +305,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
 
        /**
         * Shows the page with the given type.
-        * 
+        *
         * @param pageType
         *            The page type to show
         */
@@ -295,7 +318,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
 
        /**
         * Saves the configuration.
-        * 
+        *
         * @return <code>true</code> if the configuration could be saved,
         *         <code>false</code> otherwise
         */
@@ -314,7 +337,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
 
        /**
         * Finds a supported locale for the given locale.
-        * 
+        *
         * @param forLocale
         *            The locale to find a supported locale for
         * @return The supported locale that was found, or the default locale if no
@@ -345,7 +368,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
 
        /**
         * Switches the language of the interface to the given locale.
-        * 
+        *
         * @param locale
         *            The locale to switch to
         */
@@ -538,7 +561,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
 
        /**
         * Main method that is called by the VM.
-        * 
+        *
         * @param args
         *            The command-line arguments
         */