Explicitly create the plot with a parent window so the configuration

window can be dismissed automatically.
This commit is contained in:
kruland2607 2013-05-23 16:19:56 -05:00
parent 9107566b38
commit 4716030d1b
2 changed files with 63 additions and 110 deletions

View File

@ -16,28 +16,19 @@ import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.Configuration;
import net.sf.openrocket.simulation.FlightData;
import net.sf.openrocket.simulation.SimulationOptions;
import net.sf.openrocket.startup.Application;
public class SimulationPlotExportDialog extends JDialog {
private final Window parentWindow;
private final Simulation simulation;
private final OpenRocketDocument document;
private final SimulationOptions conditions;
private final Configuration configuration;
private static final Translator trans = Application.getTranslator();
public SimulationPlotExportDialog(Window parent, OpenRocketDocument document, Simulation s) {
//// Plot/Export simulation
super(parent, trans.get("simedtdlg.title.Editsim"), JDialog.ModalityType.DOCUMENT_MODAL);
this.document = document;
this.parentWindow = parent;
this.simulation = s;
this.conditions = simulation.getOptions();
configuration = simulation.getConfiguration();
JPanel mainPanel = new JPanel(new MigLayout("fill", "[grow]"));
@ -50,10 +41,10 @@ public class SimulationPlotExportDialog extends JDialog {
final JTabbedPane tabbedPane = new JTabbedPane();
//// Plot data
final SimulationPlotPanel plotTab = plotTab();
final SimulationPlotPanel plotTab = new SimulationPlotPanel(simulation);
tabbedPane.addTab(trans.get("simedtdlg.tab.Plotdata"), plotTab);
//// Export data
final SimulationExportPanel exportTab = exportTab();
final SimulationExportPanel exportTab = new SimulationExportPanel(simulation);
tabbedPane.addTab(trans.get("simedtdlg.tab.Exportdata"), exportTab);
mainPanel.add(tabbedPane, "grow, wrap");
@ -64,7 +55,7 @@ public class SimulationPlotExportDialog extends JDialog {
public void actionPerformed(ActionEvent e) {
if (tabbedPane.getSelectedIndex() == 0) {
JDialog plot = plotTab.doPlot();
JDialog plot = plotTab.doPlot(SimulationPlotExportDialog.this.parentWindow);
if (plot != null) {
SimulationPlotExportDialog.this.dispose();
plot.setVisible(true);
@ -98,40 +89,4 @@ public class SimulationPlotExportDialog extends JDialog {
}
/**
* A panel for plotting the previously calculated data.
*/
private SimulationPlotPanel plotTab() {
// Check that data exists
// FIXME -
/*
if (simulation.getSimulatedData() == null ||
simulation.getSimulatedData().getBranchCount() == 0) {
return noDataPanel();
}
*/
return new SimulationPlotPanel(simulation);
}
/**
* A panel for exporting the data.
*/
private SimulationExportPanel exportTab() {
FlightData data = simulation.getSimulatedData();
// Check that data exists
// FIXME -
/*
if (data == null || data.getBranchCount() == 0 ||
data.getBranch(0).getTypes().length == 0) {
return noDataPanel();
}
*/
return new SimulationExportPanel(simulation);
}
}

View File

@ -17,7 +17,6 @@ import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
@ -130,7 +129,7 @@ public class SimulationPlotPanel extends JPanel {
// the UI when the selected item changes.
// TODO - this should probably be implemented as an ActionListener instead
// of ItemStateListener.
if ( e.getStateChange() == ItemEvent.DESELECTED) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
return;
}
if (modifying > 0)
@ -264,34 +263,34 @@ public class SimulationPlotPanel extends JPanel {
// Select new type smartly
FlightDataType type = null;
for (FlightDataType t :
simulation.getSimulatedData().getBranch(0).getTypes()) {
simulation.getSimulatedData().getBranch(0).getTypes()) {
boolean used = false;
if (configuration.getDomainAxisType().equals(t)) {
used = true;
} else {
for (int i = 0; i < configuration.getTypeCount(); i++) {
if (configuration.getType(i).equals(t)) {
used = true;
break;
}
boolean used = false;
if (configuration.getDomainAxisType().equals(t)) {
used = true;
} else {
for (int i = 0; i < configuration.getTypeCount(); i++) {
if (configuration.getType(i).equals(t)) {
used = true;
break;
}
}
if (!used) {
type = t;
break;
}
}
if (type == null) {
type = simulation.getSimulatedData().getBranch(0).getTypes()[0];
}
// Add new type
configuration.addPlotDataType(type);
setToCustom();
updatePlots();
if (!used) {
type = t;
break;
}
}
if (type == null) {
type = simulation.getSimulatedData().getBranch(0).getTypes()[0];
}
// Add new type
configuration.addPlotDataType(type);
setToCustom();
updatePlots();
}
});
this.add(button, "spanx, split");
@ -321,7 +320,7 @@ public class SimulationPlotPanel extends JPanel {
updatePlots();
}
public JDialog doPlot() {
public JDialog doPlot(Window parent) {
if (configuration.getTypeCount() == 0) {
JOptionPane.showMessageDialog(SimulationPlotPanel.this,
trans.get("error.noPlotSelected"),
@ -330,8 +329,7 @@ public class SimulationPlotPanel extends JPanel {
return null;
}
defaultConfiguration = configuration.clone();
return SimulationPlotDialog.getPlot((Window) SwingUtilities.getRoot(SimulationPlotPanel.this),
simulation, configuration);
return SimulationPlotDialog.getPlot(parent, simulation, configuration);
}
private void setConfiguration(PlotConfiguration conf) {