1 package net.sf.openrocket.gui.configdialog;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
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;
13 import net.miginfocom.swing.MigLayout;
14 import net.sf.openrocket.gui.BasicSlider;
15 import net.sf.openrocket.gui.SpinnerEditor;
16 import net.sf.openrocket.gui.UnitSelector;
17 import net.sf.openrocket.gui.adaptors.DoubleModel;
18 import net.sf.openrocket.gui.adaptors.EnumModel;
19 import net.sf.openrocket.gui.adaptors.IntegerModel;
20 import net.sf.openrocket.gui.adaptors.MaterialModel;
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;
28 public class ParachuteConfig extends RecoveryDeviceConfig {
30 public ParachuteConfig(final RocketComponent component) {
33 JPanel primary = new JPanel(new MigLayout());
35 JPanel panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::][]",""));
39 panel.add(new JLabel("<html><b>Canopy:</b>"), "wrap unrel");
42 panel.add(new JLabel("Diameter:"));
44 DoubleModel m = new DoubleModel(component,"Diameter",UnitGroup.UNITS_LENGTH,0);
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");
53 panel.add(new JLabel("Material:"));
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");
59 // materialPanel(panel, Material.Type.SURFACE, "Material:", null);
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);
71 m = new DoubleModel(component,"CD",UnitGroup.UNITS_COEFFICIENT,0);
73 spin = new JSpinner(m.getSpinnerModel());
74 spin.setToolTipText(tip);
75 spin.setEditor(new SpinnerEditor(spin));
76 panel.add(spin,"growx");
78 JButton button = new JButton("Reset");
79 button.addActionListener(new ActionListener() {
81 public void actionPerformed(ActionEvent e) {
82 Parachute p = (Parachute)component;
83 p.setCD(Parachute.DEFAULT_CD);
86 panel.add(button,"spanx, wrap 30lp");
91 panel.add(new JLabel("<html><b>Shroud lines:</b>"), "wrap unrel");
94 panel.add(new JLabel("Number of lines:"));
95 IntegerModel im = new IntegerModel(component,"LineCount",0);
97 spin = new JSpinner(im.getSpinnerModel());
98 spin.setEditor(new SpinnerEditor(spin));
99 panel.add(spin,"growx, wrap");
102 panel.add(new JLabel("Line length:"));
104 m = new DoubleModel(component,"LineLength",UnitGroup.UNITS_LENGTH,0);
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");
113 panel.add(new JLabel("Material:"));
115 combo = new JComboBox(new MaterialModel(component, Material.Type.LINE,
117 panel.add(combo,"spanx 3, growx, wrap");
121 primary.add(panel, "grow, gapright 20lp");
122 panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::][]",""));
129 panel.add(new JLabel("Position relative to:"));
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
139 panel.add(combo,"spanx, growx, wrap");
141 panel.add(new JLabel("plus"),"right");
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");
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"))),
156 panel.add(new JLabel("Packed length:"));
158 m = new DoubleModel(component,"Length",UnitGroup.UNITS_LENGTH,0);
160 spin = new JSpinner(m.getSpinnerModel());
161 spin.setEditor(new SpinnerEditor(spin));
162 panel.add(spin,"growx");
164 panel.add(new UnitSelector(m),"growx");
165 panel.add(new BasicSlider(m.getSliderModel(0, 0.1, 0.5)),"w 100lp, wrap");
169 panel.add(new JLabel("Packed diameter:"));
171 DoubleModel od = new DoubleModel(component,"Radius",2,UnitGroup.UNITS_LENGTH,0);
172 // Diameter = 2*Radius
174 spin = new JSpinner(od.getSpinnerModel());
175 spin.setEditor(new SpinnerEditor(spin));
176 panel.add(spin,"growx");
178 panel.add(new UnitSelector(od),"growx");
179 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap 30lp");
184 panel.add(new JLabel("Deploys at:"),"");
186 combo = new JComboBox(new EnumModel<IgnitionEvent>(component, "DeployEvent"));
187 panel.add(combo,"spanx 3, growx, wrap");
190 panel.add(new JLabel("plus"),"right");
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");
197 panel.add(new JLabel("seconds"),"wrap paragraph");
200 label = new JLabel("Altitude:");
201 altitudeComponents.add(label);
204 m = new DoubleModel(component,"DeployAltitude",UnitGroup.UNITS_DISTANCE,0);
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");
218 primary.add(panel, "grow");
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);
232 protected JPanel positionTab() {
233 JPanel panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]",""));
236 panel.add(new JLabel("Radial distance:"));
238 DoubleModel m = new DoubleModel(component,"RadialPosition",UnitGroup.UNITS_LENGTH,0);
240 JSpinner spin = new JSpinner(m.getSpinnerModel());
241 spin.setEditor(new SpinnerEditor(spin));
242 panel.add(spin,"growx");
244 panel.add(new UnitSelector(m),"growx");
245 panel.add(new BasicSlider(m.getSliderModel(0, 0.1, 1.0)),"w 100lp, wrap");
248 //// Radial direction
249 panel.add(new JLabel("Radial direction:"));
251 m = new DoubleModel(component,"RadialDirection",UnitGroup.UNITS_ANGLE,0);
253 spin = new JSpinner(m.getSpinnerModel());
254 spin.setEditor(new SpinnerEditor(spin));
255 panel.add(spin,"growx");
257 panel.add(new UnitSelector(m),"growx");
258 panel.add(new BasicSlider(m.getSliderModel(-Math.PI, Math.PI)),"w 100lp, wrap");
262 JButton button = new JButton("Reset");
263 button.addActionListener(new ActionListener() {
265 public void actionPerformed(ActionEvent e) {
266 ((MassComponent) component).setRadialDirection(0.0);
267 ((MassComponent) component).setRadialPosition(0.0);
270 panel.add(button,"spanx, right");