bug fixes and rocket optimization
[debian/openrocket] / src / net / sf / openrocket / gui / configdialog / RingComponentConfig.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.components.BasicSlider;
19 import net.sf.openrocket.gui.components.DescriptionArea;
20 import net.sf.openrocket.gui.components.UnitSelector;
21 import net.sf.openrocket.l10n.Translator;
22 import net.sf.openrocket.material.Material;
23 import net.sf.openrocket.rocketcomponent.EngineBlock;
24 import net.sf.openrocket.rocketcomponent.RingComponent;
25 import net.sf.openrocket.rocketcomponent.RocketComponent;
26 import net.sf.openrocket.startup.Application;
27 import net.sf.openrocket.unit.UnitGroup;
28
29 public class RingComponentConfig extends RocketComponentConfig {
30         private static final Translator trans = Application.getTranslator();
31         
32         public RingComponentConfig(RocketComponent component) {
33                 super(component);
34         }
35         
36         
37         protected JPanel generalTab(String outer, String inner, String thickness, String length) {
38                 JPanel panel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::]", ""));
39                 DoubleModel m;
40                 JSpinner spin;
41                 DoubleModel od = null;
42                 
43
44                 //// Outer diameter
45                 if (outer != null) {
46                         panel.add(new JLabel(outer));
47                         
48                         //// OuterRadius
49                         od = new DoubleModel(component, "OuterRadius", 2, UnitGroup.UNITS_LENGTH, 0);
50                         // Diameter = 2*Radius
51                         
52                         spin = new JSpinner(od.getSpinnerModel());
53                         spin.setEditor(new SpinnerEditor(spin));
54                         panel.add(spin, "growx");
55                         
56                         panel.add(new UnitSelector(od), "growx");
57                         panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
58                         
59                         if (od.isAutomaticAvailable()) {
60                                 JCheckBox check = new JCheckBox(od.getAutomaticAction());
61                                 //// Automatic
62                                 check.setText(trans.get("ringcompcfg.Automatic"));
63                                 panel.add(check, "skip, span 2, wrap");
64                         }
65                 }
66                 
67
68                 ////  Inner diameter
69                 if (inner != null) {
70                         panel.add(new JLabel(inner));
71                         
72                         //// InnerRadius
73                         m = new DoubleModel(component, "InnerRadius", 2, UnitGroup.UNITS_LENGTH, 0);
74                         
75                         spin = new JSpinner(m.getSpinnerModel());
76                         spin.setEditor(new SpinnerEditor(spin));
77                         panel.add(spin, "growx");
78                         
79                         panel.add(new UnitSelector(m), "growx");
80                         if (od == null)
81                                 panel.add(new BasicSlider(m.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
82                         else
83                                 panel.add(new BasicSlider(m.getSliderModel(new DoubleModel(0), od)),
84                                                 "w 100lp, wrap");
85                         
86                         if (m.isAutomaticAvailable()) {
87                                 JCheckBox check = new JCheckBox(m.getAutomaticAction());
88                                 //// Automatic
89                                 check.setText(trans.get("ringcompcfg.Automatic"));
90                                 panel.add(check, "skip, span 2, wrap");
91                         }
92                 }
93                 
94
95                 ////  Wall thickness
96                 if (thickness != null) {
97                         panel.add(new JLabel(thickness));
98                         
99                         //// Thickness
100                         m = new DoubleModel(component, "Thickness", UnitGroup.UNITS_LENGTH, 0);
101                         
102                         spin = new JSpinner(m.getSpinnerModel());
103                         spin.setEditor(new SpinnerEditor(spin));
104                         panel.add(spin, "growx");
105                         
106                         panel.add(new UnitSelector(m), "growx");
107                         panel.add(new BasicSlider(m.getSliderModel(0, 0.01)), "w 100lp, wrap");
108                 }
109                 
110
111                 ////  Inner tube length
112                 if (length != null) {
113                         panel.add(new JLabel(length));
114                         
115                         //// Length
116                         m = new DoubleModel(component, "Length", UnitGroup.UNITS_LENGTH, 0);
117                         
118                         spin = new JSpinner(m.getSpinnerModel());
119                         spin.setEditor(new SpinnerEditor(spin));
120                         panel.add(spin, "growx");
121                         
122                         panel.add(new UnitSelector(m), "growx");
123                         panel.add(new BasicSlider(m.getSliderModel(0, 0.1, 1.0)), "w 100lp, wrap");
124                 }
125                 
126
127                 ////  Position
128                 
129                 //// Position relative to:
130                 panel.add(new JLabel(trans.get("ringcompcfg.Positionrelativeto")));
131                 
132                 JComboBox 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 3, growx, wrap");
141                 
142                 //// plus
143                 panel.add(new JLabel(trans.get("ringcompcfg.plus")), "right");
144                 
145                 //// PositionValue
146                 m = new DoubleModel(component, "PositionValue", UnitGroup.UNITS_LENGTH);
147                 spin = new JSpinner(m.getSpinnerModel());
148                 spin.setEditor(new SpinnerEditor(spin));
149                 panel.add(spin, "growx");
150                 
151                 panel.add(new UnitSelector(m), "growx");
152                 panel.add(new BasicSlider(m.getSliderModel(
153                                 new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE),
154                                 new DoubleModel(component.getParent(), "Length"))),
155                                 "w 100lp, wrap");
156                 
157
158                 //// Material
159                 JPanel sub = materialPanel(new JPanel(new MigLayout()), Material.Type.BULK);
160                 
161                 if (component instanceof EngineBlock) {
162                         final DescriptionArea desc = new DescriptionArea(6);
163                         //// <html>An <b>engine block</b> stops the motor from moving forwards in the motor mount tube.<br><br>In order to add a motor, create a <b>body tube</b> or <b>inner tube</b> and mark it as a motor mount in the <em>Motor</em> tab.
164                         desc.setText(trans.get("ringcompcfg.EngineBlock.desc"));
165                         sub.add(desc, "width 1px, growx, wrap");
166                 }
167                 panel.add(sub, "cell 4 0, gapleft paragraph, aligny 0%, spany");
168                 
169                 return panel;
170         }
171         
172         
173         protected JPanel positionTab() {
174                 JPanel panel = new JPanel(new MigLayout("align 20% 20%, gap rel unrel",
175                                 "[][65lp::][30lp::]", ""));
176                 
177                 ////  Radial position
178                 JLabel l = new JLabel(trans.get("ringcompcfg.Radialdistance"));
179                 //// Distance from the rocket centerline
180                 l.setToolTipText(trans.get("ringcompcfg.Distancefrom"));
181                 panel.add(l);
182                 
183                 DoubleModel m = new DoubleModel(component, "RadialPosition", UnitGroup.UNITS_LENGTH, 0);
184                 
185                 JSpinner spin = new JSpinner(m.getSpinnerModel());
186                 spin.setEditor(new SpinnerEditor(spin));
187                 //// Distance from the rocket centerline
188                 spin.setToolTipText(trans.get("ringcompcfg.Distancefrom"));
189                 panel.add(spin, "growx");
190                 
191                 panel.add(new UnitSelector(m), "growx");
192                 BasicSlider bs = new BasicSlider(m.getSliderModel(0, 0.1, 1.0));
193                 //// Distance from the rocket centerline
194                 bs.setToolTipText(trans.get("ringcompcfg.Distancefrom"));
195                 panel.add(bs, "w 100lp, wrap");
196                 
197
198                 //// Radial direction
199                 l = new JLabel(trans.get("ringcompcfg.Radialdirection"));
200                 //// The radial direction from the rocket centerline
201                 l.setToolTipText(trans.get("ringcompcfg.radialdirectionfrom"));
202                 panel.add(l);
203                 
204                 m = new DoubleModel(component, "RadialDirection", UnitGroup.UNITS_ANGLE, 0);
205                 
206                 spin = new JSpinner(m.getSpinnerModel());
207                 spin.setEditor(new SpinnerEditor(spin));
208                 //// The radial direction from the rocket centerline
209                 spin.setToolTipText(trans.get("ringcompcfg.radialdirectionfrom"));
210                 panel.add(spin, "growx");
211                 
212                 panel.add(new UnitSelector(m), "growx");
213                 bs = new BasicSlider(m.getSliderModel(-Math.PI, Math.PI));
214                 //// The radial direction from the rocket centerline
215                 bs.setToolTipText(trans.get("ringcompcfg.radialdirectionfrom"));
216                 panel.add(bs, "w 100lp, wrap");
217                 
218
219                 //// Reset button
220                 JButton button = new JButton(trans.get("ringcompcfg.but.Reset"));
221                 //// Reset the component to the rocket centerline
222                 button.setToolTipText(trans.get("ringcompcfg.but.Resetcomponant"));
223                 button.addActionListener(new ActionListener() {
224                         @Override
225                         public void actionPerformed(ActionEvent e) {
226                                 ((RingComponent) component).setRadialDirection(0.0);
227                                 ((RingComponent) component).setRadialPosition(0.0);
228                         }
229                 });
230                 panel.add(button, "spanx, right, wrap para");
231                 
232
233                 DescriptionArea note = new DescriptionArea(3);
234                 //// Note: An inner tube will not affect the aerodynamics of the rocket even if it is located outside of the body tube.
235                 note.setText(trans.get("ringcompcfg.note.desc"));
236                 panel.add(note, "spanx, growx");
237                 
238
239                 return panel;
240         }
241         
242 }