From 8ab6aa803c30f44ee0f587b0901fef2df36e2cd8 Mon Sep 17 00:00:00 2001 From: jppetrakis <> Date: Sat, 4 Mar 2023 21:27:29 -0500 Subject: [PATCH] Commit of several suggested changes. --- core/resources/l10n/messages.properties | 7 +++--- .../sf/openrocket/gui/main/BasicFrame.java | 2 +- .../openrocket/gui/main/SimulationPanel.java | 2 +- .../SimulationTableToCSVFileExporter.java | 22 ++++++++++--------- .../net/sf/openrocket/utils/StringUtils.java | 14 ++++++++++++ 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 8899954bc..1b3f67f10 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -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 diff --git a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java index 005e70931..1539939eb 100644 --- a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java +++ b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java @@ -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() { diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index 65dfec699..f43fb4545 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -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); } diff --git a/swing/src/net/sf/openrocket/utils/SimulationTableToCSVFileExporter.java b/swing/src/net/sf/openrocket/utils/SimulationTableToCSVFileExporter.java index a5763f0d8..8fe1668bc 100644 --- a/swing/src/net/sf/openrocket/utils/SimulationTableToCSVFileExporter.java +++ b/swing/src/net/sf/openrocket/utils/SimulationTableToCSVFileExporter.java @@ -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; diff --git a/swing/src/net/sf/openrocket/utils/StringUtils.java b/swing/src/net/sf/openrocket/utils/StringUtils.java index e362252c4..bba5c0789 100644 --- a/swing/src/net/sf/openrocket/utils/StringUtils.java +++ b/swing/src/net/sf/openrocket/utils/StringUtils.java @@ -1,5 +1,7 @@ package net.sf.openrocket.utils; +import java.util.List; + public class StringUtils { public static String join(String sep, Object[] values) { @@ -15,5 +17,17 @@ 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 listValues) { + String[] values = listValues.toArray(new String[listValues.size()]); + return join(sep, values); + } + }