Set version to 0.9.2.
[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.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, 9, 2);
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 };
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                                 optionsPreferencesAction.setEnabled(true);
213                                 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
214                                 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
215                         }
216                 };
217                 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
218
219                         /**
220                          * {@inheritDoc}
221                          */
222                         @SuppressWarnings("synthetic-access")
223                         public void actionPerformed(ActionEvent actionEvent) {
224                                 optionsPreferences();
225                         }
226                 };
227                 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
228
229                         /**
230                          * {@inheritDoc}
231                          */
232                         @SuppressWarnings("synthetic-access")
233                         public void actionPerformed(ActionEvent actionEvent) {
234                                 showLatestUpdate();
235                         }
236                 };
237                 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
238
239                         @SuppressWarnings("synthetic-access")
240                         public void actionPerformed(ActionEvent e) {
241                                 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
242                         }
243                 };
244
245                 I18nContainer.getInstance().registerRunnable(new Runnable() {
246
247                         @SuppressWarnings("synthetic-access")
248                         public void run() {
249                                 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
250                                 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
251                                 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
252                                 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
253                         }
254                 });
255         }
256
257         /**
258          * Creates the menu bar.
259          *
260          * @return The menu bar
261          */
262         private JMenuBar createMenuBar() {
263                 JMenuBar menuBar = new JMenuBar();
264                 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
265                 menuBar.add(languageMenu);
266                 ButtonGroup languageButtonGroup = new ButtonGroup();
267                 for (Locale locale : SUPPORTED_LOCALES) {
268                         Action languageAction = languageActions.get(locale);
269                         JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
270                         if (locale.equals(Locale.getDefault())) {
271                                 menuItem.setSelected(true);
272                         }
273                         languageAction.putValue("menuItem", menuItem);
274                         languageButtonGroup.add(menuItem);
275                         languageMenu.add(menuItem);
276                 }
277                 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
278                 menuBar.add(nodeMenu);
279                 selectedNode = configuration.getSelectedNode();
280                 nodesUpdated(configuration.getNodes());
281
282                 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
283                 menuBar.add(optionsMenu);
284                 optionsMenu.add(optionsPreferencesAction);
285
286                 /* evil hack to right-align the help menu */
287                 JPanel panel = new JPanel();
288                 panel.setOpaque(false);
289                 menuBar.add(panel);
290
291                 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
292                 menuBar.add(helpMenu);
293                 helpMenu.add(checkForUpdatesAction);
294                 helpMenu.add(aboutAction);
295
296                 I18nContainer.getInstance().registerRunnable(new Runnable() {
297
298                         @SuppressWarnings("synthetic-access")
299                         public void run() {
300                                 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
301                                 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
302                                 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
303                                 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
304                                 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
305                                         languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
306                                 }
307                         }
308                 });
309
310                 return menuBar;
311         }
312
313         /**
314          * Initializes all pages.
315          */
316         private void initPages() {
317                 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
318                 nodeManagerPage.setName("page.node-manager");
319                 nodeManagerPage.addNodeManagerListener(this);
320                 nodeManagerPage.setNodes(configuration.getNodes());
321                 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
322
323                 ProjectPage projectPage = new ProjectPage(wizard);
324                 projectPage.setName("page.project");
325                 projectPage.setProjects(configuration.getProjects());
326                 projectPage.setFreenetInterface(freenetInterface);
327                 projectPage.addListSelectionListener(this);
328                 pages.put(PageType.PAGE_PROJECTS, projectPage);
329
330                 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
331                 projectFilesPage.setName("page.project.files");
332                 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
333
334                 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
335                 projectInsertPage.setName("page.project.insert");
336                 projectInsertPage.setFreenetInterface(freenetInterface);
337                 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
338
339                 PreferencesPage preferencesPage = new PreferencesPage(wizard);
340                 preferencesPage.setName("page.preferences");
341                 preferencesPage.setTempDirectory(configuration.getTempDirectory());
342                 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
343         }
344
345         /**
346          * Shows the page with the given type.
347          *
348          * @param pageType
349          *            The page type to show
350          */
351         private void showPage(PageType pageType) {
352                 wizard.setPreviousEnabled(pageType.ordinal() > 0);
353                 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
354                 wizard.setPage(pages.get(pageType));
355                 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
356         }
357
358         /**
359          * Saves the configuration.
360          *
361          * @return <code>true</code> if the configuration could be saved,
362          *         <code>false</code> otherwise
363          */
364         private boolean saveConfiguration() {
365                 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
366                 configuration.setNodes(nodeManagerPage.getNodes());
367                 if (selectedNode != null) {
368                         configuration.setSelectedNode(selectedNode);
369                 }
370
371                 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
372                 configuration.setProjects(projectPage.getProjects());
373
374                 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
375                 configuration.setTempDirectory(preferencesPage.getTempDirectory());
376
377                 return configuration.save();
378         }
379
380         /**
381          * Finds a supported locale for the given locale.
382          *
383          * @param forLocale
384          *            The locale to find a supported locale for
385          * @return The supported locale that was found, or the default locale if no
386          *         supported locale could be found
387          */
388         private Locale findSupportedLocale(Locale forLocale) {
389                 for (Locale locale : SUPPORTED_LOCALES) {
390                         if (locale.equals(forLocale)) {
391                                 return locale;
392                         }
393                 }
394                 for (Locale locale : SUPPORTED_LOCALES) {
395                         if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
396                                 return locale;
397                         }
398                 }
399                 for (Locale locale : SUPPORTED_LOCALES) {
400                         if (locale.getLanguage().equals(forLocale.getLanguage())) {
401                                 return locale;
402                         }
403                 }
404                 return SUPPORTED_LOCALES[0];
405         }
406
407         /**
408          * Returns the version.
409          *
410          * @return The version
411          */
412         public static final Version getVersion() {
413                 return VERSION;
414         }
415
416         //
417         // ACTIONS
418         //
419
420         /**
421          * Switches the language of the interface to the given locale.
422          *
423          * @param locale
424          *            The locale to switch to
425          */
426         private void switchLanguage(Locale locale) {
427                 Locale supportedLocale = findSupportedLocale(locale);
428                 Action languageAction = languageActions.get(supportedLocale);
429                 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
430                 menuItem.setSelected(true);
431                 I18n.setLocale(supportedLocale);
432                 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
433                         try {
434                                 i18nRunnable.run();
435                         } catch (Throwable t) {
436                                 /* we probably shouldn't swallow this. */
437                         }
438                 }
439                 wizard.setPage(wizard.getPage());
440                 configuration.setLocale(supportedLocale);
441         }
442
443         /**
444          * Shows a dialog with general preferences.
445          */
446         private void optionsPreferences() {
447                 showPage(PageType.PAGE_PREFERENCES);
448                 optionsPreferencesAction.setEnabled(false);
449                 wizard.setNextEnabled(true);
450                 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
451         }
452
453         /**
454          * Shows a dialog box that shows the last version that was found by the
455          * {@link UpdateChecker}.
456          */
457         private void showLatestUpdate() {
458                 Version latestVersion = updateChecker.getLatestVersion();
459                 int versionDifference = latestVersion.compareTo(VERSION);
460                 if (versionDifference > 0) {
461                         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);
462                 } else if (versionDifference < 0) {
463                         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);
464                 } else {
465                         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);
466                 }
467         }
468
469         //
470         // INTERFACE ListSelectionListener
471         //
472
473         /**
474          * {@inheritDoc}
475          */
476         public void valueChanged(ListSelectionEvent e) {
477                 JList list = (JList) e.getSource();
478                 int selectedRow = list.getSelectedIndex();
479                 wizard.setNextEnabled(selectedRow > -1);
480         }
481
482         //
483         // INTERFACE WizardListener
484         //
485
486         /**
487          * {@inheritDoc}
488          */
489         public void wizardNextPressed(TWizard wizard) {
490                 String pageName = wizard.getPage().getName();
491                 if ("page.node-manager".equals(pageName)) {
492                         showPage(PageType.PAGE_PROJECTS);
493                 } else if ("page.project".equals(pageName)) {
494                         ProjectPage projectPage = (ProjectPage) wizard.getPage();
495                         Project project = projectPage.getSelectedProject();
496                         if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
497                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
498                                 return;
499                         }
500                         if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
501                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
502                                 return;
503                         }
504                         ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
505                         ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
506                         showPage(PageType.PAGE_PROJECT_FILES);
507                 } else if ("page.project.files".equals(pageName)) {
508                         ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
509                         Project project = projectPage.getSelectedProject();
510                         if (selectedNode == null) {
511                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
512                                 return;
513                         }
514                         CheckReport checkReport = ProjectInserter.validateProject(project);
515                         for (Issue issue : checkReport) {
516                                 if (issue.isFatal()) {
517                                         JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
518                                         return;
519                                 }
520                                 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) {
521                                         return;
522                                 }
523                         }
524                         boolean nodeRunning = false;
525                         try {
526                                 nodeRunning = freenetInterface.isNodePresent();
527                         } catch (IOException e) {
528                                 /* ignore. */
529                         }
530                         if (!nodeRunning) {
531                                 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
532                                 return;
533                         }
534                         configuration.save();
535                         showPage(PageType.PAGE_INSERT_PROJECT);
536                         ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
537                         String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
538                         projectInsertPage.setTempDirectory(tempDirectory);
539                         projectInsertPage.startInsert();
540                         nodeMenu.setEnabled(false);
541                         optionsPreferencesAction.setEnabled(false);
542                 } else if ("page.project.insert".equals(pageName)) {
543                         ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
544                         if (projectInsertPage.isRunning()) {
545                                 projectInsertPage.stopInsert();
546                         } else {
547                                 showPage(PageType.PAGE_PROJECTS);
548                                 nodeMenu.setEnabled(true);
549                                 optionsPreferencesAction.setEnabled(true);
550                         }
551                 } else if ("page.preferences".equals(pageName)) {
552                         showPage(PageType.PAGE_PROJECTS);
553                         optionsPreferencesAction.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) || "page.preferences".equals(pageName)) {
563                         showPage(PageType.PAGE_NODE_MANAGER);
564                         optionsPreferencesAction.setEnabled(true);
565                 } else if ("page.project.files".equals(pageName)) {
566                         showPage(PageType.PAGE_PROJECTS);
567                 } else if ("page.project.insert".equals(pageName)) {
568                         showPage(PageType.PAGE_PROJECT_FILES);
569                 }
570         }
571
572         /**
573          * {@inheritDoc}
574          */
575         public void wizardQuitPressed(TWizard wizard) {
576                 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
577                         JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
578                 }
579                 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.question"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
580                         if (saveConfiguration()) {
581                                 System.exit(0);
582                         }
583                         if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
584                                 System.exit(0);
585                         }
586                 }
587         }
588
589         //
590         // INTERFACE NodeManagerListener
591         //
592
593         /**
594          * {@inheritDoc}
595          */
596         public void nodesUpdated(Node[] nodes) {
597                 nodeMenu.removeAll();
598                 ButtonGroup nodeButtonGroup = new ButtonGroup();
599                 Node newSelectedNode = null;
600                 for (Node node : nodes) {
601                         JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
602                         nodeMenuItem.putClientProperty("Node", node);
603                         nodeMenuItem.addActionListener(this);
604                         nodeButtonGroup.add(nodeMenuItem);
605                         if (node.equals(selectedNode)) {
606                                 newSelectedNode = node;
607                                 nodeMenuItem.setSelected(true);
608                         }
609                         nodeMenu.add(nodeMenuItem);
610                 }
611                 nodeMenu.addSeparator();
612                 nodeMenu.add(manageNodeAction);
613                 selectedNode = newSelectedNode;
614                 freenetInterface.setNode(selectedNode);
615         }
616
617         /**
618          * {@inheritDoc}
619          */
620         public void actionPerformed(ActionEvent e) {
621                 Object source = e.getSource();
622                 if (source instanceof JRadioButtonMenuItem) {
623                         JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
624                         Node node = (Node) menuItem.getClientProperty("Node");
625                         selectedNode = node;
626                         freenetInterface.setNode(selectedNode);
627                 }
628         }
629
630         //
631         // INTERFACE UpdateListener
632         //
633
634         /**
635          * {@inheritDoc}
636          */
637         public void foundUpdateData(Version foundVersion, long versionTimestamp) {
638                 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, 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 }