2 * jSite - Main.java - Copyright Ā© 2006ā2019 David Roden
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package de.todesbaum.jsite.main;
21 import java.awt.Component;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.io.IOException;
25 import java.text.MessageFormat;
26 import java.util.Date;
27 import java.util.HashMap;
28 import java.util.Locale;
30 import java.util.logging.ConsoleHandler;
31 import java.util.logging.Handler;
32 import java.util.logging.Level;
33 import java.util.logging.Logger;
35 import javax.swing.AbstractAction;
36 import javax.swing.Action;
37 import javax.swing.ButtonGroup;
38 import javax.swing.Icon;
39 import javax.swing.JList;
40 import javax.swing.JMenu;
41 import javax.swing.JMenuBar;
42 import javax.swing.JMenuItem;
43 import javax.swing.JOptionPane;
44 import javax.swing.JPanel;
45 import javax.swing.JRadioButtonMenuItem;
46 import javax.swing.event.ListSelectionEvent;
47 import javax.swing.event.ListSelectionListener;
49 import net.pterodactylus.util.image.IconLoader;
51 import de.todesbaum.jsite.application.Freenet7Interface;
52 import de.todesbaum.jsite.application.Node;
53 import de.todesbaum.jsite.application.Project;
54 import de.todesbaum.jsite.application.UpdateChecker;
55 import de.todesbaum.jsite.application.UpdateListener;
56 import de.todesbaum.jsite.application.WebOfTrustInterface;
57 import de.todesbaum.jsite.application.validation.CheckReport;
58 import de.todesbaum.jsite.application.validation.Issue;
59 import de.todesbaum.jsite.application.validation.ProjectValidator;
60 import de.todesbaum.jsite.gui.NodeManagerListener;
61 import de.todesbaum.jsite.gui.NodeManagerPage;
62 import de.todesbaum.jsite.gui.PreferencesPage;
63 import de.todesbaum.jsite.gui.ProjectFilesPage;
64 import de.todesbaum.jsite.gui.ProjectInsertPage;
65 import de.todesbaum.jsite.gui.ProjectPage;
66 import de.todesbaum.jsite.i18n.I18n;
67 import de.todesbaum.jsite.i18n.I18nContainer;
68 import de.todesbaum.jsite.main.ConfigurationLocator.ConfigurationLocation;
69 import de.todesbaum.jsite.main.JarFileLocator.DefaultJarFileLocator;
70 import de.todesbaum.util.swing.TWizard;
71 import de.todesbaum.util.swing.TWizardPage;
72 import de.todesbaum.util.swing.WizardListener;
75 * The main class that ties together everything.
77 * @author David āBombeā Roden <bombe@freenetproject.org>
79 public class Main implements ActionListener, ListSelectionListener, WizardListener, NodeManagerListener, UpdateListener {
82 private static final Logger logger = Logger.getLogger(Main.class.getName());
85 private static final Version VERSION = new Version(0, 14);
87 /** The configuration. */
88 private Configuration configuration;
90 /** The freenet interface. */
91 private Freenet7Interface freenetInterface = new Freenet7Interface();
93 /** The update checker. */
94 private final UpdateChecker updateChecker;
96 /** The web of trust interface. */
97 private final WebOfTrustInterface webOfTrustInterface;
99 /** The jSite icon. */
100 private Icon jSiteIcon;
103 * Enumeration for all possible pages.
105 * @author David āBombeā Roden <bombe@freenetproject.org>
107 private static enum PageType {
109 /** The node manager page. */
112 /** The project page. */
115 /** The project files page. */
118 /** The project insert page. */
121 /** The preferences page. */
126 /** The supported locales. */
127 private static final Locale[] SUPPORTED_LOCALES = new Locale[] {
137 /** The actions that switch the language. */
138 private Map<Locale, Action> languageActions = new HashMap<Locale, Action>();
140 /** The āmanage nodesā action. */
141 private Action manageNodeAction;
143 /** The āpreferencesā action. */
144 private Action optionsPreferencesAction;
146 /** The ācheck for updatesā action. */
147 private Action checkForUpdatesAction;
149 /** The āabout jSiteā action. */
150 private Action aboutAction;
153 private TWizard wizard;
155 /** The node menu. */
156 private JMenu nodeMenu;
158 /** The currently selected node. */
159 private Node selectedNode;
161 /** Mapping from page type to page. */
162 private final Map<PageType, TWizardPage> pages = new HashMap<PageType, TWizardPage>();
164 /** The original location of the configuration file. */
165 private ConfigurationLocation originalLocation;
168 * Creates a new core with the default configuration file.
175 * Creates a new core with the given configuration from the given file.
177 * @param configFilename
178 * The name of the configuration file
180 private Main(String configFilename) {
181 /* collect all possible configuration file locations. */
182 ConfigurationLocator configurationLocator = new ConfigurationLocator(new DefaultJarFileLocator(getClass().getClassLoader()));
183 if (configFilename != null) {
184 configurationLocator.setCustomLocation(configFilename);
187 originalLocation = configurationLocator.findPreferredLocation();
188 logger.log(Level.CONFIG, "Using configuration from " + originalLocation + ".");
189 configuration = new Configuration(configurationLocator, originalLocation);
191 Locale.setDefault(configuration.getLocale());
192 I18n.setLocale(configuration.getLocale());
193 wizard = new TWizard();
195 wizard.setJMenuBar(createMenuBar());
196 wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
197 wizard.setPreviousEnabled(false);
198 wizard.setNextEnabled(true);
199 wizard.addWizardListener(this);
200 jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
201 wizard.setIcon(jSiteIcon);
203 updateChecker = new UpdateChecker(freenetInterface, getVersion());
204 updateChecker.addUpdateListener(this);
205 updateChecker.start();
207 webOfTrustInterface = new WebOfTrustInterface(freenetInterface);
210 showPage(PageType.PAGE_PROJECTS);
214 * Creates all actions.
216 private void createActions() {
217 for (final Locale locale : SUPPORTED_LOCALES) {
218 languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
221 @SuppressWarnings("synthetic-access")
222 public void actionPerformed(ActionEvent actionEvent) {
223 switchLanguage(locale);
227 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
230 @SuppressWarnings("synthetic-access")
231 public void actionPerformed(ActionEvent actionEvent) {
232 showPage(PageType.PAGE_NODE_MANAGER);
233 optionsPreferencesAction.setEnabled(true);
234 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
235 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
238 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
244 @SuppressWarnings("synthetic-access")
245 public void actionPerformed(ActionEvent actionEvent) {
246 optionsPreferences();
249 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
255 @SuppressWarnings("synthetic-access")
256 public void actionPerformed(ActionEvent actionEvent) {
260 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
263 @SuppressWarnings("synthetic-access")
264 public void actionPerformed(ActionEvent e) {
265 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
269 I18nContainer.getInstance().registerRunnable(new Runnable() {
272 @SuppressWarnings("synthetic-access")
274 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
275 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
276 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
277 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
283 * Creates the menu bar.
285 * @return The menu bar
287 private JMenuBar createMenuBar() {
288 JMenuBar menuBar = new JMenuBar();
289 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
290 menuBar.add(languageMenu);
291 ButtonGroup languageButtonGroup = new ButtonGroup();
292 for (Locale locale : SUPPORTED_LOCALES) {
293 Action languageAction = languageActions.get(locale);
294 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
295 if (locale.equals(Locale.getDefault())) {
296 menuItem.setSelected(true);
298 languageAction.putValue("menuItem", menuItem);
299 languageButtonGroup.add(menuItem);
300 languageMenu.add(menuItem);
302 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
303 menuBar.add(nodeMenu);
304 selectedNode = configuration.getSelectedNode();
305 nodesUpdated(configuration.getNodes());
307 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
308 menuBar.add(optionsMenu);
309 optionsMenu.add(optionsPreferencesAction);
311 /* evil hack to right-align the help menu */
312 JPanel panel = new JPanel();
313 panel.setOpaque(false);
316 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
317 menuBar.add(helpMenu);
318 helpMenu.add(checkForUpdatesAction);
319 helpMenu.add(aboutAction);
321 I18nContainer.getInstance().registerRunnable(new Runnable() {
324 @SuppressWarnings("synthetic-access")
326 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
327 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
328 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
329 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
330 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
331 languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
340 * Initializes all pages.
342 private void initPages() {
343 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
344 nodeManagerPage.setName("page.node-manager");
345 nodeManagerPage.addNodeManagerListener(this);
346 nodeManagerPage.setNodes(configuration.getNodes());
347 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
349 ProjectPage projectPage = new ProjectPage(wizard);
350 projectPage.setName("page.project");
351 projectPage.setProjects(configuration.getProjects());
352 projectPage.setFreenetInterface(freenetInterface);
353 projectPage.setWebOfTrustInterface(webOfTrustInterface);
354 projectPage.addListSelectionListener(this);
355 pages.put(PageType.PAGE_PROJECTS, projectPage);
357 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
358 projectFilesPage.setName("page.project.files");
359 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
361 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
362 projectInsertPage.setName("page.project.insert");
363 projectInsertPage.setFreenetInterface(freenetInterface);
364 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
366 PreferencesPage preferencesPage = new PreferencesPage(wizard);
367 preferencesPage.setName("page.preferences");
368 preferencesPage.setTempDirectory(configuration.getTempDirectory());
369 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
373 * Shows the page with the given type.
376 * The page type to show
378 private void showPage(PageType pageType) {
379 wizard.setPreviousEnabled(pageType.ordinal() > 0);
380 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
381 wizard.setPage(pages.get(pageType));
382 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
386 * Returns whether a configuration file would be overwritten when calling
387 * {@link #saveConfiguration()}.
389 * @return {@code true} if {@link #saveConfiguration()} would overwrite an
390 * existing file, {@code false} otherwise
392 private boolean isOverwritingConfiguration() {
393 return configuration.getConfigurationLocator().hasFile(configuration.getConfigurationDirectory());
397 * Saves the configuration.
399 * @return <code>true</code> if the configuration could be saved,
400 * <code>false</code> otherwise
402 private boolean saveConfiguration() {
403 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
404 configuration.setNodes(nodeManagerPage.getNodes());
405 if (selectedNode != null) {
406 configuration.setSelectedNode(selectedNode);
409 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
410 configuration.setProjects(projectPage.getProjects());
412 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
413 configuration.setTempDirectory(preferencesPage.getTempDirectory());
415 return configuration.save();
419 * Finds a supported locale for the given locale.
422 * The locale to find a supported locale for
423 * @return The supported locale that was found, or the default locale if no
424 * supported locale could be found
426 private static Locale findSupportedLocale(Locale forLocale) {
427 for (Locale locale : SUPPORTED_LOCALES) {
428 if (locale.equals(forLocale)) {
432 for (Locale locale : SUPPORTED_LOCALES) {
433 if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
437 for (Locale locale : SUPPORTED_LOCALES) {
438 if (locale.getLanguage().equals(forLocale.getLanguage())) {
442 return SUPPORTED_LOCALES[0];
446 * Returns the version.
448 * @return The version
450 public static final Version getVersion() {
459 * Switches the language of the interface to the given locale.
462 * The locale to switch to
464 private void switchLanguage(Locale locale) {
465 Locale supportedLocale = findSupportedLocale(locale);
466 Action languageAction = languageActions.get(supportedLocale);
467 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
468 menuItem.setSelected(true);
469 I18n.setLocale(supportedLocale);
470 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
473 } catch (Throwable t) {
474 /* we probably shouldn't swallow this. */
477 wizard.setPage(wizard.getPage());
478 configuration.setLocale(supportedLocale);
482 * Shows a dialog with general preferences.
484 private void optionsPreferences() {
485 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationLocation(configuration.getConfigurationDirectory());
486 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasNextToJarConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.NEXT_TO_JAR_FILE));
487 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
488 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode());
489 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority());
490 showPage(PageType.PAGE_PREFERENCES);
491 optionsPreferencesAction.setEnabled(false);
492 wizard.setNextEnabled(true);
493 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
497 * Shows a dialog box that shows the last version that was found by the
498 * {@link UpdateChecker}.
500 private void showLatestUpdate() {
501 Version latestVersion = updateChecker.getLatestVersion();
502 int versionDifference = latestVersion.compareTo(VERSION);
503 if (versionDifference > 0) {
504 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);
505 } else if (versionDifference < 0) {
506 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);
508 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);
513 * Quits jSite, stopping all background services.
515 private void quit() {
516 updateChecker.stop();
521 // INTERFACE ListSelectionListener
528 public void valueChanged(ListSelectionEvent e) {
529 JList list = (JList) e.getSource();
530 int selectedRow = list.getSelectedIndex();
531 wizard.setNextEnabled(selectedRow > -1);
535 // INTERFACE WizardListener
542 public void wizardNextPressed(TWizard wizard) {
543 String pageName = wizard.getPage().getName();
544 if ("page.node-manager".equals(pageName)) {
545 showPage(PageType.PAGE_PROJECTS);
546 } else if ("page.project".equals(pageName)) {
547 ProjectPage projectPage = (ProjectPage) wizard.getPage();
548 Project project = projectPage.getSelectedProject();
549 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
550 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
553 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
554 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
557 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
558 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
559 showPage(PageType.PAGE_PROJECT_FILES);
560 } else if ("page.project.files".equals(pageName)) {
561 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
562 Project project = projectPage.getSelectedProject();
563 if (selectedNode == null) {
564 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
567 CheckReport checkReport = ProjectValidator.validateProject(project);
568 for (Issue issue : checkReport) {
569 if (issue.isFatal()) {
570 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
573 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) {
577 boolean nodeRunning = false;
579 nodeRunning = freenetInterface.isNodePresent();
580 } catch (IOException e) {
584 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
587 configuration.save();
588 showPage(PageType.PAGE_INSERT_PROJECT);
589 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
590 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
591 projectInsertPage.setTempDirectory(tempDirectory);
592 projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
593 projectInsertPage.setPriority(configuration.getPriority());
594 projectInsertPage.startInsert();
595 nodeMenu.setEnabled(false);
596 optionsPreferencesAction.setEnabled(false);
597 } else if ("page.project.insert".equals(pageName)) {
598 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
599 if (projectInsertPage.isRunning()) {
600 projectInsertPage.stopInsert();
602 showPage(PageType.PAGE_PROJECTS);
603 nodeMenu.setEnabled(true);
604 optionsPreferencesAction.setEnabled(true);
606 } else if ("page.preferences".equals(pageName)) {
607 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
608 showPage(PageType.PAGE_PROJECTS);
609 optionsPreferencesAction.setEnabled(true);
610 configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode());
611 configuration.setPriority(preferencesPage.getPriority());
612 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
620 public void wizardPreviousPressed(TWizard wizard) {
621 String pageName = wizard.getPage().getName();
622 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
623 showPage(PageType.PAGE_NODE_MANAGER);
624 optionsPreferencesAction.setEnabled(true);
625 } else if ("page.project.files".equals(pageName)) {
626 showPage(PageType.PAGE_PROJECTS);
627 } else if ("page.project.insert".equals(pageName)) {
628 showPage(PageType.PAGE_PROJECT_FILES);
636 public void wizardQuitPressed(TWizard wizard) {
637 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
638 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
640 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) {
641 if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
642 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);
643 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
644 if (saveConfiguration()) {
647 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
650 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
654 if (saveConfiguration()) {
658 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
665 // INTERFACE NodeManagerListener
672 public void nodesUpdated(Node[] nodes) {
673 nodeMenu.removeAll();
674 ButtonGroup nodeButtonGroup = new ButtonGroup();
675 Node newSelectedNode = null;
676 for (Node node : nodes) {
677 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
678 nodeMenuItem.putClientProperty("Node", node);
679 nodeMenuItem.addActionListener(this);
680 nodeButtonGroup.add(nodeMenuItem);
681 if (node.equals(selectedNode)) {
682 newSelectedNode = node;
683 nodeMenuItem.setSelected(true);
685 nodeMenu.add(nodeMenuItem);
687 nodeMenu.addSeparator();
688 nodeMenu.add(manageNodeAction);
689 selectedNode = newSelectedNode;
690 freenetInterface.setNode(selectedNode);
697 public void nodeSelected(Node node) {
698 for (Component menuItem : nodeMenu.getMenuComponents()) {
699 if (menuItem instanceof JMenuItem) {
700 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
701 ((JMenuItem) menuItem).setSelected(true);
705 freenetInterface.setNode(node);
710 // INTERFACE ActionListener
717 public void actionPerformed(ActionEvent e) {
718 Object source = e.getSource();
719 if (source instanceof JRadioButtonMenuItem) {
720 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
721 Node node = (Node) menuItem.getClientProperty("Node");
723 freenetInterface.setNode(selectedNode);
728 // INTERFACE UpdateListener
735 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
736 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
737 if (foundVersion.compareTo(VERSION) > 0) {
738 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);
747 * Main method that is called by the VM.
750 * The command-line arguments
752 public static void main(String[] args) {
753 /* initialize logger. */
754 Logger logger = Logger.getLogger("de.todesbaum");
755 Handler handler = new ConsoleHandler();
756 logger.addHandler(handler);
757 String configFilename = null;
758 boolean nextIsConfigFilename = false;
759 for (String argument : args) {
760 if (nextIsConfigFilename) {
761 configFilename = argument;
762 nextIsConfigFilename = false;
764 if ("--help".equals(argument)) {
767 } else if ("--debug".equals(argument)) {
768 logger.setLevel(Level.ALL);
769 handler.setLevel(Level.ALL);
770 } else if ("--config-file".equals(argument)) {
771 nextIsConfigFilename = true;
774 if (nextIsConfigFilename) {
775 System.out.println("--config-file needs parameter!");
778 new Main(configFilename);
782 * Prints a small syntax help.
784 private static void printHelp() {
785 System.out.println("--help\tshows this cruft");
786 System.out.println("--debug\tenables some debug output");
787 System.out.println("--config-file <file>\tuse specified configuration file");