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, 10);
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")) {
205 @SuppressWarnings("synthetic-access")
206 public void actionPerformed(ActionEvent actionEvent) {
207 switchLanguage(locale);
211 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
214 @SuppressWarnings("synthetic-access")
215 public void actionPerformed(ActionEvent actionEvent) {
216 showPage(PageType.PAGE_NODE_MANAGER);
217 optionsPreferencesAction.setEnabled(true);
218 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
219 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
222 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
228 @SuppressWarnings("synthetic-access")
229 public void actionPerformed(ActionEvent actionEvent) {
230 optionsPreferences();
233 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
239 @SuppressWarnings("synthetic-access")
240 public void actionPerformed(ActionEvent actionEvent) {
244 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
247 @SuppressWarnings("synthetic-access")
248 public void actionPerformed(ActionEvent e) {
249 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
253 I18nContainer.getInstance().registerRunnable(new Runnable() {
256 @SuppressWarnings("synthetic-access")
258 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
259 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
260 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
261 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
267 * Creates the menu bar.
269 * @return The menu bar
271 private JMenuBar createMenuBar() {
272 JMenuBar menuBar = new JMenuBar();
273 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
274 menuBar.add(languageMenu);
275 ButtonGroup languageButtonGroup = new ButtonGroup();
276 for (Locale locale : SUPPORTED_LOCALES) {
277 Action languageAction = languageActions.get(locale);
278 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
279 if (locale.equals(Locale.getDefault())) {
280 menuItem.setSelected(true);
282 languageAction.putValue("menuItem", menuItem);
283 languageButtonGroup.add(menuItem);
284 languageMenu.add(menuItem);
286 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
287 menuBar.add(nodeMenu);
288 selectedNode = configuration.getSelectedNode();
289 nodesUpdated(configuration.getNodes());
291 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
292 menuBar.add(optionsMenu);
293 optionsMenu.add(optionsPreferencesAction);
295 /* evil hack to right-align the help menu */
296 JPanel panel = new JPanel();
297 panel.setOpaque(false);
300 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
301 menuBar.add(helpMenu);
302 helpMenu.add(checkForUpdatesAction);
303 helpMenu.add(aboutAction);
305 I18nContainer.getInstance().registerRunnable(new Runnable() {
308 @SuppressWarnings("synthetic-access")
310 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
311 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
312 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
313 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
314 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
315 languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
324 * Initializes all pages.
326 private void initPages() {
327 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
328 nodeManagerPage.setName("page.node-manager");
329 nodeManagerPage.addNodeManagerListener(this);
330 nodeManagerPage.setNodes(configuration.getNodes());
331 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
333 ProjectPage projectPage = new ProjectPage(wizard);
334 projectPage.setName("page.project");
335 projectPage.setProjects(configuration.getProjects());
336 projectPage.setFreenetInterface(freenetInterface);
337 projectPage.addListSelectionListener(this);
338 pages.put(PageType.PAGE_PROJECTS, projectPage);
340 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
341 projectFilesPage.setName("page.project.files");
342 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
344 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
345 projectInsertPage.setName("page.project.insert");
346 projectInsertPage.setFreenetInterface(freenetInterface);
347 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
349 PreferencesPage preferencesPage = new PreferencesPage(wizard);
350 preferencesPage.setName("page.preferences");
351 preferencesPage.setTempDirectory(configuration.getTempDirectory());
352 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
356 * Shows the page with the given type.
359 * The page type to show
361 private void showPage(PageType pageType) {
362 wizard.setPreviousEnabled(pageType.ordinal() > 0);
363 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
364 wizard.setPage(pages.get(pageType));
365 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
369 * Returns whether a configuration file would be overwritten when calling
370 * {@link #saveConfiguration()}.
372 * @return {@code true} if {@link #saveConfiguration()} would overwrite an
373 * existing file, {@code false} otherwise
375 private boolean isOverwritingConfiguration() {
376 return configuration.getConfigurationLocator().hasFile(configuration.getConfigurationDirectory());
380 * Saves the configuration.
382 * @return <code>true</code> if the configuration could be saved,
383 * <code>false</code> otherwise
385 private boolean saveConfiguration() {
386 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
387 configuration.setNodes(nodeManagerPage.getNodes());
388 if (selectedNode != null) {
389 configuration.setSelectedNode(selectedNode);
392 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
393 configuration.setProjects(projectPage.getProjects());
395 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
396 configuration.setTempDirectory(preferencesPage.getTempDirectory());
398 return configuration.save();
402 * Finds a supported locale for the given locale.
405 * The locale to find a supported locale for
406 * @return The supported locale that was found, or the default locale if no
407 * supported locale could be found
409 private static Locale findSupportedLocale(Locale forLocale) {
410 for (Locale locale : SUPPORTED_LOCALES) {
411 if (locale.equals(forLocale)) {
415 for (Locale locale : SUPPORTED_LOCALES) {
416 if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
420 for (Locale locale : SUPPORTED_LOCALES) {
421 if (locale.getLanguage().equals(forLocale.getLanguage())) {
425 return SUPPORTED_LOCALES[0];
429 * Returns the version.
431 * @return The version
433 public static final Version getVersion() {
442 * Switches the language of the interface to the given locale.
445 * The locale to switch to
447 private void switchLanguage(Locale locale) {
448 Locale supportedLocale = findSupportedLocale(locale);
449 Action languageAction = languageActions.get(supportedLocale);
450 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
451 menuItem.setSelected(true);
452 I18n.setLocale(supportedLocale);
453 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
456 } catch (Throwable t) {
457 /* we probably shouldn't swallow this. */
460 wizard.setPage(wizard.getPage());
461 configuration.setLocale(supportedLocale);
465 * Shows a dialog with general preferences.
467 private void optionsPreferences() {
468 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationLocation(configuration.getConfigurationDirectory());
469 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasNextToJarConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.NEXT_TO_JAR_FILE));
470 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
471 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode());
472 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority());
473 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setManifestPutter(configuration.getManifestPutter());
474 showPage(PageType.PAGE_PREFERENCES);
475 optionsPreferencesAction.setEnabled(false);
476 wizard.setNextEnabled(true);
477 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
481 * Shows a dialog box that shows the last version that was found by the
482 * {@link UpdateChecker}.
484 private void showLatestUpdate() {
485 Version latestVersion = updateChecker.getLatestVersion();
486 int versionDifference = latestVersion.compareTo(VERSION);
487 if (versionDifference > 0) {
488 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);
489 } else if (versionDifference < 0) {
490 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);
492 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);
497 // INTERFACE ListSelectionListener
504 public void valueChanged(ListSelectionEvent e) {
505 JList list = (JList) e.getSource();
506 int selectedRow = list.getSelectedIndex();
507 wizard.setNextEnabled(selectedRow > -1);
511 // INTERFACE WizardListener
518 public void wizardNextPressed(TWizard wizard) {
519 String pageName = wizard.getPage().getName();
520 if ("page.node-manager".equals(pageName)) {
521 showPage(PageType.PAGE_PROJECTS);
522 } else if ("page.project".equals(pageName)) {
523 ProjectPage projectPage = (ProjectPage) wizard.getPage();
524 Project project = projectPage.getSelectedProject();
525 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
526 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
529 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
530 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
533 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
534 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
535 showPage(PageType.PAGE_PROJECT_FILES);
536 } else if ("page.project.files".equals(pageName)) {
537 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
538 Project project = projectPage.getSelectedProject();
539 if (selectedNode == null) {
540 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
543 CheckReport checkReport = ProjectInserter.validateProject(project);
544 for (Issue issue : checkReport) {
545 if (issue.isFatal()) {
546 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
549 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) {
553 boolean nodeRunning = false;
555 nodeRunning = freenetInterface.isNodePresent();
556 } catch (IOException e) {
560 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
563 configuration.save();
564 showPage(PageType.PAGE_INSERT_PROJECT);
565 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
566 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
567 projectInsertPage.setTempDirectory(tempDirectory);
568 projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
569 projectInsertPage.setPriority(configuration.getPriority());
570 projectInsertPage.setManifestPutter(configuration.getManifestPutter());
571 projectInsertPage.startInsert();
572 nodeMenu.setEnabled(false);
573 optionsPreferencesAction.setEnabled(false);
574 } else if ("page.project.insert".equals(pageName)) {
575 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
576 if (projectInsertPage.isRunning()) {
577 projectInsertPage.stopInsert();
579 showPage(PageType.PAGE_PROJECTS);
580 nodeMenu.setEnabled(true);
581 optionsPreferencesAction.setEnabled(true);
583 } else if ("page.preferences".equals(pageName)) {
584 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
585 showPage(PageType.PAGE_PROJECTS);
586 optionsPreferencesAction.setEnabled(true);
587 configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode());
588 configuration.setPriority(preferencesPage.getPriority());
589 configuration.setManifestPutter(preferencesPage.getManifestPutter());
590 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
598 public void wizardPreviousPressed(TWizard wizard) {
599 String pageName = wizard.getPage().getName();
600 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
601 showPage(PageType.PAGE_NODE_MANAGER);
602 optionsPreferencesAction.setEnabled(true);
603 } else if ("page.project.files".equals(pageName)) {
604 showPage(PageType.PAGE_PROJECTS);
605 } else if ("page.project.insert".equals(pageName)) {
606 showPage(PageType.PAGE_PROJECT_FILES);
614 public void wizardQuitPressed(TWizard wizard) {
615 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
616 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
618 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) {
619 if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
620 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);
621 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
622 if (saveConfiguration()) {
625 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
628 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
632 if (saveConfiguration()) {
636 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
643 // INTERFACE NodeManagerListener
650 public void nodesUpdated(Node[] nodes) {
651 nodeMenu.removeAll();
652 ButtonGroup nodeButtonGroup = new ButtonGroup();
653 Node newSelectedNode = null;
654 for (Node node : nodes) {
655 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
656 nodeMenuItem.putClientProperty("Node", node);
657 nodeMenuItem.addActionListener(this);
658 nodeButtonGroup.add(nodeMenuItem);
659 if (node.equals(selectedNode)) {
660 newSelectedNode = node;
661 nodeMenuItem.setSelected(true);
663 nodeMenu.add(nodeMenuItem);
665 nodeMenu.addSeparator();
666 nodeMenu.add(manageNodeAction);
667 selectedNode = newSelectedNode;
668 freenetInterface.setNode(selectedNode);
675 public void nodeSelected(Node node) {
676 for (Component menuItem : nodeMenu.getMenuComponents()) {
677 if (menuItem instanceof JMenuItem) {
678 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
679 ((JMenuItem) menuItem).setSelected(true);
683 freenetInterface.setNode(node);
688 // INTERFACE ActionListener
695 public void actionPerformed(ActionEvent e) {
696 Object source = e.getSource();
697 if (source instanceof JRadioButtonMenuItem) {
698 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
699 Node node = (Node) menuItem.getClientProperty("Node");
701 freenetInterface.setNode(selectedNode);
706 // INTERFACE UpdateListener
713 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
714 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
715 if (foundVersion.compareTo(VERSION) > 0) {
716 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);
725 * Main method that is called by the VM.
728 * The command-line arguments
730 public static void main(String[] args) {
731 /* initialize logger. */
732 Logger logger = Logger.getLogger("de.todesbaum");
733 Handler handler = new ConsoleHandler();
734 logger.addHandler(handler);
735 String configFilename = null;
736 boolean nextIsConfigFilename = false;
737 for (String argument : args) {
738 if (nextIsConfigFilename) {
739 configFilename = argument;
740 nextIsConfigFilename = false;
742 if ("--help".equals(argument)) {
745 } else if ("--debug".equals(argument)) {
746 logger.setLevel(Level.ALL);
747 handler.setLevel(Level.ALL);
748 } else if ("--config-file".equals(argument)) {
749 nextIsConfigFilename = true;
752 if (nextIsConfigFilename) {
753 System.out.println("--config-file needs parameter!");
756 new Main(configFilename);
760 * Prints a small syntax help.
762 private static void printHelp() {
763 System.out.println("--help\tshows this cruft");
764 System.out.println("--debug\tenables some debug output");
765 System.out.println("--config-file <file>\tuse specified configuration file");