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 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, 10);
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[] { Locale.ENGLISH, Locale.GERMAN, Locale.FRENCH };
127 /** The actions that switch the language. */
128 private Map<Locale, Action> languageActions = new HashMap<Locale, Action>();
130 /** The “manage nodes” action. */
131 private Action manageNodeAction;
133 /** The “preferences” action. */
134 private Action optionsPreferencesAction;
136 /** The “check for updates” action. */
137 private Action checkForUpdatesAction;
139 /** The “about jSite” action. */
140 private Action aboutAction;
143 private TWizard wizard;
145 /** The node menu. */
146 private JMenu nodeMenu;
148 /** The currently selected node. */
149 private Node selectedNode;
151 /** Mapping from page type to page. */
152 private final Map<PageType, TWizardPage> pages = new HashMap<PageType, TWizardPage>();
154 /** The original location of the configuration file. */
155 private ConfigurationLocation originalLocation;
158 * Creates a new core with the default configuration file.
165 * Creates a new core with the given configuration from the given file.
167 * @param configFilename
168 * The name of the configuration file
170 private Main(String configFilename) {
171 /* collect all possible configuration file locations. */
172 ConfigurationLocator configurationLocator = new ConfigurationLocator();
173 if (configFilename != null) {
174 configurationLocator.setCustomLocation(configFilename);
177 originalLocation = configurationLocator.findPreferredLocation();
178 logger.log(Level.CONFIG, "Using configuration from " + originalLocation + ".");
179 configuration = new Configuration(configurationLocator, originalLocation);
181 Locale.setDefault(configuration.getLocale());
182 I18n.setLocale(configuration.getLocale());
183 wizard = new TWizard();
185 wizard.setJMenuBar(createMenuBar());
186 wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
187 wizard.setPreviousEnabled(false);
188 wizard.setNextEnabled(true);
189 wizard.addWizardListener(this);
190 jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
191 wizard.setIcon(jSiteIcon);
193 updateChecker = new UpdateChecker(freenetInterface);
194 updateChecker.addUpdateListener(this);
195 updateChecker.start();
197 webOfTrustInterface = new WebOfTrustInterface(freenetInterface);
198 webOfTrustInterface.start();
201 showPage(PageType.PAGE_PROJECTS);
205 * Creates all actions.
207 private void createActions() {
208 for (final Locale locale : SUPPORTED_LOCALES) {
209 languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
212 @SuppressWarnings("synthetic-access")
213 public void actionPerformed(ActionEvent actionEvent) {
214 switchLanguage(locale);
218 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
221 @SuppressWarnings("synthetic-access")
222 public void actionPerformed(ActionEvent actionEvent) {
223 showPage(PageType.PAGE_NODE_MANAGER);
224 optionsPreferencesAction.setEnabled(true);
225 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
226 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
229 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
235 @SuppressWarnings("synthetic-access")
236 public void actionPerformed(ActionEvent actionEvent) {
237 optionsPreferences();
240 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
246 @SuppressWarnings("synthetic-access")
247 public void actionPerformed(ActionEvent actionEvent) {
251 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
254 @SuppressWarnings("synthetic-access")
255 public void actionPerformed(ActionEvent e) {
256 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
260 I18nContainer.getInstance().registerRunnable(new Runnable() {
263 @SuppressWarnings("synthetic-access")
265 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
266 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
267 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
268 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
274 * Creates the menu bar.
276 * @return The menu bar
278 private JMenuBar createMenuBar() {
279 JMenuBar menuBar = new JMenuBar();
280 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
281 menuBar.add(languageMenu);
282 ButtonGroup languageButtonGroup = new ButtonGroup();
283 for (Locale locale : SUPPORTED_LOCALES) {
284 Action languageAction = languageActions.get(locale);
285 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
286 if (locale.equals(Locale.getDefault())) {
287 menuItem.setSelected(true);
289 languageAction.putValue("menuItem", menuItem);
290 languageButtonGroup.add(menuItem);
291 languageMenu.add(menuItem);
293 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
294 menuBar.add(nodeMenu);
295 selectedNode = configuration.getSelectedNode();
296 nodesUpdated(configuration.getNodes());
298 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
299 menuBar.add(optionsMenu);
300 optionsMenu.add(optionsPreferencesAction);
302 /* evil hack to right-align the help menu */
303 JPanel panel = new JPanel();
304 panel.setOpaque(false);
307 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
308 menuBar.add(helpMenu);
309 helpMenu.add(checkForUpdatesAction);
310 helpMenu.add(aboutAction);
312 I18nContainer.getInstance().registerRunnable(new Runnable() {
315 @SuppressWarnings("synthetic-access")
317 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
318 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
319 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
320 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
321 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
322 languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
331 * Initializes all pages.
333 private void initPages() {
334 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
335 nodeManagerPage.setName("page.node-manager");
336 nodeManagerPage.addNodeManagerListener(this);
337 nodeManagerPage.setNodes(configuration.getNodes());
338 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
340 ProjectPage projectPage = new ProjectPage(wizard);
341 projectPage.setName("page.project");
342 projectPage.setProjects(configuration.getProjects());
343 projectPage.setFreenetInterface(freenetInterface);
344 projectPage.addListSelectionListener(this);
345 pages.put(PageType.PAGE_PROJECTS, projectPage);
347 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
348 projectFilesPage.setName("page.project.files");
349 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
351 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
352 projectInsertPage.setName("page.project.insert");
353 projectInsertPage.setFreenetInterface(freenetInterface);
354 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
356 PreferencesPage preferencesPage = new PreferencesPage(wizard);
357 preferencesPage.setName("page.preferences");
358 preferencesPage.setTempDirectory(configuration.getTempDirectory());
359 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
363 * Shows the page with the given type.
366 * The page type to show
368 private void showPage(PageType pageType) {
369 wizard.setPreviousEnabled(pageType.ordinal() > 0);
370 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
371 wizard.setPage(pages.get(pageType));
372 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
376 * Returns whether a configuration file would be overwritten when calling
377 * {@link #saveConfiguration()}.
379 * @return {@code true} if {@link #saveConfiguration()} would overwrite an
380 * existing file, {@code false} otherwise
382 private boolean isOverwritingConfiguration() {
383 return configuration.getConfigurationLocator().hasFile(configuration.getConfigurationDirectory());
387 * Saves the configuration.
389 * @return <code>true</code> if the configuration could be saved,
390 * <code>false</code> otherwise
392 private boolean saveConfiguration() {
393 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
394 configuration.setNodes(nodeManagerPage.getNodes());
395 if (selectedNode != null) {
396 configuration.setSelectedNode(selectedNode);
399 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
400 configuration.setProjects(projectPage.getProjects());
402 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
403 configuration.setTempDirectory(preferencesPage.getTempDirectory());
405 return configuration.save();
409 * Finds a supported locale for the given locale.
412 * The locale to find a supported locale for
413 * @return The supported locale that was found, or the default locale if no
414 * supported locale could be found
416 private static Locale findSupportedLocale(Locale forLocale) {
417 for (Locale locale : SUPPORTED_LOCALES) {
418 if (locale.equals(forLocale)) {
422 for (Locale locale : SUPPORTED_LOCALES) {
423 if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
427 for (Locale locale : SUPPORTED_LOCALES) {
428 if (locale.getLanguage().equals(forLocale.getLanguage())) {
432 return SUPPORTED_LOCALES[0];
436 * Returns the version.
438 * @return The version
440 public static final Version getVersion() {
449 * Switches the language of the interface to the given locale.
452 * The locale to switch to
454 private void switchLanguage(Locale locale) {
455 Locale supportedLocale = findSupportedLocale(locale);
456 Action languageAction = languageActions.get(supportedLocale);
457 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
458 menuItem.setSelected(true);
459 I18n.setLocale(supportedLocale);
460 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
463 } catch (Throwable t) {
464 /* we probably shouldn't swallow this. */
467 wizard.setPage(wizard.getPage());
468 configuration.setLocale(supportedLocale);
472 * Shows a dialog with general preferences.
474 private void optionsPreferences() {
475 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationLocation(configuration.getConfigurationDirectory());
476 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasNextToJarConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.NEXT_TO_JAR_FILE));
477 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
478 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode());
479 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority());
480 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setManifestPutter(configuration.getManifestPutter());
481 showPage(PageType.PAGE_PREFERENCES);
482 optionsPreferencesAction.setEnabled(false);
483 wizard.setNextEnabled(true);
484 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
488 * Shows a dialog box that shows the last version that was found by the
489 * {@link UpdateChecker}.
491 private void showLatestUpdate() {
492 Version latestVersion = updateChecker.getLatestVersion();
493 int versionDifference = latestVersion.compareTo(VERSION);
494 if (versionDifference > 0) {
495 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);
496 } else if (versionDifference < 0) {
497 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);
499 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);
504 // INTERFACE ListSelectionListener
511 public void valueChanged(ListSelectionEvent e) {
512 JList list = (JList) e.getSource();
513 int selectedRow = list.getSelectedIndex();
514 wizard.setNextEnabled(selectedRow > -1);
518 // INTERFACE WizardListener
525 public void wizardNextPressed(TWizard wizard) {
526 String pageName = wizard.getPage().getName();
527 if ("page.node-manager".equals(pageName)) {
528 showPage(PageType.PAGE_PROJECTS);
529 } else if ("page.project".equals(pageName)) {
530 ProjectPage projectPage = (ProjectPage) wizard.getPage();
531 Project project = projectPage.getSelectedProject();
532 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
533 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
536 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
537 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
540 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
541 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
542 showPage(PageType.PAGE_PROJECT_FILES);
543 } else if ("page.project.files".equals(pageName)) {
544 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
545 Project project = projectPage.getSelectedProject();
546 if (selectedNode == null) {
547 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
550 CheckReport checkReport = ProjectInserter.validateProject(project);
551 for (Issue issue : checkReport) {
552 if (issue.isFatal()) {
553 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
556 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) {
560 boolean nodeRunning = false;
562 nodeRunning = freenetInterface.isNodePresent();
563 } catch (IOException e) {
567 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
570 configuration.save();
571 showPage(PageType.PAGE_INSERT_PROJECT);
572 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
573 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
574 projectInsertPage.setTempDirectory(tempDirectory);
575 projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
576 projectInsertPage.setPriority(configuration.getPriority());
577 projectInsertPage.setManifestPutter(configuration.getManifestPutter());
578 projectInsertPage.startInsert();
579 nodeMenu.setEnabled(false);
580 optionsPreferencesAction.setEnabled(false);
581 } else if ("page.project.insert".equals(pageName)) {
582 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
583 if (projectInsertPage.isRunning()) {
584 projectInsertPage.stopInsert();
586 showPage(PageType.PAGE_PROJECTS);
587 nodeMenu.setEnabled(true);
588 optionsPreferencesAction.setEnabled(true);
590 } else if ("page.preferences".equals(pageName)) {
591 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
592 showPage(PageType.PAGE_PROJECTS);
593 optionsPreferencesAction.setEnabled(true);
594 configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode());
595 configuration.setPriority(preferencesPage.getPriority());
596 configuration.setManifestPutter(preferencesPage.getManifestPutter());
597 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
605 public void wizardPreviousPressed(TWizard wizard) {
606 String pageName = wizard.getPage().getName();
607 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
608 showPage(PageType.PAGE_NODE_MANAGER);
609 optionsPreferencesAction.setEnabled(true);
610 } else if ("page.project.files".equals(pageName)) {
611 showPage(PageType.PAGE_PROJECTS);
612 } else if ("page.project.insert".equals(pageName)) {
613 showPage(PageType.PAGE_PROJECT_FILES);
621 public void wizardQuitPressed(TWizard wizard) {
622 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
623 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
625 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) {
626 if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
627 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);
628 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
629 if (saveConfiguration()) {
632 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
635 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
639 if (saveConfiguration()) {
643 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
650 // INTERFACE NodeManagerListener
657 public void nodesUpdated(Node[] nodes) {
658 nodeMenu.removeAll();
659 ButtonGroup nodeButtonGroup = new ButtonGroup();
660 Node newSelectedNode = null;
661 for (Node node : nodes) {
662 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
663 nodeMenuItem.putClientProperty("Node", node);
664 nodeMenuItem.addActionListener(this);
665 nodeButtonGroup.add(nodeMenuItem);
666 if (node.equals(selectedNode)) {
667 newSelectedNode = node;
668 nodeMenuItem.setSelected(true);
670 nodeMenu.add(nodeMenuItem);
672 nodeMenu.addSeparator();
673 nodeMenu.add(manageNodeAction);
674 selectedNode = newSelectedNode;
675 freenetInterface.setNode(selectedNode);
682 public void nodeSelected(Node node) {
683 for (Component menuItem : nodeMenu.getMenuComponents()) {
684 if (menuItem instanceof JMenuItem) {
685 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
686 ((JMenuItem) menuItem).setSelected(true);
690 freenetInterface.setNode(node);
695 // INTERFACE ActionListener
702 public void actionPerformed(ActionEvent e) {
703 Object source = e.getSource();
704 if (source instanceof JRadioButtonMenuItem) {
705 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
706 Node node = (Node) menuItem.getClientProperty("Node");
708 freenetInterface.setNode(selectedNode);
713 // INTERFACE UpdateListener
720 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
721 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
722 if (foundVersion.compareTo(VERSION) > 0) {
723 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);
732 * Main method that is called by the VM.
735 * The command-line arguments
737 public static void main(String[] args) {
738 /* initialize logger. */
739 Logger logger = Logger.getLogger("de.todesbaum");
740 Handler handler = new ConsoleHandler();
741 logger.addHandler(handler);
742 String configFilename = null;
743 boolean nextIsConfigFilename = false;
744 for (String argument : args) {
745 if (nextIsConfigFilename) {
746 configFilename = argument;
747 nextIsConfigFilename = false;
749 if ("--help".equals(argument)) {
752 } else if ("--debug".equals(argument)) {
753 logger.setLevel(Level.ALL);
754 handler.setLevel(Level.ALL);
755 } else if ("--config-file".equals(argument)) {
756 nextIsConfigFilename = true;
759 if (nextIsConfigFilename) {
760 System.out.println("--config-file needs parameter!");
763 new Main(configFilename);
767 * Prints a small syntax help.
769 private static void printHelp() {
770 System.out.println("--help\tshows this cruft");
771 System.out.println("--debug\tenables some debug output");
772 System.out.println("--config-file <file>\tuse specified configuration file");