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