513c49eb849bf01a032f78e2a01036f6347fddb7
[debian/openrocket] / 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.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;
26
27 public class TransitionConfig extends RocketComponentConfig {
28
29         private static final Translator trans = Application.getTranslator();
30         private JComboBox typeBox;
31         //private JLabel description;
32         
33         private JLabel shapeLabel;
34         private JSpinner shapeSpinner;
35         private BasicSlider shapeSlider;
36         private DescriptionArea description;
37         
38
39         // Prepended to the description from Transition.DESCRIPTIONS
40         private static final String PREDESC = "<html>";
41         
42         
43         public TransitionConfig(RocketComponent c) {
44                 super(c);
45                 
46                 DoubleModel m;
47                 JSpinner spin;
48                 JCheckBox checkbox;
49
50                 JPanel panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]",""));
51                 
52
53
54                 ////  Shape selection
55                 //// Transition shape:
56                 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Transitionshape")));
57
58                 Transition.Shape selected = ((Transition)component).getType();
59                 Transition.Shape[] typeList = Transition.Shape.values();
60                 
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());
69                                 updateEnabled();
70                         }
71                 });
72                 panel.add(typeBox,"span, split 2");
73
74                 //// Clipped
75                 checkbox = new JCheckBox(new BooleanModel(component,"Clipped"));
76                 //// Clipped
77                 checkbox.setText(trans.get("TransitionCfg.checkbox.Clipped"));
78                 panel.add(checkbox,"wrap");
79                 
80                 
81                 ////  Shape parameter:
82                 shapeLabel = new JLabel(trans.get("TransitionCfg.lbl.Shapeparam"));
83                 panel.add(shapeLabel);
84                 
85                 m = new DoubleModel(component,"ShapeParameter");
86                 
87                 shapeSpinner = new JSpinner(m.getSpinnerModel());
88                 shapeSpinner.setEditor(new SpinnerEditor(shapeSpinner));
89                 panel.add(shapeSpinner,"growx");
90                 
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");
95                 
96                 updateEnabled();
97                 
98                 
99                 ////  Length
100                 //// Transition length:
101                 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Transitionlength")));
102                 
103                 m = new DoubleModel(component,"Length",UnitGroup.UNITS_LENGTH,0);
104                 
105                 spin = new JSpinner(m.getSpinnerModel());
106                 spin.setEditor(new SpinnerEditor(spin));
107                 panel.add(spin,"growx");
108                 
109                 panel.add(new UnitSelector(m),"growx");
110                 panel.add(new BasicSlider(m.getSliderModel(0, 0.05, 0.3)),"w 100lp, wrap");
111                 
112                 
113                 //// Transition diameter 1
114                 //// Fore diameter:
115                 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Forediam")));
116
117                 DoubleModel od  = new DoubleModel(component,"ForeRadius",2,UnitGroup.UNITS_LENGTH,0);
118                 // Diameter = 2*Radius
119
120                 spin = new JSpinner(od.getSpinnerModel());
121                 spin.setEditor(new SpinnerEditor(spin));
122                 panel.add(spin,"growx");
123                 
124                 panel.add(new UnitSelector(od),"growx");
125                 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap 0px");
126
127                 checkbox = new JCheckBox(od.getAutomaticAction());
128                 //// Automatic
129                 checkbox.setText(trans.get("TransitionCfg.checkbox.Automatic"));
130                 panel.add(checkbox,"skip, span 2, wrap");
131                 
132                 
133                 //// Transition diameter 2
134                 //// Aft diameter:
135                 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Aftdiam")));
136
137                 od  = new DoubleModel(component,"AftRadius",2,UnitGroup.UNITS_LENGTH,0);
138                 // Diameter = 2*Radius
139
140                 spin = new JSpinner(od.getSpinnerModel());
141                 spin.setEditor(new SpinnerEditor(spin));
142                 panel.add(spin,"growx");
143                 
144                 panel.add(new UnitSelector(od),"growx");
145                 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap 0px");
146
147                 checkbox = new JCheckBox(od.getAutomaticAction());
148                 //// Automatic
149                 checkbox.setText(trans.get("TransitionCfg.checkbox.Automatic"));
150                 panel.add(checkbox,"skip, span 2, wrap");
151                 
152                 
153                 ////  Wall thickness:
154                 panel.add(new JLabel(trans.get("TransitionCfg.lbl.Wallthickness")));
155                 
156                 m = new DoubleModel(component,"Thickness",UnitGroup.UNITS_LENGTH,0);
157                 
158                 spin = new JSpinner(m.getSpinnerModel());
159                 spin.setEditor(new SpinnerEditor(spin));
160                 panel.add(spin,"growx");
161                 
162                 panel.add(new UnitSelector(m),"growx");
163                 panel.add(new BasicSlider(m.getSliderModel(0,0.01)),"w 100lp, wrap 0px");
164                 
165                 //// Filled
166                 checkbox = new JCheckBox(new BooleanModel(component,"Filled"));
167                 //// Filled
168                 checkbox.setText(trans.get("TransitionCfg.checkbox.Filled"));
169                 panel.add(checkbox,"skip, span 2, wrap");
170
171                 
172                 
173                 ////  Description
174                 
175                 JPanel panel2 = new JPanel(new MigLayout("ins 0"));
176                 
177                 description = new DescriptionArea(5);
178                 description.setText(PREDESC + ((Transition)component).getType().
179                                 getTransitionDescription());
180                 panel2.add(description, "wmin 250lp, spanx, growx, wrap para");
181                 
182
183                 //// Material
184                 
185                 
186                 materialPanel(panel2, Material.Type.BULK);
187                 panel.add(panel2, "cell 4 0, gapleft paragraph, aligny 0%, spany");
188                 
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);
196         }
197         
198         
199         
200         private void updateEnabled() {
201                 boolean e = ((Transition)component).getType().usesParameter();
202                 shapeLabel.setEnabled(e);
203                 shapeSpinner.setEnabled(e);
204                 shapeSlider.setEnabled(e);
205         }
206
207 }