Bug fixes and startup checks
[debian/openrocket] / src / net / sf / openrocket / gui / configdialog / ParachuteConfig.java
1 package net.sf.openrocket.gui.configdialog;
2
3
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6
7 import javax.swing.JButton;
8 import javax.swing.JComboBox;
9 import javax.swing.JLabel;
10 import javax.swing.JPanel;
11 import javax.swing.JSpinner;
12
13 import net.miginfocom.swing.MigLayout;
14 import net.sf.openrocket.gui.SpinnerEditor;
15 import net.sf.openrocket.gui.adaptors.DoubleModel;
16 import net.sf.openrocket.gui.adaptors.EnumModel;
17 import net.sf.openrocket.gui.adaptors.IntegerModel;
18 import net.sf.openrocket.gui.adaptors.MaterialModel;
19 import net.sf.openrocket.gui.components.BasicSlider;
20 import net.sf.openrocket.gui.components.UnitSelector;
21 import net.sf.openrocket.material.Material;
22 import net.sf.openrocket.rocketcomponent.MassComponent;
23 import net.sf.openrocket.rocketcomponent.Parachute;
24 import net.sf.openrocket.rocketcomponent.RocketComponent;
25 import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent;
26 import net.sf.openrocket.unit.UnitGroup;
27
28 public class ParachuteConfig extends RecoveryDeviceConfig {
29
30         public ParachuteConfig(final RocketComponent component) {
31                 super(component);
32
33                 JPanel primary = new JPanel(new MigLayout());
34                 
35                 JPanel panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::][]",""));
36                 
37                 
38                 //// Canopy
39                 panel.add(new JLabel("<html><b>Canopy:</b>"), "wrap unrel");
40                 
41
42                 panel.add(new JLabel("Diameter:"));
43                 
44                 DoubleModel m = new DoubleModel(component,"Diameter",UnitGroup.UNITS_LENGTH,0);
45                 
46                 JSpinner spin = new JSpinner(m.getSpinnerModel());
47                 spin.setEditor(new SpinnerEditor(spin));
48                 panel.add(spin,"growx");
49                 panel.add(new UnitSelector(m),"growx");
50                 panel.add(new BasicSlider(m.getSliderModel(0, 0.4, 1.5)),"w 100lp, wrap");
51
52                 
53                 panel.add(new JLabel("Material:"));
54                 
55                 JComboBox combo = new JComboBox(new MaterialModel(component, Material.Type.SURFACE));
56                 combo.setToolTipText("The component material affects the weight of the component.");
57                 panel.add(combo,"spanx 3, growx, wrap paragraph");
58
59 //              materialPanel(panel, Material.Type.SURFACE, "Material:", null);
60                 
61                 
62                 
63                 // CD
64                 JLabel label = new JLabel("<html>Drag coefficient C<sub>D</sub>:");
65                 String tip = "<html>The drag coefficient relative to the total area of the parachute.<br>" +
66                                 "A larger drag coefficient yields a slowed descent rate.  " +
67                                 "A typical value for parachutes is 0.8.";
68                 label.setToolTipText(tip);
69                 panel.add(label);
70                 
71                 m = new DoubleModel(component,"CD",UnitGroup.UNITS_COEFFICIENT,0);
72                 
73                 spin = new JSpinner(m.getSpinnerModel());
74                 spin.setToolTipText(tip);
75                 spin.setEditor(new SpinnerEditor(spin));
76                 panel.add(spin,"growx");
77                 
78                 JButton button = new JButton("Reset");
79                 button.addActionListener(new ActionListener() {
80                         @Override
81                         public void actionPerformed(ActionEvent e) {
82                                 Parachute p = (Parachute)component;
83                                 p.setCD(Parachute.DEFAULT_CD);
84                         }
85                 });
86                 panel.add(button,"spanx, wrap 30lp");
87
88                 
89                 
90                 ////  Shroud lines
91                 panel.add(new JLabel("<html><b>Shroud lines:</b>"), "wrap unrel");
92
93
94                 panel.add(new JLabel("Number of lines:"));
95                 IntegerModel im = new IntegerModel(component,"LineCount",0);
96                 
97                 spin = new JSpinner(im.getSpinnerModel());
98                 spin.setEditor(new SpinnerEditor(spin));
99                 panel.add(spin,"growx, wrap");
100                 
101                 
102                 panel.add(new JLabel("Line length:"));
103
104                 m = new DoubleModel(component,"LineLength",UnitGroup.UNITS_LENGTH,0);
105                 
106                 spin = new JSpinner(m.getSpinnerModel());
107                 spin.setEditor(new SpinnerEditor(spin));
108                 panel.add(spin,"growx");
109                 panel.add(new UnitSelector(m),"growx");
110                 panel.add(new BasicSlider(m.getSliderModel(0, 0.4, 1.5)),"w 100lp, wrap");
111
112                 
113                 panel.add(new JLabel("Material:"));
114                 
115                 combo = new JComboBox(new MaterialModel(component, Material.Type.LINE, 
116                                 "LineMaterial"));
117                 panel.add(combo,"spanx 3, growx, wrap");
118
119                 
120                 
121                 primary.add(panel, "grow, gapright 20lp");
122                 panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::][]",""));
123
124                 
125                 
126                 
127                 //// Position
128
129                 panel.add(new JLabel("Position relative to:"));
130
131                 combo = new JComboBox(
132                                 new EnumModel<RocketComponent.Position>(component, "RelativePosition",
133                                                 new RocketComponent.Position[] {
134                                                 RocketComponent.Position.TOP,
135                                                 RocketComponent.Position.MIDDLE,
136                                                 RocketComponent.Position.BOTTOM,
137                                                 RocketComponent.Position.ABSOLUTE
138                                 }));
139                 panel.add(combo,"spanx, growx, wrap");
140                 
141                 panel.add(new JLabel("plus"),"right");
142
143                 m = new DoubleModel(component,"PositionValue",UnitGroup.UNITS_LENGTH);
144                 spin = new JSpinner(m.getSpinnerModel());
145                 spin.setEditor(new SpinnerEditor(spin));
146                 panel.add(spin,"growx");
147                 
148                 panel.add(new UnitSelector(m),"growx");
149                 panel.add(new BasicSlider(m.getSliderModel(
150                                 new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE),
151                                 new DoubleModel(component.getParent(), "Length"))),
152                                 "w 100lp, wrap");
153
154
155                 ////  Spatial length
156                 panel.add(new JLabel("Packed length:"));
157                 
158                 m = new DoubleModel(component,"Length",UnitGroup.UNITS_LENGTH,0);
159                 
160                 spin = new JSpinner(m.getSpinnerModel());
161                 spin.setEditor(new SpinnerEditor(spin));
162                 panel.add(spin,"growx");
163                 
164                 panel.add(new UnitSelector(m),"growx");
165                 panel.add(new BasicSlider(m.getSliderModel(0, 0.1, 0.5)),"w 100lp, wrap");
166                 
167                 
168                 //// Tube diameter
169                 panel.add(new JLabel("Packed diameter:"));
170
171                 DoubleModel od  = new DoubleModel(component,"Radius",2,UnitGroup.UNITS_LENGTH,0);
172                 // Diameter = 2*Radius
173
174                 spin = new JSpinner(od.getSpinnerModel());
175                 spin.setEditor(new SpinnerEditor(spin));
176                 panel.add(spin,"growx");
177                 
178                 panel.add(new UnitSelector(od),"growx");
179                 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap 30lp");
180                 
181                 
182                 //// Deployment
183
184                 panel.add(new JLabel("Deploys at:"),"");
185                 
186                 combo = new JComboBox(new EnumModel<IgnitionEvent>(component, "DeployEvent"));
187                 panel.add(combo,"spanx 3, growx, wrap");
188                 
189                 // ... and delay
190                 panel.add(new JLabel("plus"),"right");
191                 
192                 m = new DoubleModel(component,"DeployDelay",0);
193                 spin = new JSpinner(m.getSpinnerModel());
194                 spin.setEditor(new SpinnerEditor(spin));
195                 panel.add(spin,"spanx, split");
196                 
197                 panel.add(new JLabel("seconds"),"wrap paragraph");
198
199                 // Altitude
200                 label = new JLabel("Altitude:");
201                 altitudeComponents.add(label);
202                 panel.add(label);
203                 
204                 m = new DoubleModel(component,"DeployAltitude",UnitGroup.UNITS_DISTANCE,0);
205                 
206                 spin = new JSpinner(m.getSpinnerModel());
207                 spin.setEditor(new SpinnerEditor(spin));
208                 altitudeComponents.add(spin);
209                 panel.add(spin,"growx");
210                 UnitSelector unit = new UnitSelector(m);
211                 altitudeComponents.add(unit);
212                 panel.add(unit,"growx");
213                 BasicSlider slider = new BasicSlider(m.getSliderModel(100, 1000));
214                 altitudeComponents.add(slider);
215                 panel.add(slider,"w 100lp, wrap");
216
217                 
218                 primary.add(panel, "grow");
219                 
220                 updateFields();
221
222                 tabbedPane.insertTab("General", null, primary, "General properties", 0);
223                 tabbedPane.insertTab("Radial position", null, positionTab(), 
224                                 "Radial position configuration", 1);
225                 tabbedPane.setSelectedIndex(0);
226         }
227         
228         
229         
230
231
232         protected JPanel positionTab() {
233                 JPanel panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]",""));
234                 
235                 ////  Radial position
236                 panel.add(new JLabel("Radial distance:"));
237                 
238                 DoubleModel m = new DoubleModel(component,"RadialPosition",UnitGroup.UNITS_LENGTH,0);
239                 
240                 JSpinner spin = new JSpinner(m.getSpinnerModel());
241                 spin.setEditor(new SpinnerEditor(spin));
242                 panel.add(spin,"growx");
243                 
244                 panel.add(new UnitSelector(m),"growx");
245                 panel.add(new BasicSlider(m.getSliderModel(0, 0.1, 1.0)),"w 100lp, wrap");
246                 
247                 
248                 //// Radial direction
249                 panel.add(new JLabel("Radial direction:"));
250                 
251                 m = new DoubleModel(component,"RadialDirection",UnitGroup.UNITS_ANGLE,0);
252                 
253                 spin = new JSpinner(m.getSpinnerModel());
254                 spin.setEditor(new SpinnerEditor(spin));
255                 panel.add(spin,"growx");
256                 
257                 panel.add(new UnitSelector(m),"growx");
258                 panel.add(new BasicSlider(m.getSliderModel(-Math.PI, Math.PI)),"w 100lp, wrap");
259
260                 
261                 //// Reset button
262                 JButton button = new JButton("Reset");
263                 button.addActionListener(new ActionListener() {
264                         @Override
265                         public void actionPerformed(ActionEvent e) {
266                                 ((MassComponent) component).setRadialDirection(0.0);
267                                 ((MassComponent) component).setRadialPosition(0.0);
268                         }
269                 });
270                 panel.add(button,"spanx, right");
271                 
272                 return panel;
273         }
274 }