mirror of https://github.com/rusefi/RomRaider.git
added some keyboard shortcuts to logger
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@498 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
fb8f2f792e
commit
337f613ac4
|
@ -42,7 +42,6 @@ import enginuity.logger.profile.UserProfileLoaderImpl;
|
|||
import enginuity.logger.ui.DataRegistrationBroker;
|
||||
import enginuity.logger.ui.DataRegistrationBrokerImpl;
|
||||
import enginuity.logger.ui.EcuDataComparator;
|
||||
import enginuity.logger.ui.EcuLoggerMenuBar;
|
||||
import enginuity.logger.ui.MessageListener;
|
||||
import enginuity.logger.ui.SerialPortComboBox;
|
||||
import enginuity.logger.ui.StatusIndicator;
|
||||
|
@ -59,6 +58,7 @@ import enginuity.logger.ui.handler.table.TableUpdateHandler;
|
|||
import enginuity.logger.ui.paramlist.ParameterListTable;
|
||||
import enginuity.logger.ui.paramlist.ParameterListTableModel;
|
||||
import enginuity.logger.ui.paramlist.ParameterRow;
|
||||
import enginuity.logger.ui.swing.menubar.EcuLoggerMenuBar;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
import static enginuity.util.ParamChecker.isNullOrEmpty;
|
||||
import static enginuity.util.ThreadUtil.sleep;
|
||||
|
|
|
@ -1,277 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* Enginuity Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006 Enginuity.org
|
||||
*
|
||||
* 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 enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
import enginuity.logger.profile.UserProfileFileFilter;
|
||||
|
||||
import javax.swing.*;
|
||||
import static javax.swing.JFileChooser.APPROVE_OPTION;
|
||||
import static javax.swing.JFileChooser.DIRECTORIES_ONLY;
|
||||
import static javax.swing.JOptionPane.OK_OPTION;
|
||||
import static javax.swing.JOptionPane.showConfirmDialog;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class EcuLoggerMenuBar extends JMenuBar implements ActionListener {
|
||||
private static final String USER_HOME_DIR = System.getProperty("user.home");
|
||||
|
||||
private JMenu fileMenu = new JMenu("File");
|
||||
private JMenuItem loadProfile = new JMenuItem("Load Profile...");
|
||||
private JMenuItem reloadProfile = new JMenuItem("Reload Profile");
|
||||
private JMenuItem saveProfile = new JMenuItem("Save Profile");
|
||||
private JMenuItem saveProfileAs = new JMenuItem("Save Profile As...");
|
||||
private JMenuItem exit = new JMenuItem("Exit");
|
||||
|
||||
private JMenu settingsMenu = new JMenu("Settings");
|
||||
private JMenuItem logFileLocation = new JMenuItem("Log File Output Location...");
|
||||
private JMenuItem logFileControllerSwitch = new JRadioButtonMenuItem("Control File Logging With Defogger Switch");
|
||||
private JMenuItem logFileAbsoluteTimestamp = new JRadioButtonMenuItem("Use Absolute Timestamp In Log File");
|
||||
|
||||
private JMenu connectionMenu = new JMenu("Connection");
|
||||
private JMenuItem resetConnection = new JMenuItem("Reset");
|
||||
private JMenuItem disconnect = new JMenuItem("Disconnect");
|
||||
|
||||
private JMenu helpMenu = new JMenu("Help");
|
||||
private JMenuItem about = new JMenuItem("About Enginuity ECU Logger");
|
||||
|
||||
private EcuLogger parent;
|
||||
|
||||
public EcuLoggerMenuBar(EcuLogger parent) {
|
||||
this.parent = parent;
|
||||
|
||||
// file menu items
|
||||
add(fileMenu);
|
||||
fileMenu.setMnemonic('F');
|
||||
loadProfile.setMnemonic('O');
|
||||
reloadProfile.setMnemonic('R');
|
||||
saveProfile.setMnemonic('S');
|
||||
saveProfileAs.setMnemonic('A');
|
||||
exit.setMnemonic('X');
|
||||
fileMenu.add(loadProfile);
|
||||
fileMenu.add(reloadProfile);
|
||||
fileMenu.add(saveProfile);
|
||||
fileMenu.add(saveProfileAs);
|
||||
fileMenu.add(new JSeparator());
|
||||
fileMenu.add(exit);
|
||||
loadProfile.addActionListener(this);
|
||||
reloadProfile.addActionListener(this);
|
||||
saveProfile.addActionListener(this);
|
||||
saveProfileAs.addActionListener(this);
|
||||
exit.addActionListener(this);
|
||||
|
||||
// settings menu items
|
||||
add(settingsMenu);
|
||||
settingsMenu.setMnemonic('E');
|
||||
logFileLocation.setMnemonic('F');
|
||||
logFileControllerSwitch.setMnemonic('C');
|
||||
logFileAbsoluteTimestamp.setMnemonic('A');
|
||||
settingsMenu.add(logFileLocation);
|
||||
settingsMenu.add(new JSeparator());
|
||||
settingsMenu.add(logFileControllerSwitch);
|
||||
settingsMenu.add(logFileAbsoluteTimestamp);
|
||||
logFileLocation.addActionListener(this);
|
||||
logFileControllerSwitch.addActionListener(this);
|
||||
logFileAbsoluteTimestamp.addActionListener(this);
|
||||
logFileControllerSwitch.setSelected(parent.getSettings().isFileLoggingControllerSwitchActive());
|
||||
logFileAbsoluteTimestamp.setSelected(parent.getSettings().isFileLoggingAbsoluteTimestamp());
|
||||
|
||||
// connection menu items
|
||||
add(connectionMenu);
|
||||
connectionMenu.setMnemonic('C');
|
||||
resetConnection.setMnemonic('R');
|
||||
disconnect.setMnemonic('D');
|
||||
connectionMenu.add(resetConnection);
|
||||
connectionMenu.add(disconnect);
|
||||
resetConnection.addActionListener(this);
|
||||
disconnect.addActionListener(this);
|
||||
|
||||
// help menu stuff
|
||||
add(helpMenu);
|
||||
helpMenu.setMnemonic('H');
|
||||
about.setMnemonic('A');
|
||||
helpMenu.add(about);
|
||||
about.addActionListener(this);
|
||||
|
||||
// disable unimplemented buttons!
|
||||
about.setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
if (evt.getSource() == loadProfile) {
|
||||
try {
|
||||
loadProfileDialog();
|
||||
} catch (Exception e) {
|
||||
parent.reportError(e);
|
||||
}
|
||||
|
||||
} else if (evt.getSource() == reloadProfile) {
|
||||
try {
|
||||
parent.loadUserProfile(parent.getSettings().getLoggerProfileFilePath());
|
||||
} catch (Exception e) {
|
||||
parent.reportError(e);
|
||||
}
|
||||
|
||||
} else if (evt.getSource() == saveProfile) {
|
||||
try {
|
||||
saveProfile();
|
||||
} catch (Exception e) {
|
||||
parent.reportError(e);
|
||||
}
|
||||
|
||||
} else if (evt.getSource() == saveProfileAs) {
|
||||
try {
|
||||
saveProfileAs();
|
||||
} catch (Exception e) {
|
||||
parent.reportError(e);
|
||||
}
|
||||
|
||||
} else if (evt.getSource() == exit) {
|
||||
parent.handleExit();
|
||||
parent.dispose();
|
||||
parent.setVisible(false);
|
||||
|
||||
} else if (evt.getSource() == logFileLocation) {
|
||||
try {
|
||||
setLogFileLocationDialog();
|
||||
} catch (Exception e) {
|
||||
parent.reportError(e);
|
||||
}
|
||||
|
||||
} else if (evt.getSource() == logFileControllerSwitch) {
|
||||
try {
|
||||
parent.getSettings().setFileLoggingControllerSwitchActive(logFileControllerSwitch.isSelected());
|
||||
} catch (Exception e) {
|
||||
parent.reportError(e);
|
||||
}
|
||||
|
||||
} else if (evt.getSource() == logFileAbsoluteTimestamp) {
|
||||
try {
|
||||
parent.getSettings().setFileLoggingAbsoluteTimestamp(logFileAbsoluteTimestamp.isSelected());
|
||||
} catch (Exception e) {
|
||||
parent.reportError(e);
|
||||
}
|
||||
|
||||
} else if (evt.getSource() == resetConnection) {
|
||||
try {
|
||||
parent.restartLogging();
|
||||
} catch (Exception e) {
|
||||
parent.reportError(e);
|
||||
}
|
||||
|
||||
} else if (evt.getSource() == disconnect) {
|
||||
try {
|
||||
parent.stopLogging();
|
||||
} catch (Exception e) {
|
||||
parent.reportError(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void setLogFileLocationDialog() throws Exception {
|
||||
File lastLoggerOutputDir = getFile(parent.getSettings().getLoggerOutputDirPath());
|
||||
JFileChooser fc = getLoggerOutputDirFileChooser(lastLoggerOutputDir);
|
||||
if (fc.showOpenDialog(parent) == APPROVE_OPTION) {
|
||||
String loggerOutputDirPath = fc.getSelectedFile().getAbsolutePath();
|
||||
parent.getSettings().setLoggerOutputDirPath(loggerOutputDirPath);
|
||||
parent.reportMessage("Log file output location successfully updated: " + loggerOutputDirPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadProfileDialog() throws Exception {
|
||||
File lastProfileFile = getFile(parent.getSettings().getLoggerProfileFilePath());
|
||||
JFileChooser fc = getProfileFileChooser(lastProfileFile);
|
||||
if (fc.showOpenDialog(parent) == APPROVE_OPTION) {
|
||||
String profileFilePath = fc.getSelectedFile().getAbsolutePath();
|
||||
parent.loadUserProfile(profileFilePath);
|
||||
parent.getSettings().setLoggerProfileFilePath(profileFilePath);
|
||||
parent.reportMessageInTitleBar("Profile: " + profileFilePath);
|
||||
parent.reportMessage("Profile succesfully loaded: " + profileFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveProfile() throws Exception {
|
||||
File lastProfileFile = new File(parent.getSettings().getLoggerProfileFilePath());
|
||||
saveProfileToFile(lastProfileFile);
|
||||
}
|
||||
|
||||
private void saveProfileAs() throws Exception {
|
||||
File lastProfileFile = getFile(parent.getSettings().getLoggerProfileFilePath());
|
||||
JFileChooser fc = getProfileFileChooser(lastProfileFile);
|
||||
if (fc.showSaveDialog(parent) == APPROVE_OPTION) {
|
||||
File selectedFile = fc.getSelectedFile();
|
||||
if (!selectedFile.exists()
|
||||
|| showConfirmDialog(parent, selectedFile.getName() + " already exists! Overwrite?") == OK_OPTION) {
|
||||
saveProfileToFile(selectedFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveProfileToFile(File destinationFile) throws IOException {
|
||||
String profileFilePath = destinationFile.getAbsolutePath();
|
||||
if (!profileFilePath.endsWith(".xml")) {
|
||||
profileFilePath += ".xml";
|
||||
destinationFile = new File(profileFilePath);
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(destinationFile);
|
||||
try {
|
||||
fos.write(parent.getCurrentProfile().getBytes());
|
||||
} finally {
|
||||
fos.close();
|
||||
}
|
||||
parent.getSettings().setLoggerProfileFilePath(profileFilePath);
|
||||
parent.reportMessageInTitleBar("Profile: " + profileFilePath);
|
||||
parent.reportMessage("Profile succesfully saved: " + profileFilePath);
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
private JFileChooser getLoggerOutputDirFileChooser(File lastLoggerOutputDir) {
|
||||
JFileChooser fc;
|
||||
if (lastLoggerOutputDir.exists() && lastLoggerOutputDir.isDirectory()) {
|
||||
fc = new JFileChooser(lastLoggerOutputDir.getAbsolutePath());
|
||||
} else {
|
||||
fc = new JFileChooser();
|
||||
}
|
||||
fc.setFileSelectionMode(DIRECTORIES_ONLY);
|
||||
return fc;
|
||||
}
|
||||
|
||||
private File getFile(String filePath) {
|
||||
return filePath == null ? new File(USER_HOME_DIR) : new File(filePath);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package enginuity.logger.ui.swing.menubar;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public final class EcuLoggerMenu extends JMenu {
|
||||
|
||||
public EcuLoggerMenu(String text, int mnemonic) {
|
||||
setText(text);
|
||||
setMnemonic(mnemonic);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package enginuity.logger.ui.swing.menubar;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
import enginuity.logger.ui.swing.menubar.action.AboutAction;
|
||||
import enginuity.logger.ui.swing.menubar.action.DisconnectAction;
|
||||
import enginuity.logger.ui.swing.menubar.action.ExitAction;
|
||||
import enginuity.logger.ui.swing.menubar.action.LoadProfileAction;
|
||||
import enginuity.logger.ui.swing.menubar.action.LogFileAbsoluteTimestampAction;
|
||||
import enginuity.logger.ui.swing.menubar.action.LogFileControllerSwitchAction;
|
||||
import enginuity.logger.ui.swing.menubar.action.LogFileLocationAction;
|
||||
import enginuity.logger.ui.swing.menubar.action.ReloadProfileAction;
|
||||
import enginuity.logger.ui.swing.menubar.action.ResetConnectionAction;
|
||||
import enginuity.logger.ui.swing.menubar.action.SaveProfileAction;
|
||||
import enginuity.logger.ui.swing.menubar.action.SaveProfileAsAction;
|
||||
|
||||
import javax.swing.*;
|
||||
import static javax.swing.KeyStroke.getKeyStroke;
|
||||
import static java.awt.event.KeyEvent.CTRL_MASK;
|
||||
import static java.awt.event.KeyEvent.SHIFT_MASK;
|
||||
import static java.awt.event.KeyEvent.VK_A;
|
||||
import static java.awt.event.KeyEvent.VK_C;
|
||||
import static java.awt.event.KeyEvent.VK_D;
|
||||
import static java.awt.event.KeyEvent.VK_F;
|
||||
import static java.awt.event.KeyEvent.VK_H;
|
||||
import static java.awt.event.KeyEvent.VK_L;
|
||||
import static java.awt.event.KeyEvent.VK_P;
|
||||
import static java.awt.event.KeyEvent.VK_R;
|
||||
import static java.awt.event.KeyEvent.VK_S;
|
||||
import static java.awt.event.KeyEvent.VK_T;
|
||||
import static java.awt.event.KeyEvent.VK_X;
|
||||
|
||||
public class EcuLoggerMenuBar extends JMenuBar {
|
||||
|
||||
public EcuLoggerMenuBar(EcuLogger logger) {
|
||||
|
||||
// file menu items
|
||||
JMenu fileMenu = new EcuLoggerMenu("File", VK_F);
|
||||
fileMenu.add(new EcuLoggerMenuItem("Load Profile...", VK_L, getKeyStroke(VK_L, CTRL_MASK), new LoadProfileAction(logger)));
|
||||
fileMenu.add(new EcuLoggerMenuItem("Reload Profile", VK_P, getKeyStroke(VK_P, CTRL_MASK), new ReloadProfileAction(logger)));
|
||||
fileMenu.add(new EcuLoggerMenuItem("Save Profile", VK_S, getKeyStroke(VK_S, CTRL_MASK), new SaveProfileAction(logger)));
|
||||
fileMenu.add(new EcuLoggerMenuItem("Save Profile As...", VK_A, getKeyStroke(VK_S, CTRL_MASK | SHIFT_MASK), new SaveProfileAsAction(logger)));
|
||||
fileMenu.add(new JSeparator());
|
||||
fileMenu.add(new EcuLoggerMenuItem("Exit", VK_X, new ExitAction(logger)));
|
||||
add(fileMenu);
|
||||
|
||||
// settings menu items
|
||||
JMenu settingsMenu = new EcuLoggerMenu("Settings", VK_S);
|
||||
settingsMenu.add(new EcuLoggerMenuItem("Log File Output Location...", VK_F, getKeyStroke(VK_F, CTRL_MASK), new LogFileLocationAction(logger)));
|
||||
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()));
|
||||
settingsMenu.add(new EcuLoggerRadioButtonMenuItem("Use Absolute Timestamp In Log File", VK_T, getKeyStroke(VK_T, CTRL_MASK), new LogFileAbsoluteTimestampAction(logger), logger.getSettings().isFileLoggingAbsoluteTimestamp()));
|
||||
add(settingsMenu);
|
||||
|
||||
// connection menu items
|
||||
JMenu connectionMenu = new EcuLoggerMenu("Connection", VK_C);
|
||||
connectionMenu.add(new EcuLoggerMenuItem("Reset", VK_R, getKeyStroke(VK_R, CTRL_MASK), new ResetConnectionAction(logger)));
|
||||
connectionMenu.add(new EcuLoggerMenuItem("Disconnect", VK_D, getKeyStroke(VK_D, CTRL_MASK), new DisconnectAction(logger)));
|
||||
add(connectionMenu);
|
||||
|
||||
// help menu stuff
|
||||
JMenu helpMenu = new EcuLoggerMenu("Help", VK_H);
|
||||
helpMenu.add(new EcuLoggerMenuItem("About", VK_A, new AboutAction(logger)));
|
||||
add(helpMenu);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package enginuity.logger.ui.swing.menubar;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public final class EcuLoggerMenuItem extends JMenuItem {
|
||||
|
||||
public EcuLoggerMenuItem(String text, int mnemonic, Action action) {
|
||||
super(action);
|
||||
setText(text);
|
||||
setMnemonic(mnemonic);
|
||||
}
|
||||
|
||||
public EcuLoggerMenuItem(String text, int mnemonic, KeyStroke accelerator, Action action) {
|
||||
this(text, mnemonic, action);
|
||||
setAccelerator(accelerator);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package enginuity.logger.ui.swing.menubar;
|
||||
|
||||
import enginuity.logger.ui.swing.menubar.util.SelectionStateAdaptor;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public final class EcuLoggerRadioButtonMenuItem extends JRadioButtonMenuItem {
|
||||
|
||||
public EcuLoggerRadioButtonMenuItem(String text, int mnemonic, KeyStroke accelerator, Action action, boolean selected) {
|
||||
super(action);
|
||||
initSelectionStateAdaptor(action);
|
||||
setText(text);
|
||||
setMnemonic(mnemonic);
|
||||
setAccelerator(accelerator);
|
||||
setSelected(selected);
|
||||
}
|
||||
|
||||
private void initSelectionStateAdaptor(Action action) {
|
||||
new SelectionStateAdaptor(action, this).configure();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
|
||||
import static javax.swing.JOptionPane.INFORMATION_MESSAGE;
|
||||
import static javax.swing.JOptionPane.showMessageDialog;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public final class AboutAction extends AbstractAction {
|
||||
|
||||
public AboutAction(EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
showMessageDialog(logger, "Enginuity ECU Logger\nhttp://www.enginuity.org/", "About", INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractAction implements Action {
|
||||
public static final String SELECTED = "selected";
|
||||
private final Map<String, Object> valueMap = new HashMap<String, Object>();
|
||||
private boolean enabled = true;
|
||||
protected EcuLogger logger;
|
||||
public static final String SELECTED_KEY = "selected";
|
||||
|
||||
public AbstractAction(EcuLogger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener) {
|
||||
}
|
||||
|
||||
public Object getValue(String key) {
|
||||
return valueMap.get(key);
|
||||
}
|
||||
|
||||
public void putValue(String key, Object value) {
|
||||
valueMap.put(key, value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public final class DisconnectAction extends AbstractAction {
|
||||
|
||||
public DisconnectAction(EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
logger.stopLogging();
|
||||
} catch (Exception e) {
|
||||
logger.reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public final class ExitAction extends AbstractAction {
|
||||
|
||||
public ExitAction(EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
logger.handleExit();
|
||||
logger.dispose();
|
||||
logger.setVisible(false);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
import static enginuity.logger.ui.swing.menubar.util.FileHelper.getFile;
|
||||
import static enginuity.logger.ui.swing.menubar.util.FileHelper.getProfileFileChooser;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
|
||||
public final class LoadProfileAction extends AbstractAction {
|
||||
|
||||
public LoadProfileAction(EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
loadProfileDialog();
|
||||
} catch (Exception e) {
|
||||
logger.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadProfileDialog() throws Exception {
|
||||
File lastProfileFile = getFile(logger.getSettings().getLoggerProfileFilePath());
|
||||
JFileChooser fc = getProfileFileChooser(lastProfileFile);
|
||||
if (fc.showOpenDialog(logger) == JFileChooser.APPROVE_OPTION) {
|
||||
String profileFilePath = fc.getSelectedFile().getAbsolutePath();
|
||||
logger.loadUserProfile(profileFilePath);
|
||||
logger.getSettings().setLoggerProfileFilePath(profileFilePath);
|
||||
logger.reportMessageInTitleBar("Profile: " + profileFilePath);
|
||||
logger.reportMessage("Profile succesfully loaded: " + profileFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public final class LogFileAbsoluteTimestampAction extends AbstractAction {
|
||||
|
||||
public LogFileAbsoluteTimestampAction(EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
logger.getSettings().setFileLoggingAbsoluteTimestamp((Boolean) getValue(SELECTED_KEY));
|
||||
} catch (Exception e) {
|
||||
logger.reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public final class LogFileControllerSwitchAction extends AbstractAction {
|
||||
|
||||
public LogFileControllerSwitchAction(EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
logger.getSettings().setFileLoggingControllerSwitchActive((Boolean) getValue(SELECTED_KEY));
|
||||
} catch (Exception e) {
|
||||
logger.reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
import static enginuity.logger.ui.swing.menubar.util.FileHelper.getFile;
|
||||
import static enginuity.logger.ui.swing.menubar.util.FileHelper.getLoggerOutputDirFileChooser;
|
||||
|
||||
import javax.swing.*;
|
||||
import static javax.swing.JFileChooser.APPROVE_OPTION;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
|
||||
public final class LogFileLocationAction extends AbstractAction {
|
||||
|
||||
public LogFileLocationAction(EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
setLogFileLocationDialog();
|
||||
} catch (Exception e) {
|
||||
logger.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void setLogFileLocationDialog() throws Exception {
|
||||
File lastLoggerOutputDir = getFile(logger.getSettings().getLoggerOutputDirPath());
|
||||
JFileChooser fc = getLoggerOutputDirFileChooser(lastLoggerOutputDir);
|
||||
if (fc.showOpenDialog(logger) == APPROVE_OPTION) {
|
||||
String loggerOutputDirPath = fc.getSelectedFile().getAbsolutePath();
|
||||
logger.getSettings().setLoggerOutputDirPath(loggerOutputDirPath);
|
||||
logger.reportMessage("Log file output location successfully updated: " + loggerOutputDirPath);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public final class ReloadProfileAction extends AbstractAction {
|
||||
|
||||
public ReloadProfileAction(EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
logger.loadUserProfile(logger.getSettings().getLoggerProfileFilePath());
|
||||
} catch (Exception e) {
|
||||
logger.reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public final class ResetConnectionAction extends AbstractAction {
|
||||
|
||||
public ResetConnectionAction(EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
logger.restartLogging();
|
||||
} catch (Exception e) {
|
||||
logger.reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
import static enginuity.logger.ui.swing.menubar.util.FileHelper.saveProfileToFile;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
|
||||
public final class SaveProfileAction extends AbstractAction {
|
||||
|
||||
public SaveProfileAction(EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
saveProfile();
|
||||
} catch (Exception e) {
|
||||
logger.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveProfile() throws Exception {
|
||||
File lastProfileFile = new File(logger.getSettings().getLoggerProfileFilePath());
|
||||
String profileFilePath = saveProfileToFile(logger.getCurrentProfile(), lastProfileFile);
|
||||
logger.getSettings().setLoggerProfileFilePath(profileFilePath);
|
||||
logger.reportMessageInTitleBar("Profile: " + profileFilePath);
|
||||
logger.reportMessage("Profile succesfully saved: " + profileFilePath);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package enginuity.logger.ui.swing.menubar.action;
|
||||
|
||||
import enginuity.logger.EcuLogger;
|
||||
import static enginuity.logger.ui.swing.menubar.util.FileHelper.getFile;
|
||||
import static enginuity.logger.ui.swing.menubar.util.FileHelper.getProfileFileChooser;
|
||||
import static enginuity.logger.ui.swing.menubar.util.FileHelper.saveProfileToFile;
|
||||
|
||||
import javax.swing.*;
|
||||
import static javax.swing.JFileChooser.APPROVE_OPTION;
|
||||
import static javax.swing.JOptionPane.OK_OPTION;
|
||||
import static javax.swing.JOptionPane.showConfirmDialog;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
|
||||
public final class SaveProfileAsAction extends AbstractAction {
|
||||
|
||||
public SaveProfileAsAction(EcuLogger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
saveProfileAs();
|
||||
} catch (Exception e) {
|
||||
logger.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveProfileAs() throws Exception {
|
||||
File lastProfileFile = getFile(logger.getSettings().getLoggerProfileFilePath());
|
||||
JFileChooser fc = getProfileFileChooser(lastProfileFile);
|
||||
if (fc.showSaveDialog(logger) == APPROVE_OPTION) {
|
||||
File selectedFile = fc.getSelectedFile();
|
||||
if (!selectedFile.exists() || showConfirmDialog(logger, selectedFile.getName() + " already exists! Overwrite?") == OK_OPTION) {
|
||||
saveProfileToFile(logger.getCurrentProfile(), selectedFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package enginuity.logger.ui.swing.menubar.util;
|
||||
|
||||
import enginuity.logger.profile.UserProfile;
|
||||
|
||||
import javax.swing.*;
|
||||
import static javax.swing.JFileChooser.DIRECTORIES_ONLY;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class FileHelper {
|
||||
private static final String USER_HOME_DIR = System.getProperty("user.home");
|
||||
|
||||
private FileHelper() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public static File getFile(String filePath) {
|
||||
return filePath == null ? new File(USER_HOME_DIR) : new File(filePath);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static String saveProfileToFile(UserProfile profile, File destinationFile) throws IOException {
|
||||
String profileFilePath = destinationFile.getAbsolutePath();
|
||||
if (!profileFilePath.endsWith(".xml")) {
|
||||
profileFilePath += ".xml";
|
||||
destinationFile = new File(profileFilePath);
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(destinationFile);
|
||||
try {
|
||||
fos.write(profile.getBytes());
|
||||
} finally {
|
||||
fos.close();
|
||||
}
|
||||
return profileFilePath;
|
||||
}
|
||||
|
||||
public static JFileChooser getLoggerOutputDirFileChooser(File lastLoggerOutputDir) {
|
||||
JFileChooser fc;
|
||||
if (lastLoggerOutputDir.exists() && lastLoggerOutputDir.isDirectory()) {
|
||||
fc = new JFileChooser(lastLoggerOutputDir.getAbsolutePath());
|
||||
} else {
|
||||
fc = new JFileChooser();
|
||||
}
|
||||
fc.setFileSelectionMode(DIRECTORIES_ONLY);
|
||||
return fc;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package enginuity.logger.ui.swing.menubar.util;
|
||||
|
||||
import static enginuity.logger.ui.swing.menubar.action.AbstractAction.SELECTED_KEY;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
||||
public final class SelectionStateAdaptor implements PropertyChangeListener, ItemListener {
|
||||
private final Action action;
|
||||
private final AbstractButton button;
|
||||
|
||||
public SelectionStateAdaptor(Action action, AbstractButton button) {
|
||||
this.action = action;
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
public void configure() {
|
||||
action.addPropertyChangeListener(this);
|
||||
button.addItemListener(this);
|
||||
}
|
||||
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
action.putValue(SELECTED_KEY, e.getStateChange() == ItemEvent.SELECTED);
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (evt.getPropertyName().equals(SELECTED_KEY)) {
|
||||
button.setSelected((Boolean) evt.getNewValue());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package enginuity.logger.ui.swing.menubar.util;
|
||||
|
||||
import enginuity.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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue