2 * jSite - Main.java - Copyright © 2006–2014 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 net.pterodactylus.util.image.IconLoader;
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.application.UpdateChecker;
55 import de.todesbaum.jsite.application.UpdateListener;
56 import de.todesbaum.jsite.application.WebOfTrustInterface;
57 import de.todesbaum.jsite.application.validation.CheckReport;
58 import de.todesbaum.jsite.application.validation.Issue;
59 import de.todesbaum.jsite.application.validation.ProjectValidator;
60 import de.todesbaum.jsite.gui.NodeManagerListener;
61 import de.todesbaum.jsite.gui.NodeManagerPage;
62 import de.todesbaum.jsite.gui.PreferencesPage;
63 import de.todesbaum.jsite.gui.ProjectFilesPage;
64 import de.todesbaum.jsite.gui.ProjectInsertPage;
65 import de.todesbaum.jsite.gui.ProjectPage;
66 import de.todesbaum.jsite.i18n.I18n;
67 import de.todesbaum.jsite.i18n.I18nContainer;
68 import de.todesbaum.jsite.main.ConfigurationLocator.ConfigurationLocation;
69 import de.todesbaum.util.swing.TWizard;
70 import de.todesbaum.util.swing.TWizardPage;
71 import de.todesbaum.util.swing.WizardListener;
74 * The main class that ties together everything.
76 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
78 public class Main implements ActionListener, ListSelectionListener, WizardListener, NodeManagerListener, UpdateListener {
81 private static final Logger logger = Logger.getLogger(Main.class.getName());
84 private static final Version VERSION = new Version(0, 13);
86 /** The configuration. */
87 private Configuration configuration;
89 /** The freenet interface. */
90 private Freenet7Interface freenetInterface = new Freenet7Interface();
92 /** The update checker. */
93 private final UpdateChecker updateChecker;
95 /** The web of trust interface. */
96 private final WebOfTrustInterface webOfTrustInterface;
98 /** The jSite icon. */
99 private Icon jSiteIcon;
102 * Enumeration for all possible pages.
104 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
106 private static enum PageType {
108 /** The node manager page. */
111 /** The project page. */
114 /** The project files page. */
117 /** The project insert page. */
120 /** The preferences page. */
125 /** The supported locales. */
126 private static final Locale[] SUPPORTED_LOCALES = new Locale[] {
135 /** The actions that switch the language. */
136 private Map<Locale, Action> languageActions = new HashMap<Locale, Action>();
138 /** The “manage nodes” action. */
139 private Action manageNodeAction;
141 /** The “preferences” action. */
142 private Action optionsPreferencesAction;
144 /** The “check for updates” action. */
145 private Action checkForUpdatesAction;
147 /** The “about jSite” action. */
148 private Action aboutAction;
151 private TWizard wizard;
153 /** The node menu. */
154 private JMenu nodeMenu;
156 /** The currently selected node. */
157 private Node selectedNode;
159 /** Mapping from page type to page. */
160 private final Map<PageType, TWizardPage> pages = new HashMap<PageType, TWizardPage>();
162 /** The original location of the configuration file. */
163 private ConfigurationLocation originalLocation;
166 * Creates a new core with the default configuration file.
173 * Creates a new core with the given configuration from the given file.
175 * @param configFilename
176 * The name of the configuration file
178 private Main(String configFilename) {
179 /* collect all possible configuration file locations. */
180 ConfigurationLocator configurationLocator = new ConfigurationLocator();
181 if (configFilename != null) {
182 configurationLocator.setCustomLocation(configFilename);
185 originalLocation = configurationLocator.findPreferredLocation();
186 logger.log(Level.CONFIG, "Using configuration from " + originalLocation + ".");
187 configuration = new Configuration(configurationLocator, originalLocation);
189 Locale.setDefault(configuration.getLocale());
190 I18n.setLocale(configuration.getLocale());
191 wizard = new TWizard();
193 wizard.setJMenuBar(createMenuBar());
194 wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
195 wizard.setPreviousEnabled(false);
196 wizard.setNextEnabled(true);
197 wizard.addWizardListener(this);
198 jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
199 wizard.setIcon(jSiteIcon);
201 updateChecker = new UpdateChecker(freenetInterface, getVersion());
202 updateChecker.addUpdateListener(this);
203 updateChecker.start();
205 webOfTrustInterface = new WebOfTrustInterface(freenetInterface);
208 showPage(PageType.PAGE_PROJECTS);
212 * Creates all actions.
214 private void createActions() {
215 for (final Locale locale : SUPPORTED_LOCALES) {
216 languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
219 @SuppressWarnings("synthetic-access")
220 public void actionPerformed(ActionEvent actionEvent) {
221 switchLanguage(locale);
225 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
228 @SuppressWarnings("synthetic-access")
229 public void actionPerformed(ActionEvent actionEvent) {
230 showPage(PageType.PAGE_NODE_MANAGER);
231 optionsPreferencesAction.setEnabled(true);
232 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
233 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
236 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
242 @SuppressWarnings("synthetic-access")
243 public void actionPerformed(ActionEvent actionEvent) {
244 optionsPreferences();
247 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
253 @SuppressWarnings("synthetic-access")
254 public void actionPerformed(ActionEvent actionEvent) {
258 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
261 @SuppressWarnings("synthetic-access")
262 public void actionPerformed(ActionEvent e) {
263 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
267 I18nContainer.getInstance().registerRunnable(new Runnable() {
270 @SuppressWarnings("synthetic-access")
272 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
273 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
274 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
275 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
281 * Creates the menu bar.
283 * @return The menu bar
285 private JMenuBar createMenuBar() {
286 JMenuBar menuBar = new JMenuBar();
287 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
288 menuBar.add(languageMenu);
289 ButtonGroup languageButtonGroup = new ButtonGroup();
290 for (Locale locale : SUPPORTED_LOCALES) {
291 Action languageAction = languageActions.get(locale);
292 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
293 if (locale.equals(Locale.getDefault())) {
294 menuItem.setSelected(true);
296 languageAction.putValue("menuItem", menuItem);
297 languageButtonGroup.add(menuItem);
298 languageMenu.add(menuItem);
300 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
301 menuBar.add(nodeMenu);
302 selectedNode = configuration.getSelectedNode();
303 nodesUpdated(configuration.getNodes());
305 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
306 menuBar.add(optionsMenu);
307 optionsMenu.add(optionsPreferencesAction);
309 /* evil hack to right-align the help menu */
310 JPanel panel = new JPanel();
311 panel.setOpaque(false);
314 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
315 menuBar.add(helpMenu);
316 helpMenu.add(checkForUpdatesAction);
317 helpMenu.add(aboutAction);
319 I18nContainer.getInstance().registerRunnable(new Runnable() {
322 @SuppressWarnings("synthetic-access")
324 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
325 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
326 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
327 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
328 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
329 languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
338 * Initializes all pages.
340 private void initPages() {
341 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
342 nodeManagerPage.setName("page.node-manager");
343 nodeManagerPage.addNodeManagerListener(this);
344 nodeManagerPage.setNodes(configuration.getNodes());
345 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
347 ProjectPage projectPage = new ProjectPage(wizard);
348 projectPage.setName("page.project");
349 projectPage.setProjects(configuration.getProjects());
350 projectPage.setFreenetInterface(freenetInterface);
351 projectPage.setWebOfTrustInterface(webOfTrustInterface);
352 projectPage.addListSelectionListener(this);
353 pages.put(PageType.PAGE_PROJECTS, projectPage);
355 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
356 projectFilesPage.setName("page.project.files");
357 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
359 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
360 projectInsertPage.setName("page.project.insert");
361 projectInsertPage.setFreenetInterface(freenetInterface);
362 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
364 PreferencesPage preferencesPage = new PreferencesPage(wizard);
365 preferencesPage.setName("page.preferences");
366 preferencesPage.setTempDirectory(configuration.getTempDirectory());
367 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
371 * Shows the page with the given type.
374 * The page type to show
376 private void showPage(PageType pageType) {
377 wizard.setPreviousEnabled(pageType.ordinal() > 0);
378 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
379 wizard.setPage(pages.get(pageType));
380 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
384 * Returns whether a configuration file would be overwritten when calling
385 * {@link #saveConfiguration()}.
387 * @return {@code true} if {@link #saveConfiguration()} would overwrite an
388 * existing file, {@code false} otherwise
390 private boolean isOverwritingConfiguration() {
391 return configuration.getConfigurationLocator().hasFile(configuration.getConfigurationDirectory());
395 * Saves the configuration.
397 * @return <code>true</code> if the configuration could be saved,
398 * <code>false</code> otherwise
400 private boolean saveConfiguration() {
401 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
402 configuration.setNodes(nodeManagerPage.getNodes());
403 if (selectedNode != null) {
404 configuration.setSelectedNode(selectedNode);
407 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
408 configuration.setProjects(projectPage.getProjects());
410 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
411 configuration.setTempDirectory(preferencesPage.getTempDirectory());
413 return configuration.save();
417 * Finds a supported locale for the given locale.
420 * The locale to find a supported locale for
421 * @return The supported locale that was found, or the default locale if no
422 * supported locale could be found
424 private static Locale findSupportedLocale(Locale forLocale) {
425 for (Locale locale : SUPPORTED_LOCALES) {
426 if (locale.equals(forLocale)) {
430 for (Locale locale : SUPPORTED_LOCALES) {
431 if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
435 for (Locale locale : SUPPORTED_LOCALES) {
436 if (locale.getLanguage().equals(forLocale.getLanguage())) {
440 return SUPPORTED_LOCALES[0];
444 * Returns the version.
446 * @return The version
448 public static final Version getVersion() {
457 * Switches the language of the interface to the given locale.
460 * The locale to switch to
462 private void switchLanguage(Locale locale) {
463 Locale supportedLocale = findSupportedLocale(locale);
464 Action languageAction = languageActions.get(supportedLocale);
465 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
466 menuItem.setSelected(true);
467 I18n.setLocale(supportedLocale);
468 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
471 } catch (Throwable t) {
472 /* we probably shouldn't swallow this. */
475 wizard.setPage(wizard.getPage());
476 configuration.setLocale(supportedLocale);
480 * Shows a dialog with general preferences.
482 private void optionsPreferences() {
483 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationLocation(configuration.getConfigurationDirectory());
484 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasNextToJarConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.NEXT_TO_JAR_FILE));
485 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
486 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode());
487 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority());
488 showPage(PageType.PAGE_PREFERENCES);
489 optionsPreferencesAction.setEnabled(false);
490 wizard.setNextEnabled(true);
491 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
495 * Shows a dialog box that shows the last version that was found by the
496 * {@link UpdateChecker}.
498 private void showLatestUpdate() {
499 Version latestVersion = updateChecker.getLatestVersion();
500 int versionDifference = latestVersion.compareTo(VERSION);
501 if (versionDifference > 0) {
502 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);
503 } else if (versionDifference < 0) {
504 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);
506 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);
511 * Quits jSite, stopping all background services.
513 private void quit() {
514 updateChecker.stop();
519 // INTERFACE ListSelectionListener
526 public void valueChanged(ListSelectionEvent e) {
527 JList list = (JList) e.getSource();
528 int selectedRow = list.getSelectedIndex();
529 wizard.setNextEnabled(selectedRow > -1);
533 // INTERFACE WizardListener
540 public void wizardNextPressed(TWizard wizard) {
541 String pageName = wizard.getPage().getName();
542 if ("page.node-manager".equals(pageName)) {
543 showPage(PageType.PAGE_PROJECTS);
544 } else if ("page.project".equals(pageName)) {
545 ProjectPage projectPage = (ProjectPage) wizard.getPage();
546 Project project = projectPage.getSelectedProject();
547 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
548 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
551 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
552 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
555 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
556 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
557 showPage(PageType.PAGE_PROJECT_FILES);
558 } else if ("page.project.files".equals(pageName)) {
559 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
560 Project project = projectPage.getSelectedProject();
561 if (selectedNode == null) {
562 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
565 CheckReport checkReport = ProjectValidator.validateProject(project);
566 for (Issue issue : checkReport) {
567 if (issue.isFatal()) {
568 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
571 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) {
575 boolean nodeRunning = false;
577 nodeRunning = freenetInterface.isNodePresent();
578 } catch (IOException e) {
582 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
585 configuration.save();
586 showPage(PageType.PAGE_INSERT_PROJECT);
587 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
588 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
589 projectInsertPage.setTempDirectory(tempDirectory);
590 projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
591 projectInsertPage.setPriority(configuration.getPriority());
592 projectInsertPage.startInsert();
593 nodeMenu.setEnabled(false);
594 optionsPreferencesAction.setEnabled(false);
595 } else if ("page.project.insert".equals(pageName)) {
596 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
597 if (projectInsertPage.isRunning()) {
598 projectInsertPage.stopInsert();
600 showPage(PageType.PAGE_PROJECTS);
601 nodeMenu.setEnabled(true);
602 optionsPreferencesAction.setEnabled(true);
604 } else if ("page.preferences".equals(pageName)) {
605 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
606 showPage(PageType.PAGE_PROJECTS);
607 optionsPreferencesAction.setEnabled(true);
608 configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode());
609 configuration.setPriority(preferencesPage.getPriority());
610 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
618 public void wizardPreviousPressed(TWizard wizard) {
619 String pageName = wizard.getPage().getName();
620 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
621 showPage(PageType.PAGE_NODE_MANAGER);
622 optionsPreferencesAction.setEnabled(true);
623 } else if ("page.project.files".equals(pageName)) {
624 showPage(PageType.PAGE_PROJECTS);
625 } else if ("page.project.insert".equals(pageName)) {
626 showPage(PageType.PAGE_PROJECT_FILES);
634 public void wizardQuitPressed(TWizard wizard) {
635 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
636 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
638 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) {
639 if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
640 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);
641 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
642 if (saveConfiguration()) {
645 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
648 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
652 if (saveConfiguration()) {
656 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
663 // INTERFACE NodeManagerListener
670 public void nodesUpdated(Node[] nodes) {
671 nodeMenu.removeAll();
672 ButtonGroup nodeButtonGroup = new ButtonGroup();
673 Node newSelectedNode = null;
674 for (Node node : nodes) {
675 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
676 nodeMenuItem.putClientProperty("Node", node);
677 nodeMenuItem.addActionListener(this);
678 nodeButtonGroup.add(nodeMenuItem);
679 if (node.equals(selectedNode)) {
680 newSelectedNode = node;
681 nodeMenuItem.setSelected(true);
683 nodeMenu.add(nodeMenuItem);
685 nodeMenu.addSeparator();
686 nodeMenu.add(manageNodeAction);
687 selectedNode = newSelectedNode;
688 freenetInterface.setNode(selectedNode);
695 public void nodeSelected(Node node) {
696 for (Component menuItem : nodeMenu.getMenuComponents()) {
697 if (menuItem instanceof JMenuItem) {
698 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
699 ((JMenuItem) menuItem).setSelected(true);
703 freenetInterface.setNode(node);
708 // INTERFACE ActionListener
715 public void actionPerformed(ActionEvent e) {
716 Object source = e.getSource();
717 if (source instanceof JRadioButtonMenuItem) {
718 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
719 Node node = (Node) menuItem.getClientProperty("Node");
721 freenetInterface.setNode(selectedNode);
726 // INTERFACE UpdateListener
733 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
734 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
735 if (foundVersion.compareTo(VERSION) > 0) {
736 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);
745 * Main method that is called by the VM.
748 * The command-line arguments
750 public static void main(String[] args) {
751 /* initialize logger. */
752 Logger logger = Logger.getLogger("de.todesbaum");
753 Handler handler = new ConsoleHandler();
754 logger.addHandler(handler);
755 String configFilename = null;
756 boolean nextIsConfigFilename = false;
757 for (String argument : args) {
758 if (nextIsConfigFilename) {
759 configFilename = argument;
760 nextIsConfigFilename = false;
762 if ("--help".equals(argument)) {
765 } else if ("--debug".equals(argument)) {
766 logger.setLevel(Level.ALL);
767 handler.setLevel(Level.ALL);
768 } else if ("--config-file".equals(argument)) {
769 nextIsConfigFilename = true;
772 if (nextIsConfigFilename) {
773 System.out.println("--config-file needs parameter!");
776 new Main(configFilename);
780 * Prints a small syntax help.
782 private static void printHelp() {
783 System.out.println("--help\tshows this cruft");
784 System.out.println("--debug\tenables some debug output");
785 System.out.println("--config-file <file>\tuse specified configuration file");