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.jsite.main.JarFileLocator.DefaultJarFileLocator;
70 import de.todesbaum.util.swing.TWizard;
71 import de.todesbaum.util.swing.TWizardPage;
72 import de.todesbaum.util.swing.WizardListener;
75 * The main class that ties together everything.
77 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
79 public class Main implements ActionListener, ListSelectionListener, WizardListener, NodeManagerListener, UpdateListener {
82 private static final Logger logger = Logger.getLogger(Main.class.getName());
85 private static final Version VERSION = new Version(0, 13);
87 /** The configuration. */
88 private Configuration configuration;
90 /** The freenet interface. */
91 private Freenet7Interface freenetInterface = new Freenet7Interface();
93 /** The update checker. */
94 private final UpdateChecker updateChecker;
96 /** The web of trust interface. */
97 private final WebOfTrustInterface webOfTrustInterface;
99 /** The jSite icon. */
100 private Icon jSiteIcon;
103 * Enumeration for all possible pages.
105 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
107 private static enum PageType {
109 /** The node manager page. */
112 /** The project page. */
115 /** The project files page. */
118 /** The project insert page. */
121 /** The preferences page. */
126 /** The supported locales. */
127 private static final Locale[] SUPPORTED_LOCALES = new Locale[] {
136 /** The actions that switch the language. */
137 private Map<Locale, Action> languageActions = new HashMap<Locale, Action>();
139 /** The “manage nodes” action. */
140 private Action manageNodeAction;
142 /** The “preferences” action. */
143 private Action optionsPreferencesAction;
145 /** The “check for updates” action. */
146 private Action checkForUpdatesAction;
148 /** The “about jSite” action. */
149 private Action aboutAction;
152 private TWizard wizard;
154 /** The node menu. */
155 private JMenu nodeMenu;
157 /** The currently selected node. */
158 private Node selectedNode;
160 /** Mapping from page type to page. */
161 private final Map<PageType, TWizardPage> pages = new HashMap<PageType, TWizardPage>();
163 /** The original location of the configuration file. */
164 private ConfigurationLocation originalLocation;
167 * Creates a new core with the default configuration file.
174 * Creates a new core with the given configuration from the given file.
176 * @param configFilename
177 * The name of the configuration file
179 private Main(String configFilename) {
180 /* collect all possible configuration file locations. */
181 ConfigurationLocator configurationLocator = new ConfigurationLocator(new DefaultJarFileLocator(getClass().getClassLoader()));
182 if (configFilename != null) {
183 configurationLocator.setCustomLocation(configFilename);
186 originalLocation = configurationLocator.findPreferredLocation();
187 logger.log(Level.CONFIG, "Using configuration from " + originalLocation + ".");
188 configuration = new Configuration(configurationLocator, originalLocation);
190 Locale.setDefault(configuration.getLocale());
191 I18n.setLocale(configuration.getLocale());
192 wizard = new TWizard();
194 wizard.setJMenuBar(createMenuBar());
195 wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
196 wizard.setPreviousEnabled(false);
197 wizard.setNextEnabled(true);
198 wizard.addWizardListener(this);
199 jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
200 wizard.setIcon(jSiteIcon);
202 updateChecker = new UpdateChecker(freenetInterface, getVersion());
203 updateChecker.addUpdateListener(this);
204 updateChecker.start();
206 webOfTrustInterface = new WebOfTrustInterface(freenetInterface);
209 showPage(PageType.PAGE_PROJECTS);
213 * Creates all actions.
215 private void createActions() {
216 for (final Locale locale : SUPPORTED_LOCALES) {
217 languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
220 @SuppressWarnings("synthetic-access")
221 public void actionPerformed(ActionEvent actionEvent) {
222 switchLanguage(locale);
226 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
229 @SuppressWarnings("synthetic-access")
230 public void actionPerformed(ActionEvent actionEvent) {
231 showPage(PageType.PAGE_NODE_MANAGER);
232 optionsPreferencesAction.setEnabled(true);
233 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
234 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
237 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
243 @SuppressWarnings("synthetic-access")
244 public void actionPerformed(ActionEvent actionEvent) {
245 optionsPreferences();
248 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
254 @SuppressWarnings("synthetic-access")
255 public void actionPerformed(ActionEvent actionEvent) {
259 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
262 @SuppressWarnings("synthetic-access")
263 public void actionPerformed(ActionEvent e) {
264 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
268 I18nContainer.getInstance().registerRunnable(new Runnable() {
271 @SuppressWarnings("synthetic-access")
273 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
274 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
275 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
276 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
282 * Creates the menu bar.
284 * @return The menu bar
286 private JMenuBar createMenuBar() {
287 JMenuBar menuBar = new JMenuBar();
288 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
289 menuBar.add(languageMenu);
290 ButtonGroup languageButtonGroup = new ButtonGroup();
291 for (Locale locale : SUPPORTED_LOCALES) {
292 Action languageAction = languageActions.get(locale);
293 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
294 if (locale.equals(Locale.getDefault())) {
295 menuItem.setSelected(true);
297 languageAction.putValue("menuItem", menuItem);
298 languageButtonGroup.add(menuItem);
299 languageMenu.add(menuItem);
301 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
302 menuBar.add(nodeMenu);
303 selectedNode = configuration.getSelectedNode();
304 nodesUpdated(configuration.getNodes());
306 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
307 menuBar.add(optionsMenu);
308 optionsMenu.add(optionsPreferencesAction);
310 /* evil hack to right-align the help menu */
311 JPanel panel = new JPanel();
312 panel.setOpaque(false);
315 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
316 menuBar.add(helpMenu);
317 helpMenu.add(checkForUpdatesAction);
318 helpMenu.add(aboutAction);
320 I18nContainer.getInstance().registerRunnable(new Runnable() {
323 @SuppressWarnings("synthetic-access")
325 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
326 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
327 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
328 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
329 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
330 languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
339 * Initializes all pages.
341 private void initPages() {
342 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
343 nodeManagerPage.setName("page.node-manager");
344 nodeManagerPage.addNodeManagerListener(this);
345 nodeManagerPage.setNodes(configuration.getNodes());
346 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
348 ProjectPage projectPage = new ProjectPage(wizard);
349 projectPage.setName("page.project");
350 projectPage.setProjects(configuration.getProjects());
351 projectPage.setFreenetInterface(freenetInterface);
352 projectPage.setWebOfTrustInterface(webOfTrustInterface);
353 projectPage.addListSelectionListener(this);
354 pages.put(PageType.PAGE_PROJECTS, projectPage);
356 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
357 projectFilesPage.setName("page.project.files");
358 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
360 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
361 projectInsertPage.setName("page.project.insert");
362 projectInsertPage.setFreenetInterface(freenetInterface);
363 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
365 PreferencesPage preferencesPage = new PreferencesPage(wizard);
366 preferencesPage.setName("page.preferences");
367 preferencesPage.setTempDirectory(configuration.getTempDirectory());
368 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
372 * Shows the page with the given type.
375 * The page type to show
377 private void showPage(PageType pageType) {
378 wizard.setPreviousEnabled(pageType.ordinal() > 0);
379 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
380 wizard.setPage(pages.get(pageType));
381 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
385 * Returns whether a configuration file would be overwritten when calling
386 * {@link #saveConfiguration()}.
388 * @return {@code true} if {@link #saveConfiguration()} would overwrite an
389 * existing file, {@code false} otherwise
391 private boolean isOverwritingConfiguration() {
392 return configuration.getConfigurationLocator().hasFile(configuration.getConfigurationDirectory());
396 * Saves the configuration.
398 * @return <code>true</code> if the configuration could be saved,
399 * <code>false</code> otherwise
401 private boolean saveConfiguration() {
402 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
403 configuration.setNodes(nodeManagerPage.getNodes());
404 if (selectedNode != null) {
405 configuration.setSelectedNode(selectedNode);
408 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
409 configuration.setProjects(projectPage.getProjects());
411 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
412 configuration.setTempDirectory(preferencesPage.getTempDirectory());
414 return configuration.save();
418 * Finds a supported locale for the given locale.
421 * The locale to find a supported locale for
422 * @return The supported locale that was found, or the default locale if no
423 * supported locale could be found
425 private static Locale findSupportedLocale(Locale forLocale) {
426 for (Locale locale : SUPPORTED_LOCALES) {
427 if (locale.equals(forLocale)) {
431 for (Locale locale : SUPPORTED_LOCALES) {
432 if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
436 for (Locale locale : SUPPORTED_LOCALES) {
437 if (locale.getLanguage().equals(forLocale.getLanguage())) {
441 return SUPPORTED_LOCALES[0];
445 * Returns the version.
447 * @return The version
449 public static final Version getVersion() {
458 * Switches the language of the interface to the given locale.
461 * The locale to switch to
463 private void switchLanguage(Locale locale) {
464 Locale supportedLocale = findSupportedLocale(locale);
465 Action languageAction = languageActions.get(supportedLocale);
466 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
467 menuItem.setSelected(true);
468 I18n.setLocale(supportedLocale);
469 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
472 } catch (Throwable t) {
473 /* we probably shouldn't swallow this. */
476 wizard.setPage(wizard.getPage());
477 configuration.setLocale(supportedLocale);
481 * Shows a dialog with general preferences.
483 private void optionsPreferences() {
484 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationLocation(configuration.getConfigurationDirectory());
485 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasNextToJarConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.NEXT_TO_JAR_FILE));
486 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
487 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode());
488 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority());
489 showPage(PageType.PAGE_PREFERENCES);
490 optionsPreferencesAction.setEnabled(false);
491 wizard.setNextEnabled(true);
492 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
496 * Shows a dialog box that shows the last version that was found by the
497 * {@link UpdateChecker}.
499 private void showLatestUpdate() {
500 Version latestVersion = updateChecker.getLatestVersion();
501 int versionDifference = latestVersion.compareTo(VERSION);
502 if (versionDifference > 0) {
503 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);
504 } else if (versionDifference < 0) {
505 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);
507 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);
512 * Quits jSite, stopping all background services.
514 private void quit() {
515 updateChecker.stop();
520 // INTERFACE ListSelectionListener
527 public void valueChanged(ListSelectionEvent e) {
528 JList list = (JList) e.getSource();
529 int selectedRow = list.getSelectedIndex();
530 wizard.setNextEnabled(selectedRow > -1);
534 // INTERFACE WizardListener
541 public void wizardNextPressed(TWizard wizard) {
542 String pageName = wizard.getPage().getName();
543 if ("page.node-manager".equals(pageName)) {
544 showPage(PageType.PAGE_PROJECTS);
545 } else if ("page.project".equals(pageName)) {
546 ProjectPage projectPage = (ProjectPage) wizard.getPage();
547 Project project = projectPage.getSelectedProject();
548 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
549 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
552 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
553 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
556 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
557 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
558 showPage(PageType.PAGE_PROJECT_FILES);
559 } else if ("page.project.files".equals(pageName)) {
560 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
561 Project project = projectPage.getSelectedProject();
562 if (selectedNode == null) {
563 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
566 CheckReport checkReport = ProjectValidator.validateProject(project);
567 for (Issue issue : checkReport) {
568 if (issue.isFatal()) {
569 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
572 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) {
576 boolean nodeRunning = false;
578 nodeRunning = freenetInterface.isNodePresent();
579 } catch (IOException e) {
583 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
586 configuration.save();
587 showPage(PageType.PAGE_INSERT_PROJECT);
588 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
589 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
590 projectInsertPage.setTempDirectory(tempDirectory);
591 projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
592 projectInsertPage.setPriority(configuration.getPriority());
593 projectInsertPage.startInsert();
594 nodeMenu.setEnabled(false);
595 optionsPreferencesAction.setEnabled(false);
596 } else if ("page.project.insert".equals(pageName)) {
597 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
598 if (projectInsertPage.isRunning()) {
599 projectInsertPage.stopInsert();
601 showPage(PageType.PAGE_PROJECTS);
602 nodeMenu.setEnabled(true);
603 optionsPreferencesAction.setEnabled(true);
605 } else if ("page.preferences".equals(pageName)) {
606 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
607 showPage(PageType.PAGE_PROJECTS);
608 optionsPreferencesAction.setEnabled(true);
609 configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode());
610 configuration.setPriority(preferencesPage.getPriority());
611 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
619 public void wizardPreviousPressed(TWizard wizard) {
620 String pageName = wizard.getPage().getName();
621 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
622 showPage(PageType.PAGE_NODE_MANAGER);
623 optionsPreferencesAction.setEnabled(true);
624 } else if ("page.project.files".equals(pageName)) {
625 showPage(PageType.PAGE_PROJECTS);
626 } else if ("page.project.insert".equals(pageName)) {
627 showPage(PageType.PAGE_PROJECT_FILES);
635 public void wizardQuitPressed(TWizard wizard) {
636 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
637 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
639 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) {
640 if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
641 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);
642 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
643 if (saveConfiguration()) {
646 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
649 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
653 if (saveConfiguration()) {
657 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
664 // INTERFACE NodeManagerListener
671 public void nodesUpdated(Node[] nodes) {
672 nodeMenu.removeAll();
673 ButtonGroup nodeButtonGroup = new ButtonGroup();
674 Node newSelectedNode = null;
675 for (Node node : nodes) {
676 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
677 nodeMenuItem.putClientProperty("Node", node);
678 nodeMenuItem.addActionListener(this);
679 nodeButtonGroup.add(nodeMenuItem);
680 if (node.equals(selectedNode)) {
681 newSelectedNode = node;
682 nodeMenuItem.setSelected(true);
684 nodeMenu.add(nodeMenuItem);
686 nodeMenu.addSeparator();
687 nodeMenu.add(manageNodeAction);
688 selectedNode = newSelectedNode;
689 freenetInterface.setNode(selectedNode);
696 public void nodeSelected(Node node) {
697 for (Component menuItem : nodeMenu.getMenuComponents()) {
698 if (menuItem instanceof JMenuItem) {
699 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
700 ((JMenuItem) menuItem).setSelected(true);
704 freenetInterface.setNode(node);
709 // INTERFACE ActionListener
716 public void actionPerformed(ActionEvent e) {
717 Object source = e.getSource();
718 if (source instanceof JRadioButtonMenuItem) {
719 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
720 Node node = (Node) menuItem.getClientProperty("Node");
722 freenetInterface.setNode(selectedNode);
727 // INTERFACE UpdateListener
734 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
735 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
736 if (foundVersion.compareTo(VERSION) > 0) {
737 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);
746 * Main method that is called by the VM.
749 * The command-line arguments
751 public static void main(String[] args) {
752 /* initialize logger. */
753 Logger logger = Logger.getLogger("de.todesbaum");
754 Handler handler = new ConsoleHandler();
755 logger.addHandler(handler);
756 String configFilename = null;
757 boolean nextIsConfigFilename = false;
758 for (String argument : args) {
759 if (nextIsConfigFilename) {
760 configFilename = argument;
761 nextIsConfigFilename = false;
763 if ("--help".equals(argument)) {
766 } else if ("--debug".equals(argument)) {
767 logger.setLevel(Level.ALL);
768 handler.setLevel(Level.ALL);
769 } else if ("--config-file".equals(argument)) {
770 nextIsConfigFilename = true;
773 if (nextIsConfigFilename) {
774 System.out.println("--config-file needs parameter!");
777 new Main(configFilename);
781 * Prints a small syntax help.
783 private static void printHelp() {
784 System.out.println("--help\tshows this cruft");
785 System.out.println("--debug\tenables some debug output");
786 System.out.println("--config-file <file>\tuse specified configuration file");