1 package net.sf.openrocket.gui.dialogs.motor;
4 import java.awt.Dialog;
5 import java.awt.Window;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
9 import javax.swing.JButton;
10 import javax.swing.JComponent;
11 import javax.swing.JDialog;
12 import javax.swing.JPanel;
14 import net.miginfocom.swing.MigLayout;
15 import net.sf.openrocket.gui.dialogs.MotorDatabaseLoadingDialog;
16 import net.sf.openrocket.gui.dialogs.motor.thrustcurve.ThrustCurveMotorSelectionPanel;
17 import net.sf.openrocket.motor.Motor;
18 import net.sf.openrocket.motor.ThrustCurveMotor;
19 import net.sf.openrocket.util.GUIUtil;
21 public class MotorChooserDialog extends JDialog implements CloseableDialog {
23 private final ThrustCurveMotorSelectionPanel selectionPanel;
25 private boolean okClicked = false;
28 public MotorChooserDialog(Motor current, double delay, double diameter, Window owner) {
29 super(owner, "Select a rocket motor", Dialog.ModalityType.APPLICATION_MODAL);
31 // Check that the motor database has been loaded properly
32 MotorDatabaseLoadingDialog.check(null);
35 JPanel panel = new JPanel(new MigLayout("fill"));
37 selectionPanel = new ThrustCurveMotorSelectionPanel((ThrustCurveMotor) current, delay, diameter);
39 panel.add(selectionPanel, "grow, wrap para");
42 // OK / Cancel buttons
44 JButton okButton = new JButton("OK");
45 okButton.addActionListener(new ActionListener() {
47 public void actionPerformed(ActionEvent e) {
51 panel.add(okButton, "tag ok, spanx, split");
53 JButton cancelButton = new JButton("Cancel");
54 cancelButton.addActionListener(new ActionListener() {
56 public void actionPerformed(ActionEvent e) {
60 panel.add(cancelButton, "tag cancel");
66 this.setLocationByPlatform(true);
67 GUIUtil.setDisposableDialogOptions(this, okButton);
69 JComponent focus = selectionPanel.getDefaultFocus();
74 // Set the closeable dialog after all initialization
75 selectionPanel.setCloseableDialog(this);
80 * Return the motor selected by this chooser dialog, or <code>null</code> if the selection has been aborted.
82 * @return the selected motor, or <code>null</code> if no motor has been selected or the selection was canceled.
84 public Motor getSelectedMotor() {
87 return selectionPanel.getSelectedMotor();
91 * Return the selected ejection charge delay.
93 * @return the selected ejection charge delay.
95 public double getSelectedDelay() {
96 return selectionPanel.getSelectedDelay();
102 public void close(boolean ok) {
104 this.setVisible(false);
106 Motor selected = getSelectedMotor();
107 if (okClicked && selected != null) {
108 selectionPanel.selectedMotor(selected);