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