1 package net.sf.openrocket.gui.configdialog;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
7 import javax.swing.JCheckBox;
8 import javax.swing.JComboBox;
9 import javax.swing.JLabel;
10 import javax.swing.JPanel;
11 import javax.swing.JSpinner;
13 import net.miginfocom.swing.MigLayout;
14 import net.sf.openrocket.gui.BasicSlider;
15 import net.sf.openrocket.gui.DescriptionArea;
16 import net.sf.openrocket.gui.SpinnerEditor;
17 import net.sf.openrocket.gui.UnitSelector;
18 import net.sf.openrocket.gui.adaptors.BooleanModel;
19 import net.sf.openrocket.gui.adaptors.DoubleModel;
20 import net.sf.openrocket.material.Material;
21 import net.sf.openrocket.rocketcomponent.RocketComponent;
22 import net.sf.openrocket.rocketcomponent.Transition;
23 import net.sf.openrocket.unit.UnitGroup;
25 public class TransitionConfig extends RocketComponentConfig {
27 private JComboBox typeBox;
28 //private JLabel description;
30 private JLabel shapeLabel;
31 private JSpinner shapeSpinner;
32 private BasicSlider shapeSlider;
33 private DescriptionArea description;
36 // Prepended to the description from Transition.DESCRIPTIONS
37 private static final String PREDESC = "<html><p style=\"font-size: x-small\">";
40 public TransitionConfig(RocketComponent c) {
47 JPanel panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]",""));
53 panel.add(new JLabel("Transition shape:"));
55 Transition.Shape selected = ((Transition)component).getType();
56 Transition.Shape[] typeList = Transition.Shape.values();
58 typeBox = new JComboBox(typeList);
59 typeBox.setEditable(false);
60 typeBox.setSelectedItem(selected);
61 typeBox.addActionListener(new ActionListener() {
62 public void actionPerformed(ActionEvent e) {
63 Transition.Shape s = (Transition.Shape)typeBox.getSelectedItem();
64 ((Transition)component).setType(s);
65 description.setText(PREDESC + s.getTransitionDescription());
69 panel.add(typeBox,"span, split 2");
72 checkbox = new JCheckBox(new BooleanModel(component,"Clipped"));
73 checkbox.setText("Clipped");
74 panel.add(checkbox,"wrap");
78 shapeLabel = new JLabel("Shape parameter:");
79 panel.add(shapeLabel);
81 m = new DoubleModel(component,"ShapeParameter");
83 shapeSpinner = new JSpinner(m.getSpinnerModel());
84 shapeSpinner.setEditor(new SpinnerEditor(shapeSpinner));
85 panel.add(shapeSpinner,"growx");
87 DoubleModel min = new DoubleModel(component,"ShapeParameterMin");
88 DoubleModel max = new DoubleModel(component,"ShapeParameterMax");
89 shapeSlider = new BasicSlider(m.getSliderModel(min,max));
90 panel.add(shapeSlider,"skip, w 100lp, wrap");
96 panel.add(new JLabel("Transition length:"));
98 m = new DoubleModel(component,"Length",UnitGroup.UNITS_LENGTH,0);
100 spin = new JSpinner(m.getSpinnerModel());
101 spin.setEditor(new SpinnerEditor(spin));
102 panel.add(spin,"growx");
104 panel.add(new UnitSelector(m),"growx");
105 panel.add(new BasicSlider(m.getSliderModel(0, 0.05, 0.3)),"w 100lp, wrap");
108 //// Transition diameter 1
109 panel.add(new JLabel("Fore diameter:"));
111 DoubleModel od = new DoubleModel(component,"ForeRadius",2,UnitGroup.UNITS_LENGTH,0);
112 // Diameter = 2*Radius
114 spin = new JSpinner(od.getSpinnerModel());
115 spin.setEditor(new SpinnerEditor(spin));
116 panel.add(spin,"growx");
118 panel.add(new UnitSelector(od),"growx");
119 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap 0px");
121 checkbox = new JCheckBox(od.getAutomaticAction());
122 checkbox.setText("Automatic");
123 panel.add(checkbox,"skip, span 2, wrap");
126 //// Transition diameter 2
127 panel.add(new JLabel("Aft diameter:"));
129 od = new DoubleModel(component,"AftRadius",2,UnitGroup.UNITS_LENGTH,0);
130 // Diameter = 2*Radius
132 spin = new JSpinner(od.getSpinnerModel());
133 spin.setEditor(new SpinnerEditor(spin));
134 panel.add(spin,"growx");
136 panel.add(new UnitSelector(od),"growx");
137 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap 0px");
139 checkbox = new JCheckBox(od.getAutomaticAction());
140 checkbox.setText("Automatic");
141 panel.add(checkbox,"skip, span 2, wrap");
145 panel.add(new JLabel("Wall thickness:"));
147 m = new DoubleModel(component,"Thickness",UnitGroup.UNITS_LENGTH,0);
149 spin = new JSpinner(m.getSpinnerModel());
150 spin.setEditor(new SpinnerEditor(spin));
151 panel.add(spin,"growx");
153 panel.add(new UnitSelector(m),"growx");
154 panel.add(new BasicSlider(m.getSliderModel(0,0.01)),"w 100lp, wrap 0px");
157 checkbox = new JCheckBox(new BooleanModel(component,"Filled"));
158 checkbox.setText("Filled");
159 panel.add(checkbox,"skip, span 2, wrap");
165 JPanel panel2 = new JPanel(new MigLayout("ins 0"));
167 description = new DescriptionArea(5);
168 description.setText(PREDESC + ((Transition)component).getType().
169 getTransitionDescription());
170 panel2.add(description, "wmin 250lp, spanx, growx, wrap para");
176 materialPanel(panel2, Material.Type.BULK);
177 panel.add(panel2, "cell 4 0, gapleft paragraph, aligny 0%, spany");
180 tabbedPane.insertTab("General", null, panel, "General properties", 0);
181 tabbedPane.insertTab("Shoulder", null, shoulderTab(), "Shoulder properties", 1);
182 tabbedPane.setSelectedIndex(0);
189 private void updateEnabled() {
190 boolean e = ((Transition)component).getType().usesParameter();
191 shapeLabel.setEnabled(e);
192 shapeSpinner.setEnabled(e);
193 shapeSlider.setEnabled(e);