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;
50 import de.todesbaum.jsite.application.Freenet7Interface;
51 import de.todesbaum.jsite.application.Node;
52 import de.todesbaum.jsite.application.Project;
53 import de.todesbaum.jsite.application.ProjectInserter;
54 import de.todesbaum.jsite.application.ProjectInserter.CheckReport;
55 import de.todesbaum.jsite.application.ProjectInserter.Issue;
56 import de.todesbaum.jsite.application.UpdateChecker;
57 import de.todesbaum.jsite.application.UpdateListener;
58 import de.todesbaum.jsite.application.WebOfTrustInterface;
59 import de.todesbaum.jsite.gui.NodeManagerListener;
60 import de.todesbaum.jsite.gui.NodeManagerPage;
61 import de.todesbaum.jsite.gui.PreferencesPage;
62 import de.todesbaum.jsite.gui.ProjectFilesPage;
63 import de.todesbaum.jsite.gui.ProjectInsertPage;
64 import de.todesbaum.jsite.gui.ProjectPage;
65 import de.todesbaum.jsite.i18n.I18n;
66 import de.todesbaum.jsite.i18n.I18nContainer;
67 import de.todesbaum.jsite.main.ConfigurationLocator.ConfigurationLocation;
68 import de.todesbaum.util.swing.TWizard;
69 import de.todesbaum.util.swing.TWizardPage;
70 import de.todesbaum.util.swing.WizardListener;
73 * The main class that ties together everything.
75 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
77 public class Main implements ActionListener, ListSelectionListener, WizardListener, NodeManagerListener, UpdateListener {
80 private static final Logger logger = Logger.getLogger(Main.class.getName());
83 private static final Version VERSION = new Version(0, 13);
85 /** The configuration. */
86 private Configuration configuration;
88 /** The freenet interface. */
89 private Freenet7Interface freenetInterface = new Freenet7Interface();
91 /** The update checker. */
92 private final UpdateChecker updateChecker;
94 /** The web of trust interface. */
95 private final WebOfTrustInterface webOfTrustInterface;
97 /** The jSite icon. */
98 private Icon jSiteIcon;
101 * Enumeration for all possible pages.
103 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
105 private static enum PageType {
107 /** The node manager page. */
110 /** The project page. */
113 /** The project files page. */
116 /** The project insert page. */
119 /** The preferences page. */
124 /** The supported locales. */
125 private static final Locale[] SUPPORTED_LOCALES = new Locale[] {
134 /** The actions that switch the language. */
135 private Map<Locale, Action> languageActions = new HashMap<Locale, Action>();
137 /** The “manage nodes” action. */
138 private Action manageNodeAction;
140 /** The “preferences” action. */
141 private Action optionsPreferencesAction;
143 /** The “check for updates” action. */
144 private Action checkForUpdatesAction;
146 /** The “about jSite” action. */
147 private Action aboutAction;
150 private TWizard wizard;
152 /** The node menu. */
153 private JMenu nodeMenu;
155 /** The currently selected node. */
156 private Node selectedNode;
158 /** Mapping from page type to page. */
159 private final Map<PageType, TWizardPage> pages = new HashMap<PageType, TWizardPage>();
161 /** The original location of the configuration file. */
162 private ConfigurationLocation originalLocation;
165 * Creates a new core with the default configuration file.
172 * Creates a new core with the given configuration from the given file.
174 * @param configFilename
175 * The name of the configuration file
177 private Main(String configFilename) {
178 /* collect all possible configuration file locations. */
179 ConfigurationLocator configurationLocator = new ConfigurationLocator();
180 if (configFilename != null) {
181 configurationLocator.setCustomLocation(configFilename);
184 originalLocation = configurationLocator.findPreferredLocation();
185 logger.log(Level.CONFIG, "Using configuration from " + originalLocation + ".");
186 configuration = new Configuration(configurationLocator, originalLocation);
188 Locale.setDefault(configuration.getLocale());
189 I18n.setLocale(configuration.getLocale());
190 wizard = new TWizard();
192 wizard.setJMenuBar(createMenuBar());
193 wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
194 wizard.setPreviousEnabled(false);
195 wizard.setNextEnabled(true);
196 wizard.addWizardListener(this);
197 jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
198 wizard.setIcon(jSiteIcon);
200 updateChecker = new UpdateChecker(freenetInterface, getVersion());
201 updateChecker.addUpdateListener(this);
202 updateChecker.start();
204 webOfTrustInterface = new WebOfTrustInterface(freenetInterface);
207 showPage(PageType.PAGE_PROJECTS);
211 * Creates all actions.
213 private void createActions() {
214 for (final Locale locale : SUPPORTED_LOCALES) {
215 languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
218 @SuppressWarnings("synthetic-access")
219 public void actionPerformed(ActionEvent actionEvent) {
220 switchLanguage(locale);
224 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
227 @SuppressWarnings("synthetic-access")
228 public void actionPerformed(ActionEvent actionEvent) {
229 showPage(PageType.PAGE_NODE_MANAGER);
230 optionsPreferencesAction.setEnabled(true);
231 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
232 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
235 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
241 @SuppressWarnings("synthetic-access")
242 public void actionPerformed(ActionEvent actionEvent) {
243 optionsPreferences();
246 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
252 @SuppressWarnings("synthetic-access")
253 public void actionPerformed(ActionEvent actionEvent) {
257 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
260 @SuppressWarnings("synthetic-access")
261 public void actionPerformed(ActionEvent e) {
262 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
266 I18nContainer.getInstance().registerRunnable(new Runnable() {
269 @SuppressWarnings("synthetic-access")
271 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
272 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
273 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
274 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
280 * Creates the menu bar.
282 * @return The menu bar
284 private JMenuBar createMenuBar() {
285 JMenuBar menuBar = new JMenuBar();
286 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
287 menuBar.add(languageMenu);
288 ButtonGroup languageButtonGroup = new ButtonGroup();
289 for (Locale locale : SUPPORTED_LOCALES) {
290 Action languageAction = languageActions.get(locale);
291 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
292 if (locale.equals(Locale.getDefault())) {
293 menuItem.setSelected(true);
295 languageAction.putValue("menuItem", menuItem);
296 languageButtonGroup.add(menuItem);
297 languageMenu.add(menuItem);
299 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
300 menuBar.add(nodeMenu);
301 selectedNode = configuration.getSelectedNode();
302 nodesUpdated(configuration.getNodes());
304 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
305 menuBar.add(optionsMenu);
306 optionsMenu.add(optionsPreferencesAction);
308 /* evil hack to right-align the help menu */
309 JPanel panel = new JPanel();
310 panel.setOpaque(false);
313 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
314 menuBar.add(helpMenu);
315 helpMenu.add(checkForUpdatesAction);
316 helpMenu.add(aboutAction);
318 I18nContainer.getInstance().registerRunnable(new Runnable() {
321 @SuppressWarnings("synthetic-access")
323 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
324 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
325 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
326 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
327 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
328 languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
337 * Initializes all pages.
339 private void initPages() {
340 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
341 nodeManagerPage.setName("page.node-manager");
342 nodeManagerPage.addNodeManagerListener(this);
343 nodeManagerPage.setNodes(configuration.getNodes());
344 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
346 ProjectPage projectPage = new ProjectPage(wizard);
347 projectPage.setName("page.project");
348 projectPage.setProjects(configuration.getProjects());
349 projectPage.setFreenetInterface(freenetInterface);
350 projectPage.setWebOfTrustInterface(webOfTrustInterface);
351 projectPage.addListSelectionListener(this);
352 pages.put(PageType.PAGE_PROJECTS, projectPage);
354 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
355 projectFilesPage.setName("page.project.files");
356 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
358 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
359 projectInsertPage.setName("page.project.insert");
360 projectInsertPage.setFreenetInterface(freenetInterface);
361 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
363 PreferencesPage preferencesPage = new PreferencesPage(wizard);
364 preferencesPage.setName("page.preferences");
365 preferencesPage.setTempDirectory(configuration.getTempDirectory());
366 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
370 * Shows the page with the given type.
373 * The page type to show
375 private void showPage(PageType pageType) {
376 wizard.setPreviousEnabled(pageType.ordinal() > 0);
377 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
378 wizard.setPage(pages.get(pageType));
379 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
383 * Returns whether a configuration file would be overwritten when calling
384 * {@link #saveConfiguration()}.
386 * @return {@code true} if {@link #saveConfiguration()} would overwrite an
387 * existing file, {@code false} otherwise
389 private boolean isOverwritingConfiguration() {
390 return configuration.getConfigurationLocator().hasFile(configuration.getConfigurationDirectory());
394 * Saves the configuration.
396 * @return <code>true</code> if the configuration could be saved,
397 * <code>false</code> otherwise
399 private boolean saveConfiguration() {
400 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
401 configuration.setNodes(nodeManagerPage.getNodes());
402 if (selectedNode != null) {
403 configuration.setSelectedNode(selectedNode);
406 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
407 configuration.setProjects(projectPage.getProjects());
409 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
410 configuration.setTempDirectory(preferencesPage.getTempDirectory());
412 return configuration.save();
416 * Finds a supported locale for the given locale.
419 * The locale to find a supported locale for
420 * @return The supported locale that was found, or the default locale if no
421 * supported locale could be found
423 private static Locale findSupportedLocale(Locale forLocale) {
424 for (Locale locale : SUPPORTED_LOCALES) {
425 if (locale.equals(forLocale)) {
429 for (Locale locale : SUPPORTED_LOCALES) {
430 if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
434 for (Locale locale : SUPPORTED_LOCALES) {
435 if (locale.getLanguage().equals(forLocale.getLanguage())) {
439 return SUPPORTED_LOCALES[0];
443 * Returns the version.
445 * @return The version
447 public static final Version getVersion() {
456 * Switches the language of the interface to the given locale.
459 * The locale to switch to
461 private void switchLanguage(Locale locale) {
462 Locale supportedLocale = findSupportedLocale(locale);
463 Action languageAction = languageActions.get(supportedLocale);
464 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
465 menuItem.setSelected(true);
466 I18n.setLocale(supportedLocale);
467 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
470 } catch (Throwable t) {
471 /* we probably shouldn't swallow this. */
474 wizard.setPage(wizard.getPage());
475 configuration.setLocale(supportedLocale);
479 * Shows a dialog with general preferences.
481 private void optionsPreferences() {
482 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationLocation(configuration.getConfigurationDirectory());
483 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasNextToJarConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.NEXT_TO_JAR_FILE));
484 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
485 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode());
486 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority());
487 showPage(PageType.PAGE_PREFERENCES);
488 optionsPreferencesAction.setEnabled(false);
489 wizard.setNextEnabled(true);
490 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
494 * Shows a dialog box that shows the last version that was found by the
495 * {@link UpdateChecker}.
497 private void showLatestUpdate() {
498 Version latestVersion = updateChecker.getLatestVersion();
499 int versionDifference = latestVersion.compareTo(VERSION);
500 if (versionDifference > 0) {
501 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);
502 } else if (versionDifference < 0) {
503 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);
505 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);
510 * Quits jSite, stopping all background services.
512 private void quit() {
513 updateChecker.stop();
518 // INTERFACE ListSelectionListener
525 public void valueChanged(ListSelectionEvent e) {
526 JList list = (JList) e.getSource();
527 int selectedRow = list.getSelectedIndex();
528 wizard.setNextEnabled(selectedRow > -1);
532 // INTERFACE WizardListener
539 public void wizardNextPressed(TWizard wizard) {
540 String pageName = wizard.getPage().getName();
541 if ("page.node-manager".equals(pageName)) {
542 showPage(PageType.PAGE_PROJECTS);
543 } else if ("page.project".equals(pageName)) {
544 ProjectPage projectPage = (ProjectPage) wizard.getPage();
545 Project project = projectPage.getSelectedProject();
546 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
547 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
550 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
551 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
554 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
555 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
556 showPage(PageType.PAGE_PROJECT_FILES);
557 } else if ("page.project.files".equals(pageName)) {
558 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
559 Project project = projectPage.getSelectedProject();
560 if (selectedNode == null) {
561 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
564 CheckReport checkReport = ProjectInserter.validateProject(project);
565 for (Issue issue : checkReport) {
566 if (issue.isFatal()) {
567 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
570 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) {
574 boolean nodeRunning = false;
576 nodeRunning = freenetInterface.isNodePresent();
577 } catch (IOException e) {
581 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
584 configuration.save();
585 showPage(PageType.PAGE_INSERT_PROJECT);
586 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
587 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
588 projectInsertPage.setTempDirectory(tempDirectory);
589 projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
590 projectInsertPage.setPriority(configuration.getPriority());
591 projectInsertPage.startInsert();
592 nodeMenu.setEnabled(false);
593 optionsPreferencesAction.setEnabled(false);
594 } else if ("page.project.insert".equals(pageName)) {
595 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
596 if (projectInsertPage.isRunning()) {
597 projectInsertPage.stopInsert();
599 showPage(PageType.PAGE_PROJECTS);
600 nodeMenu.setEnabled(true);
601 optionsPreferencesAction.setEnabled(true);
603 } else if ("page.preferences".equals(pageName)) {
604 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
605 showPage(PageType.PAGE_PROJECTS);
606 optionsPreferencesAction.setEnabled(true);
607 configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode());
608 configuration.setPriority(preferencesPage.getPriority());
609 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
617 public void wizardPreviousPressed(TWizard wizard) {
618 String pageName = wizard.getPage().getName();
619 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
620 showPage(PageType.PAGE_NODE_MANAGER);
621 optionsPreferencesAction.setEnabled(true);
622 } else if ("page.project.files".equals(pageName)) {
623 showPage(PageType.PAGE_PROJECTS);
624 } else if ("page.project.insert".equals(pageName)) {
625 showPage(PageType.PAGE_PROJECT_FILES);
633 public void wizardQuitPressed(TWizard wizard) {
634 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
635 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
637 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) {
638 if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
639 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);
640 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
641 if (saveConfiguration()) {
644 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
647 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
651 if (saveConfiguration()) {
655 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
662 // INTERFACE NodeManagerListener
669 public void nodesUpdated(Node[] nodes) {
670 nodeMenu.removeAll();
671 ButtonGroup nodeButtonGroup = new ButtonGroup();
672 Node newSelectedNode = null;
673 for (Node node : nodes) {
674 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
675 nodeMenuItem.putClientProperty("Node", node);
676 nodeMenuItem.addActionListener(this);
677 nodeButtonGroup.add(nodeMenuItem);
678 if (node.equals(selectedNode)) {
679 newSelectedNode = node;
680 nodeMenuItem.setSelected(true);
682 nodeMenu.add(nodeMenuItem);
684 nodeMenu.addSeparator();
685 nodeMenu.add(manageNodeAction);
686 selectedNode = newSelectedNode;
687 freenetInterface.setNode(selectedNode);
694 public void nodeSelected(Node node) {
695 for (Component menuItem : nodeMenu.getMenuComponents()) {
696 if (menuItem instanceof JMenuItem) {
697 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
698 ((JMenuItem) menuItem).setSelected(true);
702 freenetInterface.setNode(node);
707 // INTERFACE ActionListener
714 public void actionPerformed(ActionEvent e) {
715 Object source = e.getSource();
716 if (source instanceof JRadioButtonMenuItem) {
717 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
718 Node node = (Node) menuItem.getClientProperty("Node");
720 freenetInterface.setNode(selectedNode);
725 // INTERFACE UpdateListener
732 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
733 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
734 if (foundVersion.compareTo(VERSION) > 0) {
735 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);
744 * Main method that is called by the VM.
747 * The command-line arguments
749 public static void main(String[] args) {
750 /* initialize logger. */
751 Logger logger = Logger.getLogger("de.todesbaum");
752 Handler handler = new ConsoleHandler();
753 logger.addHandler(handler);
754 String configFilename = null;
755 boolean nextIsConfigFilename = false;
756 for (String argument : args) {
757 if (nextIsConfigFilename) {
758 configFilename = argument;
759 nextIsConfigFilename = false;
761 if ("--help".equals(argument)) {
764 } else if ("--debug".equals(argument)) {
765 logger.setLevel(Level.ALL);
766 handler.setLevel(Level.ALL);
767 } else if ("--config-file".equals(argument)) {
768 nextIsConfigFilename = true;
771 if (nextIsConfigFilename) {
772 System.out.println("--config-file needs parameter!");
775 new Main(configFilename);
779 * Prints a small syntax help.
781 private static void printHelp() {
782 System.out.println("--help\tshows this cruft");
783 System.out.println("--debug\tenables some debug output");
784 System.out.println("--config-file <file>\tuse specified configuration file");