suggested source changes.
This commit is contained in:
parent
8ab6aa803c
commit
3947458cca
@ -28,6 +28,7 @@ import net.sf.openrocket.l10n.Translator;
|
|||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.startup.Preferences;
|
import net.sf.openrocket.startup.Preferences;
|
||||||
import net.sf.openrocket.unit.Value;
|
import net.sf.openrocket.unit.Value;
|
||||||
|
import net.sf.openrocket.util.TextUtil;
|
||||||
|
|
||||||
public class SimulationTableToCSVFileExporter {
|
public class SimulationTableToCSVFileExporter {
|
||||||
private final OpenRocketDocument document;
|
private final OpenRocketDocument document;
|
||||||
@ -50,8 +51,8 @@ public class SimulationTableToCSVFileExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Means by which the CSV export will clean up units on the values and
|
* To make a lookup of table header to units. For those columns which are of type Value, the
|
||||||
* describe them on the header fields instead.
|
* units will be added to the header...
|
||||||
*/
|
*/
|
||||||
private void populateColumnNameToUnitsHashTable() {
|
private void populateColumnNameToUnitsHashTable() {
|
||||||
if (null == simulationTableModel) {
|
if (null == simulationTableModel) {
|
||||||
@ -159,9 +160,12 @@ public class SimulationTableToCSVFileExporter {
|
|||||||
ArrayList<String> rowColumnElement = new ArrayList<>();
|
ArrayList<String> rowColumnElement = new ArrayList<>();
|
||||||
for (int j=1; j<modelColumnCount ; j++) {
|
for (int j=1; j<modelColumnCount ; j++) {
|
||||||
String colName = simulationTable.getColumnName(j);
|
String colName = simulationTable.getColumnName(j);
|
||||||
String unitString = valueColumnToUnitString.get(colName);
|
|
||||||
if (unitString != null) {
|
// get the unit string and append to column that it applies to.
|
||||||
colName += " (" + unitString + ")";
|
// columns w/o units will remain unchanged.
|
||||||
|
if (valueColumnToUnitString.containsKey(colName)) {
|
||||||
|
String unitString = valueColumnToUnitString.get(colName);
|
||||||
|
colName += " (" + unitString + ")";
|
||||||
}
|
}
|
||||||
rowColumnElement.add(colName);
|
rowColumnElement.add(colName);
|
||||||
}
|
}
|
||||||
@ -193,21 +197,15 @@ public class SimulationTableToCSVFileExporter {
|
|||||||
|
|
||||||
// piece together the column data for the ith row, skipping any rows with null counts > 0!
|
// piece together the column data for the ith row, skipping any rows with null counts > 0!
|
||||||
for (int j=1; j<modelColumnCount ; j++) { // skip first column
|
for (int j=1; j<modelColumnCount ; j++) { // skip first column
|
||||||
String colName = simulationTable.getColumnName(j);
|
|
||||||
String unitString = valueColumnToUnitString.get(colName); // unit string MAY be null!
|
|
||||||
|
|
||||||
Object o = simulationTableModel.getValueAt(i, j);
|
Object o = simulationTableModel.getValueAt(i, j);
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
String value = null;
|
final String value;
|
||||||
if (o instanceof Value) {
|
if (o instanceof Value) {
|
||||||
double dvalue = ((Value) o).getValue();
|
double dvalue = ((Value) o).getValue();
|
||||||
value = String.format("%."+precision+"f", dvalue);
|
value = TextUtil.doubleToString(dvalue, precision);
|
||||||
} else {
|
} else {
|
||||||
value = o.toString();
|
value = o.toString();
|
||||||
}
|
}
|
||||||
if (unitString != null) {
|
|
||||||
value = value.replace(" " + unitString, "");
|
|
||||||
}
|
|
||||||
rowColumnElement.add(StringEscapeUtils.escapeCsv(value));
|
rowColumnElement.add(StringEscapeUtils.escapeCsv(value));
|
||||||
} else {
|
} else {
|
||||||
rowColumnElement.add("");
|
rowColumnElement.add("");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user