Factor out project validation, re-order warning and error messages.
[jSite.git] / src / de / todesbaum / jsite / main / Main.java
1 /*
2  * jSite - a tool for uploading websites into Freenet
3  * Copyright (C) 2006-2009 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.main;
21
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.io.IOException;
25 import java.text.MessageFormat;
26 import java.util.Date;
27 import java.util.HashMap;
28 import java.util.Locale;
29 import java.util.Map;
30 import java.util.logging.ConsoleHandler;
31 import java.util.logging.Handler;
32 import java.util.logging.Level;
33 import java.util.logging.Logger;
34
35 import javax.swing.AbstractAction;
36 import javax.swing.Action;
37 import javax.swing.ButtonGroup;
38 import javax.swing.Icon;
39 import javax.swing.JList;
40 import javax.swing.JMenu;
41 import javax.swing.JMenuBar;
42 import javax.swing.JOptionPane;
43 import javax.swing.JPanel;
44 import javax.swing.JRadioButtonMenuItem;
45 import javax.swing.event.ListSelectionEvent;
46 import javax.swing.event.ListSelectionListener;
47
48 import de.todesbaum.jsite.application.Freenet7Interface;
49 import de.todesbaum.jsite.application.Node;
50 import de.todesbaum.jsite.application.Project;
51 import de.todesbaum.jsite.application.ProjectInserter;
52 import de.todesbaum.jsite.application.UpdateChecker;
53 import de.todesbaum.jsite.application.UpdateListener;
54 import de.todesbaum.jsite.application.ProjectInserter.CheckReport;
55 import de.todesbaum.jsite.application.ProjectInserter.CheckReport.Issue;
56 import de.todesbaum.jsite.gui.NodeManagerListener;
57 import de.todesbaum.jsite.gui.NodeManagerPage;
58 import de.todesbaum.jsite.gui.PreferencesPage;
59 import de.todesbaum.jsite.gui.ProjectFilesPage;
60 import de.todesbaum.jsite.gui.ProjectInsertPage;
61 import de.todesbaum.jsite.gui.ProjectPage;
62 import de.todesbaum.jsite.i18n.I18n;
63 import de.todesbaum.jsite.i18n.I18nContainer;
64 import de.todesbaum.util.image.IconLoader;
65 import de.todesbaum.util.swing.TWizard;
66 import de.todesbaum.util.swing.TWizardPage;
67 import de.todesbaum.util.swing.WizardListener;
68
69 /**
70  * The main class that ties together everything.
71  *
72  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
73  */
74 public class Main implements ActionListener, ListSelectionListener, WizardListener, NodeManagerListener, UpdateListener {
75
76         /** The logger. */
77         private static final Logger logger = Logger.getLogger(Main.class.getName());
78
79         /** The version. */
80         private static final Version VERSION = new Version(0, 8);
81
82         /** The configuration. */
83         private Configuration configuration;
84
85         /** The freenet interface. */
86         private Freenet7Interface freenetInterface = new Freenet7Interface();
87
88         /** The update checker. */
89         private final UpdateChecker updateChecker;
90
91         /** The jSite icon. */
92         private Icon jSiteIcon;
93
94         /**
95          * Enumeration for all possible pages.
96          *
97          * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
98          */
99         private static enum PageType {
100
101                 /** The node manager page. */
102                 PAGE_NODE_MANAGER,
103
104                 /** The project page. */
105                 PAGE_PROJECTS,
106
107                 /** The project files page. */
108                 PAGE_PROJECT_FILES,
109
110                 /** The project insert page. */
111                 PAGE_INSERT_PROJECT,
112
113                 /** The preferences page. */
114                 PAGE_PREFERENCES
115
116         }
117
118         /** The supported locales. */
119         private static final Locale[] SUPPORTED_LOCALES = new Locale[] { Locale.ENGLISH, Locale.GERMAN, Locale.FRENCH, Locale.ITALIAN, new Locale("pl") };
120
121         /** The actions that switch the language. */
122         private Map<Locale, Action> languageActions = new HashMap<Locale, Action>();
123
124         /** The “manage nodes” action. */
125         private Action manageNodeAction;
126
127         /** The “preferences” action. */
128         private Action optionsPreferencesAction;
129
130         /** The “check for updates” action. */
131         private Action checkForUpdatesAction;
132
133         /** The “about jSite” action. */
134         private Action aboutAction;
135
136         /** The wizard. */
137         private TWizard wizard;
138
139         /** The node menu. */
140         private JMenu nodeMenu;
141
142         /** The currently selected node. */
143         private Node selectedNode;
144
145         /** Mapping from page type to page. */
146         private final Map<PageType, TWizardPage> pages = new HashMap<PageType, TWizardPage>();
147
148         /**
149          * Creates a new core with the default configuration file.
150          */
151         private Main() {
152                 this(null);
153         }
154
155         /**
156          * Creates a new core with the given configuration from the given file.
157          *
158          * @param configFilename
159          *            The name of the configuration file
160          */
161         private Main(String configFilename) {
162                 if (configFilename != null) {
163                         configuration = new Configuration(configFilename);
164                 } else {
165                         configuration = new Configuration();
166                 }
167                 Locale.setDefault(configuration.getLocale());
168                 I18n.setLocale(configuration.getLocale());
169                 if (!configuration.createLockFile()) {
170                         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"));
171                         if (option != 0) {
172                                 throw new IllegalStateException("Lockfile override not active, refusing start.");
173                         }
174                         configuration.removeLockfileOnExit();
175                 }
176                 wizard = new TWizard();
177                 createActions();
178                 wizard.setJMenuBar(createMenuBar());
179                 wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
180                 wizard.setPreviousEnabled(false);
181                 wizard.setNextEnabled(true);
182                 wizard.addWizardListener(this);
183                 jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
184                 wizard.setIcon(jSiteIcon);
185
186                 updateChecker = new UpdateChecker(freenetInterface);
187                 updateChecker.addUpdateListener(this);
188                 updateChecker.start();
189
190                 initPages();
191                 showPage(PageType.PAGE_PROJECTS);
192         }
193
194         /**
195          * Creates all actions.
196          */
197         private void createActions() {
198                 for (final Locale locale : SUPPORTED_LOCALES) {
199                         languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
200
201                                 @SuppressWarnings("synthetic-access")
202                                 public void actionPerformed(ActionEvent actionEvent) {
203                                         switchLanguage(locale);
204                                 }
205                         });
206                 }
207                 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
208
209                         @SuppressWarnings("synthetic-access")
210                         public void actionPerformed(ActionEvent actionEvent) {
211                                 showPage(PageType.PAGE_NODE_MANAGER);
212                                 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
213                                 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
214                         }
215                 };
216                 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
217
218                         /**
219                          * {@inheritDoc}
220                          */
221                         @SuppressWarnings("synthetic-access")
222                         public void actionPerformed(ActionEvent actionEvent) {
223                                 optionsPreferences();
224                         }
225                 };
226                 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
227
228                         /**
229                          * {@inheritDoc}
230                          */
231                         @SuppressWarnings("synthetic-access")
232                         public void actionPerformed(ActionEvent actionEvent) {
233                                 showLatestUpdate();
234                         }
235                 };
236                 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
237
238                         @SuppressWarnings("synthetic-access")
239                         public void actionPerformed(ActionEvent e) {
240                                 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
241                         }
242                 };
243
244                 I18nContainer.getInstance().registerRunnable(new Runnable() {
245
246                         @SuppressWarnings("synthetic-access")
247                         public void run() {
248                                 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
249                                 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
250                                 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
251                                 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
252                         }
253                 });
254         }
255
256         /**
257          * Creates the menu bar.
258          *
259          * @return The menu bar
260          */
261         private JMenuBar createMenuBar() {
262                 JMenuBar menuBar = new JMenuBar();
263                 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
264                 menuBar.add(languageMenu);
265                 ButtonGroup languageButtonGroup = new ButtonGroup();
266                 for (Locale locale : SUPPORTED_LOCALES) {
267                         Action languageAction = languageActions.get(locale);
268                         JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
269                         if (locale.equals(Locale.getDefault())) {
270                                 menuItem.setSelected(true);
271                         }
272                         languageAction.putValue("menuItem", menuItem);
273                         languageButtonGroup.add(menuItem);
274                         languageMenu.add(menuItem);
275                 }
276                 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
277                 menuBar.add(nodeMenu);
278                 selectedNode = configuration.getSelectedNode();
279                 nodesUpdated(configuration.getNodes());
280
281                 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
282                 menuBar.add(optionsMenu);
283                 optionsMenu.add(optionsPreferencesAction);
284
285                 /* evil hack to right-align the help menu */
286                 JPanel panel = new JPanel();
287                 panel.setOpaque(false);
288                 menuBar.add(panel);
289
290                 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
291                 menuBar.add(helpMenu);
292                 helpMenu.add(checkForUpdatesAction);
293                 helpMenu.add(aboutAction);
294
295                 I18nContainer.getInstance().registerRunnable(new Runnable() {
296
297                         @SuppressWarnings("synthetic-access")
298                         public void run() {
299                                 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
300                                 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
301                                 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
302                                 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
303                                 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
304                                         languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
305                                 }
306                         }
307                 });
308
309                 return menuBar;
310         }
311
312         /**
313          * Initializes all pages.
314          */
315         private void initPages() {
316                 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
317                 nodeManagerPage.setName("page.node-manager");
318                 nodeManagerPage.addNodeManagerListener(this);
319                 nodeManagerPage.setNodes(configuration.getNodes());
320                 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
321
322                 ProjectPage projectPage = new ProjectPage(wizard);
323                 projectPage.setName("page.project");
324                 projectPage.setProjects(configuration.getProjects());
325                 projectPage.setFreenetInterface(freenetInterface);
326                 projectPage.addListSelectionListener(this);
327                 pages.put(PageType.PAGE_PROJECTS, projectPage);
328
329                 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
330                 projectFilesPage.setName("page.project.files");
331                 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
332
333                 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
334                 projectInsertPage.setName("page.project.insert");
335                 projectInsertPage.setFreenetInterface(freenetInterface);
336                 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
337
338                 PreferencesPage preferencesPage = new PreferencesPage(wizard);
339                 preferencesPage.setName("page.preferences");
340                 preferencesPage.setTempDirectory(configuration.getTempDirectory());
341                 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
342         }
343
344         /**
345          * Shows the page with the given type.
346          *
347          * @param pageType
348          *            The page type to show
349          */
350         private void showPage(PageType pageType) {
351                 wizard.setPreviousEnabled(pageType.ordinal() > 0);
352                 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
353                 wizard.setPage(pages.get(pageType));
354                 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
355         }
356
357         /**
358          * Saves the configuration.
359          *
360          * @return <code>true</code> if the configuration could be saved,
361          *         <code>false</code> otherwise
362          */
363         private boolean saveConfiguration() {
364                 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
365                 configuration.setNodes(nodeManagerPage.getNodes());
366                 if (selectedNode != null) {
367                         configuration.setSelectedNode(selectedNode);
368                 }
369
370                 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
371                 configuration.setProjects(projectPage.getProjects());
372
373                 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
374                 configuration.setTempDirectory(preferencesPage.getTempDirectory());
375
376                 return configuration.save();
377         }
378
379         /**
380          * Finds a supported locale for the given locale.
381          *
382          * @param forLocale
383          *            The locale to find a supported locale for
384          * @return The supported locale that was found, or the default locale if no
385          *         supported locale could be found
386          */
387         private Locale findSupportedLocale(Locale forLocale) {
388                 for (Locale locale : SUPPORTED_LOCALES) {
389                         if (locale.equals(forLocale)) {
390                                 return locale;
391                         }
392                 }
393                 for (Locale locale : SUPPORTED_LOCALES) {
394                         if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
395                                 return locale;
396                         }
397                 }
398                 for (Locale locale : SUPPORTED_LOCALES) {
399                         if (locale.getLanguage().equals(forLocale.getLanguage())) {
400                                 return locale;
401                         }
402                 }
403                 return SUPPORTED_LOCALES[0];
404         }
405
406         /**
407          * Returns the version.
408          *
409          * @return The version
410          */
411         public static final Version getVersion() {
412                 return VERSION;
413         }
414
415         //
416         // ACTIONS
417         //
418
419         /**
420          * Switches the language of the interface to the given locale.
421          *
422          * @param locale
423          *            The locale to switch to
424          */
425         private void switchLanguage(Locale locale) {
426                 Locale supportedLocale = findSupportedLocale(locale);
427                 Action languageAction = languageActions.get(supportedLocale);
428                 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
429                 menuItem.setSelected(true);
430                 I18n.setLocale(supportedLocale);
431                 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
432                         try {
433                                 i18nRunnable.run();
434                         } catch (Throwable t) {
435                                 /* we probably shouldn't swallow this. */
436                         }
437                 }
438                 wizard.setPage(wizard.getPage());
439                 configuration.setLocale(supportedLocale);
440         }
441
442         /**
443          * Shows a dialog with general preferences.
444          */
445         private void optionsPreferences() {
446                 showPage(PageType.PAGE_PREFERENCES);
447                 optionsPreferencesAction.setEnabled(false);
448                 wizard.setNextEnabled(true);
449                 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
450         }
451
452         /**
453          * Shows a dialog box that shows the last version that was found by the
454          * {@link UpdateChecker}.
455          */
456         private void showLatestUpdate() {
457                 Version latestVersion = updateChecker.getLatestVersion();
458                 int versionDifference = latestVersion.compareTo(VERSION);
459                 if (versionDifference > 0) {
460                         JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.update-checker.latest-version.newer.message"), VERSION, latestVersion), I18n.getMessage("jsite.update-checker.latest-version.title"), JOptionPane.INFORMATION_MESSAGE);
461                 } else if (versionDifference < 0) {
462                         JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.update-checker.latest-version.older.message"), VERSION, latestVersion), I18n.getMessage("jsite.update-checker.latest-version.title"), JOptionPane.INFORMATION_MESSAGE);
463                 } else {
464                         JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.update-checker.latest-version.okay.message"), VERSION, latestVersion), I18n.getMessage("jsite.update-checker.latest-version.title"), JOptionPane.INFORMATION_MESSAGE);
465                 }
466         }
467
468         //
469         // INTERFACE ListSelectionListener
470         //
471
472         /**
473          * {@inheritDoc}
474          */
475         public void valueChanged(ListSelectionEvent e) {
476                 JList list = (JList) e.getSource();
477                 int selectedRow = list.getSelectedIndex();
478                 wizard.setNextEnabled(selectedRow > -1);
479         }
480
481         //
482         // INTERFACE WizardListener
483         //
484
485         /**
486          * {@inheritDoc}
487          */
488         public void wizardNextPressed(TWizard wizard) {
489                 String pageName = wizard.getPage().getName();
490                 if ("page.node-manager".equals(pageName)) {
491                         showPage(PageType.PAGE_PROJECTS);
492                 } else if ("page.project".equals(pageName)) {
493                         ProjectPage projectPage = (ProjectPage) wizard.getPage();
494                         Project project = projectPage.getSelectedProject();
495                         if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
496                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
497                                 return;
498                         }
499                         if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
500                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
501                                 return;
502                         }
503                         ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
504                         ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
505                         showPage(PageType.PAGE_PROJECT_FILES);
506                 } else if ("page.project.files".equals(pageName)) {
507                         ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
508                         Project project = projectPage.getSelectedProject();
509                         if (selectedNode == null) {
510                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
511                                 return;
512                         }
513                         CheckReport checkReport = ProjectInserter.validateProject(project);
514                         for (Issue issue : checkReport) {
515                                 if (issue.isFatal()) {
516                                         JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
517                                         return;
518                                 }
519                                 if (JOptionPane.showConfirmDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
520                                         return;
521                                 }
522                         }
523                         boolean nodeRunning = false;
524                         try {
525                                 nodeRunning = freenetInterface.isNodePresent();
526                         } catch (IOException e) {
527                                 /* ignore. */
528                         }
529                         if (!nodeRunning) {
530                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
531                                 return;
532                         }
533                         configuration.save();
534                         showPage(PageType.PAGE_INSERT_PROJECT);
535                         ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
536                         String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
537                         projectInsertPage.setTempDirectory(tempDirectory);
538                         projectInsertPage.startInsert();
539                         nodeMenu.setEnabled(false);
540                         optionsPreferencesAction.setEnabled(false);
541                 } else if ("page.project.insert".equals(pageName)) {
542                         showPage(PageType.PAGE_PROJECTS);
543                         nodeMenu.setEnabled(true);
544                         optionsPreferencesAction.setEnabled(true);
545                 } else if ("page.preferences".equals(pageName)) {
546                         showPage(PageType.PAGE_PROJECTS);
547                         optionsPreferencesAction.setEnabled(true);
548                 }
549         }
550
551         /**
552          * {@inheritDoc}
553          */
554         public void wizardPreviousPressed(TWizard wizard) {
555                 String pageName = wizard.getPage().getName();
556                 if ("page.project".equals(pageName)) {
557                         showPage(PageType.PAGE_NODE_MANAGER);
558                 } else if ("page.project.files".equals(pageName)) {
559                         showPage(PageType.PAGE_PROJECTS);
560                 } else if ("page.project.insert".equals(pageName)) {
561                         showPage(PageType.PAGE_PROJECT_FILES);
562                 }
563         }
564
565         /**
566          * {@inheritDoc}
567          */
568         public void wizardQuitPressed(TWizard wizard) {
569                 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
570                         JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
571                 }
572                 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.question"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
573                         if (saveConfiguration()) {
574                                 System.exit(0);
575                         }
576                         if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
577                                 System.exit(0);
578                         }
579                 }
580         }
581
582         //
583         // INTERFACE NodeManagerListener
584         //
585
586         /**
587          * {@inheritDoc}
588          */
589         public void nodesUpdated(Node[] nodes) {
590                 nodeMenu.removeAll();
591                 ButtonGroup nodeButtonGroup = new ButtonGroup();
592                 Node newSelectedNode = null;
593                 for (Node node : nodes) {
594                         JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
595                         nodeMenuItem.putClientProperty("Node", node);
596                         nodeMenuItem.addActionListener(this);
597                         nodeButtonGroup.add(nodeMenuItem);
598                         if (node.equals(selectedNode)) {
599                                 newSelectedNode = node;
600                                 nodeMenuItem.setSelected(true);
601                         }
602                         nodeMenu.add(nodeMenuItem);
603                 }
604                 nodeMenu.addSeparator();
605                 nodeMenu.add(manageNodeAction);
606                 selectedNode = newSelectedNode;
607                 freenetInterface.setNode(selectedNode);
608         }
609
610         /**
611          * {@inheritDoc}
612          */
613         public void actionPerformed(ActionEvent e) {
614                 Object source = e.getSource();
615                 if (source instanceof JRadioButtonMenuItem) {
616                         JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
617                         Node node = (Node) menuItem.getClientProperty("Node");
618                         selectedNode = node;
619                         freenetInterface.setNode(selectedNode);
620                 }
621         }
622
623         //
624         // INTERFACE UpdateListener
625         //
626
627         /**
628          * {@inheritDoc}
629          */
630         public void foundUpdateData(Version foundVersion, long versionTimestamp) {
631                 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
632                 if (foundVersion.compareTo(VERSION) > 0) {
633                         JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.update-checker.found-version.message"), foundVersion.toString(), new Date(versionTimestamp)), I18n.getMessage("jsite.update-checker.found-version.title"), JOptionPane.INFORMATION_MESSAGE);
634                 }
635         }
636
637         //
638         // MAIN METHOD
639         //
640
641         /**
642          * Main method that is called by the VM.
643          *
644          * @param args
645          *            The command-line arguments
646          */
647         public static void main(String[] args) {
648                 /* initialize logger. */
649                 Logger logger = Logger.getLogger("de.todesbaum");
650                 Handler handler = new ConsoleHandler();
651                 logger.addHandler(handler);
652                 String configFilename = null;
653                 boolean nextIsConfigFilename = false;
654                 for (String argument : args) {
655                         if (nextIsConfigFilename) {
656                                 configFilename = argument;
657                                 nextIsConfigFilename = false;
658                         }
659                         if ("--help".equals(argument)) {
660                                 printHelp();
661                                 return;
662                         } else if ("--debug".equals(argument)) {
663                                 logger.setLevel(Level.ALL);
664                                 handler.setLevel(Level.ALL);
665                         } else if ("--config-file".equals(argument)) {
666                                 nextIsConfigFilename = true;
667                         }
668                 }
669                 if (nextIsConfigFilename) {
670                         System.out.println("--config-file needs parameter!");
671                         return;
672                 }
673                 new Main(configFilename);
674         }
675
676         /**
677          * Prints a small syntax help.
678          */
679         private static void printHelp() {
680                 System.out.println("--help\tshows this cruft");
681                 System.out.println("--debug\tenables some debug output");
682                 System.out.println("--config-file <file>\tuse specified configuration file");
683         }
684
685 }