a5c74943560a843bdfe18f6a5748236be4d73519
[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                         desc.setText("<html>An <b>engine block</b> stops the motor from moving forwards " +
164                                         "in the motor mount tube.<br><br>In order to add a motor, create a " +
165                                         "<b>body tube</b> or <b>inner tube</b> and mark it as a motor mount in " +
166                                         "the <em>Motor</em> tab.");
167                         sub.add(desc, "width 1px, growx, wrap");
168                 }
169                 panel.add(sub,"cell 4 0, gapleft paragraph, aligny 0%, spany");
170                 
171                 return panel;
172         }
173         
174         
175         protected JPanel positionTab() {
176                 JPanel panel = new JPanel(new MigLayout("align 20% 20%, gap rel unrel",
177                                 "[][65lp::][30lp::]",""));
178                 
179                 ////  Radial position
180                 JLabel l = new JLabel(trans.get("ringcompcfg.Radialdistance"));
181                 //// Distance from the rocket centerline
182                 l.setToolTipText(trans.get("ringcompcfg.Distancefrom"));
183                 panel.add(l);
184                 
185                 DoubleModel m = new DoubleModel(component,"RadialPosition",UnitGroup.UNITS_LENGTH,0);
186                 
187                 JSpinner spin = new JSpinner(m.getSpinnerModel());
188                 spin.setEditor(new SpinnerEditor(spin));
189                 //// Distance from the rocket centerline
190                 spin.setToolTipText(trans.get("ringcompcfg.Distancefrom"));
191                 panel.add(spin,"growx");
192                 
193                 panel.add(new UnitSelector(m),"growx");
194                 BasicSlider bs = new BasicSlider(m.getSliderModel(0, 0.1, 1.0));
195                 //// Distance from the rocket centerline
196                 bs.setToolTipText(trans.get("ringcompcfg.Distancefrom"));
197                 panel.add(bs,"w 100lp, wrap");
198                 
199                 
200                 //// Radial direction
201                 l = new JLabel(trans.get("ringcompcfg.Radialdirection"));
202                 //// The radial direction from the rocket centerline
203                 l.setToolTipText(trans.get("ringcompcfg.radialdirectionfrom"));
204                 panel.add(l);
205                 
206                 m = new DoubleModel(component,"RadialDirection",UnitGroup.UNITS_ANGLE,0);
207                 
208                 spin = new JSpinner(m.getSpinnerModel());
209                 spin.setEditor(new SpinnerEditor(spin));
210                 //// The radial direction from the rocket centerline
211                 spin.setToolTipText(trans.get("ringcompcfg.radialdirectionfrom"));
212                 panel.add(spin,"growx");
213                 
214                 panel.add(new UnitSelector(m),"growx");
215                 bs = new BasicSlider(m.getSliderModel(-Math.PI, Math.PI));
216                 //// The radial direction from the rocket centerline
217                 bs.setToolTipText(trans.get("ringcompcfg.radialdirectionfrom"));
218                 panel.add(bs,"w 100lp, wrap");
219
220                 
221                 //// Reset button
222                 JButton button = new JButton(trans.get("ringcompcfg.but.Reset"));
223                 //// Reset the component to the rocket centerline
224                 button.setToolTipText(trans.get("ringcompcfg.but.Resetcomponant"));
225                 button.addActionListener(new ActionListener() {
226                         @Override
227                         public void actionPerformed(ActionEvent e) {
228                                 ((RingComponent) component).setRadialDirection(0.0);
229                                 ((RingComponent) component).setRadialPosition(0.0);
230                         }
231                 });
232                 panel.add(button,"spanx, right, wrap para");
233                 
234                 
235                 DescriptionArea note = new DescriptionArea(2);
236                 note.setText("Note: An inner tube will not affect the aerodynamics" +
237                                 " of the rocket even if it is located outside of the body tube.");
238                 panel.add(note, "spanx, growx");
239                 
240                 
241                 return panel;
242         }
243
244 }