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[] {
132 /** The actions that switch the language. */
133 private Map<Locale, Action> languageActions = new HashMap<Locale, Action>();
135 /** The “manage nodes” action. */
136 private Action manageNodeAction;
138 /** The “preferences” action. */
139 private Action optionsPreferencesAction;
141 /** The “check for updates” action. */
142 private Action checkForUpdatesAction;
144 /** The “about jSite” action. */
145 private Action aboutAction;
148 private TWizard wizard;
150 /** The node menu. */
151 private JMenu nodeMenu;
153 /** The currently selected node. */
154 private Node selectedNode;
156 /** Mapping from page type to page. */
157 private final Map<PageType, TWizardPage> pages = new HashMap<PageType, TWizardPage>();
159 /** The original location of the configuration file. */
160 private ConfigurationLocation originalLocation;
163 * Creates a new core with the default configuration file.
170 * Creates a new core with the given configuration from the given file.
172 * @param configFilename
173 * The name of the configuration file
175 private Main(String configFilename) {
176 /* collect all possible configuration file locations. */
177 ConfigurationLocator configurationLocator = new ConfigurationLocator();
178 if (configFilename != null) {
179 configurationLocator.setCustomLocation(configFilename);
182 originalLocation = configurationLocator.findPreferredLocation();
183 logger.log(Level.CONFIG, "Using configuration from " + originalLocation + ".");
184 configuration = new Configuration(configurationLocator, originalLocation);
186 Locale.setDefault(configuration.getLocale());
187 I18n.setLocale(configuration.getLocale());
188 wizard = new TWizard();
190 wizard.setJMenuBar(createMenuBar());
191 wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
192 wizard.setPreviousEnabled(false);
193 wizard.setNextEnabled(true);
194 wizard.addWizardListener(this);
195 jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
196 wizard.setIcon(jSiteIcon);
198 updateChecker = new UpdateChecker(freenetInterface);
199 updateChecker.addUpdateListener(this);
200 updateChecker.start();
202 webOfTrustInterface = new WebOfTrustInterface(freenetInterface);
205 showPage(PageType.PAGE_PROJECTS);
209 * Creates all actions.
211 private void createActions() {
212 for (final Locale locale : SUPPORTED_LOCALES) {
213 languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
216 @SuppressWarnings("synthetic-access")
217 public void actionPerformed(ActionEvent actionEvent) {
218 switchLanguage(locale);
222 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
225 @SuppressWarnings("synthetic-access")
226 public void actionPerformed(ActionEvent actionEvent) {
227 showPage(PageType.PAGE_NODE_MANAGER);
228 optionsPreferencesAction.setEnabled(true);
229 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
230 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
233 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
239 @SuppressWarnings("synthetic-access")
240 public void actionPerformed(ActionEvent actionEvent) {
241 optionsPreferences();
244 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
250 @SuppressWarnings("synthetic-access")
251 public void actionPerformed(ActionEvent actionEvent) {
255 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
258 @SuppressWarnings("synthetic-access")
259 public void actionPerformed(ActionEvent e) {
260 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
264 I18nContainer.getInstance().registerRunnable(new Runnable() {
267 @SuppressWarnings("synthetic-access")
269 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
270 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
271 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
272 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
278 * Creates the menu bar.
280 * @return The menu bar
282 private JMenuBar createMenuBar() {
283 JMenuBar menuBar = new JMenuBar();
284 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
285 menuBar.add(languageMenu);
286 ButtonGroup languageButtonGroup = new ButtonGroup();
287 for (Locale locale : SUPPORTED_LOCALES) {
288 Action languageAction = languageActions.get(locale);
289 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
290 if (locale.equals(Locale.getDefault())) {
291 menuItem.setSelected(true);
293 languageAction.putValue("menuItem", menuItem);
294 languageButtonGroup.add(menuItem);
295 languageMenu.add(menuItem);
297 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
298 menuBar.add(nodeMenu);
299 selectedNode = configuration.getSelectedNode();
300 nodesUpdated(configuration.getNodes());
302 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
303 menuBar.add(optionsMenu);
304 optionsMenu.add(optionsPreferencesAction);
306 /* evil hack to right-align the help menu */
307 JPanel panel = new JPanel();
308 panel.setOpaque(false);
311 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
312 menuBar.add(helpMenu);
313 helpMenu.add(checkForUpdatesAction);
314 helpMenu.add(aboutAction);
316 I18nContainer.getInstance().registerRunnable(new Runnable() {
319 @SuppressWarnings("synthetic-access")
321 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
322 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
323 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
324 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
325 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
326 languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
335 * Initializes all pages.
337 private void initPages() {
338 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
339 nodeManagerPage.setName("page.node-manager");
340 nodeManagerPage.addNodeManagerListener(this);
341 nodeManagerPage.setNodes(configuration.getNodes());
342 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
344 ProjectPage projectPage = new ProjectPage(wizard);
345 projectPage.setName("page.project");
346 projectPage.setProjects(configuration.getProjects());
347 projectPage.setFreenetInterface(freenetInterface);
348 projectPage.setWebOfTrustInterface(webOfTrustInterface);
349 projectPage.addListSelectionListener(this);
350 pages.put(PageType.PAGE_PROJECTS, projectPage);
352 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
353 projectFilesPage.setName("page.project.files");
354 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
356 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
357 projectInsertPage.setName("page.project.insert");
358 projectInsertPage.setFreenetInterface(freenetInterface);
359 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
361 PreferencesPage preferencesPage = new PreferencesPage(wizard);
362 preferencesPage.setName("page.preferences");
363 preferencesPage.setTempDirectory(configuration.getTempDirectory());
364 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
368 * Shows the page with the given type.
371 * The page type to show
373 private void showPage(PageType pageType) {
374 wizard.setPreviousEnabled(pageType.ordinal() > 0);
375 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
376 wizard.setPage(pages.get(pageType));
377 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
381 * Returns whether a configuration file would be overwritten when calling
382 * {@link #saveConfiguration()}.
384 * @return {@code true} if {@link #saveConfiguration()} would overwrite an
385 * existing file, {@code false} otherwise
387 private boolean isOverwritingConfiguration() {
388 return configuration.getConfigurationLocator().hasFile(configuration.getConfigurationDirectory());
392 * Saves the configuration.
394 * @return <code>true</code> if the configuration could be saved,
395 * <code>false</code> otherwise
397 private boolean saveConfiguration() {
398 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
399 configuration.setNodes(nodeManagerPage.getNodes());
400 if (selectedNode != null) {
401 configuration.setSelectedNode(selectedNode);
404 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
405 configuration.setProjects(projectPage.getProjects());
407 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
408 configuration.setTempDirectory(preferencesPage.getTempDirectory());
410 return configuration.save();
414 * Finds a supported locale for the given locale.
417 * The locale to find a supported locale for
418 * @return The supported locale that was found, or the default locale if no
419 * supported locale could be found
421 private static Locale findSupportedLocale(Locale forLocale) {
422 for (Locale locale : SUPPORTED_LOCALES) {
423 if (locale.equals(forLocale)) {
427 for (Locale locale : SUPPORTED_LOCALES) {
428 if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
432 for (Locale locale : SUPPORTED_LOCALES) {
433 if (locale.getLanguage().equals(forLocale.getLanguage())) {
437 return SUPPORTED_LOCALES[0];
441 * Returns the version.
443 * @return The version
445 public static final Version getVersion() {
454 * Switches the language of the interface to the given locale.
457 * The locale to switch to
459 private void switchLanguage(Locale locale) {
460 Locale supportedLocale = findSupportedLocale(locale);
461 Action languageAction = languageActions.get(supportedLocale);
462 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
463 menuItem.setSelected(true);
464 I18n.setLocale(supportedLocale);
465 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
468 } catch (Throwable t) {
469 /* we probably shouldn't swallow this. */
472 wizard.setPage(wizard.getPage());
473 configuration.setLocale(supportedLocale);
477 * Shows a dialog with general preferences.
479 private void optionsPreferences() {
480 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationLocation(configuration.getConfigurationDirectory());
481 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasNextToJarConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.NEXT_TO_JAR_FILE));
482 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
483 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode());
484 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority());
485 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setManifestPutter(configuration.getManifestPutter());
486 showPage(PageType.PAGE_PREFERENCES);
487 optionsPreferencesAction.setEnabled(false);
488 wizard.setNextEnabled(true);
489 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
493 * Shows a dialog box that shows the last version that was found by the
494 * {@link UpdateChecker}.
496 private void showLatestUpdate() {
497 Version latestVersion = updateChecker.getLatestVersion();
498 int versionDifference = latestVersion.compareTo(VERSION);
499 if (versionDifference > 0) {
500 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);
501 } else if (versionDifference < 0) {
502 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);
504 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);
509 * Quits jSite, stopping all background services.
511 private void quit() {
512 updateChecker.stop();
517 // INTERFACE ListSelectionListener
524 public void valueChanged(ListSelectionEvent e) {
525 JList list = (JList) e.getSource();
526 int selectedRow = list.getSelectedIndex();
527 wizard.setNextEnabled(selectedRow > -1);
531 // INTERFACE WizardListener
538 public void wizardNextPressed(TWizard wizard) {
539 String pageName = wizard.getPage().getName();
540 if ("page.node-manager".equals(pageName)) {
541 showPage(PageType.PAGE_PROJECTS);
542 } else if ("page.project".equals(pageName)) {
543 ProjectPage projectPage = (ProjectPage) wizard.getPage();
544 Project project = projectPage.getSelectedProject();
545 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
546 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
549 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
550 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
553 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
554 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
555 showPage(PageType.PAGE_PROJECT_FILES);
556 } else if ("page.project.files".equals(pageName)) {
557 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
558 Project project = projectPage.getSelectedProject();
559 if (selectedNode == null) {
560 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
563 CheckReport checkReport = ProjectInserter.validateProject(project);
564 for (Issue issue : checkReport) {
565 if (issue.isFatal()) {
566 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
569 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) {
573 boolean nodeRunning = false;
575 nodeRunning = freenetInterface.isNodePresent();
576 } catch (IOException e) {
580 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
583 configuration.save();
584 showPage(PageType.PAGE_INSERT_PROJECT);
585 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
586 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
587 projectInsertPage.setTempDirectory(tempDirectory);
588 projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
589 projectInsertPage.setPriority(configuration.getPriority());
590 projectInsertPage.setManifestPutter(configuration.getManifestPutter());
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.setManifestPutter(preferencesPage.getManifestPutter());
610 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
618 public void wizardPreviousPressed(TWizard wizard) {
619 String pageName = wizard.getPage().getName();
620 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
621 showPage(PageType.PAGE_NODE_MANAGER);
622 optionsPreferencesAction.setEnabled(true);
623 } else if ("page.project.files".equals(pageName)) {
624 showPage(PageType.PAGE_PROJECTS);
625 } else if ("page.project.insert".equals(pageName)) {
626 showPage(PageType.PAGE_PROJECT_FILES);
634 public void wizardQuitPressed(TWizard wizard) {
635 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
636 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
638 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.question"), I18n.getMessage("jsite.quit.question.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
639 if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
640 int overwriteConfigurationAnswer = JOptionPane.showConfirmDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.quit.overwrite-configuration"), configuration.getConfigurationLocator().getFile(configuration.getConfigurationDirectory())), I18n.getMessage("jsite.quit.overwrite-configuration.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
641 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
642 if (saveConfiguration()) {
645 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
648 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
652 if (saveConfiguration()) {
656 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
663 // INTERFACE NodeManagerListener
670 public void nodesUpdated(Node[] nodes) {
671 nodeMenu.removeAll();
672 ButtonGroup nodeButtonGroup = new ButtonGroup();
673 Node newSelectedNode = null;
674 for (Node node : nodes) {
675 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
676 nodeMenuItem.putClientProperty("Node", node);
677 nodeMenuItem.addActionListener(this);
678 nodeButtonGroup.add(nodeMenuItem);
679 if (node.equals(selectedNode)) {
680 newSelectedNode = node;
681 nodeMenuItem.setSelected(true);
683 nodeMenu.add(nodeMenuItem);
685 nodeMenu.addSeparator();
686 nodeMenu.add(manageNodeAction);
687 selectedNode = newSelectedNode;
688 freenetInterface.setNode(selectedNode);
695 public void nodeSelected(Node node) {
696 for (Component menuItem : nodeMenu.getMenuComponents()) {
697 if (menuItem instanceof JMenuItem) {
698 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
699 ((JMenuItem) menuItem).setSelected(true);
703 freenetInterface.setNode(node);
708 // INTERFACE ActionListener
715 public void actionPerformed(ActionEvent e) {
716 Object source = e.getSource();
717 if (source instanceof JRadioButtonMenuItem) {
718 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
719 Node node = (Node) menuItem.getClientProperty("Node");
721 freenetInterface.setNode(selectedNode);
726 // INTERFACE UpdateListener
733 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
734 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
735 if (foundVersion.compareTo(VERSION) > 0) {
736 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.update-checker.found-version.message"), foundVersion.toString(), new Date(versionTimestamp)), I18n.getMessage("jsite.update-checker.found-version.title"), JOptionPane.INFORMATION_MESSAGE);
745 * Main method that is called by the VM.
748 * The command-line arguments
750 public static void main(String[] args) {
751 /* initialize logger. */
752 Logger logger = Logger.getLogger("de.todesbaum");
753 Handler handler = new ConsoleHandler();
754 logger.addHandler(handler);
755 String configFilename = null;
756 boolean nextIsConfigFilename = false;
757 for (String argument : args) {
758 if (nextIsConfigFilename) {
759 configFilename = argument;
760 nextIsConfigFilename = false;
762 if ("--help".equals(argument)) {
765 } else if ("--debug".equals(argument)) {
766 logger.setLevel(Level.ALL);
767 handler.setLevel(Level.ALL);
768 } else if ("--config-file".equals(argument)) {
769 nextIsConfigFilename = true;
772 if (nextIsConfigFilename) {
773 System.out.println("--config-file needs parameter!");
776 new Main(configFilename);
780 * Prints a small syntax help.
782 private static void printHelp() {
783 System.out.println("--help\tshows this cruft");
784 System.out.println("--debug\tenables some debug output");
785 System.out.println("--config-file <file>\tuse specified configuration file");