1 package net.sf.openrocket.gui.configdialog;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
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;
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;
30 public class RingComponentConfig extends RocketComponentConfig {
31 private static final Translator trans = Application.getTranslator();
33 public RingComponentConfig(OpenRocketDocument d, RocketComponent component) {
38 protected JPanel generalTab(String outer, String inner, String thickness, String length) {
39 JPanel panel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::]", ""));
42 DoubleModel od = null;
47 panel.add(new JLabel(outer));
50 od = new DoubleModel(component, "OuterRadius", 2, UnitGroup.UNITS_LENGTH, 0);
51 // Diameter = 2*Radius
53 spin = new JSpinner(od.getSpinnerModel());
54 spin.setEditor(new SpinnerEditor(spin));
55 panel.add(spin, "growx");
57 panel.add(new UnitSelector(od), "growx");
58 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
60 if (od.isAutomaticAvailable()) {
61 JCheckBox check = new JCheckBox(od.getAutomaticAction());
63 check.setText(trans.get("ringcompcfg.Automatic"));
64 panel.add(check, "skip, span 2, wrap");
71 panel.add(new JLabel(inner));
74 m = new DoubleModel(component, "InnerRadius", 2, UnitGroup.UNITS_LENGTH, 0);
76 spin = new JSpinner(m.getSpinnerModel());
77 spin.setEditor(new SpinnerEditor(spin));
78 panel.add(spin, "growx");
80 panel.add(new UnitSelector(m), "growx");
82 panel.add(new BasicSlider(m.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
84 panel.add(new BasicSlider(m.getSliderModel(new DoubleModel(0), od)),
87 if (m.isAutomaticAvailable()) {
88 JCheckBox check = new JCheckBox(m.getAutomaticAction());
90 check.setText(trans.get("ringcompcfg.Automatic"));
91 panel.add(check, "skip, span 2, wrap");
97 if (thickness != null) {
98 panel.add(new JLabel(thickness));
101 m = new DoubleModel(component, "Thickness", UnitGroup.UNITS_LENGTH, 0);
103 spin = new JSpinner(m.getSpinnerModel());
104 spin.setEditor(new SpinnerEditor(spin));
105 panel.add(spin, "growx");
107 panel.add(new UnitSelector(m), "growx");
108 panel.add(new BasicSlider(m.getSliderModel(0, 0.01)), "w 100lp, wrap");
112 //// Inner tube length
113 if (length != null) {
114 panel.add(new JLabel(length));
117 m = new DoubleModel(component, "Length", UnitGroup.UNITS_LENGTH, 0);
119 spin = new JSpinner(m.getSpinnerModel());
120 spin.setEditor(new SpinnerEditor(spin));
121 panel.add(spin, "growx");
123 panel.add(new UnitSelector(m), "growx");
124 panel.add(new BasicSlider(m.getSliderModel(0, 0.1, 1.0)), "w 100lp, wrap");
130 //// Position relative to:
131 panel.add(new JLabel(trans.get("ringcompcfg.Positionrelativeto")));
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
141 panel.add(combo, "spanx 3, growx, wrap");
144 panel.add(new JLabel(trans.get("ringcompcfg.plus")), "right");
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");
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"))),
160 JPanel sub = materialPanel(new JPanel(new MigLayout()), Material.Type.BULK);
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");
168 panel.add(sub, "cell 4 0, gapleft paragraph, aligny 0%, spany");
174 protected JPanel positionTab() {
175 JPanel panel = new JPanel(new MigLayout("align 20% 20%, gap rel unrel",
176 "[][65lp::][30lp::]", ""));
179 JLabel l = new JLabel(trans.get("ringcompcfg.Radialdistance"));
180 //// Distance from the rocket centerline
181 l.setToolTipText(trans.get("ringcompcfg.Distancefrom"));
184 DoubleModel m = new DoubleModel(component, "RadialPosition", UnitGroup.UNITS_LENGTH, 0);
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");
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");
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"));
205 m = new DoubleModel(component, "RadialDirection", UnitGroup.UNITS_ANGLE);
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");
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");
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() {
226 public void actionPerformed(ActionEvent e) {
227 ((RingComponent) component).setRadialDirection(0.0);
228 ((RingComponent) component).setRadialPosition(0.0);
231 panel.add(button, "spanx, right, wrap para");
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");