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