Moved DynoChartPanel.java to the com.romraider.logger.ecu.ui.tab.dyno package.

Formatted ECUEditorMenuBar.java.
This commit is contained in:
Scotthew 2012-06-22 09:51:04 -07:00
parent 0d7c00b6b8
commit 2a3cb779cb
4 changed files with 356 additions and 317 deletions

View File

@ -17,9 +17,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
package com.romraider.logger.ecu.ui.tab; package com.romraider.logger.ecu.ui.tab.dyno;
import com.romraider.logger.ecu.ui.handler.graph.SpringUtilities; import com.romraider.logger.ecu.ui.handler.graph.SpringUtilities;
import com.romraider.logger.ecu.ui.tab.CircleDrawer;
import com.romraider.logger.ecu.ui.tab.XYTrendline;
import static com.romraider.util.ParamChecker.checkNotNull; import static com.romraider.util.ParamChecker.checkNotNull;
import jamlab.Polyfit; import jamlab.Polyfit;
import static java.awt.Color.BLACK; import static java.awt.Color.BLACK;

View File

@ -21,16 +21,9 @@ package com.romraider.logger.ecu.ui.tab.dyno;
import static com.centerkey.utils.BareBonesBrowserLaunch.openURL; import static com.centerkey.utils.BareBonesBrowserLaunch.openURL;
import static com.romraider.Version.CARS_DEFS_URL; import static com.romraider.Version.CARS_DEFS_URL;
import com.romraider.editor.ecu.ECUEditor; import static com.romraider.logger.car.util.SpeedCalculator.calculateMph;
import com.romraider.logger.ecu.definition.EcuDataConvertor; import static com.romraider.logger.car.util.SpeedCalculator.calculateRpm;
import com.romraider.logger.ecu.definition.EcuParameter;
import com.romraider.logger.ecu.definition.EcuSwitch;
import com.romraider.logger.ecu.definition.ExternalData;
import com.romraider.logger.ecu.definition.LoggerData;
import com.romraider.logger.ecu.ui.DataRegistrationBroker;
import com.romraider.logger.ecu.ui.tab.DynoChartPanel;
import static com.romraider.logger.car.util.TorqueCalculator.calculateTorque; import static com.romraider.logger.car.util.TorqueCalculator.calculateTorque;
import static com.romraider.logger.car.util.SpeedCalculator.*;
import static com.romraider.util.ParamChecker.checkNotNull; import static com.romraider.util.ParamChecker.checkNotNull;
import static java.awt.GridBagConstraints.CENTER; import static java.awt.GridBagConstraints.CENTER;
import static java.awt.GridBagConstraints.HORIZONTAL; import static java.awt.GridBagConstraints.HORIZONTAL;
@ -40,13 +33,24 @@ import static javax.swing.JOptionPane.ERROR_MESSAGE;
import static javax.swing.JOptionPane.WARNING_MESSAGE; import static javax.swing.JOptionPane.WARNING_MESSAGE;
import static javax.swing.JOptionPane.showMessageDialog; import static javax.swing.JOptionPane.showMessageDialog;
import static javax.swing.JOptionPane.showOptionDialog; import static javax.swing.JOptionPane.showOptionDialog;
import org.apache.log4j.Logger;
import org.w3c.dom.Document; import java.awt.Component;
import org.w3c.dom.Element; import java.awt.GridBagConstraints;
import org.w3c.dom.Node; import java.awt.GridBagLayout;
import org.w3c.dom.NodeList; import java.awt.event.ActionEvent;
import org.xml.sax.SAXException; import java.awt.event.ActionListener;
import org.xml.sax.SAXParseException; import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.ButtonGroup; import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton; import javax.swing.JButton;
@ -63,26 +67,22 @@ import javax.swing.border.TitledBorder;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import java.awt.Component;
import java.awt.GridBagConstraints; import org.apache.log4j.Logger;
import java.awt.GridBagLayout; import org.w3c.dom.Document;
import java.awt.event.ActionEvent; import org.w3c.dom.Element;
import java.awt.event.ActionListener; import org.w3c.dom.Node;
import java.awt.event.FocusAdapter; import org.w3c.dom.NodeList;
import java.awt.event.FocusEvent; import org.xml.sax.SAXException;
import java.io.BufferedReader; import org.xml.sax.SAXParseException;
import java.io.BufferedWriter;
import java.io.File; import com.romraider.editor.ecu.ECUEditor;
import java.io.FileReader; import com.romraider.logger.ecu.definition.EcuDataConvertor;
import java.io.FileWriter; import com.romraider.logger.ecu.definition.EcuParameter;
import java.io.IOException; import com.romraider.logger.ecu.definition.EcuSwitch;
import java.util.ArrayList; import com.romraider.logger.ecu.definition.ExternalData;
import java.util.Arrays; import com.romraider.logger.ecu.definition.LoggerData;
import java.util.HashSet; import com.romraider.logger.ecu.ui.DataRegistrationBroker;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
public final class DynoControlPanel extends JPanel { public final class DynoControlPanel extends JPanel {
private static final long serialVersionUID = 3787020251963102201L; private static final long serialVersionUID = 3787020251963102201L;
@ -181,26 +181,26 @@ public final class DynoControlPanel extends JPanel {
private String[] widthArr; private String[] widthArr;
private String[] aspectArr; private String[] aspectArr;
private String[] sizeArr; private String[] sizeArr;
private JTextField carMass = new JTextField("0", 4); private final JTextField carMass = new JTextField("0", 4);
private JTextField deltaMass = new JTextField("225", 4); private final JTextField deltaMass = new JTextField("225", 4);
private JTextField dragCoeff = new JTextField("0", 4); private final JTextField dragCoeff = new JTextField("0", 4);
private JTextField rollCoeff = new JTextField("0", 4); private final JTextField rollCoeff = new JTextField("0", 4);
private JTextField frontalArea = new JTextField("0", 4); private final JTextField frontalArea = new JTextField("0", 4);
private JTextField rpmMin = new JTextField("2000", 4); private final JTextField rpmMin = new JTextField("2000", 4);
private JTextField rpmMax = new JTextField("6500", 4); private final JTextField rpmMax = new JTextField("6500", 4);
private JTextField elevation = new JTextField("200", 4); private final JTextField elevation = new JTextField("200", 4);
private JTextField relHumid = new JTextField("60", 4); private final JTextField relHumid = new JTextField("60", 4);
private JTextField ambTemp = new JTextField("68", 4); private final JTextField ambTemp = new JTextField("68", 4);
private JTextField gearRatio = new JTextField("0", 4); private final JTextField gearRatio = new JTextField("0", 4);
private JTextField finalRatio = new JTextField("0", 4); private final JTextField finalRatio = new JTextField("0", 4);
private JTextField transmission = new JTextField("0", 4); private final JTextField transmission = new JTextField("0", 4);
private JTextField tireWidth = new JTextField("0", 4); private final JTextField tireWidth = new JTextField("0", 4);
private JTextField tireAspect = new JTextField("0", 4); private final JTextField tireAspect = new JTextField("0", 4);
private JTextField tireSize = new JTextField("0", 4); private final JTextField tireSize = new JTextField("0", 4);
private JLabel elevLabel = new JLabel("Elevation (ft)"); private final JLabel elevLabel = new JLabel("Elevation (ft)");
private JLabel tempLabel = new JLabel("Air Temperature (\u00b0F)"); private final JLabel tempLabel = new JLabel("Air Temperature (\u00b0F)");
private JLabel deltaMassLabel = new JLabel("Delta Weight (lbs)"); private final JLabel deltaMassLabel = new JLabel("Delta Weight (lbs)");
private JLabel carMassLabel = new JLabel("Base Weight (lbs)"); private final JLabel carMassLabel = new JLabel("Base Weight (lbs)");
// private static final String SI = "SI"; // private static final String SI = "SI";
private String units = IMPERIAL; private String units = IMPERIAL;
private String preUnits = IMPERIAL; private String preUnits = IMPERIAL;
@ -212,13 +212,13 @@ public final class DynoControlPanel extends JPanel {
private String iatLogUnits = "F"; private String iatLogUnits = "F";
private String atmLogUnits = "psi"; private String atmLogUnits = "psi";
private String vsLogUnits = LOG_VS_I; private String vsLogUnits = LOG_VS_I;
private double[] results = new double[5]; private final double[] results = new double[5];
private String[] resultStrings = new String[6]; private final String[] resultStrings = new String[6];
// private String hpUnits = "hp(I)"; // private String hpUnits = "hp(I)";
// private String tqUnits = "lbf-ft"; // private String tqUnits = "lbf-ft";
private double distance = 0; private double distance = 0;
private long lastET = 0; private long lastET = 0;
private double[] etResults = new double[12]; private final double[] etResults = new double[12];
private final JPanel filterPanel = new JPanel(); private final JPanel filterPanel = new JPanel();
private final JPanel unitsPanel = new JPanel(); private final JPanel unitsPanel = new JPanel();
@ -258,16 +258,16 @@ public final class DynoControlPanel extends JPanel {
mass = (parseDouble(carMass) + parseDouble(deltaMass)); //kg mass = (parseDouble(carMass) + parseDouble(deltaMass)); //kg
pressure = atm * 1000; // [Pa] = [kPa] * 1000 pressure = atm * 1000; // [Pa] = [kPa] * 1000
} }
// if (units.equals(SI)) { // if (units.equals(SI)) {
// altitude = parseDouble(elevation); // meters // altitude = parseDouble(elevation); // meters
// airTemp = parseDouble(ambTemp); //[K] // airTemp = parseDouble(ambTemp); //[K]
// mass = (parseDouble(carMass) + parseDouble(deltaMass)); //kg // mass = (parseDouble(carMass) + parseDouble(deltaMass)); //kg
// } // }
tSize = parseDouble(tireSize) + parseDouble(tireWidth) / 25.4 * parseDouble(tireAspect) / 100 * 2; tSize = parseDouble(tireSize) + parseDouble(tireWidth) / 25.4 * parseDouble(tireAspect) / 100 * 2;
rpm2mph = parseDouble(gearRatio) * parseDouble(finalRatio) / (tSize * 0.002975); rpm2mph = parseDouble(gearRatio) * parseDouble(finalRatio) / (tSize * 0.002975);
humidity = parseDouble(relHumid) / 100; humidity = parseDouble(relHumid) / 100;
// carInfo = (String) carSelectBox.getSelectedItem() + "(" + gearSelectBox.getSelectedItem() + "), Pres: " + pressText + // carInfo = (String) carSelectBox.getSelectedItem() + "(" + gearSelectBox.getSelectedItem() + "), Pres: " + pressText +
// pressUnits + ", Hum: " + relHumid.getText().trim() + "%, Temp: " + ambTemp.getText().trim() + tempUnits; // pressUnits + ", Hum: " + relHumid.getText().trim() + "%, Temp: " + ambTemp.getText().trim() + tempUnits;
// Use elevation if ATM was not read from ECU // Use elevation if ATM was not read from ECU
if (atm == 0) { if (atm == 0) {
pressure = 101325 * Math.pow((1 - 22.5577 * Math.pow(10, -6) * altitude), 5.25578); //Pressure at altitude [Pa] pressure = 101325 * Math.pow((1 - 22.5577 * Math.pow(10, -6) * altitude), 5.25578); //Pressure at altitude [Pa]
@ -348,7 +348,7 @@ public final class DynoControlPanel extends JPanel {
elevation.setText(String.format("%1.0f", altitude)); elevation.setText(String.format("%1.0f", altitude));
} }
// disable user input if ECU parameters recorded // disable user input if ECU parameters recorded
// ambTemp.setEnabled(false); // ambTemp.setEnabled(false);
elevation.setEnabled(false); elevation.setEnabled(false);
calculateEnv(); calculateEnv();
updateChart(); updateChart();
@ -508,26 +508,26 @@ public final class DynoControlPanel extends JPanel {
} }
public boolean isValidET(long now, double vs) { public boolean isValidET(long now, double vs) {
try { try {
// LOGGER.trace("lastET: " + lastET + " now: " + now + " VS: " + vs); // LOGGER.trace("lastET: " + lastET + " now: " + now + " VS: " + vs);
if (vs > 0) { if (vs > 0) {
if (vsLogUnits.equals(LOG_VS_M)) vs = (vs / KPH_2_MPH); if (vsLogUnits.equals(LOG_VS_M)) vs = (vs / KPH_2_MPH);
distance = distance + (vs * 5280 / 3600 * (now - lastET) / 1000); distance = distance + (vs * 5280 / 3600 * (now - lastET) / 1000);
LOGGER.info("ET Distance (ft): " + distance); LOGGER.info("ET Distance (ft): " + distance);
if (distance > 1330) { if (distance > 1330) {
recordDataButton.setSelected(false); recordDataButton.setSelected(false);
deregisterData(VEHICLE_SPEED); deregisterData(VEHICLE_SPEED);
chartPanel.clearPrompt(); chartPanel.clearPrompt();
updateET(); updateET();
return false; return false;
} }
return true; return true;
} }
return false; return false;
} }
finally { finally {
lastET = now; lastET = now;
} }
} }
public boolean isValidData(double rpm, double ta) { public boolean isValidData(double rpm, double ta) {
@ -575,7 +575,7 @@ public final class DynoControlPanel extends JPanel {
add(panel, gridBagLayout, buildRadioPanel(), 0, 2, 1, HORIZONTAL); add(panel, gridBagLayout, buildRadioPanel(), 0, 2, 1, HORIZONTAL);
add(panel, gridBagLayout, buildInterpolatePanel(), 0, 3, 1, HORIZONTAL); add(panel, gridBagLayout, buildInterpolatePanel(), 0, 3, 1, HORIZONTAL);
add(panel, gridBagLayout, buildReferencePanel(), 0, 4, 1, HORIZONTAL); add(panel, gridBagLayout, buildReferencePanel(), 0, 4, 1, HORIZONTAL);
// add(panel, gridBagLayout, buildEtPanel(), 0, 5, 1, HORIZONTAL); // add(panel, gridBagLayout, buildEtPanel(), 0, 5, 1, HORIZONTAL);
add(panel); add(panel);
} }
@ -587,7 +587,7 @@ public final class DynoControlPanel extends JPanel {
} }
private JPanel buildRadioPanel() { private JPanel buildRadioPanel() {
// JPanel panel = new JPanel(); // JPanel panel = new JPanel();
unitsPanel.setBorder(new TitledBorder("Measurement Units")); unitsPanel.setBorder(new TitledBorder("Measurement Units"));
GridBagLayout gridBagLayout = new GridBagLayout(); GridBagLayout gridBagLayout = new GridBagLayout();
@ -681,9 +681,9 @@ public final class DynoControlPanel extends JPanel {
addComponent(filterPanel, gridBagLayout, recordButton, 31); addComponent(filterPanel, gridBagLayout, recordButton, 31);
addComponent(filterPanel, gridBagLayout, buildLoadFileCB(), 32); addComponent(filterPanel, gridBagLayout, buildLoadFileCB(), 32);
addComponent(filterPanel, gridBagLayout, buildResetButton(), 33); addComponent(filterPanel, gridBagLayout, buildResetButton(), 33);
// addLabeledComponent(panel, gridBagLayout, "Drag Coeff", dragCoeff, 33); // addLabeledComponent(panel, gridBagLayout, "Drag Coeff", dragCoeff, 33);
// addLabeledComponent(panel, gridBagLayout, "Frontal Area", frontalArea, 36); // addLabeledComponent(panel, gridBagLayout, "Frontal Area", frontalArea, 36);
// addLabeledComponent(panel, gridBagLayout, "Rolling Resist Coeff", rollCoeff, 39); // addLabeledComponent(panel, gridBagLayout, "Rolling Resist Coeff", rollCoeff, 39);
setSelectAllFieldText(tireWidth); setSelectAllFieldText(tireWidth);
setSelectAllFieldText(tireAspect); setSelectAllFieldText(tireAspect);
setSelectAllFieldText(tireSize); setSelectAllFieldText(tireSize);
@ -714,6 +714,7 @@ public final class DynoControlPanel extends JPanel {
private JButton buildResetButton() { private JButton buildResetButton() {
JButton resetButton = new JButton("Clear Data"); JButton resetButton = new JButton("Clear Data");
resetButton.addActionListener(new ActionListener() { resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
chartPanel.clear(); chartPanel.clear();
parent.repaint(); parent.repaint();
@ -726,6 +727,7 @@ public final class DynoControlPanel extends JPanel {
private JToggleButton buildRecordDataButton() { private JToggleButton buildRecordDataButton() {
if (!carTypeArr[0].trim().equals(MISSING_CAR_DEF)) { if (!carTypeArr[0].trim().equals(MISSING_CAR_DEF)) {
recordDataButton.addActionListener(new ActionListener() { recordDataButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
elevation.setEnabled(true); elevation.setEnabled(true);
if (dButton.isSelected()) { if (dButton.isSelected()) {
@ -778,6 +780,7 @@ public final class DynoControlPanel extends JPanel {
private JCheckBox buildLoadFileCB() { private JCheckBox buildLoadFileCB() {
loadFileCB.addActionListener(new ActionListener() { loadFileCB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
if (loadFileCB.isSelected()) { if (loadFileCB.isSelected()) {
recordDataButton.setText("Read From File"); recordDataButton.setText("Read From File");
@ -800,6 +803,7 @@ public final class DynoControlPanel extends JPanel {
private void buildModeButtons(JPanel panel) { private void buildModeButtons(JPanel panel) {
dButton.addActionListener(new ActionListener() { dButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
chartPanel.setDyno(); chartPanel.setDyno();
if (loadFileCB.isSelected()) { if (loadFileCB.isSelected()) {
@ -807,25 +811,26 @@ public final class DynoControlPanel extends JPanel {
} else { } else {
recordDataButton.setText("Record Data"); recordDataButton.setText("Record Data");
} }
// etPanel.setVisible(false); // etPanel.setVisible(false);
// filterPanel.setVisible(true); // filterPanel.setVisible(true);
unitsPanel.setVisible(true); unitsPanel.setVisible(true);
iPanel.setVisible(true); iPanel.setVisible(true);
// refPanel.setVisible(true); // refPanel.setVisible(true);
parent.repaint(); parent.repaint();
} }
}); });
dButton.setSelected(true); dButton.setSelected(true);
eButton.addActionListener(new ActionListener() { eButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
chartPanel.setET(); chartPanel.setET();
recordDataButton.setText("Record ET"); recordDataButton.setText("Record ET");
// filterPanel.setVisible(false); // filterPanel.setVisible(false);
unitsPanel.setVisible(false); unitsPanel.setVisible(false);
iPanel.setVisible(false); iPanel.setVisible(false);
// refPanel.setVisible(false); // refPanel.setVisible(false);
// etPanel.setVisible(true); // etPanel.setVisible(true);
parent.repaint(); parent.repaint();
} }
}); });
@ -839,37 +844,39 @@ public final class DynoControlPanel extends JPanel {
private void buildRadioButtons(JPanel panel) { private void buildRadioButtons(JPanel panel) {
iButton.addActionListener(new ActionListener() { iButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
buttonAction(iButton); buttonAction(iButton);
} }
}); });
// iButton.setActionCommand(IMPERIAL); // iButton.setActionCommand(IMPERIAL);
iButton.setSelected(true); iButton.setSelected(true);
mButton.addActionListener(new ActionListener() { mButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
buttonAction(mButton); buttonAction(mButton);
} }
}); });
// mButton.setActionCommand(METRIC); // mButton.setActionCommand(METRIC);
// final JRadioButton sButton = new JRadioButton(SI); // final JRadioButton sButton = new JRadioButton(SI);
// sButton.addActionListener(new ActionListener() { // sButton.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent actionEvent) { // public void actionPerformed(ActionEvent actionEvent) {
// buttonAction(sButton); // buttonAction(sButton);
// } // }
// }); // });
// sButton.setActionCommand(SI); // sButton.setActionCommand(SI);
//Group the radio buttons. //Group the radio buttons.
ButtonGroup group = new ButtonGroup(); ButtonGroup group = new ButtonGroup();
group.add(iButton); group.add(iButton);
group.add(mButton); group.add(mButton);
// group.add(sButton); // group.add(sButton);
panel.add(iButton); panel.add(iButton);
panel.add(mButton); panel.add(mButton);
// panel.add(sButton); // panel.add(sButton);
} }
@ -888,16 +895,16 @@ public final class DynoControlPanel extends JPanel {
elevation.setText(String.format("%1.0f", result)); elevation.setText(String.format("%1.0f", result));
atm = atm / 6.89475728; atm = atm / 6.89475728;
} }
// if (preUnits.equals(SI)){ // if (preUnits.equals(SI)){
// result = parseDouble(ambTemp)* 9/5 - 459.67; // result = parseDouble(ambTemp)* 9/5 - 459.67;
// ambTemp.setText(String.format("%1.0f", result)); // ambTemp.setText(String.format("%1.0f", result));
// result = parseDouble(carMass) / 0.4536; // result = parseDouble(carMass) / 0.4536;
// carMass.setText(String.format("%1.0f", result)); // carMass.setText(String.format("%1.0f", result));
// result = parseDouble(deltaMass) / 0.4536; // result = parseDouble(deltaMass) / 0.4536;
// deltaMass.setText(String.format("%1.0f", result)); // deltaMass.setText(String.format("%1.0f", result));
// result = parseDouble(elevation) / 0.3048; // result = parseDouble(elevation) / 0.3048;
// elevation.setText(String.format("%1.0f", result)); // elevation.setText(String.format("%1.0f", result));
// } // }
preUnits = IMPERIAL; preUnits = IMPERIAL;
elevUnits = "ft"; elevUnits = "ft";
tempUnits = "\u00b0F"; tempUnits = "\u00b0F";
@ -920,10 +927,10 @@ public final class DynoControlPanel extends JPanel {
elevation.setText(String.format("%1.0f", result)); elevation.setText(String.format("%1.0f", result));
atm = atm * 6.89475728; atm = atm * 6.89475728;
} }
// if (preUnits.equals(SI)){ // if (preUnits.equals(SI)){
// result = parseDouble(ambTemp) - 273.15; // result = parseDouble(ambTemp) - 273.15;
// ambTemp.setText(String.format("%1.1f", result)); // ambTemp.setText(String.format("%1.1f", result));
// } // }
preUnits = METRIC; preUnits = METRIC;
elevUnits = "m"; elevUnits = "m";
tempUnits = "\u00b0C"; tempUnits = "\u00b0C";
@ -934,30 +941,30 @@ public final class DynoControlPanel extends JPanel {
pressText = String.format("%1.2f", atm); pressText = String.format("%1.2f", atm);
pressUnits = "kPa"; pressUnits = "kPa";
} }
// if (units.equals(SI)) { // if (units.equals(SI)) {
// if (preUnits.equals(IMPERIAL)){ // if (preUnits.equals(IMPERIAL)){
// result = (parseDouble(ambTemp) + 459.67) * 5/9; // result = (parseDouble(ambTemp) + 459.67) * 5/9;
// ambTemp.setText(String.format("%1.1f", result)); // ambTemp.setText(String.format("%1.1f", result));
// result = parseDouble(carMass) * 0.4536; // result = parseDouble(carMass) * 0.4536;
// carMass.setText(String.format("%1.0f", result)); // carMass.setText(String.format("%1.0f", result));
// LOGGER.trace("units selcted: " + units + " result: " + result); // LOGGER.trace("units selcted: " + units + " result: " + result);
// result = parseDouble(deltaMass) * 0.4536; // result = parseDouble(deltaMass) * 0.4536;
// deltaMass.setText(String.format("%1.0f", result)); // deltaMass.setText(String.format("%1.0f", result));
// result = parseDouble(elevation) * 0.3048; // result = parseDouble(elevation) * 0.3048;
// elevation.setText(String.format("%1.0f", result)); // elevation.setText(String.format("%1.0f", result));
// } // }
// if (preUnits.equals(METRIC)){ // if (preUnits.equals(METRIC)){
// result = parseDouble(ambTemp) + 273.15; // result = parseDouble(ambTemp) + 273.15;
// ambTemp.setText(String.format("%1.1f", result)); // ambTemp.setText(String.format("%1.1f", result));
// } // }
// preUnits = SI; // preUnits = SI;
// elevUnits = "m"; // elevUnits = "m";
// tempUnits = "K"; // tempUnits = "K";
// elevLabel.setText("Elevation (m)"); // elevLabel.setText("Elevation (m)");
// tempLabel.setText("Air Temperature (K)"); // tempLabel.setText("Air Temperature (K)");
// deltaMassLabel.setText("Delta Weight (kg)"); // deltaMassLabel.setText("Delta Weight (kg)");
// carMassLabel.setText("Base Weight (kg)"); // carMassLabel.setText("Base Weight (kg)");
// } // }
if (resultStrings[0] != null) interpolateButton.doClick(); if (resultStrings[0] != null) interpolateButton.doClick();
LOGGER.info("DYNO Measurement units selected: " + units); LOGGER.info("DYNO Measurement units selected: " + units);
} }
@ -997,7 +1004,7 @@ public final class DynoControlPanel extends JPanel {
if (headers.length < 3) { if (headers.length < 3) {
headers = line.split(TAB); headers = line.split(TAB);
if (headers.length > 2) { if (headers.length > 2) {
delimiter = TAB; delimiter = TAB;
} }
else { else {
headers = line.split(SEMICOLON); headers = line.split(SEMICOLON);
@ -1023,9 +1030,9 @@ public final class DynoControlPanel extends JPanel {
if (headers[x].contains(LOG_VS_I)) vsLogUnits = LOG_VS_I; if (headers[x].contains(LOG_VS_I)) vsLogUnits = LOG_VS_I;
if (headers[x].contains(LOG_VS_M)) vsLogUnits = LOG_VS_M; if (headers[x].contains(LOG_VS_M)) vsLogUnits = LOG_VS_M;
} }
LOGGER.trace("DYNO log file conversions: Time Column: " + timeCol + "; Time X: " + timeMult + LOGGER.trace("DYNO log file conversions: Time Column: " + timeCol + "; Time X: " + timeMult +
"; RPM Column: " + rpmCol + "; TA Column: " + taCol + "; VS Column: " + vsCol + "; RPM Column: " + rpmCol + "; TA Column: " + taCol + "; VS Column: " + vsCol +
"; VS units: " + vsLogUnits); "; VS units: " + vsLogUnits);
while ((line = inputStream.readLine()) != null) { while ((line = inputStream.readLine()) != null) {
String[] values = line.split(delimiter); String[] values = line.split(delimiter);
if (Double.parseDouble(values[taCol]) > 98) { if (Double.parseDouble(values[taCol]) > 98) {
@ -1056,7 +1063,7 @@ public final class DynoControlPanel extends JPanel {
maxRpm = Math.max(maxRpm, calculateRpm(logRpm, rpm2mph, vsLogUnits)); maxRpm = Math.max(maxRpm, calculateRpm(logRpm, rpm2mph, vsLogUnits));
} }
chartPanel.addRawData(logTime, logRpm); chartPanel.addRawData(logTime, logRpm);
LOGGER.trace("DYNO log file time: " + logTime + "; speed: " + logRpm); LOGGER.trace("DYNO log file time: " + logTime + "; speed: " + logRpm);
} }
} }
inputStream.close(); inputStream.close();
@ -1084,6 +1091,7 @@ public final class DynoControlPanel extends JPanel {
final JButton openButton = new JButton("Open"); final JButton openButton = new JButton("Open");
openButton.addActionListener(new ActionListener() { openButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
int returnVal = openFile.showOpenDialog(openButton); int returnVal = openFile.showOpenDialog(openButton);
@ -1144,6 +1152,7 @@ public final class DynoControlPanel extends JPanel {
final JButton saveButton = new JButton("Save"); final JButton saveButton = new JButton("Save");
saveButton.addActionListener(new ActionListener() { saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
int returnVal = openFile.showSaveDialog(saveButton); int returnVal = openFile.showSaveDialog(saveButton);
@ -1157,11 +1166,11 @@ public final class DynoControlPanel extends JPanel {
outputStream = new BufferedWriter(new FileWriter(traceFile)); outputStream = new BufferedWriter(new FileWriter(traceFile));
LOGGER.info("DYNO Saving trace to file: " + traceFile.getName()); LOGGER.info("DYNO Saving trace to file: " + traceFile.getName());
String line = units + TAB + orderComboBox.getSelectedItem() + String line = units + TAB + orderComboBox.getSelectedItem() +
TAB + resultStrings[1] + TAB + resultStrings[1] +
TAB + fToE + TAB + fToE +
TAB + sToE + TAB + sToE +
TAB + tToS + TAB + tToS +
TAB + auc; TAB + auc;
outputStream.write(line, 0, line.length()); outputStream.write(line, 0, line.length());
outputStream.newLine(); outputStream.newLine();
@ -1213,6 +1222,7 @@ public final class DynoControlPanel extends JPanel {
private JButton buildClearReferenceButton() { private JButton buildClearReferenceButton() {
final JButton clearButton = new JButton("Clear"); final JButton clearButton = new JButton("Clear");
clearButton.addActionListener(new ActionListener() { clearButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
reFfToE = 0; reFfToE = 0;
reFsToE = 0; reFsToE = 0;
@ -1288,6 +1298,7 @@ public final class DynoControlPanel extends JPanel {
private JButton buildInterpolateButton(final JComboBox orderComboBox) { private JButton buildInterpolateButton(final JComboBox orderComboBox) {
interpolateButton.addActionListener(new ActionListener() { interpolateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
if (dButton.isSelected()) { if (dButton.isSelected()) {
interpolateButton.setEnabled(true); interpolateButton.setEnabled(true);
@ -1365,18 +1376,20 @@ public final class DynoControlPanel extends JPanel {
loadCars(); loadCars();
final JComboBox selectComboBox = new JComboBox(carTypeArr); final JComboBox selectComboBox = new JComboBox(carTypeArr);
selectComboBox.addActionListener(new ActionListener() { selectComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
changeCars(selectComboBox.getSelectedIndex()); changeCars(selectComboBox.getSelectedIndex());
} }
}); });
// carSelectBox.setSelectedItem("05 USDM OBXT WGN LTD 5MT"); // carSelectBox.setSelectedItem("05 USDM OBXT WGN LTD 5MT");
return selectComboBox; return selectComboBox;
} }
private JComboBox buildGearComboBox() { private JComboBox buildGearComboBox() {
// makeGearList(); // makeGearList();
final JComboBox gearSelectBox = new JComboBox(); final JComboBox gearSelectBox = new JComboBox();
gearSelectBox.addActionListener(new ActionListener() { gearSelectBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
gearRatio.setText(gearsRatioArr[carSelectBox.getSelectedIndex()][gearSelectBox.getSelectedIndex() + 1]); gearRatio.setText(gearsRatioArr[carSelectBox.getSelectedIndex()][gearSelectBox.getSelectedIndex() + 1]);
LOGGER.info("DYNO Car: " + carSelectBox.getSelectedItem() + ", Changed gear to: " + gearSelectBox.getSelectedItem() + " (" + gearRatio.getText() + ")"); LOGGER.info("DYNO Car: " + carSelectBox.getSelectedItem() + ", Changed gear to: " + gearSelectBox.getSelectedItem() + " (" + gearRatio.getText() + ")");
@ -1460,52 +1473,52 @@ public final class DynoControlPanel extends JPanel {
Element element = (Element) list.item(0); Element element = (Element) list.item(0);
if (element != null) { if (element != null) {
NodeList value = element.getChildNodes(); NodeList value = element.getChildNodes();
String data = ((Node) value.item(0)).getNodeValue().trim(); String data = value.item(0).getNodeValue().trim();
switch (i) { switch (i) {
case 0: case 0:
carTypeArr[s] = data; carTypeArr[s] = data;
// gearRatioArr[s] = data; // gearRatioArr[s] = data;
for (int g = 1; g <= 6; g++) { for (int g = 1; g <= 6; g++) {
String gearNo = "gearratio" + g; String gearNo = "gearratio" + g;
NodeList grsList = carElement.getElementsByTagName(gearNo); NodeList grsList = carElement.getElementsByTagName(gearNo);
Element carGrsElement = (Element) grsList.item(0); Element carGrsElement = (Element) grsList.item(0);
if (carGrsElement != null) { if (carGrsElement != null) {
NodeList grsValueList = carGrsElement.getChildNodes(); NodeList grsValueList = carGrsElement.getChildNodes();
if (((Node) grsValueList.item(0)).getNodeValue().trim() != null) { if (grsValueList.item(0).getNodeValue().trim() != null) {
gearsRatioArr[s][0] = Integer.toString(g); gearsRatioArr[s][0] = Integer.toString(g);
gearsRatioArr[s][g] = (String) ((Node) grsValueList.item(0)).getNodeValue().trim(); gearsRatioArr[s][g] = grsValueList.item(0).getNodeValue().trim();
}
} }
// LOGGER.trace("Car: " + s + " Gear: " + g + " Ratio: " + gearsRatioArr[s][g]);
} }
break; // LOGGER.trace("Car: " + s + " Gear: " + g + " Ratio: " + gearsRatioArr[s][g]);
case 1: }
carMassArr[s] = data; break;
break; case 1:
case 2: carMassArr[s] = data;
dragCoeffArr[s] = data; break;
break; case 2:
case 3: dragCoeffArr[s] = data;
rollCoeffArr[s] = data; break;
break; case 3:
case 4: rollCoeffArr[s] = data;
frontalAreaArr[s] = data; break;
break; case 4:
case 5: frontalAreaArr[s] = data;
finalRatioArr[s] = data; break;
break; case 5:
case 6: finalRatioArr[s] = data;
transArr[s] = data; break;
break; case 6:
case 7: transArr[s] = data;
widthArr[s] = data; break;
break; case 7:
case 8: widthArr[s] = data;
aspectArr[s] = data; break;
break; case 8:
case 9: aspectArr[s] = data;
sizeArr[s] = data; break;
break; case 9:
sizeArr[s] = data;
break;
} }
} }
} }
@ -1542,6 +1555,7 @@ public final class DynoControlPanel extends JPanel {
// selected whenever the cursor is in that field (gains focus): // selected whenever the cursor is in that field (gains focus):
if (allTextSelector == null) { if (allTextSelector == null) {
allTextSelector = new java.awt.event.FocusAdapter() { allTextSelector = new java.awt.event.FocusAdapter() {
@Override
public void focusGained(FocusEvent ev) { public void focusGained(FocusEvent ev) {
JTextComponent textComp = (JTextComponent) ev.getSource(); JTextComponent textComp = (JTextComponent) ev.getSource();
textComp.selectAll(); textComp.selectAll();

View File

@ -19,20 +19,22 @@
package com.romraider.logger.ecu.ui.tab.dyno; package com.romraider.logger.ecu.ui.tab.dyno;
import static java.awt.BorderLayout.CENTER;
import static java.awt.BorderLayout.WEST;
import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
import java.awt.BorderLayout;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import com.romraider.editor.ecu.ECUEditor; import com.romraider.editor.ecu.ECUEditor;
import com.romraider.logger.ecu.definition.EcuParameter; import com.romraider.logger.ecu.definition.EcuParameter;
import com.romraider.logger.ecu.definition.EcuSwitch; import com.romraider.logger.ecu.definition.EcuSwitch;
import com.romraider.logger.ecu.definition.ExternalData; import com.romraider.logger.ecu.definition.ExternalData;
import com.romraider.logger.ecu.ui.DataRegistrationBroker; import com.romraider.logger.ecu.ui.DataRegistrationBroker;
import com.romraider.logger.ecu.ui.tab.DynoChartPanel;
import static java.awt.BorderLayout.CENTER;
import static java.awt.BorderLayout.WEST;
import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import java.util.List;
public final class DynoTabImpl extends JPanel implements DynoTab { public final class DynoTabImpl extends JPanel implements DynoTab {
private static final long serialVersionUID = 2787020251963102201L; private static final long serialVersionUID = 2787020251963102201L;
@ -47,65 +49,81 @@ public final class DynoTabImpl extends JPanel implements DynoTab {
add(chartPanel, CENTER); add(chartPanel, CENTER);
} }
@Override
public double calcRpm(double vs) { public double calcRpm(double vs) {
return controlPanel.calcRpm(vs); return controlPanel.calcRpm(vs);
} }
@Override
public void updateEnv(double iat, double pressure) { public void updateEnv(double iat, double pressure) {
controlPanel.updateEnv(iat, pressure); controlPanel.updateEnv(iat, pressure);
} }
@Override
public boolean isValidET(long now, double vs) { public boolean isValidET(long now, double vs) {
return controlPanel.isValidET(now, vs); return controlPanel.isValidET(now, vs);
} }
@Override
public boolean isRecordET() { public boolean isRecordET() {
return controlPanel.isRecordET(); return controlPanel.isRecordET();
} }
@Override
public boolean isRecordData() { public boolean isRecordData() {
return controlPanel.isRecordData(); return controlPanel.isRecordData();
} }
@Override
public boolean isManual() { public boolean isManual() {
return controlPanel.isManual(); return controlPanel.isManual();
} }
@Override
public boolean getEnv() { public boolean getEnv() {
return controlPanel.getEnv(); return controlPanel.getEnv();
} }
@Override
public boolean isValidData(double rpm, double ta) { public boolean isValidData(double rpm, double ta) {
return controlPanel.isValidData(rpm, ta); return controlPanel.isValidData(rpm, ta);
} }
@Override
public void addData(double rpm, double hp, double tq) { public void addData(double rpm, double hp, double tq) {
chartPanel.addData(rpm, hp, tq); chartPanel.addData(rpm, hp, tq);
} }
@Override
public void addRawData(double time, double rpm) { public void addRawData(double time, double rpm) {
chartPanel.addRawData(time, rpm); chartPanel.addRawData(time, rpm);
} }
@Override
public void addData(double rpm, double hp) { public void addData(double rpm, double hp) {
} }
@Override
public int getSampleCount() { public int getSampleCount() {
return chartPanel.getSampleCount(); return chartPanel.getSampleCount();
} }
@Override
public void setEcuParams(List<EcuParameter> params) { public void setEcuParams(List<EcuParameter> params) {
controlPanel.setEcuParams(params); controlPanel.setEcuParams(params);
} }
@Override
public void setEcuSwitches(List<EcuSwitch> switches) { public void setEcuSwitches(List<EcuSwitch> switches) {
controlPanel.setEcuSwitches(switches); controlPanel.setEcuSwitches(switches);
} }
@Override
public void setExternalDatas(List<ExternalData> external) { public void setExternalDatas(List<ExternalData> external) {
controlPanel.setExternalDatas(external); controlPanel.setExternalDatas(external);
} }
@Override
public JPanel getPanel() { public JPanel getPanel() {
return this; return this;
} }

View File

@ -19,31 +19,19 @@
package com.romraider.swing; package com.romraider.swing;
import com.centerkey.utils.BareBonesBrowserLaunch;
import static com.romraider.Version.ABOUT_ICON; import static com.romraider.Version.ABOUT_ICON;
import static com.romraider.Version.BUILDNUMBER; import static com.romraider.Version.BUILDNUMBER;
import static com.romraider.Version.ECU_DEFS_URL; import static com.romraider.Version.ECU_DEFS_URL;
import static com.romraider.Version.PRODUCT_NAME; import static com.romraider.Version.PRODUCT_NAME;
import static com.romraider.Version.SUPPORT_URL; import static com.romraider.Version.SUPPORT_URL;
import static com.romraider.Version.VERSION; import static com.romraider.Version.VERSION;
import com.romraider.editor.ecu.ECUEditor;
import com.romraider.logger.ecu.EcuLogger;
import com.romraider.maps.Rom;
import com.romraider.maps.Table;
import com.romraider.ramtune.test.RamTuneTestApp;
import static javax.swing.JFrame.DISPOSE_ON_CLOSE;
import static javax.swing.JOptionPane.CANCEL_OPTION; import static javax.swing.JOptionPane.CANCEL_OPTION;
import static javax.swing.JOptionPane.ERROR_MESSAGE; import static javax.swing.JOptionPane.ERROR_MESSAGE;
import static javax.swing.JOptionPane.INFORMATION_MESSAGE; import static javax.swing.JOptionPane.INFORMATION_MESSAGE;
import static javax.swing.JOptionPane.showConfirmDialog; import static javax.swing.JOptionPane.showConfirmDialog;
import static javax.swing.JOptionPane.showMessageDialog; import static javax.swing.JOptionPane.showMessageDialog;
import javax.swing.ButtonGroup; import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JSeparator;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -52,48 +40,63 @@ import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.util.Vector; import java.util.Vector;
import javax.swing.ButtonGroup;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JSeparator;
import com.centerkey.utils.BareBonesBrowserLaunch;
import com.romraider.editor.ecu.ECUEditor;
import com.romraider.logger.ecu.EcuLogger;
import com.romraider.maps.Rom;
import com.romraider.maps.Table;
import com.romraider.ramtune.test.RamTuneTestApp;
public class ECUEditorMenuBar extends JMenuBar implements ActionListener { public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
private static final long serialVersionUID = -4777040428837855236L; private static final long serialVersionUID = -4777040428837855236L;
private JMenu fileMenu = new JMenu("File"); private final JMenu fileMenu = new JMenu("File");
private JMenuItem openImage = new JMenuItem("Open Image..."); private final JMenuItem openImage = new JMenuItem("Open Image...");
private JMenuItem openImages = new JMenuItem("Open Image(s)..."); private final JMenuItem openImages = new JMenuItem("Open Image(s)...");
private JMenuItem saveImage = new JMenuItem("Save Image As..."); private final JMenuItem saveImage = new JMenuItem("Save Image As...");
private JMenuItem saveAsRepository = new JMenuItem("Save Image As Repository..."); private final JMenuItem saveAsRepository = new JMenuItem("Save Image As Repository...");
private JMenuItem refreshImage = new JMenuItem("Refresh Image"); private final JMenuItem refreshImage = new JMenuItem("Refresh Image");
private JMenuItem closeImage = new JMenuItem("Close Image"); private final JMenuItem closeImage = new JMenuItem("Close Image");
private JMenuItem closeAll = new JMenuItem("Close All Images"); private final JMenuItem closeAll = new JMenuItem("Close All Images");
private JMenuItem exit = new JMenuItem("Exit"); private final JMenuItem exit = new JMenuItem("Exit");
private JMenu definitionMenu = new JMenu("ECU Definitions"); private final JMenu definitionMenu = new JMenu("ECU Definitions");
private JMenuItem defManager = new JMenuItem("ECU Definition Manager..."); private final JMenuItem defManager = new JMenuItem("ECU Definition Manager...");
// private JMenuItem editDefinition = new JMenuItem("Edit ECU Definitions..."); // private JMenuItem editDefinition = new JMenuItem("Edit ECU Definitions...");
private JMenuItem updateDefinition = new JMenuItem("Get ECU Definitions..."); private final JMenuItem updateDefinition = new JMenuItem("Get ECU Definitions...");
private JMenu editMenu = new JMenu("Edit"); private final JMenu editMenu = new JMenu("Edit");
private JMenuItem settings = new JMenuItem(PRODUCT_NAME + " Settings..."); private final JMenuItem settings = new JMenuItem(PRODUCT_NAME + " Settings...");
private JMenuItem compareImages = new JMenuItem("Compare Images..."); private final JMenuItem compareImages = new JMenuItem("Compare Images...");
private JMenu viewMenu = new JMenu("View"); private final JMenu viewMenu = new JMenu("View");
private JMenuItem romProperties = new JMenuItem("ECU Image Properties"); private final JMenuItem romProperties = new JMenuItem("ECU Image Properties");
private ButtonGroup levelGroup = new ButtonGroup(); private final ButtonGroup levelGroup = new ButtonGroup();
private JMenu levelMenu = new JMenu("User Level"); private final JMenu levelMenu = new JMenu("User Level");
private JRadioButtonMenuItem level1 = new JRadioButtonMenuItem("1 Beginner"); private final JRadioButtonMenuItem level1 = new JRadioButtonMenuItem("1 Beginner");
private JRadioButtonMenuItem level2 = new JRadioButtonMenuItem("2 Intermediate"); private final JRadioButtonMenuItem level2 = new JRadioButtonMenuItem("2 Intermediate");
private JRadioButtonMenuItem level3 = new JRadioButtonMenuItem("3 Advanced"); private final JRadioButtonMenuItem level3 = new JRadioButtonMenuItem("3 Advanced");
private JRadioButtonMenuItem level4 = new JRadioButtonMenuItem("4 Highest"); private final JRadioButtonMenuItem level4 = new JRadioButtonMenuItem("4 Highest");
private JRadioButtonMenuItem level5 = new JRadioButtonMenuItem("5 Debug Mode"); private final JRadioButtonMenuItem level5 = new JRadioButtonMenuItem("5 Debug Mode");
private JMenu loggerMenu = new JMenu("Logger"); private final JMenu loggerMenu = new JMenu("Logger");
private JMenuItem openLogger = new JMenuItem("Launch Logger..."); private final JMenuItem openLogger = new JMenuItem("Launch Logger...");
private JMenu ramTuneMenu = new JMenu("SSM"); private final JMenu ramTuneMenu = new JMenu("SSM");
private JMenuItem launchRamTuneTestApp = new JMenuItem("Launch Test App..."); private final JMenuItem launchRamTuneTestApp = new JMenuItem("Launch Test App...");
private JMenu helpMenu = new JMenu("Help"); private final JMenu helpMenu = new JMenu("Help");
private JMenuItem about = new JMenuItem("About " + PRODUCT_NAME); private final JMenuItem about = new JMenuItem("About " + PRODUCT_NAME);
private ECUEditor parent; private final ECUEditor parent;
public ECUEditorMenuBar(ECUEditor parent) { public ECUEditorMenuBar(ECUEditor parent) {
this.parent = parent; this.parent = parent;
@ -140,15 +143,15 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
add(definitionMenu); add(definitionMenu);
definitionMenu.setMnemonic('D'); definitionMenu.setMnemonic('D');
defManager.setMnemonic('D'); defManager.setMnemonic('D');
// editDefinition.setMnemonic('E'); // editDefinition.setMnemonic('E');
updateDefinition.setMnemonic('U'); updateDefinition.setMnemonic('U');
settings.setMnemonic('S'); settings.setMnemonic('S');
compareImages.setMnemonic('C'); compareImages.setMnemonic('C');
definitionMenu.add(defManager); definitionMenu.add(defManager);
// definitionMenu.add(editDefinition); // definitionMenu.add(editDefinition);
definitionMenu.add(updateDefinition); definitionMenu.add(updateDefinition);
defManager.addActionListener(this); defManager.addActionListener(this);
// editDefinition.addActionListener(this); // editDefinition.addActionListener(this);
updateDefinition.addActionListener(this); updateDefinition.addActionListener(this);
// view menu items // view menu items
@ -214,7 +217,7 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
about.addActionListener(this); about.addActionListener(this);
// disable unused buttons! 0.3.1 // disable unused buttons! 0.3.1
// editDefinition.setEnabled(false); // editDefinition.setEnabled(false);
updateMenu(); updateMenu();
} }
@ -244,6 +247,7 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
romProperties.setText(file + "Properties"); romProperties.setText(file + "Properties");
} }
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (e.getSource() == openImage) { if (e.getSource() == openImage) {
try { try {
@ -254,13 +258,13 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
} }
} else if (e.getSource() == openImages) { } else if (e.getSource() == openImages) {
try { try {
openImagesDialog(); openImagesDialog();
} catch (Exception ex) { } catch (Exception ex) {
showMessageDialog(parent, showMessageDialog(parent,
new DebugPanel(ex, parent.getSettings().getSupportURL()), "Exception", ERROR_MESSAGE); new DebugPanel(ex, parent.getSettings().getSupportURL()), "Exception", ERROR_MESSAGE);
} }
} else if (e.getSource() == saveImage) { } else if (e.getSource() == saveImage) {
try { try {
this.saveImage(parent.getLastSelectedRom()); this.saveImage(parent.getLastSelectedRom());
@ -269,12 +273,12 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
new DebugPanel(ex, parent.getSettings().getSupportURL()), "Exception", ERROR_MESSAGE); new DebugPanel(ex, parent.getSettings().getSupportURL()), "Exception", ERROR_MESSAGE);
} }
} else if (e.getSource() == saveAsRepository) { } else if (e.getSource() == saveAsRepository) {
try { try {
this.saveAsRepository(parent.getLastSelectedRom(), parent.getSettings().getLastRepositoryDir()); this.saveAsRepository(parent.getLastSelectedRom(), parent.getSettings().getLastRepositoryDir());
} catch(Exception ex) { } catch(Exception ex) {
showMessageDialog(parent, showMessageDialog(parent,
new DebugPanel(ex, parent.getSettings().getSupportURL()), "Exception", ERROR_MESSAGE); new DebugPanel(ex, parent.getSettings().getSupportURL()), "Exception", ERROR_MESSAGE);
} }
} else if (e.getSource() == closeImage) { } else if (e.getSource() == closeImage) {
this.closeImage(); this.closeImage();
@ -304,10 +308,10 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
form.setVisible(true); form.setVisible(true);
} else if (e.getSource() == compareImages){ } else if (e.getSource() == compareImages){
CompareImagesForm form = new CompareImagesForm(parent.getImages()); CompareImagesForm form = new CompareImagesForm(parent.getImages());
form.setLocationRelativeTo(parent); form.setLocationRelativeTo(parent);
form.setVisible(true); form.setVisible(true);
} else if (e.getSource() == defManager) { } else if (e.getSource() == defManager) {
DefinitionManager form = new DefinitionManager(parent); DefinitionManager form = new DefinitionManager(parent);
form.setLocationRelativeTo(parent); form.setLocationRelativeTo(parent);
@ -329,9 +333,9 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
parent.setUserLevel(5); parent.setUserLevel(5);
} else if (e.getSource() == openLogger) { } else if (e.getSource() == openLogger) {
parent.statusPanel.update("Launching Logger...", 10); parent.statusPanel.update("Launching Logger...", 10);
EcuLogger.startLogger(DISPOSE_ON_CLOSE, parent); EcuLogger.startLogger(DISPOSE_ON_CLOSE, parent);
parent.statusPanel.update("Ready...", 0); parent.statusPanel.update("Ready...", 0);
} else if (e.getSource() == updateDefinition) { } else if (e.getSource() == updateDefinition) {
BareBonesBrowserLaunch.openURL(ECU_DEFS_URL); BareBonesBrowserLaunch.openURL(ECU_DEFS_URL);
@ -368,17 +372,17 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
parent.getSettings().setLastImageDir(fc.getCurrentDirectory()); parent.getSettings().setLastImageDir(fc.getCurrentDirectory());
} }
} }
public void openImagesDialog() throws Exception { public void openImagesDialog() throws Exception {
JFileChooser fc = new JFileChooser(parent.getSettings().getLastImageDir()); JFileChooser fc = new JFileChooser(parent.getSettings().getLastImageDir());
fc.setFileFilter(new ECUImageFilter()); fc.setFileFilter(new ECUImageFilter());
fc.setMultiSelectionEnabled(true); fc.setMultiSelectionEnabled(true);
fc.setDialogTitle("Open Image(s)"); fc.setDialogTitle("Open Image(s)");
if(fc.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { if(fc.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
parent.openImages(fc.getSelectedFiles()); parent.openImages(fc.getSelectedFiles());
parent.getSettings().setLastImageDir(fc.getCurrentDirectory()); parent.getSettings().setLastImageDir(fc.getCurrentDirectory());
} }
} }
public void closeImage() { public void closeImage() {
@ -397,9 +401,9 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
boolean save = true; boolean save = true;
File selectedFile = fc.getSelectedFile(); File selectedFile = fc.getSelectedFile();
if (selectedFile.exists()) { if (selectedFile.exists()) {
int option = showConfirmDialog(parent, selectedFile.getName() + " already exists! Overwrite?"); int option = showConfirmDialog(parent, selectedFile.getName() + " already exists! Overwrite?");
// option: 0 = Cancel, 1 = No // option: 0 = Cancel, 1 = No
if (option == CANCEL_OPTION || option == 1) { if (option == CANCEL_OPTION || option == 1) {
save = false; save = false;
} }
@ -427,47 +431,47 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
// disable the "All files" option // disable the "All files" option
fc.setAcceptAllFileFilterUsed(false); fc.setAcceptAllFileFilterUsed(false);
String separator = System.getProperty("file.separator"); String separator = System.getProperty("file.separator");
if (fc.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) { if (fc.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
boolean save = true; boolean save = true;
File selectedDir = fc.getSelectedFile(); File selectedDir = fc.getSelectedFile();
if (selectedDir.exists()) { if (selectedDir.exists()) {
int option = showConfirmDialog(parent, selectedDir.getName() + " already exists! Overwrite?"); int option = showConfirmDialog(parent, selectedDir.getName() + " already exists! Overwrite?");
// option: 0 = Cancel, 1 = No // option: 0 = Cancel, 1 = No
if (option == CANCEL_OPTION || option == 1) { if (option == CANCEL_OPTION || option == 1) {
save = false; save = false;
} }
} }
if(save) { if(save) {
Vector<Table> romTables = image.getTables(); Vector<Table> romTables = image.getTables();
for(int i=0;i<romTables.size();i++) { for(int i=0;i<romTables.size();i++) {
Table curTable = romTables.get(i); Table curTable = romTables.get(i);
String category = curTable.getCategory(); String category = curTable.getCategory();
String tableName = curTable.getName(); String tableName = curTable.getName();
String tableDirString = selectedDir.getAbsolutePath() + separator + category; String tableDirString = selectedDir.getAbsolutePath() + separator + category;
File tableDir = new File(tableDirString.replace('/', '-')); File tableDir = new File(tableDirString.replace('/', '-'));
tableDir.mkdirs(); tableDir.mkdirs();
String tableFileString = tableDir.getAbsolutePath() + separator + tableName+".txt"; String tableFileString = tableDir.getAbsolutePath() + separator + tableName+".txt";
File tableFile = new File(tableFileString.replace('/', '-')); File tableFile = new File(tableFileString.replace('/', '-'));
if(tableFile.exists()) if(tableFile.exists())
{ {
tableFile.delete(); tableFile.delete();
} }
tableFile.createNewFile(); tableFile.createNewFile();
StringBuffer tableData = curTable.getTableAsString(); StringBuffer tableData = curTable.getTableAsString();
BufferedWriter out = new BufferedWriter(new FileWriter(tableFile)); BufferedWriter out = new BufferedWriter(new FileWriter(tableFile));
try { try {
out.write(tableData.toString()); out.write(tableData.toString());
} finally { } finally {
out.close(); out.close();
} }
} }
} }
} }
} }
private String getLastSelectedRomFileName() { private String getLastSelectedRomFileName() {
Rom lastSelectedRom = parent.getLastSelectedRom(); Rom lastSelectedRom = parent.getLastSelectedRom();
return lastSelectedRom == null ? "" : lastSelectedRom.getFileName() + " "; return lastSelectedRom == null ? "" : lastSelectedRom.getFileName() + " ";