23640217d042168fb22718f501928ffffa53f68f
[debian/openrocket] / core / src / net / sf / openrocket / gui / dialogs / preset / ComponentPresetChooserDialog.java
1 package net.sf.openrocket.gui.dialogs.preset;
2
3
4 import java.awt.Dialog;
5 import java.awt.Window;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8
9 import javax.swing.JButton;
10 import javax.swing.JDialog;
11 import javax.swing.JPanel;
12
13 import net.miginfocom.swing.MigLayout;
14 import net.sf.openrocket.gui.util.GUIUtil;
15 import net.sf.openrocket.l10n.Translator;
16 import net.sf.openrocket.preset.ComponentPreset;
17 import net.sf.openrocket.startup.Application;
18
19 public class ComponentPresetChooserDialog extends JDialog {
20         
21 //      private final ThrustCurveMotorSelectionPanel selectionPanel;
22         
23         private boolean okClicked = false;
24         private static final Translator trans = Application.getTranslator();
25
26         
27         public ComponentPresetChooserDialog(Window owner) {
28                 super(owner, trans.get("CompPresetChooser.title"), Dialog.ModalityType.APPLICATION_MODAL);
29                 
30                 JPanel panel = new JPanel(new MigLayout("fill"));
31                 
32                 //selectionPanel = new ThrustCurveMotorSelectionPanel((ThrustCurveMotor) current, delay, diameter);
33                 
34                 //panel.add(selectionPanel, "grow, wrap para");
35                 
36
37                 // OK / Cancel buttons
38                 JButton okButton = new JButton(trans.get("dlg.but.ok"));
39                 okButton.addActionListener(new ActionListener() {
40                         @Override
41                         public void actionPerformed(ActionEvent e) {
42                                 close(true);
43                         }
44                 });
45                 panel.add(okButton, "tag ok, spanx, split");
46                 
47                 //// Cancel button
48                 JButton cancelButton = new JButton(trans.get("dlg.but.cancel"));
49                 cancelButton.addActionListener(new ActionListener() {
50                         @Override
51                         public void actionPerformed(ActionEvent e) {
52                                 close(false);
53                         }
54                 });
55                 panel.add(cancelButton, "tag cancel");
56                 
57                 this.add(panel);
58                 
59                 this.setModal(true);
60                 this.pack();
61                 this.setLocationByPlatform(true);
62                 GUIUtil.setDisposableDialogOptions(this, okButton);
63                 
64                 //JComponent focus = selectionPanel.getDefaultFocus();
65                 //if (focus != null) {
66                 //      focus.grabFocus();
67                 //}
68                 
69                 // Set the closeable dialog after all initialization
70                 //selectionPanel.setCloseableDialog(this);
71         }
72         
73         
74         /**
75          * Return the motor selected by this chooser dialog, or <code>null</code> if the selection has been aborted.
76          * 
77          * @return      the selected motor, or <code>null</code> if no motor has been selected or the selection was canceled.
78          */
79         public ComponentPreset getSelectedComponentPreset() {
80                 if (!okClicked)
81                         return null;
82                 //return selectionPanel.getSelectedMotor();
83                 return null;
84         }
85         
86         public void close(boolean ok) {
87                 okClicked = ok;
88                 this.setVisible(false);
89                 
90                 ComponentPreset preset = getSelectedComponentPreset();
91                 if (okClicked && preset != null) {
92                         //selectionPanel.selectedMotor(selected);
93                 }
94         }
95         
96 }