Commit of several suggested changes.
This commit is contained in:
parent
0822e8d7f3
commit
8ab6aa803c
@ -536,9 +536,8 @@ simpanel.pop.plot = Plot / Export
|
|||||||
simpanel.pop.run = Run
|
simpanel.pop.run = Run
|
||||||
simpanel.pop.delete = Delete
|
simpanel.pop.delete = Delete
|
||||||
simpanel.pop.duplicate = Duplicate
|
simpanel.pop.duplicate = Duplicate
|
||||||
simpanel.pop.export_to_csv = Export table as CSV file
|
simpanel.pop.exportToCSV = Export table as CSV file
|
||||||
simpanel.pop.export_to_csv.save.dialog.title = Save as CSV file
|
simpanel.pop.exportToCSV.save.dialog.title = Save as CSV file
|
||||||
simpanel.pop.export_to_csv.save.button.text = Save
|
|
||||||
simpanel.dlg.no.simulation.table.rows = Simulation table has no entries... run a simulation please
|
simpanel.dlg.no.simulation.table.rows = Simulation table has no entries... run a simulation please
|
||||||
simpanel.checkbox.donotask = Do not ask me again
|
simpanel.checkbox.donotask = Do not ask me again
|
||||||
simpanel.lbl.defpref = You can change the default operation in the preferences.
|
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.quit.desc = Quit the program
|
||||||
main.menu.file.exportDecal = Save decal image\u2026
|
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.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 = Edit
|
||||||
main.menu.edit.desc = Rocket editing
|
main.menu.edit.desc = Rocket editing
|
||||||
|
@ -567,7 +567,7 @@ public class BasicFrame extends JFrame {
|
|||||||
//// END CREATE and implement File > "Encode 3D" menu and submenu
|
//// END CREATE and implement File > "Encode 3D" menu and submenu
|
||||||
*/
|
*/
|
||||||
// export sim table...
|
// 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);
|
exportSimTableToCSVMenuItem.setIcon(Icons.FILE_EXPORT_AS);
|
||||||
menu.add(exportSimTableToCSVMenuItem);
|
menu.add(exportSimTableToCSVMenuItem);
|
||||||
exportSimTableToCSVMenuItem.addActionListener(new ActionListener() {
|
exportSimTableToCSVMenuItem.addActionListener(new ActionListener() {
|
||||||
|
@ -617,7 +617,7 @@ public class SimulationPanel extends JPanel {
|
|||||||
class DumpSimulationToCSVAction extends SimulationAction {
|
class DumpSimulationToCSVAction extends SimulationAction {
|
||||||
|
|
||||||
public DumpSimulationToCSVAction() {
|
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);
|
putValue(SMALL_ICON, Icons.FILE_EXPORT_AS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.sf.openrocket.utils;
|
package net.sf.openrocket.utils;
|
||||||
|
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -14,7 +13,6 @@ import javax.swing.JFileChooser;
|
|||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.commons.text.StringEscapeUtils;
|
import org.apache.commons.text.StringEscapeUtils;
|
||||||
|
|
||||||
import net.sf.openrocket.aerodynamics.Warning;
|
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.ColumnTableModel;
|
||||||
import net.sf.openrocket.gui.adaptors.ValueColumn;
|
import net.sf.openrocket.gui.adaptors.ValueColumn;
|
||||||
import net.sf.openrocket.gui.components.CsvOptionPanel;
|
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.FileHelper;
|
||||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||||
import net.sf.openrocket.l10n.Translator;
|
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;
|
||||||
|
|
||||||
public class SimulationTableToCSVFileExporter {
|
public class SimulationTableToCSVFileExporter {
|
||||||
private final OpenRocketDocument document;
|
private final OpenRocketDocument document;
|
||||||
@ -101,11 +99,8 @@ public class SimulationTableToCSVFileExporter {
|
|||||||
|
|
||||||
private JFileChooser setUpFileChooser() {
|
private JFileChooser setUpFileChooser() {
|
||||||
JFileChooser fch = new JFileChooser();
|
JFileChooser fch = new JFileChooser();
|
||||||
String saveDialogTitle = trans.get("simpanel.pop.export_to_csv.save.dialog.title");
|
String saveDialogTitle = trans.get("simpanel.pop.exportToCSV.save.dialog.title");
|
||||||
String saveButtonText = trans.get("simpanel.pop.export_to_csv.save.button.text");
|
|
||||||
fch.setApproveButtonText(saveButtonText);
|
|
||||||
fch.setDialogTitle(saveDialogTitle);
|
fch.setDialogTitle(saveDialogTitle);
|
||||||
fch.setApproveButtonToolTipText(saveDialogTitle);
|
|
||||||
|
|
||||||
fch.setFileFilter(FileHelper.CSV_FILTER);
|
fch.setFileFilter(FileHelper.CSV_FILTER);
|
||||||
|
|
||||||
@ -148,6 +143,7 @@ public class SimulationTableToCSVFileExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fieldSep = ((CsvOptionPanel) fch.getAccessory()).getFieldSeparator();
|
fieldSep = ((CsvOptionPanel) fch.getAccessory()).getFieldSeparator();
|
||||||
|
int precision = ((CsvOptionPanel) fch.getAccessory()).getDecimalPlaces();
|
||||||
((CsvOptionPanel) fch.getAccessory()).storePreferences();
|
((CsvOptionPanel) fch.getAccessory()).storePreferences();
|
||||||
|
|
||||||
if (fieldSep.equals(SPACE)) {
|
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.
|
// 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;
|
String fullOutputResult = csvSimResultString;
|
||||||
|
|
||||||
@ -202,7 +198,13 @@ public class SimulationTableToCSVFileExporter {
|
|||||||
|
|
||||||
Object o = simulationTableModel.getValueAt(i, j);
|
Object o = simulationTableModel.getValueAt(i, j);
|
||||||
if (o != null) {
|
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) {
|
if (unitString != null) {
|
||||||
value = value.replace(" " + unitString, "");
|
value = value.replace(" " + unitString, "");
|
||||||
}
|
}
|
||||||
@ -221,7 +223,7 @@ public class SimulationTableToCSVFileExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the column data comma separated string for the ith row...
|
// 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
|
// piece together all rows into one big ginourmous string, adding any warnings to the item
|
||||||
fullOutputResult += "\n" + csvSimResultString + fieldSep + warningsText;
|
fullOutputResult += "\n" + csvSimResultString + fieldSep + warningsText;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.sf.openrocket.utils;
|
package net.sf.openrocket.utils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class StringUtils {
|
public class StringUtils {
|
||||||
|
|
||||||
public static String join(String sep, Object[] values) {
|
public static String join(String sep, Object[] values) {
|
||||||
@ -16,4 +18,16 @@ public class StringUtils {
|
|||||||
return value.toString();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user