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