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.l10n.Translator;
18 import net.sf.openrocket.motor.Motor;
19 import net.sf.openrocket.motor.ThrustCurveMotor;
20 import net.sf.openrocket.startup.Application;
21 import net.sf.openrocket.util.GUIUtil;
23 public class MotorChooserDialog extends JDialog implements CloseableDialog {
25 private final ThrustCurveMotorSelectionPanel selectionPanel;
27 private boolean okClicked = false;
28 private static final Translator trans = Application.getTranslator();
31 public MotorChooserDialog(Motor current, double delay, double diameter, Window owner) {
32 super(owner, "Select a rocket motor", Dialog.ModalityType.APPLICATION_MODAL);
34 // Check that the motor database has been loaded properly
35 MotorDatabaseLoadingDialog.check(null);
38 JPanel panel = new JPanel(new MigLayout("fill"));
40 selectionPanel = new ThrustCurveMotorSelectionPanel((ThrustCurveMotor) current, delay, diameter);
42 panel.add(selectionPanel, "grow, wrap para");
45 // OK / Cancel buttons
46 JButton okButton = new JButton(trans.get("dlg.but.ok"));
47 okButton.addActionListener(new ActionListener() {
49 public void actionPerformed(ActionEvent e) {
53 panel.add(okButton, "tag ok, spanx, split");
56 JButton cancelButton = new JButton(trans.get("dlg.but.cancel"));
57 cancelButton.addActionListener(new ActionListener() {
59 public void actionPerformed(ActionEvent e) {
63 panel.add(cancelButton, "tag cancel");
69 this.setLocationByPlatform(true);
70 GUIUtil.setDisposableDialogOptions(this, okButton);
72 JComponent focus = selectionPanel.getDefaultFocus();
77 // Set the closeable dialog after all initialization
78 selectionPanel.setCloseableDialog(this);
83 * Return the motor selected by this chooser dialog, or <code>null</code> if the selection has been aborted.
85 * @return the selected motor, or <code>null</code> if no motor has been selected or the selection was canceled.
87 public Motor getSelectedMotor() {
90 return selectionPanel.getSelectedMotor();
94 * Return the selected ejection charge delay.
96 * @return the selected ejection charge delay.
98 public double getSelectedDelay() {
99 return selectionPanel.getSelectedDelay();
105 public void close(boolean ok) {
107 this.setVisible(false);
109 Motor selected = getSelectedMotor();
110 if (okClicked && selected != null) {
111 selectionPanel.selectedMotor(selected);