From 3e082551a0055ccaa0c5499b8f68ea93b767285a Mon Sep 17 00:00:00 2001 From: jppetrakis <> Date: Sat, 4 Mar 2023 19:43:12 -0500 Subject: [PATCH] Refactor guts of dump csv action to another class... in util for now. Fixed wrong filechooser (used open instead of save). --- .../openrocket/gui/main/SimulationPanel.java | 210 +----------------- 1 file changed, 5 insertions(+), 205 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index 6b371f513..65dfec699 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -3,7 +3,6 @@ package net.sf.openrocket.gui.main; import java.awt.Color; import java.awt.Component; -import java.awt.Container; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; @@ -14,12 +13,7 @@ import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; import java.io.IOException; -import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; @@ -28,7 +22,6 @@ import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; -import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JOptionPane; @@ -41,11 +34,8 @@ import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.filechooser.FileFilter; import javax.swing.table.DefaultTableCellRenderer; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,11 +70,11 @@ import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Preferences; import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.util.AlphanumComparator; +import net.sf.openrocket.utils.SimulationTableToCSVFileExporter; import net.sf.openrocket.utils.TableRowTraversalPolicy; @SuppressWarnings("serial") public class SimulationPanel extends JPanel { - private static final String SPACE = "SPACE"; private static final String TAB = "TAB"; @@ -625,205 +615,16 @@ public class SimulationPanel extends JPanel { } class DumpSimulationToCSVAction extends SimulationAction { - private String lastSelectedLocation = ""; - private HashMap cToUnit; + public DumpSimulationToCSVAction() { putValue(NAME, trans.get("simpanel.pop.export_to_csv")); putValue(SMALL_ICON, Icons.FILE_EXPORT_AS); } - /** - * Means by wich the CSV export will clean up units on the values and - * describe them on the header fields instead. - */ - private void populateColumnNameToUnitsHashTable() { - if (null == simulationTableModel) { - return; - } - valueColumnToUnitString.clear(); // necessary if units changed during session - for (int i=0; i rowColumnElement = new ArrayList<>(); - for (int j=1; j 0! - for (int j=1; j 1) { // ignore rows that have null column fields 1 through 8... - continue; - } - - // create the column data comma separated string for the ith row... - csvSimResultString = StringUtils.join(rowColumnElement, fieldSep); - - // piece together all rows into one big ginourmous string, adding any warnings to the item - fullOutputResult += "\n" + csvSimResultString + fieldSep + warningsText; - } - - // dump the string to the file. - this.dumpDataToFile(fullOutputResult, csvFile); + SimulationTableToCSVFileExporter exporter = new SimulationTableToCSVFileExporter(document, simulationTable, simulationTableModel); + exporter.performTableDataConversion(); return; } @@ -1265,7 +1066,7 @@ public class SimulationPanel extends JPanel { // an example being loaded will have file == null and simulationTableModel != null... likewise a new rocket // will probably be the same... so this is probably belt-and-suspenders - if (/*documentFile != null ||*/ (simulationTableModel != null && simulationTableModel.getRowCount() > 0)) { + if (simulationTableModel != null && simulationTableModel.getRowCount() > 0) { return true; } return false; @@ -1275,7 +1076,6 @@ public class SimulationPanel extends JPanel { * A menu state updater that is an analog to the button state updater. */ private void updateMenuStates() { - // update the File->Export simulations table... menu entry this.exportSimTableToCSVMenuItem.setEnabled(simulationTableModel != null && simulationTableModel.getRowCount() > 0); }