mirror of https://github.com/rusefi/RomRaider.git
logger profile loading fixes
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@416 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
e6c5ec4df4
commit
7224290c0d
|
@ -239,7 +239,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
private void loadUserProfile(EcuDataLoader dataLoader, String profileFilePath) {
|
||||
UserProfileLoader profileLoader = new UserProfileLoaderImpl();
|
||||
UserProfile profile = profileLoader.loadProfile(profileFilePath);
|
||||
initSelectedPort(profile);
|
||||
setSelectedPort(profile);
|
||||
List<EcuParameter> ecuParams = dataLoader.getEcuParameters();
|
||||
addConvertorUpdateListeners(ecuParams);
|
||||
clearParamTableModels();
|
||||
|
@ -248,9 +248,10 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
loadEcuSwitches(dataLoader.getEcuSwitches(), profile);
|
||||
}
|
||||
|
||||
private void initSelectedPort(UserProfile profile) {
|
||||
private void setSelectedPort(UserProfile profile) {
|
||||
if (profile != null) {
|
||||
settings.setLoggerPort(profile.getSerialPort());
|
||||
portsComboBox.setSelectedItem(profile.getSerialPort());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -570,6 +571,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
|
||||
|
||||
public static void main(String... args) {
|
||||
System.out.println(System.getProperty("user.dir"));
|
||||
startLogger(EXIT_ON_CLOSE, new Settings());
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ public class EcuLoggerMenuBar extends JMenuBar implements ActionListener {
|
|||
|
||||
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");
|
||||
|
@ -62,15 +63,18 @@ public class EcuLoggerMenuBar extends JMenuBar implements ActionListener {
|
|||
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);
|
||||
|
@ -115,6 +119,13 @@ public class EcuLoggerMenuBar extends JMenuBar implements ActionListener {
|
|||
parent.reportError(e);
|
||||
}
|
||||
|
||||
} else if (evt.getSource() == reloadProfile) {
|
||||
try {
|
||||
parent.reloadUserProfile(parent.getSettings().getLoggerProfileFilePath());
|
||||
} catch (Exception e) {
|
||||
parent.reportError(e);
|
||||
}
|
||||
|
||||
} else if (evt.getSource() == saveProfile) {
|
||||
try {
|
||||
saveProfile();
|
||||
|
|
|
@ -37,7 +37,7 @@ public final class SerialPortComboBox extends JComboBox implements SerialPortRef
|
|||
this.settings = settings;
|
||||
}
|
||||
|
||||
public void refreshPortList(Set<String> ports, String defaultSelectedPort) {
|
||||
public synchronized void refreshPortList(Set<String> ports, String defaultSelectedPort) {
|
||||
checkNotNull(ports);
|
||||
boolean changeDetected = ports.isEmpty() || ports.size() != getItemCount();
|
||||
if (!changeDetected) {
|
||||
|
@ -83,4 +83,23 @@ public final class SerialPortComboBox extends JComboBox implements SerialPortRef
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelectedItem(Object object) {
|
||||
if (contains(object)) {
|
||||
super.setSelectedItem(object);
|
||||
} else {
|
||||
if (getItemCount() >= 1) {
|
||||
setSelectedIndex(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean contains(Object object) {
|
||||
for (int i = 0; i < getItemCount(); i++) {
|
||||
if (getItemAt(i) != null && getItemAt(i).equals(object)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue