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