mirror of https://github.com/rusefi/RomRaider.git
unit comboxes added to param list for parameters with multiple unit conversions
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@284 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
faeaf31f11
commit
c34587445b
|
@ -8,6 +8,7 @@ import enginuity.logger.definition.EcuSwitch;
|
|||
import enginuity.logger.io.serial.SerialPortRefresher;
|
||||
import enginuity.logger.ui.LoggerDataTableModel;
|
||||
import enginuity.logger.ui.MessageListener;
|
||||
import enginuity.logger.ui.ParameterListTable;
|
||||
import enginuity.logger.ui.ParameterListTableModel;
|
||||
import enginuity.logger.ui.ParameterRegistrationBroker;
|
||||
import enginuity.logger.ui.ParameterRegistrationBrokerImpl;
|
||||
|
@ -168,9 +169,9 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
}
|
||||
|
||||
private JTable buildParamListTable(TableModel tableModel) {
|
||||
JTable paramListTable = new JTable(tableModel);
|
||||
JTable paramListTable = new ParameterListTable(tableModel);
|
||||
changeColumnWidth(paramListTable, 0, 20, 55, 55);
|
||||
changeColumnWidth(paramListTable, 2, 50, 60, 60);
|
||||
changeColumnWidth(paramListTable, 2, 50, 250, 80);
|
||||
return paramListTable;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ public interface EcuData {
|
|||
|
||||
EcuDataConvertor[] getConvertors();
|
||||
|
||||
void selectConvertor(int index);
|
||||
void selectConvertor(EcuDataConvertor convertor);
|
||||
|
||||
EcuDataType getDataType();
|
||||
|
||||
|
|
|
@ -50,4 +50,8 @@ public final class EcuDerivedParameterConvertorImpl implements EcuDerivedParamet
|
|||
checkNotNullOrEmpty(ecuDatas, "ecuDatas");
|
||||
this.ecuDatas = ecuDatas;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getUnits();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,13 +50,12 @@ public final class EcuDerivedParameterImpl implements EcuParameter {
|
|||
return convertors;
|
||||
}
|
||||
|
||||
public void selectConvertor(int index) {
|
||||
if (index < 0) {
|
||||
selectedConvertorIndex = 0;
|
||||
} else if (index >= convertors.length) {
|
||||
selectedConvertorIndex = convertors.length - 1;
|
||||
} else {
|
||||
selectedConvertorIndex = index;
|
||||
public void selectConvertor(EcuDataConvertor convertor) {
|
||||
for (int i = 0; i < convertors.length; i++) {
|
||||
EcuDerivedParameterConvertor parameterConvertor = convertors[i];
|
||||
if (convertor == parameterConvertor) {
|
||||
selectedConvertorIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,4 +34,8 @@ public final class EcuParameterConvertorImpl implements EcuDataConvertor {
|
|||
return format.format(value);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getUnits();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,13 +49,12 @@ public final class EcuParameterImpl implements EcuParameter {
|
|||
return convertors;
|
||||
}
|
||||
|
||||
public void selectConvertor(int index) {
|
||||
if (index < 0) {
|
||||
selectedConvertorIndex = 0;
|
||||
} else if (index >= convertors.length) {
|
||||
selectedConvertorIndex = convertors.length - 1;
|
||||
} else {
|
||||
selectedConvertorIndex = index;
|
||||
public void selectConvertor(EcuDataConvertor convertor) {
|
||||
for (int i = 0; i < convertors.length; i++) {
|
||||
EcuDataConvertor dataConvertor = convertors[i];
|
||||
if (convertor == dataConvertor) {
|
||||
selectedConvertorIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,10 @@ public final class EcuSwitchConvertorImpl implements EcuDataConvertor {
|
|||
return value > 0 ? "1" : "0";
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getUnits();
|
||||
}
|
||||
|
||||
private void checkBit(int bit) {
|
||||
if (bit < 0 || bit > 7) {
|
||||
throw new IllegalArgumentException("Bit must be between 0 and 7 inclusive.");
|
||||
|
|
|
@ -51,13 +51,12 @@ public final class EcuSwitchImpl implements EcuSwitch {
|
|||
return convertors;
|
||||
}
|
||||
|
||||
public void selectConvertor(int index) {
|
||||
if (index < 0) {
|
||||
selectedConvertorIndex = 0;
|
||||
} else if (index >= convertors.length) {
|
||||
selectedConvertorIndex = convertors.length - 1;
|
||||
} else {
|
||||
selectedConvertorIndex = index;
|
||||
public void selectConvertor(EcuDataConvertor convertor) {
|
||||
for (int i = 0; i < convertors.length; i++) {
|
||||
EcuDataConvertor dataConvertor = convertors[i];
|
||||
if (convertor == dataConvertor) {
|
||||
selectedConvertorIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuData;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableModel;
|
||||
|
||||
public final class ParameterListTable extends JTable {
|
||||
private UnitsComboBoxEditor comboBoxEditor = new UnitsComboBoxEditor();
|
||||
private UnitsComboBoxRenderer comboBoxRenderer = new UnitsComboBoxRenderer();
|
||||
|
||||
public ParameterListTable(TableModel tableModel) {
|
||||
super(tableModel);
|
||||
}
|
||||
|
||||
public TableCellRenderer getCellRenderer(int row, int col) {
|
||||
return displayComboBox(row, col) ? comboBoxRenderer : super.getCellRenderer(row, col);
|
||||
}
|
||||
|
||||
public TableCellEditor getCellEditor(int row, int col) {
|
||||
return displayComboBox(row, col) ? comboBoxEditor : super.getCellEditor(row, col);
|
||||
}
|
||||
|
||||
private boolean displayComboBox(int row, int col) {
|
||||
Object value = getValueAt(row, col);
|
||||
if (EcuData.class.isAssignableFrom(value.getClass())) {
|
||||
EcuData ecuData = (EcuData) value;
|
||||
if (ecuData.getConvertors().length > 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -45,7 +45,8 @@ public final class ParameterListTableModel extends AbstractTableModel {
|
|||
case 1:
|
||||
return paramRow.getEcuData().getName();
|
||||
case 2:
|
||||
return paramRow.getEcuData().getSelectedConvertor().getUnits();
|
||||
EcuData ecuData = paramRow.getEcuData();
|
||||
return ecuData.getConvertors().length > 1 ? ecuData : ecuData.getSelectedConvertor().getUnits();
|
||||
default:
|
||||
return "Error!";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.definition.EcuDataConvertor;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public final class UnitsComboBoxEditor extends AbstractCellEditor implements TableCellEditor, ActionListener {
|
||||
private static final String EDIT_COMMAND = "EDIT";
|
||||
private EcuData currentEcuData;
|
||||
|
||||
public Object getCellEditorValue() {
|
||||
return currentEcuData.getSelectedConvertor();
|
||||
}
|
||||
|
||||
public Component getTableCellEditorComponent(JTable table, Object ecuData, boolean isSelected, int row, int column) {
|
||||
currentEcuData = (EcuData) ecuData;
|
||||
EcuDataConvertor[] convertors = currentEcuData.getConvertors();
|
||||
JComboBox comboBox = new JComboBox();
|
||||
for (EcuDataConvertor convertor : convertors) {
|
||||
comboBox.addItem(convertor);
|
||||
}
|
||||
comboBox.setSelectedItem(currentEcuData.getSelectedConvertor());
|
||||
comboBox.setEditable(false);
|
||||
comboBox.setEnabled(true);
|
||||
comboBox.setActionCommand(EDIT_COMMAND);
|
||||
comboBox.addActionListener(this);
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
if (EDIT_COMMAND.equals(actionEvent.getActionCommand())) {
|
||||
Object source = actionEvent.getSource();
|
||||
if (source != null && JComboBox.class.isAssignableFrom(source.getClass())) {
|
||||
JComboBox comboBox = (JComboBox) source;
|
||||
currentEcuData.selectConvertor((EcuDataConvertor) comboBox.getSelectedItem());
|
||||
fireEditingStopped();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.definition.EcuDataConvertor;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import java.awt.*;
|
||||
|
||||
public final class UnitsComboBoxRenderer extends JComboBox implements TableCellRenderer {
|
||||
|
||||
public Component getTableCellRendererComponent(JTable table, Object ecuData, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
EcuData currentEcuData = (EcuData) ecuData;
|
||||
EcuDataConvertor[] convertors = currentEcuData.getConvertors();
|
||||
JComboBox comboBox = new JComboBox();
|
||||
for (EcuDataConvertor convertor : convertors) {
|
||||
comboBox.addItem(convertor);
|
||||
}
|
||||
comboBox.setSelectedItem(currentEcuData.getSelectedConvertor());
|
||||
return comboBox;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue