X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Ftodesbaum%2Fjsite%2Fmain%2FMain.java;h=6a729125734bd314af367b5acdfa9cc93c6c2696;hb=e1a4a902cee612dc9cb7b182678f862dab8924c8;hp=38a0f1cf8b8012b66d7513f3027e7b697a58027c;hpb=c1a98d590bc8a8f4d2e53a092046a8d74474adb1;p=jSite.git diff --git a/src/main/java/de/todesbaum/jsite/main/Main.java b/src/main/java/de/todesbaum/jsite/main/Main.java index 38a0f1c..6a72912 100644 --- a/src/main/java/de/todesbaum/jsite/main/Main.java +++ b/src/main/java/de/todesbaum/jsite/main/Main.java @@ -1,5 +1,5 @@ /* - * jSite - Main.java - Copyright © 2006–2012 David Roden + * jSite - Main.java - Copyright © 2006–2014 David Roden * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,14 +47,16 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import net.pterodactylus.util.image.IconLoader; + import de.todesbaum.jsite.application.Freenet7Interface; import de.todesbaum.jsite.application.Node; import de.todesbaum.jsite.application.Project; -import de.todesbaum.jsite.application.ProjectInserter; -import de.todesbaum.jsite.application.ProjectInserter.CheckReport; -import de.todesbaum.jsite.application.ProjectInserter.Issue; import de.todesbaum.jsite.application.UpdateChecker; import de.todesbaum.jsite.application.UpdateListener; +import de.todesbaum.jsite.application.WebOfTrustInterface; +import de.todesbaum.jsite.application.validation.CheckReport; +import de.todesbaum.jsite.application.validation.Issue; +import de.todesbaum.jsite.application.validation.ProjectValidator; import de.todesbaum.jsite.gui.NodeManagerListener; import de.todesbaum.jsite.gui.NodeManagerPage; import de.todesbaum.jsite.gui.PreferencesPage; @@ -64,6 +66,7 @@ import de.todesbaum.jsite.gui.ProjectPage; import de.todesbaum.jsite.i18n.I18n; import de.todesbaum.jsite.i18n.I18nContainer; import de.todesbaum.jsite.main.ConfigurationLocator.ConfigurationLocation; +import de.todesbaum.jsite.main.JarFileLocator.DefaultJarFileLocator; import de.todesbaum.util.swing.TWizard; import de.todesbaum.util.swing.TWizardPage; import de.todesbaum.util.swing.WizardListener; @@ -79,7 +82,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen private static final Logger logger = Logger.getLogger(Main.class.getName()); /** The version. */ - private static final Version VERSION = new Version(0, 10); + private static final Version VERSION = new Version(0, 14); /** The configuration. */ private Configuration configuration; @@ -90,6 +93,9 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** The update checker. */ private final UpdateChecker updateChecker; + /** The web of trust interface. */ + private final WebOfTrustInterface webOfTrustInterface; + /** The jSite icon. */ private Icon jSiteIcon; @@ -118,7 +124,15 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen } /** The supported locales. */ - private static final Locale[] SUPPORTED_LOCALES = new Locale[] { Locale.ENGLISH, Locale.GERMAN, Locale.FRENCH }; + private static final Locale[] SUPPORTED_LOCALES = new Locale[] { + Locale.ENGLISH, + Locale.GERMAN, + Locale.FRENCH, + Locale.ITALIAN, + new Locale("es"), + new Locale("pl"), + new Locale("fi") + }; /** The actions that switch the language. */ private Map languageActions = new HashMap(); @@ -165,7 +179,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen */ private Main(String configFilename) { /* collect all possible configuration file locations. */ - ConfigurationLocator configurationLocator = new ConfigurationLocator(); + ConfigurationLocator configurationLocator = new ConfigurationLocator(new DefaultJarFileLocator(getClass().getClassLoader())); if (configFilename != null) { configurationLocator.setCustomLocation(configFilename); } @@ -186,10 +200,12 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen jSiteIcon = IconLoader.loadIcon("/jsite-icon.png"); wizard.setIcon(jSiteIcon); - updateChecker = new UpdateChecker(freenetInterface); + updateChecker = new UpdateChecker(freenetInterface, getVersion()); updateChecker.addUpdateListener(this); updateChecker.start(); + webOfTrustInterface = new WebOfTrustInterface(freenetInterface); + initPages(); showPage(PageType.PAGE_PROJECTS); } @@ -201,6 +217,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen for (final Locale locale : SUPPORTED_LOCALES) { languageActions.put(locale, new AbstractAction(I18n.getMessage("jsite.menu.language." + locale.getLanguage()), IconLoader.loadIcon("/flag-" + locale.getLanguage() + ".png")) { + @Override @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { switchLanguage(locale); @@ -209,6 +226,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen } manageNodeAction = new AbstractAction(I18n.getMessage("jsite.menu.nodes.manage-nodes")) { + @Override @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { showPage(PageType.PAGE_NODE_MANAGER); @@ -222,6 +240,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** * {@inheritDoc} */ + @Override @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { optionsPreferences(); @@ -232,6 +251,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** * {@inheritDoc} */ + @Override @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { showLatestUpdate(); @@ -239,6 +259,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen }; aboutAction = new AbstractAction(I18n.getMessage("jsite.menu.help.about")) { + @Override @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.about.message"), getVersion().toString()), null, JOptionPane.INFORMATION_MESSAGE, jSiteIcon); @@ -247,6 +268,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen I18nContainer.getInstance().registerRunnable(new Runnable() { + @Override @SuppressWarnings("synthetic-access") public void run() { manageNodeAction.putValue(Action.NAME, I18n.getMessage("jsite.menu.nodes.manage-nodes")); @@ -298,6 +320,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen I18nContainer.getInstance().registerRunnable(new Runnable() { + @Override @SuppressWarnings("synthetic-access") public void run() { languageMenu.setText(I18n.getMessage("jsite.menu.languages")); @@ -327,6 +350,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen projectPage.setName("page.project"); projectPage.setProjects(configuration.getProjects()); projectPage.setFreenetInterface(freenetInterface); + projectPage.setWebOfTrustInterface(webOfTrustInterface); projectPage.addListSelectionListener(this); pages.put(PageType.PAGE_PROJECTS, projectPage); @@ -399,7 +423,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen * @return The supported locale that was found, or the default locale if no * supported locale could be found */ - private Locale findSupportedLocale(Locale forLocale) { + private static Locale findSupportedLocale(Locale forLocale) { for (Locale locale : SUPPORTED_LOCALES) { if (locale.equals(forLocale)) { return locale; @@ -463,7 +487,6 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM)); ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode()); ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority()); - ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setManifestPutter(configuration.getManifestPutter()); showPage(PageType.PAGE_PREFERENCES); optionsPreferencesAction.setEnabled(false); wizard.setNextEnabled(true); @@ -486,6 +509,14 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen } } + /** + * Quits jSite, stopping all background services. + */ + private void quit() { + updateChecker.stop(); + System.exit(0); + } + // // INTERFACE ListSelectionListener // @@ -493,6 +524,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** * {@inheritDoc} */ + @Override public void valueChanged(ListSelectionEvent e) { JList list = (JList) e.getSource(); int selectedRow = list.getSelectedIndex(); @@ -506,6 +538,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** * {@inheritDoc} */ + @Override public void wizardNextPressed(TWizard wizard) { String pageName = wizard.getPage().getName(); if ("page.node-manager".equals(pageName)) { @@ -531,7 +564,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.error.no-node-selected"), null, JOptionPane.ERROR_MESSAGE); return; } - CheckReport checkReport = ProjectInserter.validateProject(project); + CheckReport checkReport = ProjectValidator.validateProject(project); for (Issue issue : checkReport) { if (issue.isFatal()) { JOptionPane.showMessageDialog(wizard, MessageFormat.format(I18n.getMessage("jsite." + issue.getErrorKey()), (Object[]) issue.getParameters()), null, JOptionPane.ERROR_MESSAGE); @@ -558,7 +591,6 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen projectInsertPage.setTempDirectory(tempDirectory); projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode()); projectInsertPage.setPriority(configuration.getPriority()); - projectInsertPage.setManifestPutter(configuration.getManifestPutter()); projectInsertPage.startInsert(); nodeMenu.setEnabled(false); optionsPreferencesAction.setEnabled(false); @@ -577,7 +609,6 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen optionsPreferencesAction.setEnabled(true); configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode()); configuration.setPriority(preferencesPage.getPriority()); - configuration.setManifestPutter(preferencesPage.getManifestPutter()); configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation()); } } @@ -585,6 +616,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** * {@inheritDoc} */ + @Override public void wizardPreviousPressed(TWizard wizard) { String pageName = wizard.getPage().getName(); if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) { @@ -600,6 +632,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** * {@inheritDoc} */ + @Override public void wizardQuitPressed(TWizard wizard) { if (((ProjectPage) pages.get(PageType.PAGE_PROJECTS)).wasUriCopied() || ((ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT)).wasUriCopied()) { JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now")); @@ -609,21 +642,21 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen 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); if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) { if (saveConfiguration()) { - System.exit(0); + quit(); } } else if (overwriteConfigurationAnswer == JOptionPane.CANCEL_OPTION) { return; } if (overwriteConfigurationAnswer == JOptionPane.NO_OPTION) { - System.exit(0); + quit(); } } else { if (saveConfiguration()) { - System.exit(0); + quit(); } } if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.config-not-saved"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { - System.exit(0); + quit(); } } } @@ -635,6 +668,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** * {@inheritDoc} */ + @Override public void nodesUpdated(Node[] nodes) { nodeMenu.removeAll(); ButtonGroup nodeButtonGroup = new ButtonGroup(); @@ -659,6 +693,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** * {@inheritDoc} */ + @Override public void nodeSelected(Node node) { for (Component menuItem : nodeMenu.getMenuComponents()) { if (menuItem instanceof JMenuItem) { @@ -678,6 +713,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** * {@inheritDoc} */ + @Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source instanceof JRadioButtonMenuItem) { @@ -695,6 +731,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** * {@inheritDoc} */ + @Override public void foundUpdateData(Version foundVersion, long versionTimestamp) { logger.log(Level.FINEST, "Found version {0} from {1,date}.", new Object[] { foundVersion, versionTimestamp }); if (foundVersion.compareTo(VERSION) > 0) {