X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fmain%2FMain.java;h=e654c914d13b671a764e5c379689380e958f50ea;hb=a03efa6ebf81fc25c9b3e4effdd1529e956ad24b;hp=017f1c53698565f4888fd86a34590b39096e3891;hpb=a2724e9eb5094194cc9ec17185c324f84360353f;p=jSite.git diff --git a/src/de/todesbaum/jsite/main/Main.java b/src/de/todesbaum/jsite/main/Main.java index 017f1c5..e654c91 100644 --- a/src/de/todesbaum/jsite/main/Main.java +++ b/src/de/todesbaum/jsite/main/Main.java @@ -19,8 +19,10 @@ package de.todesbaum.jsite.main; +import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.File; import java.io.IOException; import java.text.MessageFormat; import java.util.Date; @@ -39,6 +41,7 @@ import javax.swing.Icon; import javax.swing.JList; import javax.swing.JMenu; import javax.swing.JMenuBar; +import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButtonMenuItem; @@ -61,6 +64,7 @@ import de.todesbaum.jsite.gui.ProjectInsertPage; import de.todesbaum.jsite.gui.ProjectPage; import de.todesbaum.jsite.i18n.I18n; import de.todesbaum.jsite.i18n.I18nContainer; +import de.todesbaum.jsite.main.Configuration.ConfigurationDirectory; import de.todesbaum.util.image.IconLoader; import de.todesbaum.util.swing.TWizard; import de.todesbaum.util.swing.TWizardPage; @@ -77,7 +81,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, 8); + private static final Version VERSION = new Version(0, 9, 2); /** The configuration. */ private Configuration configuration; @@ -162,7 +166,20 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen if (configFilename != null) { configuration = new Configuration(configFilename); } else { - configuration = new Configuration(); + /* are we executed from a JAR file? */ + String resource = getClass().getResource("/de/todesbaum/jsite/i18n/jSite.properties").toString(); + if (resource.startsWith("jar:")) { + String jarFileLocation = resource.substring(9, resource.indexOf(".jar!") + 4); + String jarFileDirectory = new File(jarFileLocation).getParent(); + File configurationFile = new File(jarFileDirectory, "jSite.conf"); + if (configurationFile.exists()) { + configuration = new Configuration(configurationFile.getAbsolutePath()); + configuration.setConfigurationDirectory(ConfigurationDirectory.NEXT_TO_JAR_FILE); + } + } + if (configuration == null) { + configuration = new Configuration(); + } } Locale.setDefault(configuration.getLocale()); I18n.setLocale(configuration.getLocale()); @@ -209,6 +226,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { showPage(PageType.PAGE_NODE_MANAGER); + optionsPreferencesAction.setEnabled(true); wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous")); wizard.setNextName(I18n.getMessage("jsite.wizard.next")); } @@ -335,7 +353,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen projectInsertPage.setFreenetInterface(freenetInterface); pages.put(PageType.PAGE_INSERT_PROJECT, projectInsertPage); - PreferencesPage preferencesPage = new PreferencesPage(wizard); + PreferencesPage preferencesPage = new PreferencesPage(wizard, configuration); preferencesPage.setName("page.preferences"); preferencesPage.setTempDirectory(configuration.getTempDirectory()); pages.put(PageType.PAGE_PREFERENCES, preferencesPage); @@ -443,6 +461,7 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen * Shows a dialog with general preferences. */ private void optionsPreferences() { + ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setConfigurationDirectory(configuration.getConfigurationDirectory()); showPage(PageType.PAGE_PREFERENCES); optionsPreferencesAction.setEnabled(false); wizard.setNextEnabled(true); @@ -539,9 +558,14 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen nodeMenu.setEnabled(false); optionsPreferencesAction.setEnabled(false); } else if ("page.project.insert".equals(pageName)) { - showPage(PageType.PAGE_PROJECTS); - nodeMenu.setEnabled(true); - optionsPreferencesAction.setEnabled(true); + ProjectInsertPage projectInsertPage = (ProjectInsertPage) pages.get(PageType.PAGE_INSERT_PROJECT); + if (projectInsertPage.isRunning()) { + projectInsertPage.stopInsert(); + } else { + showPage(PageType.PAGE_PROJECTS); + nodeMenu.setEnabled(true); + optionsPreferencesAction.setEnabled(true); + } } else if ("page.preferences".equals(pageName)) { showPage(PageType.PAGE_PROJECTS); optionsPreferencesAction.setEnabled(true); @@ -553,8 +577,9 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen */ public void wizardPreviousPressed(TWizard wizard) { String pageName = wizard.getPage().getName(); - if ("page.project".equals(pageName)) { + if ("page.project".equals(pageName) || "page.preferences".equals(pageName)) { showPage(PageType.PAGE_NODE_MANAGER); + optionsPreferencesAction.setEnabled(true); } else if ("page.project.files".equals(pageName)) { showPage(PageType.PAGE_PROJECTS); } else if ("page.project.insert".equals(pageName)) { @@ -610,6 +635,25 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen /** * {@inheritDoc} */ + public void nodeSelected(Node node) { + for (Component menuItem : nodeMenu.getMenuComponents()) { + if (menuItem instanceof JMenuItem) { + if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) { + ((JMenuItem) menuItem).setSelected(true); + } + } + } + freenetInterface.setNode(node); + selectedNode = node; + } + + // + // INTERFACE ActionListener + // + + /** + * {@inheritDoc} + */ public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source instanceof JRadioButtonMenuItem) {