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[] {
133 /** The actions that switch the language. */
134 private Map<Locale, Action> languageActions = new HashMap<Locale, Action>();
136 /** The āmanage nodesā action. */
137 private Action manageNodeAction;
139 /** The āpreferencesā action. */
140 private Action optionsPreferencesAction;
142 /** The ācheck for updatesā action. */
143 private Action checkForUpdatesAction;
145 /** The āabout jSiteā action. */
146 private Action aboutAction;
149 private TWizard wizard;
151 /** The node menu. */
152 private JMenu nodeMenu;
154 /** The currently selected node. */
155 private Node selectedNode;
157 /** Mapping from page type to page. */
158 private final Map<PageType, TWizardPage> pages = new HashMap<PageType, TWizardPage>();
160 /** The original location of the configuration file. */
161 private ConfigurationLocation originalLocation;
164 * Creates a new core with the default configuration file.
171 * Creates a new core with the given configuration from the given file.
173 * @param configFilename
174 * The name of the configuration file
176 private Main(String configFilename) {
177 /* collect all possible configuration file locations. */
178 ConfigurationLocator configurationLocator = new ConfigurationLocator();
179 if (configFilename != null) {
180 configurationLocator.setCustomLocation(configFilename);
183 originalLocation = configurationLocator.findPreferredLocation();
184 logger.log(Level.CONFIG, "Using configuration from " + originalLocation + ".");
185 configuration = new Configuration(configurationLocator, originalLocation);
187 Locale.setDefault(configuration.getLocale());
188 I18n.setLocale(configuration.getLocale());
189 wizard = new TWizard();
191 wizard.setJMenuBar(createMenuBar());
192 wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
193 wizard.setPreviousEnabled(false);
194 wizard.setNextEnabled(true);
195 wizard.addWizardListener(this);
196 jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
197 wizard.setIcon(jSiteIcon);
199 updateChecker = new UpdateChecker(freenetInterface);
200 updateChecker.addUpdateListener(this);
201 updateChecker.start();
203 webOfTrustInterface = new WebOfTrustInterface(freenetInterface);
206 showPage(PageType.PAGE_PROJECTS);
210 * Creates all actions.
212 private void createActions() {
213 for (final Locale locale : SUPPORTED_LOCALES) {
214 languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
217 @SuppressWarnings("synthetic-access")
218 public void actionPerformed(ActionEvent actionEvent) {
219 switchLanguage(locale);
223 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
226 @SuppressWarnings("synthetic-access")
227 public void actionPerformed(ActionEvent actionEvent) {
228 showPage(PageType.PAGE_NODE_MANAGER);
229 optionsPreferencesAction.setEnabled(true);
230 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
231 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
234 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
240 @SuppressWarnings("synthetic-access")
241 public void actionPerformed(ActionEvent actionEvent) {
242 optionsPreferences();
245 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
251 @SuppressWarnings("synthetic-access")
252 public void actionPerformed(ActionEvent actionEvent) {
256 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
259 @SuppressWarnings("synthetic-access")
260 public void actionPerformed(ActionEvent e) {
261 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
265 I18nContainer.getInstance().registerRunnable(new Runnable() {
268 @SuppressWarnings("synthetic-access")
270 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
271 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
272 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
273 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
279 * Creates the menu bar.
281 * @return The menu bar
283 private JMenuBar createMenuBar() {
284 JMenuBar menuBar = new JMenuBar();
285 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
286 menuBar.add(languageMenu);
287 ButtonGroup languageButtonGroup = new ButtonGroup();
288 for (Locale locale : SUPPORTED_LOCALES) {
289 Action languageAction = languageActions.get(locale);
290 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
291 if (locale.equals(Locale.getDefault())) {
292 menuItem.setSelected(true);
294 languageAction.putValue("menuItem", menuItem);
295 languageButtonGroup.add(menuItem);
296 languageMenu.add(menuItem);
298 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
299 menuBar.add(nodeMenu);
300 selectedNode = configuration.getSelectedNode();
301 nodesUpdated(configuration.getNodes());
303 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
304 menuBar.add(optionsMenu);
305 optionsMenu.add(optionsPreferencesAction);
307 /* evil hack to right-align the help menu */
308 JPanel panel = new JPanel();
309 panel.setOpaque(false);
312 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
313 menuBar.add(helpMenu);
314 helpMenu.add(checkForUpdatesAction);
315 helpMenu.add(aboutAction);
317 I18nContainer.getInstance().registerRunnable(new Runnable() {
320 @SuppressWarnings("synthetic-access")
322 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
323 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
324 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
325 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
326 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
327 languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
336 * Initializes all pages.
338 private void initPages() {
339 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
340 nodeManagerPage.setName("page.node-manager");
341 nodeManagerPage.addNodeManagerListener(this);
342 nodeManagerPage.setNodes(configuration.getNodes());
343 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
345 ProjectPage projectPage = new ProjectPage(wizard);
346 projectPage.setName("page.project");
347 projectPage.setProjects(configuration.getProjects());
348 projectPage.setFreenetInterface(freenetInterface);
349 projectPage.setWebOfTrustInterface(webOfTrustInterface);
350 projectPage.addListSelectionListener(this);
351 pages.put(PageType.PAGE_PROJECTS, projectPage);
353 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
354 projectFilesPage.setName("page.project.files");
355 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
357 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
358 projectInsertPage.setName("page.project.insert");
359 projectInsertPage.setFreenetInterface(freenetInterface);
360 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
362 PreferencesPage preferencesPage = new PreferencesPage(wizard);
363 preferencesPage.setName("page.preferences");
364 preferencesPage.setTempDirectory(configuration.getTempDirectory());
365 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
369 * Shows the page with the given type.
372 * The page type to show
374 private void showPage(PageType pageType) {
375 wizard.setPreviousEnabled(pageType.ordinal() > 0);
376 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
377 wizard.setPage(pages.get(pageType));
378 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
382 * Returns whether a configuration file would be overwritten when calling
383 * {@link #saveConfiguration()}.
385 * @return {@code true} if {@link #saveConfiguration()} would overwrite an
386 * existing file, {@code false} otherwise
388 private boolean isOverwritingConfiguration() {
389 return configuration.getConfigurationLocator().hasFile(configuration.getConfigurationDirectory());
393 * Saves the configuration.
395 * @return <code>true</code> if the configuration could be saved,
396 * <code>false</code> otherwise
398 private boolean saveConfiguration() {
399 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
400 configuration.setNodes(nodeManagerPage.getNodes());
401 if (selectedNode != null) {
402 configuration.setSelectedNode(selectedNode);
405 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
406 configuration.setProjects(projectPage.getProjects());
408 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
409 configuration.setTempDirectory(preferencesPage.getTempDirectory());
411 return configuration.save();
415 * Finds a supported locale for the given locale.
418 * The locale to find a supported locale for
419 * @return The supported locale that was found, or the default locale if no
420 * supported locale could be found
422 private static Locale findSupportedLocale(Locale forLocale) {
423 for (Locale locale : SUPPORTED_LOCALES) {
424 if (locale.equals(forLocale)) {
428 for (Locale locale : SUPPORTED_LOCALES) {
429 if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
433 for (Locale locale : SUPPORTED_LOCALES) {
434 if (locale.getLanguage().equals(forLocale.getLanguage())) {
438 return SUPPORTED_LOCALES[0];
442 * Returns the version.
444 * @return The version
446 public static final Version getVersion() {
455 * Switches the language of the interface to the given locale.
458 * The locale to switch to
460 private void switchLanguage(Locale locale) {
461 Locale supportedLocale = findSupportedLocale(locale);
462 Action languageAction = languageActions.get(supportedLocale);
463 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
464 menuItem.setSelected(true);
465 I18n.setLocale(supportedLocale);
466 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
469 } catch (Throwable t) {
470 /* we probably shouldn't swallow this. */
473 wizard.setPage(wizard.getPage());
474 configuration.setLocale(supportedLocale);
478 * Shows a dialog with general preferences.
480 private void optionsPreferences() {
481 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationLocation(configuration.getConfigurationDirectory());
482 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasNextToJarConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.NEXT_TO_JAR_FILE));
483 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
484 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode());
485 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority());
486 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setManifestPutter(configuration.getManifestPutter());
487 showPage(PageType.PAGE_PREFERENCES);
488 optionsPreferencesAction.setEnabled(false);
489 wizard.setNextEnabled(true);
490 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
494 * Shows a dialog box that shows the last version that was found by the
495 * {@link UpdateChecker}.
497 private void showLatestUpdate() {
498 Version latestVersion = updateChecker.getLatestVersion();
499 int versionDifference = latestVersion.compareTo(VERSION);
500 if (versionDifference > 0) {
501 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);
502 } else if (versionDifference < 0) {
503 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);
505 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);
510 * Quits jSite, stopping all background services.
512 private void quit() {
513 updateChecker.stop();
518 // INTERFACE ListSelectionListener
525 public void valueChanged(ListSelectionEvent e) {
526 JList list = (JList) e.getSource();
527 int selectedRow = list.getSelectedIndex();
528 wizard.setNextEnabled(selectedRow > -1);
532 // INTERFACE WizardListener
539 public void wizardNextPressed(TWizard wizard) {
540 String pageName = wizard.getPage().getName();
541 if ("page.node-manager".equals(pageName)) {
542 showPage(PageType.PAGE_PROJECTS);
543 } else if ("page.project".equals(pageName)) {
544 ProjectPage projectPage = (ProjectPage) wizard.getPage();
545 Project project = projectPage.getSelectedProject();
546 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
547 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
550 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
551 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
554 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
555 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
556 showPage(PageType.PAGE_PROJECT_FILES);
557 } else if ("page.project.files".equals(pageName)) {
558 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
559 Project project = projectPage.getSelectedProject();
560 if (selectedNode == null) {
561 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
564 CheckReport checkReport = ProjectInserter.validateProject(project);
565 for (Issue issue : checkReport) {
566 if (issue.isFatal()) {
567 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
570 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) {
574 boolean nodeRunning = false;
576 nodeRunning = freenetInterface.isNodePresent();
577 } catch (IOException e) {
581 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
584 configuration.save();
585 showPage(PageType.PAGE_INSERT_PROJECT);
586 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
587 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
588 projectInsertPage.setTempDirectory(tempDirectory);
589 projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
590 projectInsertPage.setPriority(configuration.getPriority());
591 projectInsertPage.setManifestPutter(configuration.getManifestPutter());
592 projectInsertPage.startInsert();
593 nodeMenu.setEnabled(false);
594 optionsPreferencesAction.setEnabled(false);
595 } else if ("page.project.insert".equals(pageName)) {
596 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
597 if (projectInsertPage.isRunning()) {
598 projectInsertPage.stopInsert();
600 showPage(PageType.PAGE_PROJECTS);
601 nodeMenu.setEnabled(true);
602 optionsPreferencesAction.setEnabled(true);
604 } else if ("page.preferences".equals(pageName)) {
605 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
606 showPage(PageType.PAGE_PROJECTS);
607 optionsPreferencesAction.setEnabled(true);
608 configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode());
609 configuration.setPriority(preferencesPage.getPriority());
610 configuration.setManifestPutter(preferencesPage.getManifestPutter());
611 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
619 public void wizardPreviousPressed(TWizard wizard) {
620 String pageName = wizard.getPage().getName();
621 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
622 showPage(PageType.PAGE_NODE_MANAGER);
623 optionsPreferencesAction.setEnabled(true);
624 } else if ("page.project.files".equals(pageName)) {
625 showPage(PageType.PAGE_PROJECTS);
626 } else if ("page.project.insert".equals(pageName)) {
627 showPage(PageType.PAGE_PROJECT_FILES);
635 public void wizardQuitPressed(TWizard wizard) {
636 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
637 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
639 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) {
640 if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
641 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);
642 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
643 if (saveConfiguration()) {
646 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
649 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
653 if (saveConfiguration()) {
657 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
664 // INTERFACE NodeManagerListener
671 public void nodesUpdated(Node[] nodes) {
672 nodeMenu.removeAll();
673 ButtonGroup nodeButtonGroup = new ButtonGroup();
674 Node newSelectedNode = null;
675 for (Node node : nodes) {
676 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
677 nodeMenuItem.putClientProperty("Node", node);
678 nodeMenuItem.addActionListener(this);
679 nodeButtonGroup.add(nodeMenuItem);
680 if (node.equals(selectedNode)) {
681 newSelectedNode = node;
682 nodeMenuItem.setSelected(true);
684 nodeMenu.add(nodeMenuItem);
686 nodeMenu.addSeparator();
687 nodeMenu.add(manageNodeAction);
688 selectedNode = newSelectedNode;
689 freenetInterface.setNode(selectedNode);
696 public void nodeSelected(Node node) {
697 for (Component menuItem : nodeMenu.getMenuComponents()) {
698 if (menuItem instanceof JMenuItem) {
699 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
700 ((JMenuItem) menuItem).setSelected(true);
704 freenetInterface.setNode(node);
709 // INTERFACE ActionListener
716 public void actionPerformed(ActionEvent e) {
717 Object source = e.getSource();
718 if (source instanceof JRadioButtonMenuItem) {
719 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
720 Node node = (Node) menuItem.getClientProperty("Node");
722 freenetInterface.setNode(selectedNode);
727 // INTERFACE UpdateListener
734 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
735 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
736 if (foundVersion.compareTo(VERSION) > 0) {
737 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);
746 * Main method that is called by the VM.
749 * The command-line arguments
751 public static void main(String[] args) {
752 /* initialize logger. */
753 Logger logger = Logger.getLogger("de.todesbaum");
754 Handler handler = new ConsoleHandler();
755 logger.addHandler(handler);
756 String configFilename = null;
757 boolean nextIsConfigFilename = false;
758 for (String argument : args) {
759 if (nextIsConfigFilename) {
760 configFilename = argument;
761 nextIsConfigFilename = false;
763 if ("--help".equals(argument)) {
766 } else if ("--debug".equals(argument)) {
767 logger.setLevel(Level.ALL);
768 handler.setLevel(Level.ALL);
769 } else if ("--config-file".equals(argument)) {
770 nextIsConfigFilename = true;
773 if (nextIsConfigFilename) {
774 System.out.println("--config-file needs parameter!");
777 new Main(configFilename);
781 * Prints a small syntax help.
783 private static void printHelp() {
784 System.out.println("--help\tshows this cruft");
785 System.out.println("--debug\tenables some debug output");
786 System.out.println("--config-file <file>\tuse specified configuration file");