2 * jSite - Main.java - Copyright © 2006–2011 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 de.todesbaum.jsite.application.Freenet7Interface;
50 import de.todesbaum.jsite.application.Node;
51 import de.todesbaum.jsite.application.Project;
52 import de.todesbaum.jsite.application.ProjectInserter;
53 import de.todesbaum.jsite.application.UpdateChecker;
54 import de.todesbaum.jsite.application.UpdateListener;
55 import de.todesbaum.jsite.application.ProjectInserter.CheckReport;
56 import de.todesbaum.jsite.application.ProjectInserter.Issue;
57 import de.todesbaum.jsite.gui.NodeManagerListener;
58 import de.todesbaum.jsite.gui.NodeManagerPage;
59 import de.todesbaum.jsite.gui.PreferencesPage;
60 import de.todesbaum.jsite.gui.ProjectFilesPage;
61 import de.todesbaum.jsite.gui.ProjectInsertPage;
62 import de.todesbaum.jsite.gui.ProjectPage;
63 import de.todesbaum.jsite.i18n.I18n;
64 import de.todesbaum.jsite.i18n.I18nContainer;
65 import de.todesbaum.jsite.main.ConfigurationLocator.ConfigurationLocation;
66 import de.todesbaum.util.image.IconLoader;
67 import de.todesbaum.util.swing.TWizard;
68 import de.todesbaum.util.swing.TWizardPage;
69 import de.todesbaum.util.swing.WizardListener;
72 * The main class that ties together everything.
74 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
76 public class Main implements ActionListener, ListSelectionListener, WizardListener, NodeManagerListener, UpdateListener {
79 private static final Logger logger = Logger.getLogger(Main.class.getName());
82 private static final Version VERSION = new Version(0, 9, 2);
84 /** The configuration. */
85 private Configuration configuration;
87 /** The freenet interface. */
88 private Freenet7Interface freenetInterface = new Freenet7Interface();
90 /** The update checker. */
91 private final UpdateChecker updateChecker;
93 /** The jSite icon. */
94 private Icon jSiteIcon;
97 * Enumeration for all possible pages.
99 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
101 private static enum PageType {
103 /** The node manager page. */
106 /** The project page. */
109 /** The project files page. */
112 /** The project insert page. */
115 /** The preferences page. */
120 /** The supported locales. */
121 private static final Locale[] SUPPORTED_LOCALES = new Locale[] { Locale.ENGLISH, Locale.GERMAN, Locale.FRENCH };
123 /** The actions that switch the language. */
124 private Map<Locale, Action> languageActions = new HashMap<Locale, Action>();
126 /** The “manage nodes” action. */
127 private Action manageNodeAction;
129 /** The “preferences” action. */
130 private Action optionsPreferencesAction;
132 /** The “check for updates” action. */
133 private Action checkForUpdatesAction;
135 /** The “about jSite” action. */
136 private Action aboutAction;
139 private TWizard wizard;
141 /** The node menu. */
142 private JMenu nodeMenu;
144 /** The currently selected node. */
145 private Node selectedNode;
147 /** Mapping from page type to page. */
148 private final Map<PageType, TWizardPage> pages = new HashMap<PageType, TWizardPage>();
151 * Creates a new core with the default configuration file.
158 * Creates a new core with the given configuration from the given file.
160 * @param configFilename
161 * The name of the configuration file
163 private Main(String configFilename) {
164 /* collect all possible configuration file locations. */
165 ConfigurationLocator configurationLocator = new ConfigurationLocator();
166 if (configFilename != null) {
167 configurationLocator.setCustomLocation(configFilename);
170 ConfigurationLocation preferredLocation = configurationLocator.findPreferredLocation();
171 logger.log(Level.CONFIG, "Using configuration from " + preferredLocation + ".");
172 configuration = new Configuration(configurationLocator, preferredLocation);
174 Locale.setDefault(configuration.getLocale());
175 I18n.setLocale(configuration.getLocale());
176 wizard = new TWizard();
178 wizard.setJMenuBar(createMenuBar());
179 wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
180 wizard.setPreviousEnabled(false);
181 wizard.setNextEnabled(true);
182 wizard.addWizardListener(this);
183 jSiteIcon = IconLoader.loadIcon("/jsite-icon.png");
184 wizard.setIcon(jSiteIcon);
186 updateChecker = new UpdateChecker(freenetInterface);
187 updateChecker.addUpdateListener(this);
188 updateChecker.start();
191 showPage(PageType.PAGE_PROJECTS);
195 * Creates all actions.
197 private void createActions() {
198 for (final Locale locale : SUPPORTED_LOCALES) {
199 languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) {
201 @SuppressWarnings("synthetic-access")
202 public void actionPerformed(ActionEvent actionEvent) {
203 switchLanguage(locale);
207 manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) {
209 @SuppressWarnings("synthetic-access")
210 public void actionPerformed(ActionEvent actionEvent) {
211 showPage(PageType.PAGE_NODE_MANAGER);
212 optionsPreferencesAction.setEnabled(true);
213 wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
214 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
217 optionsPreferencesAction = new AbstractAction(I18n.getMessage("jsite.menu.options.preferences")) {
222 @SuppressWarnings("synthetic-access")
223 public void actionPerformed(ActionEvent actionEvent) {
224 optionsPreferences();
227 checkForUpdatesAction = new AbstractAction(I18n.getMessage("jsite.menu.help.check-for-updates")) {
232 @SuppressWarnings("synthetic-access")
233 public void actionPerformed(ActionEvent actionEvent) {
237 aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) {
239 @SuppressWarnings("synthetic-access")
240 public void actionPerformed(ActionEvent e) {
241 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon);
245 I18nContainer.getInstance().registerRunnable(new Runnable() {
247 @SuppressWarnings("synthetic-access")
249 manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes"));
250 optionsPreferencesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.options.preferences"));
251 checkForUpdatesAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.check-for-updates"));
252 aboutAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.help.about"));
258 * Creates the menu bar.
260 * @return The menu bar
262 private JMenuBar createMenuBar() {
263 JMenuBar menuBar = new JMenuBar();
264 final JMenu languageMenu = new JMenu(I18n.getMessage("jsite.menu.languages"));
265 menuBar.add(languageMenu);
266 ButtonGroup languageButtonGroup = new ButtonGroup();
267 for (Locale locale : SUPPORTED_LOCALES) {
268 Action languageAction = languageActions.get(locale);
269 JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(languageActions.get(locale));
270 if (locale.equals(Locale.getDefault())) {
271 menuItem.setSelected(true);
273 languageAction.putValue("menuItem", menuItem);
274 languageButtonGroup.add(menuItem);
275 languageMenu.add(menuItem);
277 nodeMenu = new JMenu(I18n.getMessage("jsite.menu.nodes"));
278 menuBar.add(nodeMenu);
279 selectedNode = configuration.getSelectedNode();
280 nodesUpdated(configuration.getNodes());
282 final JMenu optionsMenu = new JMenu(I18n.getMessage("jsite.menu.options"));
283 menuBar.add(optionsMenu);
284 optionsMenu.add(optionsPreferencesAction);
286 /* evil hack to right-align the help menu */
287 JPanel panel = new JPanel();
288 panel.setOpaque(false);
291 final JMenu helpMenu = new JMenu(I18n.getMessage("jsite.menu.help"));
292 menuBar.add(helpMenu);
293 helpMenu.add(checkForUpdatesAction);
294 helpMenu.add(aboutAction);
296 I18nContainer.getInstance().registerRunnable(new Runnable() {
298 @SuppressWarnings("synthetic-access")
300 languageMenu.setText(I18n.getMessage("jsite.menu.languages"));
301 nodeMenu.setText(I18n.getMessage("jsite.menu.nodes"));
302 optionsMenu.setText(I18n.getMessage("jsite.menu.options"));
303 helpMenu.setText(I18n.getMessage("jsite.menu.help"));
304 for (Map.Entry<Locale, Action> languageActionEntry : languageActions.entrySet()) {
305 languageActionEntry.getValue().putValue(Action.NAME, I18n.getMessage("jsite.menu.language." + languageActionEntry.getKey().getLanguage()));
314 * Initializes all pages.
316 private void initPages() {
317 NodeManagerPage nodeManagerPage = new NodeManagerPage(wizard);
318 nodeManagerPage.setName("page.node-manager");
319 nodeManagerPage.addNodeManagerListener(this);
320 nodeManagerPage.setNodes(configuration.getNodes());
321 pages.put(PageType.PAGE_NODE_MANAGER, nodeManagerPage);
323 ProjectPage projectPage = new ProjectPage(wizard);
324 projectPage.setName("page.project");
325 projectPage.setProjects(configuration.getProjects());
326 projectPage.setFreenetInterface(freenetInterface);
327 projectPage.addListSelectionListener(this);
328 pages.put(PageType.PAGE_PROJECTS, projectPage);
330 ProjectFilesPage projectFilesPage = new ProjectFilesPage(wizard);
331 projectFilesPage.setName("page.project.files");
332 pages.put(PageType.PAGE_PROJECT_FILES, projectFilesPage);
334 ProjectInsertPage projectInsertPage = new ProjectInsertPage(wizard);
335 projectInsertPage.setName("page.project.insert");
336 projectInsertPage.setFreenetInterface(freenetInterface);
337 pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage);
339 PreferencesPage preferencesPage = new PreferencesPage(wizard);
340 preferencesPage.setName("page.preferences");
341 preferencesPage.setTempDirectory(configuration.getTempDirectory());
342 pages.put(PageType.PAGE_PREFERENCES, preferencesPage);
346 * Shows the page with the given type.
349 * The page type to show
351 private void showPage(PageType pageType) {
352 wizard.setPreviousEnabled(pageType.ordinal() > 0);
353 wizard.setNextEnabled(pageType.ordinal() < (pages.size() - 1));
354 wizard.setPage(pages.get(pageType));
355 wizard.setTitle(pages.get(pageType).getHeading() + " - jSite");
359 * Returns whether a configuration file would be overwritten when calling
360 * {@link #saveConfiguration()}.
362 * @return {@code true} if {@link #saveConfiguration()} would overwrite an
363 * existing file, {@code false} otherwise
365 private boolean isOverwritingConfiguration() {
366 return configuration.getConfigurationLocator().hasFile(configuration.getConfigurationDirectory());
370 * Saves the configuration.
372 * @return <code>true</code> if the configuration could be saved,
373 * <code>false</code> otherwise
375 private boolean saveConfiguration() {
376 NodeManagerPage nodeManagerPage = (NodeManagerPage) pages.get(PageType.PAGE_NODE_MANAGER);
377 configuration.setNodes(nodeManagerPage.getNodes());
378 if (selectedNode != null) {
379 configuration.setSelectedNode(selectedNode);
382 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
383 configuration.setProjects(projectPage.getProjects());
385 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
386 configuration.setTempDirectory(preferencesPage.getTempDirectory());
388 return configuration.save();
392 * Finds a supported locale for the given locale.
395 * The locale to find a supported locale for
396 * @return The supported locale that was found, or the default locale if no
397 * supported locale could be found
399 private Locale findSupportedLocale(Locale forLocale) {
400 for (Locale locale : SUPPORTED_LOCALES) {
401 if (locale.equals(forLocale)) {
405 for (Locale locale : SUPPORTED_LOCALES) {
406 if (locale.getCountry().equals(forLocale.getCountry()) && locale.getLanguage().equals(forLocale.getLanguage())) {
410 for (Locale locale : SUPPORTED_LOCALES) {
411 if (locale.getLanguage().equals(forLocale.getLanguage())) {
415 return SUPPORTED_LOCALES[0];
419 * Returns the version.
421 * @return The version
423 public static final Version getVersion() {
432 * Switches the language of the interface to the given locale.
435 * The locale to switch to
437 private void switchLanguage(Locale locale) {
438 Locale supportedLocale = findSupportedLocale(locale);
439 Action languageAction = languageActions.get(supportedLocale);
440 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) languageAction.getValue("menuItem");
441 menuItem.setSelected(true);
442 I18n.setLocale(supportedLocale);
443 for (Runnable i18nRunnable : I18nContainer.getInstance()) {
446 } catch (Throwable t) {
447 /* we probably shouldn't swallow this. */
450 wizard.setPage(wizard.getPage());
451 configuration.setLocale(supportedLocale);
455 * Shows a dialog with general preferences.
457 private void optionsPreferences() {
458 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationLocation(configuration.getConfigurationDirectory());
459 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasNextToJarConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.NEXT_TO_JAR_FILE));
460 ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
461 showPage(PageType.PAGE_PREFERENCES);
462 optionsPreferencesAction.setEnabled(false);
463 wizard.setNextEnabled(true);
464 wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
468 * Shows a dialog box that shows the last version that was found by the
469 * {@link UpdateChecker}.
471 private void showLatestUpdate() {
472 Version latestVersion = updateChecker.getLatestVersion();
473 int versionDifference = latestVersion.compareTo(VERSION);
474 if (versionDifference > 0) {
475 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);
476 } else if (versionDifference < 0) {
477 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);
479 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);
484 // INTERFACE ListSelectionListener
490 public void valueChanged(ListSelectionEvent e) {
491 JList list = (JList) e.getSource();
492 int selectedRow = list.getSelectedIndex();
493 wizard.setNextEnabled(selectedRow > -1);
497 // INTERFACE WizardListener
503 public void wizardNextPressed(TWizard wizard) {
504 String pageName = wizard.getPage().getName();
505 if ("page.node-manager".equals(pageName)) {
506 showPage(PageType.PAGE_PROJECTS);
507 } else if ("page.project".equals(pageName)) {
508 ProjectPage projectPage = (ProjectPage) wizard.getPage();
509 Project project = projectPage.getSelectedProject();
510 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
511 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-local-path"), null, JOptionPane.ERROR_MESSAGE);
514 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
515 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.warning.no-path"), null, JOptionPane.ERROR_MESSAGE);
518 ((ProjectFilesPage) pages.get(PageType.PAGE_PROJECT_FILES)).setProject(project);
519 ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).setProject(project);
520 showPage(PageType.PAGE_PROJECT_FILES);
521 } else if ("page.project.files".equals(pageName)) {
522 ProjectPage projectPage = (ProjectPage) pages.get(PageType.PAGE_PROJECTS);
523 Project project = projectPage.getSelectedProject();
524 if (selectedNode == null) {
525 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
528 CheckReport checkReport = ProjectInserter.validateProject(project);
529 for (Issue issue : checkReport) {
530 if (issue.isFatal()) {
531 JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE);
534 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) {
538 boolean nodeRunning = false;
540 nodeRunning = freenetInterface.isNodePresent();
541 } catch (IOException e) {
545 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-running"), null, JOptionPane.ERROR_MESSAGE);
548 configuration.save();
549 showPage(PageType.PAGE_INSERT_PROJECT);
550 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
551 String tempDirectory = ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).getTempDirectory();
552 projectInsertPage.setTempDirectory(tempDirectory);
553 projectInsertPage.startInsert();
554 nodeMenu.setEnabled(false);
555 optionsPreferencesAction.setEnabled(false);
556 } else if ("page.project.insert".equals(pageName)) {
557 ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT);
558 if (projectInsertPage.isRunning()) {
559 projectInsertPage.stopInsert();
561 showPage(PageType.PAGE_PROJECTS);
562 nodeMenu.setEnabled(true);
563 optionsPreferencesAction.setEnabled(true);
565 } else if ("page.preferences".equals(pageName)) {
566 PreferencesPage preferencesPage = (PreferencesPage) pages.get(PageType.PAGE_PREFERENCES);
567 showPage(PageType.PAGE_PROJECTS);
568 optionsPreferencesAction.setEnabled(true);
569 configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
576 public void wizardPreviousPressed(TWizard wizard) {
577 String pageName = wizard.getPage().getName();
578 if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) {
579 showPage(PageType.PAGE_NODE_MANAGER);
580 optionsPreferencesAction.setEnabled(true);
581 } else if ("page.project.files".equals(pageName)) {
582 showPage(PageType.PAGE_PROJECTS);
583 } else if ("page.project.insert".equals(pageName)) {
584 showPage(PageType.PAGE_PROJECT_FILES);
591 public void wizardQuitPressed(TWizard wizard) {
592 if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) {
593 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
595 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) {
596 if (isOverwritingConfiguration()) {
597 int overwriteConfigurationAnswer = JOptionPane.showConfirmDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.quite.overwrite-configuration"), configuration.getConfigurationLocator().getFile(configuration.getConfigurationDirectory())), I18n.getMessage("jsite.quit.overwrite-configuration.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
598 if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
599 if (saveConfiguration()) {
602 } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) {
605 if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) {
609 if (saveConfiguration()) {
613 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
620 // INTERFACE NodeManagerListener
626 public void nodesUpdated(Node[] nodes) {
627 nodeMenu.removeAll();
628 ButtonGroup nodeButtonGroup = new ButtonGroup();
629 Node newSelectedNode = null;
630 for (Node node : nodes) {
631 JRadioButtonMenuItem nodeMenuItem = new JRadioButtonMenuItem(node.getName());
632 nodeMenuItem.putClientProperty("Node", node);
633 nodeMenuItem.addActionListener(this);
634 nodeButtonGroup.add(nodeMenuItem);
635 if (node.equals(selectedNode)) {
636 newSelectedNode = node;
637 nodeMenuItem.setSelected(true);
639 nodeMenu.add(nodeMenuItem);
641 nodeMenu.addSeparator();
642 nodeMenu.add(manageNodeAction);
643 selectedNode = newSelectedNode;
644 freenetInterface.setNode(selectedNode);
650 public void nodeSelected(Node node) {
651 for (Component menuItem : nodeMenu.getMenuComponents()) {
652 if (menuItem instanceof JMenuItem) {
653 if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
654 ((JMenuItem) menuItem).setSelected(true);
658 freenetInterface.setNode(node);
663 // INTERFACE ActionListener
669 public void actionPerformed(ActionEvent e) {
670 Object source = e.getSource();
671 if (source instanceof JRadioButtonMenuItem) {
672 JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) source;
673 Node node = (Node) menuItem.getClientProperty("Node");
675 freenetInterface.setNode(selectedNode);
680 // INTERFACE UpdateListener
686 public void foundUpdateData(Version foundVersion, long versionTimestamp) {
687 logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp });
688 if (foundVersion.compareTo(VERSION) > 0) {
689 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);
698 * Main method that is called by the VM.
701 * The command-line arguments
703 public static void main(String[] args) {
704 /* initialize logger. */
705 Logger logger = Logger.getLogger("de.todesbaum");
706 Handler handler = new ConsoleHandler();
707 logger.addHandler(handler);
708 String configFilename = null;
709 boolean nextIsConfigFilename = false;
710 for (String argument : args) {
711 if (nextIsConfigFilename) {
712 configFilename = argument;
713 nextIsConfigFilename = false;
715 if ("--help".equals(argument)) {
718 } else if ("--debug".equals(argument)) {
719 logger.setLevel(Level.ALL);
720 handler.setLevel(Level.ALL);
721 } else if ("--config-file".equals(argument)) {
722 nextIsConfigFilename = true;
725 if (nextIsConfigFilename) {
726 System.out.println("--config-file needs parameter!");
729 new Main(configFilename);
733 * Prints a small syntax help.
735 private static void printHelp() {
736 System.out.println("--help\tshows this cruft");
737 System.out.println("--debug\tenables some debug output");
738 System.out.println("--config-file <file>\tuse specified configuration file");