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, 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);
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.setWebOfTrustInterface(webOfTrustInterface);
345 projectPage.addListSelectionListener(this);
346 pages.put(PageType.PAGE_PROJECTS, projectPage);
348 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
349 projectFilesPage.setName("page.project.files");
350 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
352 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
353 projectInsertPage.setName("page.project.insert");
354 projectInsertPage.setFreenetInterface(freenetInterface);
355 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
357 PreferencesPage preferencesPage = new PreferencesPage(wizard);
358 preferencesPage.setName("page.preferences");
359 preferencesPage.setTempDirectory(configuration.getTempDirectory());
360 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
364 * Shows the page with the given type.
367 * The page type to show
369 private void showPage(PageType pageType) {
370 wizard.setPreviousEnabled(pageType.ordinal() > 0);
371 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
372 wizard.setPage(pages.get(pageType));
373 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
377 * Returns whether a configuration file would be overwritten when calling
378 * {@link #saveConfiguration()}.
380 * @return {@code true} if {@link #saveConfiguration()} would overwrite an
381 * existing file, {@code false} otherwise
383 private boolean isOverwritingConfiguration() {
384 return configuration.getConfigurationLocator().hasFile(configuration.getConfigurationDirectory());
388 * Saves the configuration.
390 * @return <code>true</code> if the configuration could be saved,
391 * <code>false</code> otherwise
393 private boolean saveConfiguration() {
394 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
395 configuration.setNodes(nodeManagerPage.getNodes());
396 if (selectedNode != null) {
397 configuration.setSelectedNode(selectedNode);
400 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
401 configuration.setProjects(projectPage.getProjects());
403 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
404 configuration.setTempDirectory(preferencesPage.getTempDirectory());
406 return configuration.save();
410 * Finds a supported locale for the given locale.
413 * The locale to find a supported locale for
414 * @return The supported locale that was found, or the default locale if no
415 * supported locale could be found
417 private static Locale findSupportedLocale(Locale forLocale) {
418 for (Locale locale : SUPPORTED_LOCALES) {
419 if (locale.equals(forLocale)) {
423 for (Locale locale : SUPPORTED_LOCALES) {
424 if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
428 for (Locale locale : SUPPORTED_LOCALES) {
429 if (locale.getLanguage().equals(forLocale.getLanguage())) {
433 return SUPPORTED_LOCALES[0];
437 * Returns the version.
439 * @return The version
441 public static final Version getVersion() {
450 * Switches the language of the interface to the given locale.
453 * The locale to switch to
455 private void switchLanguage(Locale locale) {
456 Locale supportedLocale = findSupportedLocale(locale);
457 Action languageAction = languageActions.get(supportedLocale);
458 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
459 menuItem.setSelected(true);
460 I18n.setLocale(supportedLocale);
461 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
464 } catch (Throwable t) {
465 /* we probably shouldn't swallow this. */
468 wizard.setPage(wizard.getPage());
469 configuration.setLocale(supportedLocale);
473 * Shows a dialog with general preferences.
475 private void optionsPreferences() {
476 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationLocation(configuration.getConfigurationDirectory());
477 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasNextToJarConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.NEXT_TO_JAR_FILE));
478 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
479 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode());
480 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority());
481 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setManifestPutter(configuration.getManifestPutter());
482 showPage(PageType.PAGE_PREFERENCES);
483 optionsPreferencesAction.setEnabled(false);
484 wizard.setNextEnabled(true);
485 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
489 * Shows a dialog box that shows the last version that was found by the
490 * {@link UpdateChecker}.
492 private void showLatestUpdate() {
493 Version latestVersion = updateChecker.getLatestVersion();
494 int versionDifference = latestVersion.compareTo(VERSION);
495 if (versionDifference > 0) {
496 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);
497 } else if (versionDifference < 0) {
498 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);
500 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);
505 * Quits jSite, stopping all background services.
507 private void quit() {
508 updateChecker.stop();
509 webOfTrustInterface.stop();
514 // INTERFACE ListSelectionListener
521 public void valueChanged(ListSelectionEvent e) {
522 JList list = (JList) e.getSource();
523 int selectedRow = list.getSelectedIndex();
524 wizard.setNextEnabled(selectedRow > -1);
528 // INTERFACE WizardListener
535 public void wizardNextPressed(TWizard wizard) {
536 String pageName = wizard.getPage().getName();
537 if ("page.node-manager".equals(pageName)) {
538 showPage(PageType.PAGE_PROJECTS);
539 } else if ("page.project".equals(pageName)) {
540 ProjectPage projectPage = (ProjectPage) wizard.getPage();
541 Project project = projectPage.getSelectedProject();
542 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
543 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
546 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
547 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
550 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
551 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
552 showPage(PageType.PAGE_PROJECT_FILES);
553 } else if ("page.project.files".equals(pageName)) {
554 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
555 Project project = projectPage.getSelectedProject();
556 if (selectedNode == null) {
557 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
560 CheckReport checkReport = ProjectInserter.validateProject(project);
561 for (Issue issue : checkReport) {
562 if (issue.isFatal()) {
563 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
566 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) {
570 boolean nodeRunning = false;
572 nodeRunning = freenetInterface.isNodePresent();
573 } catch (IOException e) {
577 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
580 configuration.save();
581 showPage(PageType.PAGE_INSERT_PROJECT);
582 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
583 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
584 projectInsertPage.setTempDirectory(tempDirectory);
585 projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
586 projectInsertPage.setPriority(configuration.getPriority());
587 projectInsertPage.setManifestPutter(configuration.getManifestPutter());
588 projectInsertPage.startInsert();
589 nodeMenu.setEnabled(false);
590 optionsPreferencesAction.setEnabled(false);
591 } else if ("page.project.insert".equals(pageName)) {
592 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
593 if (projectInsertPage.isRunning()) {
594 projectInsertPage.stopInsert();
596 showPage(PageType.PAGE_PROJECTS);
597 nodeMenu.setEnabled(true);
598 optionsPreferencesAction.setEnabled(true);
600 } else if ("page.preferences".equals(pageName)) {
601 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
602 showPage(PageType.PAGE_PROJECTS);
603 optionsPreferencesAction.setEnabled(true);
604 configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode());
605 configuration.setPriority(preferencesPage.getPriority());
606 configuration.setManifestPutter(preferencesPage.getManifestPutter());
607 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
615 public void wizardPreviousPressed(TWizard wizard) {
616 String pageName = wizard.getPage().getName();
617 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
618 showPage(PageType.PAGE_NODE_MANAGER);
619 optionsPreferencesAction.setEnabled(true);
620 } else if ("page.project.files".equals(pageName)) {
621 showPage(PageType.PAGE_PROJECTS);
622 } else if ("page.project.insert".equals(pageName)) {
623 showPage(PageType.PAGE_PROJECT_FILES);
631 public void wizardQuitPressed(TWizard wizard) {
632 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
633 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
635 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) {
636 if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
637 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);
638 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
639 if (saveConfiguration()) {
642 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
645 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
649 if (saveConfiguration()) {
653 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
660 // INTERFACE NodeManagerListener
667 public void nodesUpdated(Node[] nodes) {
668 nodeMenu.removeAll();
669 ButtonGroup nodeButtonGroup = new ButtonGroup();
670 Node newSelectedNode = null;
671 for (Node node : nodes) {
672 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
673 nodeMenuItem.putClientProperty("Node", node);
674 nodeMenuItem.addActionListener(this);
675 nodeButtonGroup.add(nodeMenuItem);
676 if (node.equals(selectedNode)) {
677 newSelectedNode = node;
678 nodeMenuItem.setSelected(true);
680 nodeMenu.add(nodeMenuItem);
682 nodeMenu.addSeparator();
683 nodeMenu.add(manageNodeAction);
684 selectedNode = newSelectedNode;
685 freenetInterface.setNode(selectedNode);
692 public void nodeSelected(Node node) {
693 for (Component menuItem : nodeMenu.getMenuComponents()) {
694 if (menuItem instanceof JMenuItem) {
695 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
696 ((JMenuItem) menuItem).setSelected(true);
700 freenetInterface.setNode(node);
705 // INTERFACE ActionListener
712 public void actionPerformed(ActionEvent e) {
713 Object source = e.getSource();
714 if (source instanceof JRadioButtonMenuItem) {
715 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
716 Node node = (Node) menuItem.getClientProperty("Node");
718 freenetInterface.setNode(selectedNode);
723 // INTERFACE UpdateListener
730 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
731 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
732 if (foundVersion.compareTo(VERSION) > 0) {
733 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);
742 * Main method that is called by the VM.
745 * The command-line arguments
747 public static void main(String[] args) {
748 /* initialize logger. */
749 Logger logger = Logger.getLogger("de.todesbaum");
750 Handler handler = new ConsoleHandler();
751 logger.addHandler(handler);
752 String configFilename = null;
753 boolean nextIsConfigFilename = false;
754 for (String argument : args) {
755 if (nextIsConfigFilename) {
756 configFilename = argument;
757 nextIsConfigFilename = false;
759 if ("--help".equals(argument)) {
762 } else if ("--debug".equals(argument)) {
763 logger.setLevel(Level.ALL);
764 handler.setLevel(Level.ALL);
765 } else if ("--config-file".equals(argument)) {
766 nextIsConfigFilename = true;
769 if (nextIsConfigFilename) {
770 System.out.println("--config-file needs parameter!");
773 new Main(configFilename);
777 * Prints a small syntax help.
779 private static void printHelp() {
780 System.out.println("--help\tshows this cruft");
781 System.out.println("--debug\tenables some debug output");
782 System.out.println("--config-file <file>\tuse specified configuration file");