2 * jSite - Main.java - Copyright Ā© 2006ā2012 David Roden
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package de.todesbaum.jsite.main;
21 import java.awt.Component;
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;
30 import java.util.logging.ConsoleHandler;
31 import java.util.logging.Handler;
32 import java.util.logging.Level;
33 import java.util.logging.Logger;
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.JMenuItem;
43 import javax.swing.JOptionPane;
44 import javax.swing.JPanel;
45 import javax.swing.JRadioButtonMenuItem;
46 import javax.swing.event.ListSelectionEvent;
47 import javax.swing.event.ListSelectionListener;
49 import de.todesbaum.jsite.application.Freenet7Interface;
50 import de.todesbaum.jsite.application.Node;
51 import de.todesbaum.jsite.application.Project;
52 import de.todesbaum.jsite.application.ProjectInserter;
53 import de.todesbaum.jsite.application.ProjectInserter.CheckReport;
54 import de.todesbaum.jsite.application.ProjectInserter.Issue;
55 import de.todesbaum.jsite.application.UpdateChecker;
56 import de.todesbaum.jsite.application.UpdateListener;
57 import de.todesbaum.jsite.gui.NodeManagerListener;
58 import de.todesbaum.jsite.gui.NodeManagerPage;
59 import de.todesbaum.jsite.gui.PreferencesPage;
60 import de.todesbaum.jsite.gui.ProjectFilesPage;
61 import de.todesbaum.jsite.gui.ProjectInsertPage;
62 import de.todesbaum.jsite.gui.ProjectPage;
63 import de.todesbaum.jsite.i18n.I18n;
64 import de.todesbaum.jsite.i18n.I18nContainer;
65 import de.todesbaum.jsite.main.ConfigurationLocator.ConfigurationLocation;
66 import de.todesbaum.util.image.IconLoader;
67 import de.todesbaum.util.swing.TWizard;
68 import de.todesbaum.util.swing.TWizardPage;
69 import de.todesbaum.util.swing.WizardListener;
72 * The main class that ties together everything.
74 * @author David āBombeā Roden <bombe@freenetproject.org>
76 public class Main implements ActionListener, ListSelectionListener, WizardListener, NodeManagerListener, UpdateListener {
79 private static final Logger logger = Logger.getLogger(Main.class.getName());
82 private static final Version VERSION = new Version(0, 9, 2);
84 /** The configuration. */
85 private Configuration configuration;
87 /** The freenet interface. */
88 private Freenet7Interface freenetInterface = new Freenet7Interface();
90 /** The update checker. */
91 private final UpdateChecker updateChecker;
93 /** The jSite icon. */
94 private Icon jSiteIcon;
97 * Enumeration for all possible pages.
99 * @author David āBombeā Roden <bombe@freenetproject.org>
101 private static enum PageType {
103 /** The node manager page. */
106 /** The project page. */
109 /** The project files page. */
112 /** The project insert page. */
115 /** The preferences page. */
120 /** The supported locales. */
121 private static final Locale[] SUPPORTED_LOCALES = new Locale[] { Locale.ENGLISH, Locale.GERMAN, Locale.FRENCH };
123 /** The actions that switch the language. */
124 private Map<Locale, Action> languageActions = new HashMap<Locale, Action>();
126 /** The āmanage nodesā action. */
127 private Action manageNodeAction;
129 /** The āpreferencesā action. */
130 private Action optionsPreferencesAction;
132 /** The ācheck for updatesā action. */
133 private Action checkForUpdatesAction;
135 /** The āabout jSiteā action. */
136 private Action aboutAction;
139 private TWizard wizard;
141 /** The node menu. */
142 private JMenu nodeMenu;
144 /** The currently selected node. */
145 private Node selectedNode;
147 /** Mapping from page type to page. */
148 private final Map<PageType, TWizardPage> pages = new HashMap<PageType, TWizardPage>();
150 /** The original location of the configuration file. */
151 private ConfigurationLocation originalLocation;
154 * Creates a new core with the default configuration file.
161 * Creates a new core with the given configuration from the given file.
163 * @param configFilename
164 * The name of the configuration file
166 private Main(String configFilename) {
167 /* collect all possible configuration file locations. */
168 ConfigurationLocator configurationLocator = new ConfigurationLocator();
169 if (configFilename != null) {
170 configurationLocator.setCustomLocation(configFilename);
173 originalLocation = configurationLocator.findPreferredLocation();
174 logger.log(Level.CONFIG, "Using configuration from " + originalLocation + ".");
175 configuration = new Configuration(configurationLocator, originalLocation);
177 Locale.setDefault(configuration.getLocale());
178 I18n.setLocale(configuration.getLocale());
179 wizard = new TWizard();
181 wizard.setJMenuBar(createMenuBar());
182 wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
183 wizard.setPreviousEnabled(false);
184 wizard.setNextEnabled(true);
185 wizard.addWizardListener(this);
186 jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
187 wizard.setIcon(jSiteIcon);
189 updateChecker = new UpdateChecker(freenetInterface);
190 updateChecker.addUpdateListener(this);
191 updateChecker.start();
194 showPage(PageType.PAGE_PROJECTS);
198 * Creates all actions.
200 private void createActions() {
201 for (final Locale locale : SUPPORTED_LOCALES) {
202 languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
204 @SuppressWarnings("synthetic-access")
205 public void actionPerformed(ActionEvent actionEvent) {
206 switchLanguage(locale);
210 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
212 @SuppressWarnings("synthetic-access")
213 public void actionPerformed(ActionEvent actionEvent) {
214 showPage(PageType.PAGE_NODE_MANAGER);
215 optionsPreferencesAction.setEnabled(true);
216 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
217 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
220 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
225 @SuppressWarnings("synthetic-access")
226 public void actionPerformed(ActionEvent actionEvent) {
227 optionsPreferences();
230 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
235 @SuppressWarnings("synthetic-access")
236 public void actionPerformed(ActionEvent actionEvent) {
240 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
242 @SuppressWarnings("synthetic-access")
243 public void actionPerformed(ActionEvent e) {
244 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
248 I18nContainer.getInstance().registerRunnable(new Runnable() {
250 @SuppressWarnings("synthetic-access")
252 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
253 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
254 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
255 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
261 * Creates the menu bar.
263 * @return The menu bar
265 private JMenuBar createMenuBar() {
266 JMenuBar menuBar = new JMenuBar();
267 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
268 menuBar.add(languageMenu);
269 ButtonGroup languageButtonGroup = new ButtonGroup();
270 for (Locale locale : SUPPORTED_LOCALES) {
271 Action languageAction = languageActions.get(locale);
272 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
273 if (locale.equals(Locale.getDefault())) {
274 menuItem.setSelected(true);
276 languageAction.putValue("menuItem", menuItem);
277 languageButtonGroup.add(menuItem);
278 languageMenu.add(menuItem);
280 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
281 menuBar.add(nodeMenu);
282 selectedNode = configuration.getSelectedNode();
283 nodesUpdated(configuration.getNodes());
285 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
286 menuBar.add(optionsMenu);
287 optionsMenu.add(optionsPreferencesAction);
289 /* evil hack to right-align the help menu */
290 JPanel panel = new JPanel();
291 panel.setOpaque(false);
294 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
295 menuBar.add(helpMenu);
296 helpMenu.add(checkForUpdatesAction);
297 helpMenu.add(aboutAction);
299 I18nContainer.getInstance().registerRunnable(new Runnable() {
301 @SuppressWarnings("synthetic-access")
303 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
304 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
305 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
306 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
307 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
308 languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
317 * Initializes all pages.
319 private void initPages() {
320 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
321 nodeManagerPage.setName("page.node-manager");
322 nodeManagerPage.addNodeManagerListener(this);
323 nodeManagerPage.setNodes(configuration.getNodes());
324 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
326 ProjectPage projectPage = new ProjectPage(wizard);
327 projectPage.setName("page.project");
328 projectPage.setProjects(configuration.getProjects());
329 projectPage.setFreenetInterface(freenetInterface);
330 projectPage.addListSelectionListener(this);
331 pages.put(PageType.PAGE_PROJECTS, projectPage);
333 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
334 projectFilesPage.setName("page.project.files");
335 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
337 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
338 projectInsertPage.setName("page.project.insert");
339 projectInsertPage.setFreenetInterface(freenetInterface);
340 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
342 PreferencesPage preferencesPage = new PreferencesPage(wizard);
343 preferencesPage.setName("page.preferences");
344 preferencesPage.setTempDirectory(configuration.getTempDirectory());
345 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
349 * Shows the page with the given type.
352 * The page type to show
354 private void showPage(PageType pageType) {
355 wizard.setPreviousEnabled(pageType.ordinal() > 0);
356 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
357 wizard.setPage(pages.get(pageType));
358 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
362 * Returns whether a configuration file would be overwritten when calling
363 * {@link #saveConfiguration()}.
365 * @return {@code true} if {@link #saveConfiguration()} would overwrite an
366 * existing file, {@code false} otherwise
368 private boolean isOverwritingConfiguration() {
369 return configuration.getConfigurationLocator().hasFile(configuration.getConfigurationDirectory());
373 * Saves the configuration.
375 * @return <code>true</code> if the configuration could be saved,
376 * <code>false</code> otherwise
378 private boolean saveConfiguration() {
379 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
380 configuration.setNodes(nodeManagerPage.getNodes());
381 if (selectedNode != null) {
382 configuration.setSelectedNode(selectedNode);
385 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
386 configuration.setProjects(projectPage.getProjects());
388 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
389 configuration.setTempDirectory(preferencesPage.getTempDirectory());
391 return configuration.save();
395 * Finds a supported locale for the given locale.
398 * The locale to find a supported locale for
399 * @return The supported locale that was found, or the default locale if no
400 * supported locale could be found
402 private Locale findSupportedLocale(Locale forLocale) {
403 for (Locale locale : SUPPORTED_LOCALES) {
404 if (locale.equals(forLocale)) {
408 for (Locale locale : SUPPORTED_LOCALES) {
409 if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
413 for (Locale locale : SUPPORTED_LOCALES) {
414 if (locale.getLanguage().equals(forLocale.getLanguage())) {
418 return SUPPORTED_LOCALES[0];
422 * Returns the version.
424 * @return The version
426 public static final Version getVersion() {
435 * Switches the language of the interface to the given locale.
438 * The locale to switch to
440 private void switchLanguage(Locale locale) {
441 Locale supportedLocale = findSupportedLocale(locale);
442 Action languageAction = languageActions.get(supportedLocale);
443 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
444 menuItem.setSelected(true);
445 I18n.setLocale(supportedLocale);
446 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
449 } catch (Throwable t) {
450 /* we probably shouldn't swallow this. */
453 wizard.setPage(wizard.getPage());
454 configuration.setLocale(supportedLocale);
458 * Shows a dialog with general preferences.
460 private void optionsPreferences() {
461 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationLocation(configuration.getConfigurationDirectory());
462 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasNextToJarConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.NEXT_TO_JAR_FILE));
463 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
464 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode());
465 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority());
466 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setManifestPutter(configuration.getManifestPutter());
467 showPage(PageType.PAGE_PREFERENCES);
468 optionsPreferencesAction.setEnabled(false);
469 wizard.setNextEnabled(true);
470 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
474 * Shows a dialog box that shows the last version that was found by the
475 * {@link UpdateChecker}.
477 private void showLatestUpdate() {
478 Version latestVersion = updateChecker.getLatestVersion();
479 int versionDifference = latestVersion.compareTo(VERSION);
480 if (versionDifference > 0) {
481 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);
482 } else if (versionDifference < 0) {
483 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);
485 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);
490 // INTERFACE ListSelectionListener
496 public void valueChanged(ListSelectionEvent e) {
497 JList list = (JList) e.getSource();
498 int selectedRow = list.getSelectedIndex();
499 wizard.setNextEnabled(selectedRow > -1);
503 // INTERFACE WizardListener
509 public void wizardNextPressed(TWizard wizard) {
510 String pageName = wizard.getPage().getName();
511 if ("page.node-manager".equals(pageName)) {
512 showPage(PageType.PAGE_PROJECTS);
513 } else if ("page.project".equals(pageName)) {
514 ProjectPage projectPage = (ProjectPage) wizard.getPage();
515 Project project = projectPage.getSelectedProject();
516 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
517 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
520 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
521 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
524 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
525 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
526 showPage(PageType.PAGE_PROJECT_FILES);
527 } else if ("page.project.files".equals(pageName)) {
528 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
529 Project project = projectPage.getSelectedProject();
530 if (selectedNode == null) {
531 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
534 CheckReport checkReport = ProjectInserter.validateProject(project);
535 for (Issue issue : checkReport) {
536 if (issue.isFatal()) {
537 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
540 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) {
544 boolean nodeRunning = false;
546 nodeRunning = freenetInterface.isNodePresent();
547 } catch (IOException e) {
551 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
554 configuration.save();
555 showPage(PageType.PAGE_INSERT_PROJECT);
556 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
557 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
558 projectInsertPage.setTempDirectory(tempDirectory);
559 projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
560 projectInsertPage.setPriority(configuration.getPriority());
561 projectInsertPage.setManifestPutter(configuration.getManifestPutter());
562 projectInsertPage.startInsert();
563 nodeMenu.setEnabled(false);
564 optionsPreferencesAction.setEnabled(false);
565 } else if ("page.project.insert".equals(pageName)) {
566 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
567 if (projectInsertPage.isRunning()) {
568 projectInsertPage.stopInsert();
570 showPage(PageType.PAGE_PROJECTS);
571 nodeMenu.setEnabled(true);
572 optionsPreferencesAction.setEnabled(true);
574 } else if ("page.preferences".equals(pageName)) {
575 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
576 showPage(PageType.PAGE_PROJECTS);
577 optionsPreferencesAction.setEnabled(true);
578 configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode());
579 configuration.setPriority(preferencesPage.getPriority());
580 configuration.setManifestPutter(preferencesPage.getManifestPutter());
581 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
588 public void wizardPreviousPressed(TWizard wizard) {
589 String pageName = wizard.getPage().getName();
590 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
591 showPage(PageType.PAGE_NODE_MANAGER);
592 optionsPreferencesAction.setEnabled(true);
593 } else if ("page.project.files".equals(pageName)) {
594 showPage(PageType.PAGE_PROJECTS);
595 } else if ("page.project.insert".equals(pageName)) {
596 showPage(PageType.PAGE_PROJECT_FILES);
603 public void wizardQuitPressed(TWizard wizard) {
604 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
605 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
607 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.question"), I18n.getMessage("jsite.quit.question.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
608 if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
609 int overwriteConfigurationAnswer = JOptionPane.showConfirmDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.quit.overwrite-configuration"), configuration.getConfigurationLocator().getFile(configuration.getConfigurationDirectory())), I18n.getMessage("jsite.quit.overwrite-configuration.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
610 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
611 if (saveConfiguration()) {
614 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
617 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
621 if (saveConfiguration()) {
625 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
632 // INTERFACE NodeManagerListener
638 public void nodesUpdated(Node[] nodes) {
639 nodeMenu.removeAll();
640 ButtonGroup nodeButtonGroup = new ButtonGroup();
641 Node newSelectedNode = null;
642 for (Node node : nodes) {
643 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
644 nodeMenuItem.putClientProperty("Node", node);
645 nodeMenuItem.addActionListener(this);
646 nodeButtonGroup.add(nodeMenuItem);
647 if (node.equals(selectedNode)) {
648 newSelectedNode = node;
649 nodeMenuItem.setSelected(true);
651 nodeMenu.add(nodeMenuItem);
653 nodeMenu.addSeparator();
654 nodeMenu.add(manageNodeAction);
655 selectedNode = newSelectedNode;
656 freenetInterface.setNode(selectedNode);
662 public void nodeSelected(Node node) {
663 for (Component menuItem : nodeMenu.getMenuComponents()) {
664 if (menuItem instanceof JMenuItem) {
665 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
666 ((JMenuItem) menuItem).setSelected(true);
670 freenetInterface.setNode(node);
675 // INTERFACE ActionListener
681 public void actionPerformed(ActionEvent e) {
682 Object source = e.getSource();
683 if (source instanceof JRadioButtonMenuItem) {
684 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
685 Node node = (Node) menuItem.getClientProperty("Node");
687 freenetInterface.setNode(selectedNode);
692 // INTERFACE UpdateListener
698 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
699 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
700 if (foundVersion.compareTo(VERSION) > 0) {
701 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);
710 * Main method that is called by the VM.
713 * The command-line arguments
715 public static void main(String[] args) {
716 /* initialize logger. */
717 Logger logger = Logger.getLogger("de.todesbaum");
718 Handler handler = new ConsoleHandler();
719 logger.addHandler(handler);
720 String configFilename = null;
721 boolean nextIsConfigFilename = false;
722 for (String argument : args) {
723 if (nextIsConfigFilename) {
724 configFilename = argument;
725 nextIsConfigFilename = false;
727 if ("--help".equals(argument)) {
730 } else if ("--debug".equals(argument)) {
731 logger.setLevel(Level.ALL);
732 handler.setLevel(Level.ALL);
733 } else if ("--config-file".equals(argument)) {
734 nextIsConfigFilename = true;
737 if (nextIsConfigFilename) {
738 System.out.println("--config-file needs parameter!");
741 new Main(configFilename);
745 * Prints a small syntax help.
747 private static void printHelp() {
748 System.out.println("--help\tshows this cruft");
749 System.out.println("--debug\tenables some debug output");
750 System.out.println("--config-file <file>\tuse specified configuration file");