Explicitly create the plot with a parent window so the configuration
window can be dismissed automatically.
This commit is contained in:
parent
9107566b38
commit
4716030d1b
@ -16,28 +16,19 @@ import net.sf.openrocket.document.OpenRocketDocument;
|
|||||||
import net.sf.openrocket.document.Simulation;
|
import net.sf.openrocket.document.Simulation;
|
||||||
import net.sf.openrocket.gui.util.GUIUtil;
|
import net.sf.openrocket.gui.util.GUIUtil;
|
||||||
import net.sf.openrocket.l10n.Translator;
|
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;
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
public class SimulationPlotExportDialog extends JDialog {
|
public class SimulationPlotExportDialog extends JDialog {
|
||||||
|
|
||||||
private final Window parentWindow;
|
private final Window parentWindow;
|
||||||
private final Simulation simulation;
|
private final Simulation simulation;
|
||||||
private final OpenRocketDocument document;
|
|
||||||
private final SimulationOptions conditions;
|
|
||||||
private final Configuration configuration;
|
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
public SimulationPlotExportDialog(Window parent, OpenRocketDocument document, Simulation s) {
|
public SimulationPlotExportDialog(Window parent, OpenRocketDocument document, Simulation s) {
|
||||||
//// Plot/Export simulation
|
//// Plot/Export simulation
|
||||||
super(parent, trans.get("simedtdlg.title.Editsim"), JDialog.ModalityType.DOCUMENT_MODAL);
|
super(parent, trans.get("simedtdlg.title.Editsim"), JDialog.ModalityType.DOCUMENT_MODAL);
|
||||||
this.document = document;
|
|
||||||
this.parentWindow = parent;
|
this.parentWindow = parent;
|
||||||
this.simulation = s;
|
this.simulation = s;
|
||||||
this.conditions = simulation.getOptions();
|
|
||||||
configuration = simulation.getConfiguration();
|
|
||||||
|
|
||||||
JPanel mainPanel = new JPanel(new MigLayout("fill", "[grow]"));
|
JPanel mainPanel = new JPanel(new MigLayout("fill", "[grow]"));
|
||||||
|
|
||||||
@ -50,10 +41,10 @@ public class SimulationPlotExportDialog extends JDialog {
|
|||||||
final JTabbedPane tabbedPane = new JTabbedPane();
|
final JTabbedPane tabbedPane = new JTabbedPane();
|
||||||
|
|
||||||
//// Plot data
|
//// Plot data
|
||||||
final SimulationPlotPanel plotTab = plotTab();
|
final SimulationPlotPanel plotTab = new SimulationPlotPanel(simulation);
|
||||||
tabbedPane.addTab(trans.get("simedtdlg.tab.Plotdata"), plotTab);
|
tabbedPane.addTab(trans.get("simedtdlg.tab.Plotdata"), plotTab);
|
||||||
//// Export data
|
//// Export data
|
||||||
final SimulationExportPanel exportTab = exportTab();
|
final SimulationExportPanel exportTab = new SimulationExportPanel(simulation);
|
||||||
tabbedPane.addTab(trans.get("simedtdlg.tab.Exportdata"), exportTab);
|
tabbedPane.addTab(trans.get("simedtdlg.tab.Exportdata"), exportTab);
|
||||||
|
|
||||||
mainPanel.add(tabbedPane, "grow, wrap");
|
mainPanel.add(tabbedPane, "grow, wrap");
|
||||||
@ -64,7 +55,7 @@ public class SimulationPlotExportDialog extends JDialog {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
if (tabbedPane.getSelectedIndex() == 0) {
|
if (tabbedPane.getSelectedIndex() == 0) {
|
||||||
JDialog plot = plotTab.doPlot();
|
JDialog plot = plotTab.doPlot(SimulationPlotExportDialog.this.parentWindow);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
SimulationPlotExportDialog.this.dispose();
|
SimulationPlotExportDialog.this.dispose();
|
||||||
plot.setVisible(true);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.sf.openrocket.gui.simulation;
|
package net.sf.openrocket.gui.simulation;
|
||||||
|
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemEvent;
|
||||||
@ -11,13 +11,12 @@ import java.util.EnumSet;
|
|||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import javax.swing.table.TableColumn;
|
import javax.swing.table.TableColumn;
|
||||||
import javax.swing.table.TableColumnModel;
|
import javax.swing.table.TableColumnModel;
|
||||||
@ -75,18 +74,18 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
PRESET_ARRAY[PRESET_ARRAY.length - 1] = CUSTOM_CONFIGURATION;
|
PRESET_ARRAY[PRESET_ARRAY.length - 1] = CUSTOM_CONFIGURATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** The current default configuration, set each time a plot is made. */
|
/** The current default configuration, set each time a plot is made. */
|
||||||
private static PlotConfiguration defaultConfiguration =
|
private static PlotConfiguration defaultConfiguration =
|
||||||
PlotConfiguration.DEFAULT_CONFIGURATIONS[0].resetUnits();
|
PlotConfiguration.DEFAULT_CONFIGURATIONS[0].resetUnits();
|
||||||
|
|
||||||
|
|
||||||
private final Simulation simulation;
|
private final Simulation simulation;
|
||||||
private final FlightDataType[] types;
|
private final FlightDataType[] types;
|
||||||
private PlotConfiguration configuration;
|
private PlotConfiguration configuration;
|
||||||
|
|
||||||
|
|
||||||
private JComboBox configurationSelector;
|
private JComboBox configurationSelector;
|
||||||
|
|
||||||
private JComboBox domainTypeSelector;
|
private JComboBox domainTypeSelector;
|
||||||
@ -95,7 +94,7 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
private JPanel typeSelectorPanel;
|
private JPanel typeSelectorPanel;
|
||||||
private FlightEventTableModel eventTableModel;
|
private FlightEventTableModel eventTableModel;
|
||||||
|
|
||||||
|
|
||||||
private int modifying = 0;
|
private int modifying = 0;
|
||||||
|
|
||||||
|
|
||||||
@ -111,7 +110,7 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
types = branch.getTypes();
|
types = branch.getTypes();
|
||||||
|
|
||||||
setConfiguration(defaultConfiguration);
|
setConfiguration(defaultConfiguration);
|
||||||
|
|
||||||
//// Configuration selector
|
//// Configuration selector
|
||||||
|
|
||||||
// Setup the combo box
|
// Setup the combo box
|
||||||
@ -130,7 +129,7 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
// the UI when the selected item changes.
|
// the UI when the selected item changes.
|
||||||
// TODO - this should probably be implemented as an ActionListener instead
|
// TODO - this should probably be implemented as an ActionListener instead
|
||||||
// of ItemStateListener.
|
// of ItemStateListener.
|
||||||
if ( e.getStateChange() == ItemEvent.DESELECTED) {
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (modifying > 0)
|
if (modifying > 0)
|
||||||
@ -148,8 +147,8 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
this.add(new JLabel(trans.get("simplotpanel.lbl.Presetplotconf")), "spanx, split");
|
this.add(new JLabel(trans.get("simplotpanel.lbl.Presetplotconf")), "spanx, split");
|
||||||
this.add(configurationSelector, "growx, wrap 20lp");
|
this.add(configurationSelector, "growx, wrap 20lp");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//// X axis
|
//// X axis
|
||||||
|
|
||||||
//// X axis type:
|
//// X axis type:
|
||||||
@ -189,8 +188,8 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
desc.setViewportBorder(BorderFactory.createEmptyBorder());
|
desc.setViewportBorder(BorderFactory.createEmptyBorder());
|
||||||
this.add(desc, "width 1px, growx 1, wrap unrel");
|
this.add(desc, "width 1px, growx 1, wrap unrel");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//// Y axis selector panel
|
//// Y axis selector panel
|
||||||
//// Y axis types:
|
//// Y axis types:
|
||||||
this.add(new JLabel(trans.get("simplotpanel.lbl.Yaxistypes")));
|
this.add(new JLabel(trans.get("simplotpanel.lbl.Yaxistypes")));
|
||||||
@ -201,7 +200,7 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
JScrollPane scroll = new JScrollPane(typeSelectorPanel);
|
JScrollPane scroll = new JScrollPane(typeSelectorPanel);
|
||||||
this.add(scroll, "spany 2, height 10px, wmin 400lp, grow 100, gapright para");
|
this.add(scroll, "spany 2, height 10px, wmin 400lp, grow 100, gapright para");
|
||||||
|
|
||||||
|
|
||||||
//// Flight events
|
//// Flight events
|
||||||
eventTableModel = new FlightEventTableModel();
|
eventTableModel = new FlightEventTableModel();
|
||||||
JTable table = new JTable(eventTableModel);
|
JTable table = new JTable(eventTableModel);
|
||||||
@ -217,9 +216,9 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
col0.setPreferredWidth(w);
|
col0.setPreferredWidth(w);
|
||||||
col0.setMaxWidth(w);
|
col0.setMaxWidth(w);
|
||||||
table.addMouseListener(new GUIUtil.BooleanTableClickListener(table));
|
table.addMouseListener(new GUIUtil.BooleanTableClickListener(table));
|
||||||
this.add(new JScrollPane(table), "height 200px, width 200lp, grow 1, wrap rel");
|
this.add(new JScrollPane(table), "height 200px, width 200lp, grow 1, wrap rel");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//// All + None buttons
|
//// All + None buttons
|
||||||
JButton button = new JButton(trans.get("simplotpanel.but.All"));
|
JButton button = new JButton(trans.get("simplotpanel.but.All"));
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
@ -244,8 +243,8 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
});
|
});
|
||||||
this.add(button, "gapleft para, gapright para, growx, sizegroup buttons, wrap para");
|
this.add(button, "gapleft para, gapright para, growx, sizegroup buttons, wrap para");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//// New Y axis plot type
|
//// New Y axis plot type
|
||||||
button = new JButton(trans.get("simplotpanel.but.NewYaxisplottype"));
|
button = new JButton(trans.get("simplotpanel.but.NewYaxisplottype"));
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
@ -264,41 +263,41 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
// Select new type smartly
|
// Select new type smartly
|
||||||
FlightDataType type = null;
|
FlightDataType type = null;
|
||||||
for (FlightDataType t :
|
for (FlightDataType t :
|
||||||
simulation.getSimulatedData().getBranch(0).getTypes()) {
|
simulation.getSimulatedData().getBranch(0).getTypes()) {
|
||||||
|
|
||||||
boolean used = false;
|
boolean used = false;
|
||||||
if (configuration.getDomainAxisType().equals(t)) {
|
if (configuration.getDomainAxisType().equals(t)) {
|
||||||
used = true;
|
used = true;
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < configuration.getTypeCount(); i++) {
|
for (int i = 0; i < configuration.getTypeCount(); i++) {
|
||||||
if (configuration.getType(i).equals(t)) {
|
if (configuration.getType(i).equals(t)) {
|
||||||
used = true;
|
used = true;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!used) {
|
|
||||||
type = t;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (type == null) {
|
|
||||||
type = simulation.getSimulatedData().getBranch(0).getTypes()[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new type
|
if (!used) {
|
||||||
configuration.addPlotDataType(type);
|
type = t;
|
||||||
setToCustom();
|
break;
|
||||||
updatePlots();
|
}
|
||||||
}
|
}
|
||||||
|
if (type == null) {
|
||||||
|
type = simulation.getSimulatedData().getBranch(0).getTypes()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new type
|
||||||
|
configuration.addPlotDataType(type);
|
||||||
|
setToCustom();
|
||||||
|
updatePlots();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.add(button, "spanx, split");
|
this.add(button, "spanx, split");
|
||||||
|
|
||||||
|
|
||||||
this.add(new JPanel(), "growx");
|
this.add(new JPanel(), "growx");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//// Plot flight
|
//// Plot flight
|
||||||
button = new JButton(trans.get("simplotpanel.but.Plotflight"));
|
button = new JButton(trans.get("simplotpanel.but.Plotflight"));
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
@ -317,22 +316,21 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.add(button, "right");
|
this.add(button, "right");
|
||||||
*/
|
*/
|
||||||
updatePlots();
|
updatePlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JDialog doPlot() {
|
public JDialog doPlot(Window parent) {
|
||||||
if (configuration.getTypeCount() == 0) {
|
if (configuration.getTypeCount() == 0) {
|
||||||
JOptionPane.showMessageDialog(SimulationPlotPanel.this,
|
JOptionPane.showMessageDialog(SimulationPlotPanel.this,
|
||||||
trans.get("error.noPlotSelected"),
|
trans.get("error.noPlotSelected"),
|
||||||
trans.get("error.noPlotSelected.title"),
|
trans.get("error.noPlotSelected.title"),
|
||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
defaultConfiguration = configuration.clone();
|
defaultConfiguration = configuration.clone();
|
||||||
return SimulationPlotDialog.getPlot((Window) SwingUtilities.getRoot(SimulationPlotPanel.this),
|
return SimulationPlotDialog.getPlot(parent, simulation, configuration);
|
||||||
simulation, configuration);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void setConfiguration(PlotConfiguration conf) {
|
private void setConfiguration(PlotConfiguration conf) {
|
||||||
|
|
||||||
@ -383,14 +381,14 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
|
|
||||||
// In order to consistantly update the ui, we need to validate before repaint.
|
// In order to consistantly update the ui, we need to validate before repaint.
|
||||||
typeSelectorPanel.validate();
|
typeSelectorPanel.validate();
|
||||||
typeSelectorPanel.repaint();
|
typeSelectorPanel.repaint();
|
||||||
|
|
||||||
eventTableModel.fireTableDataChanged();
|
eventTableModel.fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A JPanel which configures a single plot of a PlotConfiguration.
|
* A JPanel which configures a single plot of a PlotConfiguration.
|
||||||
*/
|
*/
|
||||||
@ -460,7 +458,7 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
});
|
});
|
||||||
this.add(axisSelector);
|
this.add(axisSelector);
|
||||||
|
|
||||||
|
|
||||||
JButton button = new JButton(Icons.DELETE);
|
JButton button = new JButton(Icons.DELETE);
|
||||||
//// Remove this plot
|
//// Remove this plot
|
||||||
button.setToolTipText(trans.get("simplotpanel.but.ttip.Removethisplot"));
|
button.setToolTipText(trans.get("simplotpanel.but.ttip.Removethisplot"));
|
||||||
@ -478,7 +476,7 @@ public class SimulationPlotPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private class FlightEventTableModel extends AbstractTableModel {
|
private class FlightEventTableModel extends AbstractTableModel {
|
||||||
private final FlightEvent.Type[] eventTypes;
|
private final FlightEvent.Type[] eventTypes;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user