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, 11, 1);
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, new Locale("pl") };
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);
200 showPage(PageType.PAGE_PROJECTS);
204 * Creates all actions.
206 private void createActions() {
207 for (final Locale locale : SUPPORTED_LOCALES) {
208 languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
211 @SuppressWarnings("synthetic-access")
212 public void actionPerformed(ActionEvent actionEvent) {
213 switchLanguage(locale);
217 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
220 @SuppressWarnings("synthetic-access")
221 public void actionPerformed(ActionEvent actionEvent) {
222 showPage(PageType.PAGE_NODE_MANAGER);
223 optionsPreferencesAction.setEnabled(true);
224 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
225 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
228 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
234 @SuppressWarnings("synthetic-access")
235 public void actionPerformed(ActionEvent actionEvent) {
236 optionsPreferences();
239 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
245 @SuppressWarnings("synthetic-access")
246 public void actionPerformed(ActionEvent actionEvent) {
250 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
253 @SuppressWarnings("synthetic-access")
254 public void actionPerformed(ActionEvent e) {
255 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
259 I18nContainer.getInstance().registerRunnable(new Runnable() {
262 @SuppressWarnings("synthetic-access")
264 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
265 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
266 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
267 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
273 * Creates the menu bar.
275 * @return The menu bar
277 private JMenuBar createMenuBar() {
278 JMenuBar menuBar = new JMenuBar();
279 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
280 menuBar.add(languageMenu);
281 ButtonGroup languageButtonGroup = new ButtonGroup();
282 for (Locale locale : SUPPORTED_LOCALES) {
283 Action languageAction = languageActions.get(locale);
284 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
285 if (locale.equals(Locale.getDefault())) {
286 menuItem.setSelected(true);
288 languageAction.putValue("menuItem", menuItem);
289 languageButtonGroup.add(menuItem);
290 languageMenu.add(menuItem);
292 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
293 menuBar.add(nodeMenu);
294 selectedNode = configuration.getSelectedNode();
295 nodesUpdated(configuration.getNodes());
297 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
298 menuBar.add(optionsMenu);
299 optionsMenu.add(optionsPreferencesAction);
301 /* evil hack to right-align the help menu */
302 JPanel panel = new JPanel();
303 panel.setOpaque(false);
306 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
307 menuBar.add(helpMenu);
308 helpMenu.add(checkForUpdatesAction);
309 helpMenu.add(aboutAction);
311 I18nContainer.getInstance().registerRunnable(new Runnable() {
314 @SuppressWarnings("synthetic-access")
316 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
317 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
318 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
319 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
320 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
321 languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
330 * Initializes all pages.
332 private void initPages() {
333 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
334 nodeManagerPage.setName("page.node-manager");
335 nodeManagerPage.addNodeManagerListener(this);
336 nodeManagerPage.setNodes(configuration.getNodes());
337 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
339 ProjectPage projectPage = new ProjectPage(wizard);
340 projectPage.setName("page.project");
341 projectPage.setProjects(configuration.getProjects());
342 projectPage.setFreenetInterface(freenetInterface);
343 projectPage.setWebOfTrustInterface(webOfTrustInterface);
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 * Quits jSite, stopping all background services.
506 private void quit() {
507 updateChecker.stop();
512 // INTERFACE ListSelectionListener
519 public void valueChanged(ListSelectionEvent e) {
520 JList list = (JList) e.getSource();
521 int selectedRow = list.getSelectedIndex();
522 wizard.setNextEnabled(selectedRow > -1);
526 // INTERFACE WizardListener
533 public void wizardNextPressed(TWizard wizard) {
534 String pageName = wizard.getPage().getName();
535 if ("page.node-manager".equals(pageName)) {
536 showPage(PageType.PAGE_PROJECTS);
537 } else if ("page.project".equals(pageName)) {
538 ProjectPage projectPage = (ProjectPage) wizard.getPage();
539 Project project = projectPage.getSelectedProject();
540 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
541 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
544 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
545 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
548 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
549 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
550 showPage(PageType.PAGE_PROJECT_FILES);
551 } else if ("page.project.files".equals(pageName)) {
552 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
553 Project project = projectPage.getSelectedProject();
554 if (selectedNode == null) {
555 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
558 CheckReport checkReport = ProjectInserter.validateProject(project);
559 for (Issue issue : checkReport) {
560 if (issue.isFatal()) {
561 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
564 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) {
568 boolean nodeRunning = false;
570 nodeRunning = freenetInterface.isNodePresent();
571 } catch (IOException e) {
575 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
578 configuration.save();
579 showPage(PageType.PAGE_INSERT_PROJECT);
580 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
581 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
582 projectInsertPage.setTempDirectory(tempDirectory);
583 projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
584 projectInsertPage.setPriority(configuration.getPriority());
585 projectInsertPage.setManifestPutter(configuration.getManifestPutter());
586 projectInsertPage.startInsert();
587 nodeMenu.setEnabled(false);
588 optionsPreferencesAction.setEnabled(false);
589 } else if ("page.project.insert".equals(pageName)) {
590 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
591 if (projectInsertPage.isRunning()) {
592 projectInsertPage.stopInsert();
594 showPage(PageType.PAGE_PROJECTS);
595 nodeMenu.setEnabled(true);
596 optionsPreferencesAction.setEnabled(true);
598 } else if ("page.preferences".equals(pageName)) {
599 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
600 showPage(PageType.PAGE_PROJECTS);
601 optionsPreferencesAction.setEnabled(true);
602 configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode());
603 configuration.setPriority(preferencesPage.getPriority());
604 configuration.setManifestPutter(preferencesPage.getManifestPutter());
605 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
613 public void wizardPreviousPressed(TWizard wizard) {
614 String pageName = wizard.getPage().getName();
615 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
616 showPage(PageType.PAGE_NODE_MANAGER);
617 optionsPreferencesAction.setEnabled(true);
618 } else if ("page.project.files".equals(pageName)) {
619 showPage(PageType.PAGE_PROJECTS);
620 } else if ("page.project.insert".equals(pageName)) {
621 showPage(PageType.PAGE_PROJECT_FILES);
629 public void wizardQuitPressed(TWizard wizard) {
630 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
631 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
633 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) {
634 if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
635 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);
636 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
637 if (saveConfiguration()) {
640 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
643 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
647 if (saveConfiguration()) {
651 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
658 // INTERFACE NodeManagerListener
665 public void nodesUpdated(Node[] nodes) {
666 nodeMenu.removeAll();
667 ButtonGroup nodeButtonGroup = new ButtonGroup();
668 Node newSelectedNode = null;
669 for (Node node : nodes) {
670 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
671 nodeMenuItem.putClientProperty("Node", node);
672 nodeMenuItem.addActionListener(this);
673 nodeButtonGroup.add(nodeMenuItem);
674 if (node.equals(selectedNode)) {
675 newSelectedNode = node;
676 nodeMenuItem.setSelected(true);
678 nodeMenu.add(nodeMenuItem);
680 nodeMenu.addSeparator();
681 nodeMenu.add(manageNodeAction);
682 selectedNode = newSelectedNode;
683 freenetInterface.setNode(selectedNode);
690 public void nodeSelected(Node node) {
691 for (Component menuItem : nodeMenu.getMenuComponents()) {
692 if (menuItem instanceof JMenuItem) {
693 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
694 ((JMenuItem) menuItem).setSelected(true);
698 freenetInterface.setNode(node);
703 // INTERFACE ActionListener
710 public void actionPerformed(ActionEvent e) {
711 Object source = e.getSource();
712 if (source instanceof JRadioButtonMenuItem) {
713 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
714 Node node = (Node) menuItem.getClientProperty("Node");
716 freenetInterface.setNode(selectedNode);
721 // INTERFACE UpdateListener
728 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
729 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
730 if (foundVersion.compareTo(VERSION) > 0) {
731 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);
740 * Main method that is called by the VM.
743 * The command-line arguments
745 public static void main(String[] args) {
746 /* initialize logger. */
747 Logger logger = Logger.getLogger("de.todesbaum");
748 Handler handler = new ConsoleHandler();
749 logger.addHandler(handler);
750 String configFilename = null;
751 boolean nextIsConfigFilename = false;
752 for (String argument : args) {
753 if (nextIsConfigFilename) {
754 configFilename = argument;
755 nextIsConfigFilename = false;
757 if ("--help".equals(argument)) {
760 } else if ("--debug".equals(argument)) {
761 logger.setLevel(Level.ALL);
762 handler.setLevel(Level.ALL);
763 } else if ("--config-file".equals(argument)) {
764 nextIsConfigFilename = true;
767 if (nextIsConfigFilename) {
768 System.out.println("--config-file needs parameter!");
771 new Main(configFilename);
775 * Prints a small syntax help.
777 private static void printHelp() {
778 System.out.println("--help\tshows this cruft");
779 System.out.println("--debug\tenables some debug output");
780 System.out.println("--config-file <file>\tuse specified configuration file");