updates
[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.material.Material;
21 import net.sf.openrocket.rocketcomponent.RocketComponent;
22 import net.sf.openrocket.rocketcomponent.Transition;
23 import net.sf.openrocket.unit.UnitGroup;
24
25 public class TransitionConfig extends RocketComponentConfig {
26
27         private JComboBox typeBox;
28         //private JLabel description;
29         
30         private JLabel shapeLabel;
31         private JSpinner shapeSpinner;
32         private BasicSlider shapeSlider;
33         private DescriptionArea description;
34         
35
36         // Prepended to the description from Transition.DESCRIPTIONS
37         private static final String PREDESC = "<html><p style=\"font-size: x-small\">";
38         
39         
40         public TransitionConfig(RocketComponent c) {
41                 super(c);
42                 
43                 DoubleModel m;
44                 JSpinner spin;
45                 JCheckBox checkbox;
46
47                 JPanel panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]",""));
48                 
49
50
51                 ////  Shape selection
52                 
53                 panel.add(new JLabel("Transition shape:"));
54
55                 Transition.Shape selected = ((Transition)component).getType();
56                 Transition.Shape[] typeList = Transition.Shape.values();
57                 
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());
66                                 updateEnabled();
67                         }
68                 });
69                 panel.add(typeBox,"span, split 2");
70
71
72                 checkbox = new JCheckBox(new BooleanModel(component,"Clipped"));
73                 checkbox.setText("Clipped");
74                 panel.add(checkbox,"wrap");
75                 
76                 
77                 ////  Shape parameter
78                 shapeLabel = new JLabel("Shape parameter:");
79                 panel.add(shapeLabel);
80                 
81                 m = new DoubleModel(component,"ShapeParameter");
82                 
83                 shapeSpinner = new JSpinner(m.getSpinnerModel());
84                 shapeSpinner.setEditor(new SpinnerEditor(shapeSpinner));
85                 panel.add(shapeSpinner,"growx");
86                 
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");
91                 
92                 updateEnabled();
93                 
94                 
95                 ////  Length
96                 panel.add(new JLabel("Transition length:"));
97                 
98                 m = new DoubleModel(component,"Length",UnitGroup.UNITS_LENGTH,0);
99                 
100                 spin = new JSpinner(m.getSpinnerModel());
101                 spin.setEditor(new SpinnerEditor(spin));
102                 panel.add(spin,"growx");
103                 
104                 panel.add(new UnitSelector(m),"growx");
105                 panel.add(new BasicSlider(m.getSliderModel(0, 0.05, 0.3)),"w 100lp, wrap");
106                 
107                 
108                 //// Transition diameter 1
109                 panel.add(new JLabel("Fore diameter:"));
110
111                 DoubleModel od  = new DoubleModel(component,"ForeRadius",2,UnitGroup.UNITS_LENGTH,0);
112                 // Diameter = 2*Radius
113
114                 spin = new JSpinner(od.getSpinnerModel());
115                 spin.setEditor(new SpinnerEditor(spin));
116                 panel.add(spin,"growx");
117                 
118                 panel.add(new UnitSelector(od),"growx");
119                 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap 0px");
120
121                 checkbox = new JCheckBox(od.getAutomaticAction());
122                 checkbox.setText("Automatic");
123                 panel.add(checkbox,"skip, span 2, wrap");
124                 
125                 
126                 //// Transition diameter 2
127                 panel.add(new JLabel("Aft diameter:"));
128
129                 od  = new DoubleModel(component,"AftRadius",2,UnitGroup.UNITS_LENGTH,0);
130                 // Diameter = 2*Radius
131
132                 spin = new JSpinner(od.getSpinnerModel());
133                 spin.setEditor(new SpinnerEditor(spin));
134                 panel.add(spin,"growx");
135                 
136                 panel.add(new UnitSelector(od),"growx");
137                 panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)),"w 100lp, wrap 0px");
138
139                 checkbox = new JCheckBox(od.getAutomaticAction());
140                 checkbox.setText("Automatic");
141                 panel.add(checkbox,"skip, span 2, wrap");
142                 
143                 
144                 ////  Wall thickness
145                 panel.add(new JLabel("Wall thickness:"));
146                 
147                 m = new DoubleModel(component,"Thickness",UnitGroup.UNITS_LENGTH,0);
148                 
149                 spin = new JSpinner(m.getSpinnerModel());
150                 spin.setEditor(new SpinnerEditor(spin));
151                 panel.add(spin,"growx");
152                 
153                 panel.add(new UnitSelector(m),"growx");
154                 panel.add(new BasicSlider(m.getSliderModel(0,0.01)),"w 100lp, wrap 0px");
155                 
156                 
157                 checkbox = new JCheckBox(new BooleanModel(component,"Filled"));
158                 checkbox.setText("Filled");
159                 panel.add(checkbox,"skip, span 2, wrap");
160
161                 
162                 
163                 ////  Description
164                 
165                 JPanel panel2 = new JPanel(new MigLayout("ins 0"));
166                 
167                 description = new DescriptionArea(5);
168                 description.setText(PREDESC + ((Transition)component).getType().
169                                 getTransitionDescription());
170                 panel2.add(description, "wmin 250lp, spanx, growx, wrap para");
171                 
172
173                 //// Material
174                 
175                 
176                 materialPanel(panel2, Material.Type.BULK);
177                 panel.add(panel2, "cell 4 0, gapleft paragraph, aligny 0%, spany");
178                 
179
180                 tabbedPane.insertTab("General", null, panel, "General properties", 0);
181                 tabbedPane.insertTab("Shoulder", null, shoulderTab(), "Shoulder properties", 1);
182                 tabbedPane.setSelectedIndex(0);
183         }
184         
185         
186         
187         
188         
189         private void updateEnabled() {
190                 boolean e = ((Transition)component).getType().usesParameter();
191                 shapeLabel.setEnabled(e);
192                 shapeSpinner.setEnabled(e);
193                 shapeSlider.setEnabled(e);
194         }
195
196 }