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