Commit 28c0fe3a authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

fix #225. Keep dialog open after csv export.

parent 1a26f9ef
Pipeline #100634 passed with stages
in 135 minutes and 32 seconds
...@@ -10,7 +10,6 @@ import org.vadere.util.logging.Logger; ...@@ -10,7 +10,6 @@ import org.vadere.util.logging.Logger;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
...@@ -22,130 +21,123 @@ import java.util.LinkedList; ...@@ -22,130 +21,123 @@ import java.util.LinkedList;
import javax.swing.*; import javax.swing.*;
public class ProjectRunResultDialog implements ProjectFinishedListener { public class ProjectRunResultDialog implements ProjectFinishedListener {
private static Logger logger = Logger.getLogger(ProjectRunResultDialog.class); private static Logger logger = Logger.getLogger(ProjectRunResultDialog.class);
private final ProjectView projectView; private final ProjectView projectView;
private final ProjectViewModel projectViewModel; private final ProjectViewModel projectViewModel;
ProjectRunResultDialog(ProjectView projectView, ProjectViewModel projectViewModel) {
this.projectView = projectView;
this.projectViewModel = projectViewModel;
}
public ProjectRunResultDialog(ProjectView projectView, ProjectViewModel projectViewModel) { @Override
this.projectView = projectView; public void preProjectRun(VadereProject project) {
this.projectViewModel = projectViewModel;
} }
@Override @Override
public void preProjectRun(VadereProject project) { public void postProjectRun(VadereProject project) {
LinkedList<SimulationResult> simulationResultList = project.getSimulationResults();
} StringBuilder sb = new StringBuilder();
@Override for (SimulationResult res : simulationResultList) {
public void postProjectRun(VadereProject project) { String[] headers = res.getHeaders();
LinkedList<SimulationResult> simulationResultList = project.getSimulationResults(); String[] values = res.getAsTableRow();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < headers.length; i++) {
for (SimulationResult res : simulationResultList) { sb.append(" ").append(headers[i]).append(": ").append(values[i]).append("\n");
String[] headers = res.getHeaders(); }
String[] values = res.getAsTableRow(); }
for(int i = 0; i < headers.length; i++) {
sb.append(" " + headers[i] + ": ").append(values[i]).append("\n"); if (projectViewModel.isShowSimulationResultDialog()) {
} SwingUtilities.invokeLater(() -> {
} JDialog dialog = new ResultDialog(projectView, simulationResultList);
dialog.setVisible(true);
if (projectViewModel.isShowSimulationResultDialog()) { });
SwingUtilities.invokeLater(() -> { } else {
JDialog dialog = new ResultDialog(projectView, simulationResultList); logger.info(sb.toString());
dialog.setVisible(true); }
}); }
} else {
logger.info(sb.toString()); class ResultDialog extends JDialog {
} Button btnOk, btnCsv;
private JTable table;
} JPanel main;
JScrollPane scrollPane;
class ResultDialog extends JDialog { JPanel btnPane;
Button btnOk, btnCsv; LinkedList<SimulationResult> data;
private JTable table;
JPanel main;
JScrollPane scrollPane; ResultDialog(ProjectView projectView, LinkedList<SimulationResult> data) {
JPanel btnPane; super(projectView);
LinkedList<SimulationResult> data; this.data = data;
main = new JPanel();
main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS));
public ResultDialog(ProjectView projectView, LinkedList<SimulationResult> data) {
super(projectView); table = new JTable(getData(data), data.getFirst().getHeaders());
this.data = data; table.setFillsViewportHeight(true);
main = new JPanel(); table.doLayout();
main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS)); scrollPane = new JScrollPane(table);
main.add(scrollPane);
table = new JTable(getData(data), data.getFirst().getHeaders());
table.setFillsViewportHeight(true); btnOk = new Button(Messages.getString("SettingsDialog.btnClose.text"));
table.doLayout(); btnOk.addActionListener(this::btnOKListener);
scrollPane = new JScrollPane(table); btnCsv = new Button(Messages.getString("ProjectView.btnExpertCSV"));
main.add(scrollPane); btnPane = new JPanel();
btnCsv.addActionListener(this::btnCsvListener);
btnOk = new Button(Messages.getString("SettingsDialog.btnClose.text")); btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.LINE_AXIS));
btnOk.addActionListener(this::btnOKListener); btnPane.add(Box.createHorizontalGlue());
btnCsv = new Button(Messages.getString("ProjectView.btnExpertCSV")); btnPane.add(btnOk);
btnPane = new JPanel(); btnPane.add(Box.createRigidArea(new Dimension(10, 0)));
btnCsv.addActionListener(this::btnCsvListener); btnPane.add(btnCsv);
btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.LINE_AXIS));
btnPane.add(Box.createHorizontalGlue()); Container c = getContentPane();
btnPane.add(btnOk); c.add(main, BorderLayout.CENTER);
btnPane.add(Box.createRigidArea(new Dimension(10, 0))); c.add(btnPane, BorderLayout.PAGE_END);
btnPane.add(btnCsv);
setTitle(Messages.getString("ProjectView.label.simResults"));
setSize(600, 200);
Container c = getContentPane();
c.add(main, BorderLayout.CENTER); }
c.add(btnPane, BorderLayout.PAGE_END);
setTitle(Messages.getString("ProjectView.label.simResults")); Object[][] getData(LinkedList<SimulationResult> data) {
setSize(600, 200); Object[][] res = new Object[data.size()][5];
int rowIdx = 0;
} for (SimulationResult d : data) {
res[rowIdx] = d.getAsTableRow();
rowIdx++;
public Object[][] getData(LinkedList<SimulationResult> data) { }
Object[][] res = new Object[data.size()][5]; return res;
int rowIdx = 0; }
for (SimulationResult d : data) {
res[rowIdx] = d.getAsTableRow(); private void btnOKListener(ActionEvent actionEvent) {
rowIdx++; setVisible(false);
} }
return res;
} private void btnCsvListener(ActionEvent actionEvent) {
StringBuilder sj = new StringBuilder();
private void btnOKListener(ActionEvent actionEvent) { SimulationResult.addCsvHeader(data.getFirst(), sj, ';');
setVisible(false); data.forEach(simulationResult -> simulationResult.addCsvRow(sj, ';'));
}
FileDialog fd = new FileDialog(this, Messages.getString("ProjectView.chooseFile"), FileDialog.SAVE);
private void btnCsvListener(ActionEvent actionEvent) {
StringBuilder sj = new StringBuilder(); fd.setVisible(true);
SimulationResult.addCsvHeader(data.getFirst(), sj, ';'); Path p = (Paths.get(fd.getDirectory()).resolve(fd.getFile()));
data.forEach(simulationResult -> simulationResult.addCsvRow(sj, ';'));
fd.setVisible(false);
FileDialog fd = new FileDialog(this, Messages.getString("ProjectView.chooseFile"), FileDialog.SAVE); try (OutputStreamWriter writer =
new OutputStreamWriter(new FileOutputStream(p.toString(), false), StandardCharsets.UTF_8)) {
fd.setVisible(true); writer.write(sj.toString());
Path p = (Paths.get(fd.getDirectory()).resolve(fd.getFile())); } catch (IOException e) {
e.printStackTrace();
}
fd.setVisible(false); }
try (OutputStreamWriter writer = }
new OutputStreamWriter(new FileOutputStream(p.toString(), false), StandardCharsets.UTF_8)) {
writer.write(sj.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
setVisible(false);
}
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment