Commit of several suggested changes.

This commit is contained in:
jppetrakis 2023-03-04 21:27:29 -05:00
parent 0822e8d7f3
commit 8ab6aa803c
5 changed files with 31 additions and 16 deletions

View File

@ -536,9 +536,8 @@ simpanel.pop.plot = Plot / Export
simpanel.pop.run = Run
simpanel.pop.delete = Delete
simpanel.pop.duplicate = Duplicate
simpanel.pop.export_to_csv = Export table as CSV file
simpanel.pop.export_to_csv.save.dialog.title = Save as CSV file
simpanel.pop.export_to_csv.save.button.text = Save
simpanel.pop.exportToCSV = Export table as CSV file
simpanel.pop.exportToCSV.save.dialog.title = Save as CSV file
simpanel.dlg.no.simulation.table.rows = Simulation table has no entries... run a simulation please
simpanel.checkbox.donotask = Do not ask me again
simpanel.lbl.defpref = You can change the default operation in the preferences.
@ -1444,7 +1443,7 @@ main.menu.file.quit = Quit
main.menu.file.quit.desc = Quit the program
main.menu.file.exportDecal = Save decal image\u2026
main.menu.file.exportDecal.desc = Save a decal from the current rocket design to a file for editing.
main.menu.file.table.export_to_csv = Export simulations table as CSV file
main.menu.file.table.exportToCSV = Export simulations table as CSV file
main.menu.edit = Edit
main.menu.edit.desc = Rocket editing

View File

@ -567,7 +567,7 @@ public class BasicFrame extends JFrame {
//// END CREATE and implement File > "Encode 3D" menu and submenu
*/
// export sim table...
JMenuItem exportSimTableToCSVMenuItem = new JMenuItem(trans.get("main.menu.file.table.export_to_csv"));
JMenuItem exportSimTableToCSVMenuItem = new JMenuItem(trans.get("main.menu.file.table.exportToCSV"));
exportSimTableToCSVMenuItem.setIcon(Icons.FILE_EXPORT_AS);
menu.add(exportSimTableToCSVMenuItem);
exportSimTableToCSVMenuItem.addActionListener(new ActionListener() {

View File

@ -617,7 +617,7 @@ public class SimulationPanel extends JPanel {
class DumpSimulationToCSVAction extends SimulationAction {
public DumpSimulationToCSVAction() {
putValue(NAME, trans.get("simpanel.pop.export_to_csv"));
putValue(NAME, trans.get("simpanel.pop.exportToCSV"));
putValue(SMALL_ICON, Icons.FILE_EXPORT_AS);
}

View File

@ -1,7 +1,6 @@
package net.sf.openrocket.utils;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
@ -14,7 +13,6 @@ import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import net.sf.openrocket.aerodynamics.Warning;
@ -24,12 +22,12 @@ import net.sf.openrocket.gui.adaptors.Column;
import net.sf.openrocket.gui.adaptors.ColumnTableModel;
import net.sf.openrocket.gui.adaptors.ValueColumn;
import net.sf.openrocket.gui.components.CsvOptionPanel;
import net.sf.openrocket.gui.dialogs.optimization.GeneralOptimizationDialog;
import net.sf.openrocket.gui.util.FileHelper;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.startup.Preferences;
import net.sf.openrocket.unit.Value;
public class SimulationTableToCSVFileExporter {
private final OpenRocketDocument document;
@ -101,11 +99,8 @@ public class SimulationTableToCSVFileExporter {
private JFileChooser setUpFileChooser() {
JFileChooser fch = new JFileChooser();
String saveDialogTitle = trans.get("simpanel.pop.export_to_csv.save.dialog.title");
String saveButtonText = trans.get("simpanel.pop.export_to_csv.save.button.text");
fch.setApproveButtonText(saveButtonText);
String saveDialogTitle = trans.get("simpanel.pop.exportToCSV.save.dialog.title");
fch.setDialogTitle(saveDialogTitle);
fch.setApproveButtonToolTipText(saveDialogTitle);
fch.setFileFilter(FileHelper.CSV_FILTER);
@ -148,6 +143,7 @@ public class SimulationTableToCSVFileExporter {
}
fieldSep = ((CsvOptionPanel) fch.getAccessory()).getFieldSeparator();
int precision = ((CsvOptionPanel) fch.getAccessory()).getDecimalPlaces();
((CsvOptionPanel) fch.getAccessory()).storePreferences();
if (fieldSep.equals(SPACE)) {
@ -171,7 +167,7 @@ public class SimulationTableToCSVFileExporter {
}
// ONE difference here is that we'll place any warnings at the last cell in the csv.
csvSimResultString = StringUtils.join(rowColumnElement,fieldSep) + fieldSep + "Simulation Warnings";
csvSimResultString = StringUtils.join(fieldSep, rowColumnElement) + fieldSep + "Simulation Warnings";
String fullOutputResult = csvSimResultString;
@ -202,7 +198,13 @@ public class SimulationTableToCSVFileExporter {
Object o = simulationTableModel.getValueAt(i, j);
if (o != null) {
String value = o.toString();
String value = null;
if (o instanceof Value) {
double dvalue = ((Value) o).getValue();
value = String.format("%."+precision+"f", dvalue);
} else {
value = o.toString();
}
if (unitString != null) {
value = value.replace(" " + unitString, "");
}
@ -221,7 +223,7 @@ public class SimulationTableToCSVFileExporter {
}
// create the column data comma separated string for the ith row...
csvSimResultString = StringUtils.join(rowColumnElement, fieldSep);
csvSimResultString = StringUtils.join(fieldSep, rowColumnElement);
// piece together all rows into one big ginourmous string, adding any warnings to the item
fullOutputResult += "\n" + csvSimResultString + fieldSep + warningsText;

View File

@ -1,5 +1,7 @@
package net.sf.openrocket.utils;
import java.util.List;
public class StringUtils {
public static String join(String sep, Object[] values) {
@ -16,4 +18,16 @@ public class StringUtils {
return value.toString();
}
/**
* Join starting with a list of strings rather than an array
* @param sep
* @param listValues
* @return
*/
public static String join(String sep, List<String> listValues) {
String[] values = listValues.toArray(new String[listValues.size()]);
return join(sep, values);
}
}