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.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;
27 public class RingComponentConfig extends RocketComponentConfig {
29 public RingComponentConfig(RocketComponent component) {
34 protected JPanel generalTab(String outer, String inner, String thickness, String length) {
35 JPanel panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]",""));
43 panel.add(new JLabel(outer));
45 od = new DoubleModel(component,"OuterRadius",2,UnitGroup.UNITS_LENGTH,0);
46 // Diameter = 2*Radius
48 spin = new JSpinner(od.getSpinnerModel());
49 spin.setEditor(new SpinnerEditor(spin));
50 panel.add(spin,"growx");
52 panel.add(new UnitSelector(od),"growx");
53 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap");
55 if (od.isAutomaticAvailable()) {
56 JCheckBox check = new JCheckBox(od.getAutomaticAction());
57 check.setText("Automatic");
58 panel.add(check,"skip, span 2, wrap");
65 panel.add(new JLabel(inner));
67 m = new DoubleModel(component,"InnerRadius",2,UnitGroup.UNITS_LENGTH,0);
69 spin = new JSpinner(m.getSpinnerModel());
70 spin.setEditor(new SpinnerEditor(spin));
71 panel.add(spin,"growx");
73 panel.add(new UnitSelector(m),"growx");
75 panel.add(new BasicSlider(m.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
77 panel.add(new BasicSlider(m.getSliderModel(new DoubleModel(0), od)),
80 if (m.isAutomaticAvailable()) {
81 JCheckBox check = new JCheckBox(m.getAutomaticAction());
82 check.setText("Automatic");
83 panel.add(check,"skip, span 2, wrap");
89 if (thickness != null) {
90 panel.add(new JLabel(thickness));
92 m = new DoubleModel(component,"Thickness",UnitGroup.UNITS_LENGTH,0);
94 spin = new JSpinner(m.getSpinnerModel());
95 spin.setEditor(new SpinnerEditor(spin));
96 panel.add(spin,"growx");
98 panel.add(new UnitSelector(m),"growx");
99 panel.add(new BasicSlider(m.getSliderModel(0,0.01)),"w 100lp, wrap");
103 //// Inner tube length
104 if (length != null) {
105 panel.add(new JLabel(length));
107 m = new DoubleModel(component,"Length",UnitGroup.UNITS_LENGTH,0);
109 spin = new JSpinner(m.getSpinnerModel());
110 spin.setEditor(new SpinnerEditor(spin));
111 panel.add(spin,"growx");
113 panel.add(new UnitSelector(m),"growx");
114 panel.add(new BasicSlider(m.getSliderModel(0, 0.1, 1.0)),"w 100lp, wrap");
120 panel.add(new JLabel("Position relative to:"));
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
130 panel.add(combo,"spanx 3, growx, wrap");
132 panel.add(new JLabel("plus"),"right");
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");
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"))),
147 JPanel sub = materialPanel(new JPanel(new MigLayout()), Material.Type.BULK);
149 if (component instanceof EngineBlock) {
150 DescriptionArea desc = new DescriptionArea(6,-1);
151 desc.setText("<html>An engine block stops the motor from moving forwards in " +
152 "the motor mount tube.<br><br>In order to add a motor, create a body tube " +
153 "or inner tube and mark it as a motor mount in the <em>Motor</em> " +
155 sub.add(desc, "growx");
157 panel.add(sub,"cell 4 0, gapleft paragraph, aligny 0%, spany");
163 protected JPanel positionTab() {
164 JPanel panel = new JPanel(new MigLayout("align 20% 20%, gap rel unrel",
165 "[][65lp::][30lp::]",""));
168 JLabel l = new JLabel("Radial distance:");
169 l.setToolTipText("Distance from the rocket centerline");
172 DoubleModel m = new DoubleModel(component,"RadialPosition",UnitGroup.UNITS_LENGTH,0);
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");
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");
185 //// Radial direction
186 l = new JLabel("Radial direction:");
187 l.setToolTipText("The radial direction from the rocket centerline");
190 m = new DoubleModel(component,"RadialDirection",UnitGroup.UNITS_ANGLE,0);
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");
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");
204 JButton button = new JButton("Reset");
205 button.setToolTipText("Reset the component to the rocket centerline");
206 button.addActionListener(new ActionListener() {
208 public void actionPerformed(ActionEvent e) {
209 ((RingComponent) component).setRadialDirection(0.0);
210 ((RingComponent) component).setRadialPosition(0.0);
213 panel.add(button,"spanx, right");