diff --git a/src/com/romraider/Settings.java b/src/com/romraider/Settings.java index 1b29ffee..5f1751d6 100644 --- a/src/com/romraider/Settings.java +++ b/src/com/romraider/Settings.java @@ -69,7 +69,7 @@ public class Settings implements Serializable { private String loggerPort = ""; private String loggerPortDefault = ""; private String loggerProtocol = "SSM"; - private String loggerConfigFilePath = "logger.xml"; + private String loggerDefinitionFilePath = "logger.xml"; private String loggerProfileFilePath = ""; private String loggerOutputDirPath = System.getProperty("user.home"); private String fileLoggingControllerSwitchId = "S20"; // defogger switch by default @@ -329,8 +329,12 @@ public class Settings implements Serializable { return loggerProtocol; } - public String getLoggerConfigFilePath() { - return loggerConfigFilePath; + public String getLoggerDefinitionFilePath() { + return loggerDefinitionFilePath; + } + + public void setLoggerDefinitionFilePath(String loggerDefinitionFilePath) { + this.loggerDefinitionFilePath = loggerDefinitionFilePath; } public String getLoggerOutputDirPath() { diff --git a/src/com/romraider/logger/ecu/EcuLogger.java b/src/com/romraider/logger/ecu/EcuLogger.java index 16de3ca4..547947c5 100644 --- a/src/com/romraider/logger/ecu/EcuLogger.java +++ b/src/com/romraider/logger/ecu/EcuLogger.java @@ -310,7 +310,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC dashboardTabExternalListTableModel = new ParameterListTableModel(dashboardTabBroker, HEADING_EXTERNAL); } - private void loadLoggerParams() { + public void loadLoggerParams() { loadLoggerConfig(); loadFromExternalDataSources(); } @@ -370,7 +370,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC private void loadLoggerConfig() { try { EcuDataLoader dataLoader = new EcuDataLoaderImpl(); - dataLoader.loadConfigFromXml(settings.getLoggerConfigFilePath(), settings.getLoggerProtocol(), + dataLoader.loadConfigFromXml(settings.getLoggerDefinitionFilePath(), settings.getLoggerProtocol(), settings.getFileLoggingControllerSwitchId(), ecuInit); List ecuParams = dataLoader.getEcuParameters(); addConvertorUpdateListeners(ecuParams); diff --git a/src/com/romraider/logger/ecu/ui/swing/menubar/EcuLoggerMenuBar.java b/src/com/romraider/logger/ecu/ui/swing/menubar/EcuLoggerMenuBar.java index 0a0d0183..8053a1ed 100644 --- a/src/com/romraider/logger/ecu/ui/swing/menubar/EcuLoggerMenuBar.java +++ b/src/com/romraider/logger/ecu/ui/swing/menubar/EcuLoggerMenuBar.java @@ -31,6 +31,7 @@ import com.romraider.logger.ecu.ui.swing.menubar.action.LoadProfileAction; import com.romraider.logger.ecu.ui.swing.menubar.action.LogFileAbsoluteTimestampAction; import com.romraider.logger.ecu.ui.swing.menubar.action.LogFileControllerSwitchAction; import com.romraider.logger.ecu.ui.swing.menubar.action.LogFileLocationAction; +import com.romraider.logger.ecu.ui.swing.menubar.action.LoggerDefinitionLocationAction; import com.romraider.logger.ecu.ui.swing.menubar.action.ReloadProfileAction; import com.romraider.logger.ecu.ui.swing.menubar.action.ResetConnectionAction; import com.romraider.logger.ecu.ui.swing.menubar.action.ResetEcuAction; @@ -76,6 +77,7 @@ public class EcuLoggerMenuBar extends JMenuBar { // settings menu items JMenu settingsMenu = new EcuLoggerMenu("Settings", VK_S); + settingsMenu.add(new EcuLoggerMenuItem("Logger Definition Location...", new LoggerDefinitionLocationAction(logger), VK_D, getKeyStroke(VK_D, CTRL_MASK))); settingsMenu.add(new EcuLoggerMenuItem("Log File Output Location...", new LogFileLocationAction(logger), VK_O, getKeyStroke(VK_O, CTRL_MASK))); settingsMenu.add(new JSeparator()); settingsMenu.add(new EcuLoggerRadioButtonMenuItem("Control File Logging With Defogger Switch", VK_C, getKeyStroke(VK_C, CTRL_MASK), new LogFileControllerSwitchAction(logger), logger.getSettings().isFileLoggingControllerSwitchActive())); diff --git a/src/com/romraider/logger/ecu/ui/swing/menubar/action/LoggerDefinitionLocationAction.java b/src/com/romraider/logger/ecu/ui/swing/menubar/action/LoggerDefinitionLocationAction.java new file mode 100644 index 00000000..1bd1e186 --- /dev/null +++ b/src/com/romraider/logger/ecu/ui/swing/menubar/action/LoggerDefinitionLocationAction.java @@ -0,0 +1,56 @@ +/* + * + * RomRaider Open-Source Tuning, Logging and Reflashing + * Copyright (C) 2006-2008 RomRaider.com + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +package com.romraider.logger.ecu.ui.swing.menubar.action; + +import com.romraider.logger.ecu.EcuLogger; +import static com.romraider.logger.ecu.ui.swing.menubar.util.FileHelper.getDefinitionFileChooser; +import static com.romraider.logger.ecu.ui.swing.menubar.util.FileHelper.getFile; +import javax.swing.JFileChooser; +import static javax.swing.JFileChooser.APPROVE_OPTION; +import java.awt.event.ActionEvent; +import java.io.File; + +public final class LoggerDefinitionLocationAction extends AbstractAction { + + public LoggerDefinitionLocationAction(EcuLogger logger) { + super(logger); + } + + public void actionPerformed(ActionEvent actionEvent) { + try { + setDefinitionLocationDialog(); + logger.loadLoggerParams(); + } catch (Exception e) { + logger.reportError(e); + } + } + + private void setDefinitionLocationDialog() throws Exception { + File lastConfigPath = getFile(logger.getSettings().getLoggerDefinitionFilePath()); + JFileChooser fc = getDefinitionFileChooser(lastConfigPath); + if (fc.showOpenDialog(logger) == APPROVE_OPTION) { + String path = fc.getSelectedFile().getAbsolutePath(); + logger.getSettings().setLoggerDefinitionFilePath(path); + logger.reportMessage("Logger definition location successfully updated: " + path); + } + } +} \ No newline at end of file diff --git a/src/com/romraider/logger/ecu/ui/swing/menubar/util/FileHelper.java b/src/com/romraider/logger/ecu/ui/swing/menubar/util/FileHelper.java index e800bc4f..c7238833 100644 --- a/src/com/romraider/logger/ecu/ui/swing/menubar/util/FileHelper.java +++ b/src/com/romraider/logger/ecu/ui/swing/menubar/util/FileHelper.java @@ -22,6 +22,7 @@ package com.romraider.logger.ecu.ui.swing.menubar.util; import com.romraider.logger.ecu.profile.UserProfile; +import com.romraider.swing.GenericFileFilter; import static com.romraider.util.ParamChecker.isNullOrEmpty; import javax.swing.JFileChooser; import static javax.swing.JFileChooser.DIRECTORIES_ONLY; @@ -41,14 +42,11 @@ public final class FileHelper { } public static JFileChooser getProfileFileChooser(File lastProfileFile) { - JFileChooser fc; - if (lastProfileFile.exists() && lastProfileFile.isFile() && lastProfileFile.getParentFile() != null) { - fc = new JFileChooser(lastProfileFile.getParentFile().getAbsolutePath()); - } else { - fc = new JFileChooser(); - } - fc.setFileFilter(new UserProfileFileFilter()); - return fc; + return getFileChooser(lastProfileFile, "ECU Logger User Profiles", "xml"); + } + + public static JFileChooser getDefinitionFileChooser(File lastDefFile) { + return getFileChooser(lastDefFile, "ECU Logger Definitions", "xml"); } public static String saveProfileToFile(UserProfile profile, File destinationFile) throws IOException { @@ -76,4 +74,17 @@ public final class FileHelper { fc.setFileSelectionMode(DIRECTORIES_ONLY); return fc; } + + private static JFileChooser getFileChooser(File file, String description, String... extensions) { + JFileChooser fc = getFileChooser(file); + fc.setFileFilter(new GenericFileFilter(description, extensions)); + return fc; + } + + private static JFileChooser getFileChooser(File file) { + if (file.exists() && file.isFile() && file.getParentFile() != null) { + return new JFileChooser(file.getParentFile().getAbsolutePath()); + } + return new JFileChooser(); + } } diff --git a/src/com/romraider/logger/ecu/ui/swing/menubar/util/UserProfileFileFilter.java b/src/com/romraider/logger/ecu/ui/swing/menubar/util/UserProfileFileFilter.java deleted file mode 100644 index e64d917f..00000000 --- a/src/com/romraider/logger/ecu/ui/swing/menubar/util/UserProfileFileFilter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * RomRaider Open-Source Tuning, Logging and Reflashing - * Copyright (C) 2006-2008 RomRaider.com - * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -package com.romraider.logger.ecu.ui.swing.menubar.util; - -import com.romraider.swing.GenericFileFilter; -import javax.swing.filechooser.FileFilter; -import java.io.File; - -public final class UserProfileFileFilter extends FileFilter { - private final FileFilter filter = new GenericFileFilter("ECU Logger User Profiles", "xml"); - - public boolean accept(File file) { - return filter.accept(file); - } - - public String getDescription() { - return filter.getDescription(); - } - -} diff --git a/src/com/romraider/xml/DOMSettingsBuilder.java b/src/com/romraider/xml/DOMSettingsBuilder.java index ac8a1e0e..c373748a 100644 --- a/src/com/romraider/xml/DOMSettingsBuilder.java +++ b/src/com/romraider/xml/DOMSettingsBuilder.java @@ -260,6 +260,11 @@ public final class DOMSettingsBuilder { tabs.setAttribute("selected", String.valueOf(settings.getLoggerSelectedTabIndex())); loggerSettings.appendChild(tabs); + // definition path + IIOMetadataNode definition = new IIOMetadataNode("definition"); + definition.setAttribute("path", settings.getLoggerDefinitionFilePath()); + loggerSettings.appendChild(definition); + // profile path IIOMetadataNode profile = new IIOMetadataNode("profile"); profile.setAttribute("path", settings.getLoggerProfileFilePath()); diff --git a/src/com/romraider/xml/DOMSettingsUnmarshaller.java b/src/com/romraider/xml/DOMSettingsUnmarshaller.java index dea7b6b8..675c8b8f 100644 --- a/src/com/romraider/xml/DOMSettingsUnmarshaller.java +++ b/src/com/romraider/xml/DOMSettingsUnmarshaller.java @@ -230,6 +230,9 @@ public final class DOMSettingsUnmarshaller { } else if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("tabs")) { settings.setLoggerSelectedTabIndex(unmarshallAttribute(n, "selected", 0)); + } else if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("definition")) { + settings.setLoggerDefinitionFilePath(unmarshallAttribute(n, "path", settings.getLoggerDefinitionFilePath())); + } else if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("profile")) { settings.setLoggerProfileFilePath(unmarshallAttribute(n, "path", ""));