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