create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / gui / configdialog / NoseConeConfig.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.JSlider;
12 import javax.swing.JSpinner;
13
14 import net.miginfocom.swing.MigLayout;
15 import net.sf.openrocket.database.ComponentPresetDatabase;
16 import net.sf.openrocket.document.OpenRocketDocument;
17 import net.sf.openrocket.gui.SpinnerEditor;
18 import net.sf.openrocket.gui.adaptors.BooleanModel;
19 import net.sf.openrocket.gui.adaptors.DoubleModel;
20 import net.sf.openrocket.gui.adaptors.PresetModel;
21 import net.sf.openrocket.gui.components.BasicSlider;
22 import net.sf.openrocket.gui.components.DescriptionArea;
23 import net.sf.openrocket.gui.components.UnitSelector;
24 import net.sf.openrocket.l10n.Translator;
25 import net.sf.openrocket.material.Material;
26 import net.sf.openrocket.rocketcomponent.NoseCone;
27 import net.sf.openrocket.rocketcomponent.RocketComponent;
28 import net.sf.openrocket.rocketcomponent.Transition;
29 import net.sf.openrocket.startup.Application;
30 import net.sf.openrocket.unit.UnitGroup;
31
32 public class NoseConeConfig extends RocketComponentConfig {
33         
34         private JComboBox typeBox;
35         
36         private DescriptionArea description;
37         
38         private JLabel shapeLabel;
39         private JSpinner shapeSpinner;
40         private JSlider shapeSlider;
41         private static final Translator trans = Application.getTranslator();
42         
43         // Prepended to the description from NoseCone.DESCRIPTIONS
44         private static final String PREDESC = "<html>";
45         
46         public NoseConeConfig(OpenRocketDocument d, RocketComponent c) {
47                 super(d, c);
48                 
49                 DoubleModel m;
50                 JPanel panel = new JPanel(new MigLayout("", "[][65lp::][30lp::]"));
51                 
52                 ////  Shape selection
53                 //// Nose cone shape:
54                 panel.add(new JLabel(trans.get("NoseConeCfg.lbl.Noseconeshape")));
55                 
56                 Transition.Shape selected = ((NoseCone) component).getType();
57                 Transition.Shape[] typeList = Transition.Shape.values();
58                 
59                 typeBox = new JComboBox(typeList);
60                 typeBox.setEditable(false);
61                 typeBox.setSelectedItem(selected);
62                 typeBox.addActionListener(new ActionListener() {
63                         @Override
64                         public void actionPerformed(ActionEvent e) {
65                                 Transition.Shape s = (Transition.Shape) typeBox.getSelectedItem();
66                                 ((NoseCone) component).setType(s);
67                                 description.setText(PREDESC + s.getNoseConeDescription());
68                                 updateEnabled();
69                         }
70                 });
71                 panel.add(typeBox, "span, wrap rel");
72                 
73
74
75
76                 ////  Shape parameter
77                 ////  Shape parameter:
78                 shapeLabel = new JLabel(trans.get("NoseConeCfg.lbl.Shapeparam"));
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 para");
91                 
92                 updateEnabled();
93                 
94
95                 ////  Length
96                 //// Nose cone length:
97                 panel.add(new JLabel(trans.get("NoseConeCfg.lbl.Noseconelength")));
98                 
99                 m = new DoubleModel(component, "Length", UnitGroup.UNITS_LENGTH, 0);
100                 JSpinner 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.1, 0.7)), "w 100lp, wrap");
106                 
107                 ////  Diameter
108                 //// Base diameter:
109                 panel.add(new JLabel(trans.get("NoseConeCfg.lbl.Basediam")));
110                 
111                 m = new DoubleModel(component, "AftRadius", 2.0, UnitGroup.UNITS_LENGTH, 0); // Diameter = 2*Radius
112                 spin = new JSpinner(m.getSpinnerModel());
113                 spin.setEditor(new SpinnerEditor(spin));
114                 panel.add(spin, "growx");
115                 
116                 panel.add(new UnitSelector(m), "growx");
117                 panel.add(new BasicSlider(m.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap 0px");
118                 
119                 JCheckBox check = new JCheckBox(m.getAutomaticAction());
120                 //// Automatic
121                 check.setText(trans.get("NoseConeCfg.checkbox.Automatic"));
122                 panel.add(check, "skip, span 2, wrap");
123                 
124
125                 ////  Wall thickness:
126                 panel.add(new JLabel(trans.get("NoseConeCfg.lbl.Wallthickness")));
127                 
128                 m = new DoubleModel(component, "Thickness", UnitGroup.UNITS_LENGTH, 0);
129                 
130                 spin = new JSpinner(m.getSpinnerModel());
131                 spin.setEditor(new SpinnerEditor(spin));
132                 panel.add(spin, "growx");
133                 
134                 panel.add(new UnitSelector(m), "growx");
135                 panel.add(new BasicSlider(m.getSliderModel(0, 0.01)), "w 100lp, wrap 0px");
136                 
137
138                 check = new JCheckBox(new BooleanModel(component, "Filled"));
139                 //// Filled
140                 check.setText(trans.get("NoseConeCfg.checkbox.Filled"));
141                 panel.add(check, "skip, span 2, wrap");
142                 
143
144                 panel.add(new JLabel(""), "growy");
145                 
146
147
148                 ////  Description
149                 
150                 JPanel panel2 = new JPanel(new MigLayout("ins 0"));
151                 
152                 description = new DescriptionArea(5);
153                 description.setText(PREDESC + ((NoseCone) component).getType().getNoseConeDescription());
154                 panel2.add(description, "wmin 250lp, spanx, growx, wrap para");
155                 
156
157                 //// Material
158                 
159
160                 materialPanel(panel2, Material.Type.BULK);
161                 panel.add(panel2, "cell 4 0, gapleft paragraph, aligny 0%, spany");
162                 
163
164                 //// General and General properties
165                 tabbedPane.insertTab(trans.get("NoseConeCfg.tab.General"), null, panel,
166                                 trans.get("NoseConeCfg.tab.ttip.General"), 0);
167                 //// Shoulder and Shoulder properties
168                 tabbedPane.insertTab(trans.get("NoseConeCfg.tab.Shoulder"), null, shoulderTab(),
169                                 trans.get("NoseConeCfg.tab.ttip.Shoulder"), 1);
170                 tabbedPane.setSelectedIndex(0);
171         }
172         
173         
174         private void updateEnabled() {
175                 boolean e = ((NoseCone) component).getType().usesParameter();
176                 shapeLabel.setEnabled(e);
177                 shapeSpinner.setEnabled(e);
178                 shapeSlider.setEnabled(e);
179         }
180         
181
182 }