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.SpinnerEditor;
15 import net.sf.openrocket.gui.adaptors.BooleanModel;
16 import net.sf.openrocket.gui.adaptors.DoubleModel;
17 import net.sf.openrocket.gui.components.BasicSlider;
18 import net.sf.openrocket.gui.components.DescriptionArea;
19 import net.sf.openrocket.gui.components.UnitSelector;
20 import net.sf.openrocket.l10n.Translator;
21 import net.sf.openrocket.material.Material;
22 import net.sf.openrocket.rocketcomponent.RocketComponent;
23 import net.sf.openrocket.rocketcomponent.Transition;
24 import net.sf.openrocket.startup.Application;
25 import net.sf.openrocket.unit.UnitGroup;
27 public class TransitionConfig extends RocketComponentConfig {
29 private static final Translator trans = Application.getTranslator();
30 private JComboBox typeBox;
31 //private JLabel description;
33 private JLabel shapeLabel;
34 private JSpinner shapeSpinner;
35 private BasicSlider shapeSlider;
36 private DescriptionArea description;
39 // Prepended to the description from Transition.DESCRIPTIONS
40 private static final String PREDESC = "<html>";
43 public TransitionConfig(RocketComponent c) {
50 JPanel panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]",""));
55 //// Transition shape:
56 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Transitionshape")));
58 Transition.Shape selected = ((Transition)component).getType();
59 Transition.Shape[] typeList = Transition.Shape.values();
61 typeBox = new JComboBox(typeList);
62 typeBox.setEditable(false);
63 typeBox.setSelectedItem(selected);
64 typeBox.addActionListener(new ActionListener() {
65 public void actionPerformed(ActionEvent e) {
66 Transition.Shape s = (Transition.Shape)typeBox.getSelectedItem();
67 ((Transition)component).setType(s);
68 description.setText(PREDESC + s.getTransitionDescription());
72 panel.add(typeBox,"span, split 2");
75 checkbox = new JCheckBox(new BooleanModel(component,"Clipped"));
77 checkbox.setText(trans.get("TransitionCfg.checkbox.Clipped"));
78 panel.add(checkbox,"wrap");
82 shapeLabel = new JLabel(trans.get("TransitionCfg.lbl.Shapeparam"));
83 panel.add(shapeLabel);
85 m = new DoubleModel(component,"ShapeParameter");
87 shapeSpinner = new JSpinner(m.getSpinnerModel());
88 shapeSpinner.setEditor(new SpinnerEditor(shapeSpinner));
89 panel.add(shapeSpinner,"growx");
91 DoubleModel min = new DoubleModel(component,"ShapeParameterMin");
92 DoubleModel max = new DoubleModel(component,"ShapeParameterMax");
93 shapeSlider = new BasicSlider(m.getSliderModel(min,max));
94 panel.add(shapeSlider,"skip, w 100lp, wrap");
100 //// Transition length:
101 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Transitionlength")));
103 m = new DoubleModel(component,"Length",UnitGroup.UNITS_LENGTH,0);
105 spin = new JSpinner(m.getSpinnerModel());
106 spin.setEditor(new SpinnerEditor(spin));
107 panel.add(spin,"growx");
109 panel.add(new UnitSelector(m),"growx");
110 panel.add(new BasicSlider(m.getSliderModel(0, 0.05, 0.3)),"w 100lp, wrap");
113 //// Transition diameter 1
115 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Forediam")));
117 DoubleModel od = new DoubleModel(component,"ForeRadius",2,UnitGroup.UNITS_LENGTH,0);
118 // Diameter = 2*Radius
120 spin = new JSpinner(od.getSpinnerModel());
121 spin.setEditor(new SpinnerEditor(spin));
122 panel.add(spin,"growx");
124 panel.add(new UnitSelector(od),"growx");
125 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap 0px");
127 checkbox = new JCheckBox(od.getAutomaticAction());
129 checkbox.setText(trans.get("TransitionCfg.checkbox.Automatic"));
130 panel.add(checkbox,"skip, span 2, wrap");
133 //// Transition diameter 2
135 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Aftdiam")));
137 od = new DoubleModel(component,"AftRadius",2,UnitGroup.UNITS_LENGTH,0);
138 // Diameter = 2*Radius
140 spin = new JSpinner(od.getSpinnerModel());
141 spin.setEditor(new SpinnerEditor(spin));
142 panel.add(spin,"growx");
144 panel.add(new UnitSelector(od),"growx");
145 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap 0px");
147 checkbox = new JCheckBox(od.getAutomaticAction());
149 checkbox.setText(trans.get("TransitionCfg.checkbox.Automatic"));
150 panel.add(checkbox,"skip, span 2, wrap");
154 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Wallthickness")));
156 m = new DoubleModel(component,"Thickness",UnitGroup.UNITS_LENGTH,0);
158 spin = new JSpinner(m.getSpinnerModel());
159 spin.setEditor(new SpinnerEditor(spin));
160 panel.add(spin,"growx");
162 panel.add(new UnitSelector(m),"growx");
163 panel.add(new BasicSlider(m.getSliderModel(0,0.01)),"w 100lp, wrap 0px");
166 checkbox = new JCheckBox(new BooleanModel(component,"Filled"));
168 checkbox.setText(trans.get("TransitionCfg.checkbox.Filled"));
169 panel.add(checkbox,"skip, span 2, wrap");
175 JPanel panel2 = new JPanel(new MigLayout("ins 0"));
177 description = new DescriptionArea(5);
178 description.setText(PREDESC + ((Transition)component).getType().
179 getTransitionDescription());
180 panel2.add(description, "wmin 250lp, spanx, growx, wrap para");
186 materialPanel(panel2, Material.Type.BULK);
187 panel.add(panel2, "cell 4 0, gapleft paragraph, aligny 0%, spany");
189 //// General and General properties
190 tabbedPane.insertTab(trans.get("TransitionCfg.tab.General"), null, panel,
191 trans.get("TransitionCfg.tab.Generalproperties"), 0);
192 //// Shoulder and Shoulder properties
193 tabbedPane.insertTab(trans.get("TransitionCfg.tab.Shoulder"), null, shoulderTab(),
194 trans.get("TransitionCfg.tab.Shoulderproperties"), 1);
195 tabbedPane.setSelectedIndex(0);
200 private void updateEnabled() {
201 boolean e = ((Transition)component).getType().usesParameter();
202 shapeLabel.setEnabled(e);
203 shapeSpinner.setEnabled(e);
204 shapeSlider.setEnabled(e);