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.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;
29 public class RingComponentConfig extends RocketComponentConfig {
30 private static final Translator trans = Application.getTranslator();
32 public RingComponentConfig(RocketComponent component) {
37 protected JPanel generalTab(String outer, String inner, String thickness, String length) {
38 JPanel panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]",""));
46 panel.add(new JLabel(outer));
49 od = new DoubleModel(component,"OuterRadius",2,UnitGroup.UNITS_LENGTH,0);
50 // Diameter = 2*Radius
52 spin = new JSpinner(od.getSpinnerModel());
53 spin.setEditor(new SpinnerEditor(spin));
54 panel.add(spin,"growx");
56 panel.add(new UnitSelector(od),"growx");
57 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap");
59 if (od.isAutomaticAvailable()) {
60 JCheckBox check = new JCheckBox(od.getAutomaticAction());
62 check.setText(trans.get("ringcompcfg.Automatic"));
63 panel.add(check,"skip, span 2, wrap");
70 panel.add(new JLabel(inner));
73 m = new DoubleModel(component,"InnerRadius",2,UnitGroup.UNITS_LENGTH,0);
75 spin = new JSpinner(m.getSpinnerModel());
76 spin.setEditor(new SpinnerEditor(spin));
77 panel.add(spin,"growx");
79 panel.add(new UnitSelector(m),"growx");
81 panel.add(new BasicSlider(m.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
83 panel.add(new BasicSlider(m.getSliderModel(new DoubleModel(0), od)),
86 if (m.isAutomaticAvailable()) {
87 JCheckBox check = new JCheckBox(m.getAutomaticAction());
89 check.setText(trans.get("ringcompcfg.Automatic"));
90 panel.add(check,"skip, span 2, wrap");
96 if (thickness != null) {
97 panel.add(new JLabel(thickness));
100 m = new DoubleModel(component,"Thickness",UnitGroup.UNITS_LENGTH,0);
102 spin = new JSpinner(m.getSpinnerModel());
103 spin.setEditor(new SpinnerEditor(spin));
104 panel.add(spin,"growx");
106 panel.add(new UnitSelector(m),"growx");
107 panel.add(new BasicSlider(m.getSliderModel(0,0.01)),"w 100lp, wrap");
111 //// Inner tube length
112 if (length != null) {
113 panel.add(new JLabel(length));
116 m = new DoubleModel(component,"Length",UnitGroup.UNITS_LENGTH,0);
118 spin = new JSpinner(m.getSpinnerModel());
119 spin.setEditor(new SpinnerEditor(spin));
120 panel.add(spin,"growx");
122 panel.add(new UnitSelector(m),"growx");
123 panel.add(new BasicSlider(m.getSliderModel(0, 0.1, 1.0)),"w 100lp, wrap");
129 //// Position relative to:
130 panel.add(new JLabel(trans.get("ringcompcfg.Positionrelativeto")));
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
140 panel.add(combo,"spanx 3, growx, wrap");
143 panel.add(new JLabel(trans.get("ringcompcfg.plus")),"right");
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");
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"))),
159 JPanel sub = materialPanel(new JPanel(new MigLayout()), Material.Type.BULK);
161 if (component instanceof EngineBlock) {
162 final DescriptionArea desc = new DescriptionArea(6);
163 //// <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.
164 desc.setText(trans.get("ringcompcfg.EngineBlock.desc"));
165 sub.add(desc, "width 1px, growx, wrap");
167 panel.add(sub,"cell 4 0, gapleft paragraph, aligny 0%, spany");
173 protected JPanel positionTab() {
174 JPanel panel = new JPanel(new MigLayout("align 20% 20%, gap rel unrel",
175 "[][65lp::][30lp::]",""));
178 JLabel l = new JLabel(trans.get("ringcompcfg.Radialdistance"));
179 //// Distance from the rocket centerline
180 l.setToolTipText(trans.get("ringcompcfg.Distancefrom"));
183 DoubleModel m = new DoubleModel(component,"RadialPosition",UnitGroup.UNITS_LENGTH,0);
185 JSpinner spin = new JSpinner(m.getSpinnerModel());
186 spin.setEditor(new SpinnerEditor(spin));
187 //// Distance from the rocket centerline
188 spin.setToolTipText(trans.get("ringcompcfg.Distancefrom"));
189 panel.add(spin,"growx");
191 panel.add(new UnitSelector(m),"growx");
192 BasicSlider bs = new BasicSlider(m.getSliderModel(0, 0.1, 1.0));
193 //// Distance from the rocket centerline
194 bs.setToolTipText(trans.get("ringcompcfg.Distancefrom"));
195 panel.add(bs,"w 100lp, wrap");
198 //// Radial direction
199 l = new JLabel(trans.get("ringcompcfg.Radialdirection"));
200 //// The radial direction from the rocket centerline
201 l.setToolTipText(trans.get("ringcompcfg.radialdirectionfrom"));
204 m = new DoubleModel(component,"RadialDirection",UnitGroup.UNITS_ANGLE,0);
206 spin = new JSpinner(m.getSpinnerModel());
207 spin.setEditor(new SpinnerEditor(spin));
208 //// The radial direction from the rocket centerline
209 spin.setToolTipText(trans.get("ringcompcfg.radialdirectionfrom"));
210 panel.add(spin,"growx");
212 panel.add(new UnitSelector(m),"growx");
213 bs = new BasicSlider(m.getSliderModel(-Math.PI, Math.PI));
214 //// The radial direction from the rocket centerline
215 bs.setToolTipText(trans.get("ringcompcfg.radialdirectionfrom"));
216 panel.add(bs,"w 100lp, wrap");
220 JButton button = new JButton(trans.get("ringcompcfg.but.Reset"));
221 //// Reset the component to the rocket centerline
222 button.setToolTipText(trans.get("ringcompcfg.but.Resetcomponant"));
223 button.addActionListener(new ActionListener() {
225 public void actionPerformed(ActionEvent e) {
226 ((RingComponent) component).setRadialDirection(0.0);
227 ((RingComponent) component).setRadialPosition(0.0);
230 panel.add(button,"spanx, right, wrap para");
233 DescriptionArea note = new DescriptionArea(2);
234 //// Note: An inner tube will not affect the aerodynamics of the rocket even if it is located outside of the body tube.
235 note.setText(trans.get("ringcompcfg.note.desc"));
236 panel.add(note, "spanx, growx");