993add24017b27adf5c8dac0957b0669bb6d37ad
[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                 optionsPreferencesAction.setEnabled(false);
443                 wizard.setNextEnabled(true);
444         }
445
446         /**
447          * Shows a dialog box that shows the last version that was found by the
448          * {@link UpdateChecker}.
449          */
450         private void showLatestUpdate() {
451                 Version latestVersion = updateChecker.getLatestVersion();
452                 int versionDifference = latestVersion.compareTo(VERSION);
453                 if (versionDifference > 0) {
454                         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);
455                 } else if (versionDifference < 0) {
456                         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);
457                 } else {
458                         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);
459                 }
460         }
461
462         //
463         // INTERFACE ListSelectionListener
464         //
465
466         /**
467          * {@inheritDoc}
468          */
469         public void valueChanged(ListSelectionEvent e) {
470                 JList list = (JList) e.getSource();
471                 int selectedRow = list.getSelectedIndex();
472                 wizard.setNextEnabled(selectedRow > -1);
473         }
474
475         //
476         // INTERFACE WizardListener
477         //
478
479         /**
480          * {@inheritDoc}
481          */
482         public void wizardNextPressed(TWizard wizard) {
483                 String pageName = wizard.getPage().getName();
484                 if ("page.node-manager".equals(pageName)) {
485                         showPage(PageType.PAGE_PROJECTS);
486                 } else if ("page.project".equals(pageName)) {
487                         ProjectPage projectPage = (ProjectPage) wizard.getPage();
488                         Project project = projectPage.getSelectedProject();
489                         if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
490                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
491                                 return;
492                         }
493                         if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
494                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
495                                 return;
496                         }
497                         ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
498                         ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
499                         showPage(PageType.PAGE_PROJECT_FILES);
500                 } else if ("page.project.files".equals(pageName)) {
501                         ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
502                         Project project = projectPage.getSelectedProject();
503                         if (selectedNode == null) {
504                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
505                                 return;
506                         }
507                         if ((project.getIndexFile() == null) || (project.getIndexFile().length() == 0)) {
508                                 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.project-files.empty-index"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
509                                         return;
510                                 }
511                         } else {
512                                 File indexFile = new File(project.getLocalPath(), project.getIndexFile());
513                                 if (!indexFile.exists()) {
514                                         JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.index-missing"), null, JOptionPane.ERROR_MESSAGE);
515                                         return;
516                                 }
517                         }
518                         String indexFile = project.getIndexFile();
519                         boolean hasIndexFile = (indexFile != null);
520                         if (hasIndexFile && !project.getFileOption(indexFile).getContainer().equals("")) {
521                                 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.project-files.container-index"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
522                                         return;
523                                 }
524                         }
525                         if (hasIndexFile && !project.getFileOption(indexFile).getMimeType().equals("text/html")) {
526                                 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.project-files.index-not-html"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
527                                         return;
528                                 }
529                         }
530                         Map<String, FileOption> fileOptions = project.getFileOptions();
531                         Set<Entry<String, FileOption>> fileOptionEntries = fileOptions.entrySet();
532                         for (Entry<String, FileOption> fileOptionEntry : fileOptionEntries) {
533                                 FileOption fileOption = fileOptionEntry.getValue();
534                                 if (!fileOption.isInsert() && ((fileOption.getCustomKey().length() == 0) || "CHK@".equals(fileOption.getCustomKey()))) {
535                                         JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.project-files.no-custom-key"), fileOptionEntry.getKey()), null, JOptionPane.ERROR_MESSAGE);
536                                         return;
537                                 }
538                         }
539                         boolean nodeRunning = false;
540                         try {
541                                 nodeRunning = freenetInterface.isNodePresent();
542                         } catch (IOException e) {
543                                 /* ignore. */
544                         }
545                         if (!nodeRunning) {
546                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
547                                 return;
548                         }
549                         configuration.save();
550                         showPage(PageType.PAGE_INSERT_PROJECT);
551                         ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).startInsert();
552                         nodeMenu.setEnabled(false);
553                 } else if ("page.project.insert".equals(pageName)) {
554                         showPage(PageType.PAGE_PROJECTS);
555                         nodeMenu.setEnabled(true);
556                 } else if ("page.preferences".equals(pageName)) {
557                         showPage(PageType.PAGE_PROJECTS);
558                         optionsPreferencesAction.setEnabled(true);
559                 }
560         }
561
562         /**
563          * {@inheritDoc}
564          */
565         public void wizardPreviousPressed(TWizard wizard) {
566                 String pageName = wizard.getPage().getName();
567                 if ("page.project".equals(pageName)) {
568                         showPage(PageType.PAGE_NODE_MANAGER);
569                 } else if ("page.project.files".equals(pageName)) {
570                         showPage(PageType.PAGE_PROJECTS);
571                 } else if ("page.project.insert".equals(pageName)) {
572                         showPage(PageType.PAGE_PROJECT_FILES);
573                 }
574         }
575
576         /**
577          * {@inheritDoc}
578          */
579         public void wizardQuitPressed(TWizard wizard) {
580                 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.question"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
581                         if (saveConfiguration()) {
582                                 System.exit(0);
583                         }
584                         if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
585                                 System.exit(0);
586                         }
587                 }
588         }
589
590         //
591         // INTERFACE NodeManagerListener
592         //
593
594         /**
595          * {@inheritDoc}
596          */
597         public void nodesUpdated(Node[] nodes) {
598                 nodeMenu.removeAll();
599                 ButtonGroup nodeButtonGroup = new ButtonGroup();
600                 Node newSelectedNode = null;
601                 for (Node node : nodes) {
602                         JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
603                         nodeMenuItem.putClientProperty("Node", node);
604                         nodeMenuItem.addActionListener(this);
605                         nodeButtonGroup.add(nodeMenuItem);
606                         if (node.equals(selectedNode)) {
607                                 newSelectedNode = node;
608                                 nodeMenuItem.setSelected(true);
609                         }
610                         nodeMenu.add(nodeMenuItem);
611                 }
612                 nodeMenu.addSeparator();
613                 nodeMenu.add(manageNodeAction);
614                 selectedNode = newSelectedNode;
615                 freenetInterface.setNode(selectedNode);
616         }
617
618         /**
619          * {@inheritDoc}
620          */
621         public void actionPerformed(ActionEvent e) {
622                 Object source = e.getSource();
623                 if (source instanceof JRadioButtonMenuItem) {
624                         JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
625                         Node node = (Node) menuItem.getClientProperty("Node");
626                         selectedNode = node;
627                         freenetInterface.setNode(selectedNode);
628                 }
629         }
630
631         //
632         // INTERFACE UpdateListener
633         //
634
635         /**
636          * {@inheritDoc}
637          */
638         public void foundUpdateData(Version foundVersion, long versionTimestamp) {
639                 if (foundVersion.compareTo(VERSION) > 0) {
640                         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);
641                 }
642         }
643
644         //
645         // MAIN METHOD
646         //
647
648         /**
649          * Main method that is called by the VM.
650          *
651          * @param args
652          *            The command-line arguments
653          */
654         public static void main(String[] args) {
655                 /* initialize logger. */
656                 Logger logger = Logger.getLogger("de.todesbaum");
657                 Handler handler = new ConsoleHandler();
658                 logger.addHandler(handler);
659                 String configFilename = null;
660                 boolean nextIsConfigFilename = false;
661                 for (String argument : args) {
662                         if (nextIsConfigFilename) {
663                                 configFilename = argument;
664                                 nextIsConfigFilename = false;
665                         }
666                         if ("--help".equals(argument)) {
667                                 printHelp();
668                                 return;
669                         } else if ("--debug".equals(argument)) {
670                                 logger.setLevel(Level.ALL);
671                                 handler.setLevel(Level.ALL);
672                         } else if ("--config-file".equals(argument)) {
673                                 nextIsConfigFilename = true;
674                         }
675                 }
676                 if (nextIsConfigFilename) {
677                         System.out.println("--config-file needs parameter!");
678                         return;
679                 }
680                 new Main(configFilename);
681         }
682
683         /**
684          * Prints a small syntax help.
685          */
686         private static void printHelp() {
687                 System.out.println("--help\tshows this cruft");
688                 System.out.println("--debug\tenables some debug output");
689                 System.out.println("--config-file <file>\tuse specified configuration file");
690         }
691
692 }