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