Added: export from file menu, csv escaping using commons.text library
This commit is contained in:
parent
2739287a3d
commit
b17e60c62b
@ -39,5 +39,6 @@
|
|||||||
<classpathentry kind="lib" path="lib/istack-commons-runtime.jar"/>
|
<classpathentry kind="lib" path="lib/istack-commons-runtime.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/graal-sdk-22.1.0.1.jar"/>
|
<classpathentry kind="lib" path="lib/graal-sdk-22.1.0.1.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/js-scriptengine-22.1.0.1.jar"/>
|
<classpathentry kind="lib" path="lib/js-scriptengine-22.1.0.1.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/commons-text-1.10.0.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
BIN
core/lib/commons-text-1.10.0.jar
Normal file
BIN
core/lib/commons-text-1.10.0.jar
Normal file
Binary file not shown.
@ -536,7 +536,7 @@ 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 to csv file
|
simpanel.pop.export_to_csv = Export table to csv file
|
||||||
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.
|
||||||
simpanel.dlg.lbl.DeleteSim1 = Delete the selected simulations?
|
simpanel.dlg.lbl.DeleteSim1 = Delete the selected simulations?
|
||||||
@ -1441,6 +1441,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 sim table to csv file
|
||||||
|
|
||||||
main.menu.edit = Edit
|
main.menu.edit = Edit
|
||||||
main.menu.edit.desc = Rocket editing
|
main.menu.edit.desc = Rocket editing
|
||||||
|
@ -39,5 +39,6 @@
|
|||||||
<classpathentry kind="lib" path="/OpenRocket Core/lib/jaxb-api.2.3.1.jar"/>
|
<classpathentry kind="lib" path="/OpenRocket Core/lib/jaxb-api.2.3.1.jar"/>
|
||||||
<classpathentry kind="lib" path="/OpenRocket Core/lib/jaxb-runtime.2.3.1.jar"/>
|
<classpathentry kind="lib" path="/OpenRocket Core/lib/jaxb-runtime.2.3.1.jar"/>
|
||||||
<classpathentry kind="lib" path="/OpenRocket Core/lib/guava-26.0-jre.jar"/>
|
<classpathentry kind="lib" path="/OpenRocket Core/lib/guava-26.0-jre.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/OpenRocket Core/lib/commons-text-1.10.0.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -566,6 +566,17 @@ 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...
|
||||||
|
JMenuItem exportSimTableToCSVMenuItem = new JMenuItem(trans.get("main.menu.file.table.export_to_csv"));
|
||||||
|
exportSimTableToCSVMenuItem.setIcon(Icons.FILE_EXPORT_AS);
|
||||||
|
menu.add(exportSimTableToCSVMenuItem);
|
||||||
|
exportSimTableToCSVMenuItem.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
exportSimulationTableToCSVAction();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
exportSimTableToCSVMenuItem.setEnabled(simulationPanel.isReadyToExportSimTableToCSV());
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
//// Close
|
//// Close
|
||||||
@ -1430,7 +1441,10 @@ public class BasicFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
// END ROCKSIM Export Action
|
// END ROCKSIM Export Action
|
||||||
|
|
||||||
|
public boolean exportSimulationTableToCSVAction() {
|
||||||
|
simulationPanel.runExportSimTableToCSVAction();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Perform the writing of the design to the given file in RockSim format.
|
* Perform the writing of the design to the given file in RockSim format.
|
||||||
*
|
*
|
||||||
|
@ -17,10 +17,8 @@ import java.awt.event.MouseEvent;
|
|||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -45,6 +43,7 @@ import javax.swing.filechooser.FileFilter;
|
|||||||
import javax.swing.table.DefaultTableCellRenderer;
|
import javax.swing.table.DefaultTableCellRenderer;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.text.StringEscapeUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -724,7 +723,8 @@ public class SimulationPanel extends JPanel {
|
|||||||
int nullCnt = 0;
|
int nullCnt = 0;
|
||||||
rowColumnElement.clear();
|
rowColumnElement.clear();
|
||||||
|
|
||||||
// get the simulation's warning text if any... this bypasses
|
// get the simulation's warning text if any... this bypasses the need to use
|
||||||
|
// the column 0 stuff which is kind of difficult to use!
|
||||||
WarningSet ws = document.getSimulation(i).getSimulatedWarnings();
|
WarningSet ws = document.getSimulation(i).getSimulatedWarnings();
|
||||||
String warningsText = "";
|
String warningsText = "";
|
||||||
for (Warning w : ws) {
|
for (Warning w : ws) {
|
||||||
@ -738,7 +738,8 @@ public class SimulationPanel extends JPanel {
|
|||||||
for (int j=1; j<modelColumnCount ; j++) { // skip first column
|
for (int j=1; j<modelColumnCount ; j++) { // skip first column
|
||||||
Object o = simulationTableModel.getValueAt(i, j);
|
Object o = simulationTableModel.getValueAt(i, j);
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
rowColumnElement.add(o.toString());
|
String value = o.toString();
|
||||||
|
rowColumnElement.add(StringEscapeUtils.escapeCsv(value));
|
||||||
} else {
|
} else {
|
||||||
rowColumnElement.add("");
|
rowColumnElement.add("");
|
||||||
nullCnt++;
|
nullCnt++;
|
||||||
@ -766,7 +767,6 @@ public class SimulationPanel extends JPanel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEnabledState() {
|
public void updateEnabledState() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1192,4 +1192,20 @@ public class SimulationPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isReadyToExportSimTableToCSV() {
|
||||||
|
// probably belt-n-suspenders to check for row/column count...
|
||||||
|
File documentFile = document.getFile();
|
||||||
|
if (documentFile != null && simulationTableModel != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the csv export action...
|
||||||
|
*/
|
||||||
|
public void runExportSimTableToCSVAction() {
|
||||||
|
dumpSimulationTableAction.actionPerformed(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user