create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / gui / configdialog / TransitionConfig.java
1 package net.sf.openrocket.gui.configdialog;
2
3
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6
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;
12
13 import net.miginfocom.swing.MigLayout;
14 import net.sf.openrocket.document.OpenRocketDocument;
15 import net.sf.openrocket.gui.SpinnerEditor;
16 import net.sf.openrocket.gui.adaptors.BooleanModel;
17 import net.sf.openrocket.gui.adaptors.DoubleModel;
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.RocketComponent;
24 import net.sf.openrocket.rocketcomponent.Transition;
25 import net.sf.openrocket.startup.Application;
26 import net.sf.openrocket.unit.UnitGroup;
27
28 public class TransitionConfig extends RocketComponentConfig {
29         
30         private static final Translator trans = Application.getTranslator();
31         private JComboBox typeBox;
32         //private JLabel description;
33         
34         private JLabel shapeLabel;
35         private JSpinner shapeSpinner;
36         private BasicSlider shapeSlider;
37         private DescriptionArea description;
38         
39
40         // Prepended to the description from Transition.DESCRIPTIONS
41         private static final String PREDESC = "<html>";
42         
43         
44         public TransitionConfig(OpenRocketDocument d, RocketComponent c) {
45                 super(d, c);
46                 
47                 DoubleModel m;
48                 JSpinner spin;
49                 JCheckBox checkbox;
50                 
51                 JPanel panel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::]", ""));
52                 
53
54
55                 ////  Shape selection
56                 //// Transition shape:
57                 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Transitionshape")));
58                 
59                 Transition.Shape selected = ((Transition) component).getType();
60                 Transition.Shape[] typeList = Transition.Shape.values();
61                 
62                 typeBox = new JComboBox(typeList);
63                 typeBox.setEditable(false);
64                 typeBox.setSelectedItem(selected);
65                 typeBox.addActionListener(new ActionListener() {
66                         @Override
67                         public void actionPerformed(ActionEvent e) {
68                                 Transition.Shape s = (Transition.Shape) typeBox.getSelectedItem();
69                                 ((Transition) component).setType(s);
70                                 description.setText(PREDESC + s.getTransitionDescription());
71                                 updateEnabled();
72                         }
73                 });
74                 panel.add(typeBox, "span, split 2");
75                 
76                 //// Clipped
77                 checkbox = new JCheckBox(new BooleanModel(component, "Clipped"));
78                 //// Clipped
79                 checkbox.setText(trans.get("TransitionCfg.checkbox.Clipped"));
80                 panel.add(checkbox, "wrap");
81                 
82
83                 ////  Shape parameter:
84                 shapeLabel = new JLabel(trans.get("TransitionCfg.lbl.Shapeparam"));
85                 panel.add(shapeLabel);
86                 
87                 m = new DoubleModel(component, "ShapeParameter");
88                 
89                 shapeSpinner = new JSpinner(m.getSpinnerModel());
90                 shapeSpinner.setEditor(new SpinnerEditor(shapeSpinner));
91                 panel.add(shapeSpinner, "growx");
92                 
93                 DoubleModel min = new DoubleModel(component, "ShapeParameterMin");
94                 DoubleModel max = new DoubleModel(component, "ShapeParameterMax");
95                 shapeSlider = new BasicSlider(m.getSliderModel(min, max));
96                 panel.add(shapeSlider, "skip, w 100lp, wrap");
97                 
98                 updateEnabled();
99                 
100
101                 ////  Length
102                 //// Transition length:
103                 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Transitionlength")));
104                 
105                 m = new DoubleModel(component, "Length", UnitGroup.UNITS_LENGTH, 0);
106                 
107                 spin = new JSpinner(m.getSpinnerModel());
108                 spin.setEditor(new SpinnerEditor(spin));
109                 panel.add(spin, "growx");
110                 
111                 panel.add(new UnitSelector(m), "growx");
112                 panel.add(new BasicSlider(m.getSliderModel(0, 0.05, 0.3)), "w 100lp, wrap");
113                 
114
115                 //// Transition diameter 1
116                 //// Fore diameter:
117                 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Forediam")));
118                 
119                 DoubleModel od = new DoubleModel(component, "ForeRadius", 2, UnitGroup.UNITS_LENGTH, 0);
120                 // Diameter = 2*Radius
121                 
122                 spin = new JSpinner(od.getSpinnerModel());
123                 spin.setEditor(new SpinnerEditor(spin));
124                 panel.add(spin, "growx");
125                 
126                 panel.add(new UnitSelector(od), "growx");
127                 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap 0px");
128                 
129                 checkbox = new JCheckBox(od.getAutomaticAction());
130                 //// Automatic
131                 checkbox.setText(trans.get("TransitionCfg.checkbox.Automatic"));
132                 panel.add(checkbox, "skip, span 2, wrap");
133                 
134
135                 //// Transition diameter 2
136                 //// Aft diameter:
137                 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Aftdiam")));
138                 
139                 od = new DoubleModel(component, "AftRadius", 2, UnitGroup.UNITS_LENGTH, 0);
140                 // Diameter = 2*Radius
141                 
142                 spin = new JSpinner(od.getSpinnerModel());
143                 spin.setEditor(new SpinnerEditor(spin));
144                 panel.add(spin, "growx");
145                 
146                 panel.add(new UnitSelector(od), "growx");
147                 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap 0px");
148                 
149                 checkbox = new JCheckBox(od.getAutomaticAction());
150                 //// Automatic
151                 checkbox.setText(trans.get("TransitionCfg.checkbox.Automatic"));
152                 panel.add(checkbox, "skip, span 2, wrap");
153                 
154
155                 ////  Wall thickness:
156                 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Wallthickness")));
157                 
158                 m = new DoubleModel(component, "Thickness", UnitGroup.UNITS_LENGTH, 0);
159                 
160                 spin = new JSpinner(m.getSpinnerModel());
161                 spin.setEditor(new SpinnerEditor(spin));
162                 panel.add(spin, "growx");
163                 
164                 panel.add(new UnitSelector(m), "growx");
165                 panel.add(new BasicSlider(m.getSliderModel(0, 0.01)), "w 100lp, wrap 0px");
166                 
167                 //// Filled
168                 checkbox = new JCheckBox(new BooleanModel(component, "Filled"));
169                 //// Filled
170                 checkbox.setText(trans.get("TransitionCfg.checkbox.Filled"));
171                 panel.add(checkbox, "skip, span 2, wrap");
172                 
173
174
175                 ////  Description
176                 
177                 JPanel panel2 = new JPanel(new MigLayout("ins 0"));
178                 
179                 description = new DescriptionArea(5);
180                 description.setText(PREDESC + ((Transition) component).getType().
181                                 getTransitionDescription());
182                 panel2.add(description, "wmin 250lp, spanx, growx, wrap para");
183                 
184
185                 //// Material
186                 
187
188                 materialPanel(panel2, Material.Type.BULK);
189                 panel.add(panel2, "cell 4 0, gapleft paragraph, aligny 0%, spany");
190                 
191                 //// General and General properties
192                 tabbedPane.insertTab(trans.get("TransitionCfg.tab.General"), null, panel,
193                                 trans.get("TransitionCfg.tab.Generalproperties"), 0);
194                 //// Shoulder and Shoulder properties
195                 tabbedPane.insertTab(trans.get("TransitionCfg.tab.Shoulder"), null, shoulderTab(),
196                                 trans.get("TransitionCfg.tab.Shoulderproperties"), 1);
197                 tabbedPane.setSelectedIndex(0);
198         }
199         
200         
201
202         private void updateEnabled() {
203                 boolean e = ((Transition) component).getType().usesParameter();
204                 shapeLabel.setEnabled(e);
205                 shapeSpinner.setEnabled(e);
206                 shapeSlider.setEnabled(e);
207         }
208         
209 }