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