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:
kascade 2006-09-12 12:36:36 +00:00
parent faeaf31f11
commit c34587445b
12 changed files with 139 additions and 25 deletions

View File

@ -8,6 +8,7 @@ import enginuity.logger.definition.EcuSwitch;
import enginuity.logger.io.serial.SerialPortRefresher; import enginuity.logger.io.serial.SerialPortRefresher;
import enginuity.logger.ui.LoggerDataTableModel; import enginuity.logger.ui.LoggerDataTableModel;
import enginuity.logger.ui.MessageListener; import enginuity.logger.ui.MessageListener;
import enginuity.logger.ui.ParameterListTable;
import enginuity.logger.ui.ParameterListTableModel; import enginuity.logger.ui.ParameterListTableModel;
import enginuity.logger.ui.ParameterRegistrationBroker; import enginuity.logger.ui.ParameterRegistrationBroker;
import enginuity.logger.ui.ParameterRegistrationBrokerImpl; import enginuity.logger.ui.ParameterRegistrationBrokerImpl;
@ -168,9 +169,9 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
} }
private JTable buildParamListTable(TableModel tableModel) { private JTable buildParamListTable(TableModel tableModel) {
JTable paramListTable = new JTable(tableModel); JTable paramListTable = new ParameterListTable(tableModel);
changeColumnWidth(paramListTable, 0, 20, 55, 55); changeColumnWidth(paramListTable, 0, 20, 55, 55);
changeColumnWidth(paramListTable, 2, 50, 60, 60); changeColumnWidth(paramListTable, 2, 50, 250, 80);
return paramListTable; return paramListTable;
} }

View File

@ -14,7 +14,7 @@ public interface EcuData {
EcuDataConvertor[] getConvertors(); EcuDataConvertor[] getConvertors();
void selectConvertor(int index); void selectConvertor(EcuDataConvertor convertor);
EcuDataType getDataType(); EcuDataType getDataType();

View File

@ -50,4 +50,8 @@ public final class EcuDerivedParameterConvertorImpl implements EcuDerivedParamet
checkNotNullOrEmpty(ecuDatas, "ecuDatas"); checkNotNullOrEmpty(ecuDatas, "ecuDatas");
this.ecuDatas = ecuDatas; this.ecuDatas = ecuDatas;
} }
public String toString() {
return getUnits();
}
} }

View File

@ -50,13 +50,12 @@ public final class EcuDerivedParameterImpl implements EcuParameter {
return convertors; return convertors;
} }
public void selectConvertor(int index) { public void selectConvertor(EcuDataConvertor convertor) {
if (index < 0) { for (int i = 0; i < convertors.length; i++) {
selectedConvertorIndex = 0; EcuDerivedParameterConvertor parameterConvertor = convertors[i];
} else if (index >= convertors.length) { if (convertor == parameterConvertor) {
selectedConvertorIndex = convertors.length - 1; selectedConvertorIndex = i;
} else { }
selectedConvertorIndex = index;
} }
} }

View File

@ -34,4 +34,8 @@ public final class EcuParameterConvertorImpl implements EcuDataConvertor {
return format.format(value); return format.format(value);
} }
public String toString() {
return getUnits();
}
} }

View File

@ -49,13 +49,12 @@ public final class EcuParameterImpl implements EcuParameter {
return convertors; return convertors;
} }
public void selectConvertor(int index) { public void selectConvertor(EcuDataConvertor convertor) {
if (index < 0) { for (int i = 0; i < convertors.length; i++) {
selectedConvertorIndex = 0; EcuDataConvertor dataConvertor = convertors[i];
} else if (index >= convertors.length) { if (convertor == dataConvertor) {
selectedConvertorIndex = convertors.length - 1; selectedConvertorIndex = i;
} else { }
selectedConvertorIndex = index;
} }
} }

View File

@ -21,6 +21,10 @@ public final class EcuSwitchConvertorImpl implements EcuDataConvertor {
return value > 0 ? "1" : "0"; return value > 0 ? "1" : "0";
} }
public String toString() {
return getUnits();
}
private void checkBit(int bit) { private void checkBit(int bit) {
if (bit < 0 || bit > 7) { if (bit < 0 || bit > 7) {
throw new IllegalArgumentException("Bit must be between 0 and 7 inclusive."); throw new IllegalArgumentException("Bit must be between 0 and 7 inclusive.");

View File

@ -51,13 +51,12 @@ public final class EcuSwitchImpl implements EcuSwitch {
return convertors; return convertors;
} }
public void selectConvertor(int index) { public void selectConvertor(EcuDataConvertor convertor) {
if (index < 0) { for (int i = 0; i < convertors.length; i++) {
selectedConvertorIndex = 0; EcuDataConvertor dataConvertor = convertors[i];
} else if (index >= convertors.length) { if (convertor == dataConvertor) {
selectedConvertorIndex = convertors.length - 1; selectedConvertorIndex = i;
} else { }
selectedConvertorIndex = index;
} }
} }

View File

@ -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;
}
}

View File

@ -45,7 +45,8 @@ public final class ParameterListTableModel extends AbstractTableModel {
case 1: case 1:
return paramRow.getEcuData().getName(); return paramRow.getEcuData().getName();
case 2: case 2:
return paramRow.getEcuData().getSelectedConvertor().getUnits(); EcuData ecuData = paramRow.getEcuData();
return ecuData.getConvertors().length > 1 ? ecuData : ecuData.getSelectedConvertor().getUnits();
default: default:
return "Error!"; return "Error!";
} }

View File

@ -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();
}
}
}
}

View File

@ -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;
}
}