3779f5483876eda4cef9309dc882146f908b6cb6
[debian/openrocket] / src / net / sf / openrocket / gui / configdialog / RocketComponentConfig.java
1 package net.sf.openrocket.gui.configdialog;
2
3
4 import java.awt.Color;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.awt.event.FocusEvent;
8 import java.awt.event.FocusListener;
9 import java.util.ArrayList;
10 import java.util.Iterator;
11 import java.util.List;
12
13 import javax.swing.BorderFactory;
14 import javax.swing.JButton;
15 import javax.swing.JCheckBox;
16 import javax.swing.JColorChooser;
17 import javax.swing.JComboBox;
18 import javax.swing.JLabel;
19 import javax.swing.JPanel;
20 import javax.swing.JScrollPane;
21 import javax.swing.JSpinner;
22 import javax.swing.JTabbedPane;
23 import javax.swing.JTextArea;
24 import javax.swing.JTextField;
25
26 import net.miginfocom.swing.MigLayout;
27 import net.sf.openrocket.gui.SpinnerEditor;
28 import net.sf.openrocket.gui.adaptors.BooleanModel;
29 import net.sf.openrocket.gui.adaptors.DoubleModel;
30 import net.sf.openrocket.gui.adaptors.EnumModel;
31 import net.sf.openrocket.gui.adaptors.MaterialModel;
32 import net.sf.openrocket.gui.components.BasicSlider;
33 import net.sf.openrocket.gui.components.ColorIcon;
34 import net.sf.openrocket.gui.components.StyledLabel;
35 import net.sf.openrocket.gui.components.StyledLabel.Style;
36 import net.sf.openrocket.gui.components.UnitSelector;
37 import net.sf.openrocket.l10n.Translator;
38 import net.sf.openrocket.material.Material;
39 import net.sf.openrocket.rocketcomponent.ComponentAssembly;
40 import net.sf.openrocket.rocketcomponent.ExternalComponent;
41 import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
42 import net.sf.openrocket.rocketcomponent.NoseCone;
43 import net.sf.openrocket.rocketcomponent.Rocket;
44 import net.sf.openrocket.rocketcomponent.RocketComponent;
45 import net.sf.openrocket.startup.Application;
46 import net.sf.openrocket.unit.UnitGroup;
47 import net.sf.openrocket.util.GUIUtil;
48 import net.sf.openrocket.util.Invalidatable;
49 import net.sf.openrocket.util.LineStyle;
50 import net.sf.openrocket.util.Prefs;
51
52 public class RocketComponentConfig extends JPanel {
53         
54         private static final Translator trans = Application.getTranslator();
55         
56         protected final RocketComponent component;
57         protected final JTabbedPane tabbedPane;
58         
59         private final List<Invalidatable> invalidatables = new ArrayList<Invalidatable>();
60         
61
62         protected final JTextField componentNameField;
63         protected JTextArea commentTextArea;
64         private final TextFieldListener textFieldListener;
65         private JButton colorButton;
66         private JCheckBox colorDefault;
67         private JPanel buttonPanel;
68         
69         private JLabel massLabel;
70         
71         
72         public RocketComponentConfig(RocketComponent component) {
73                 setLayout(new MigLayout("fill", "[grow, fill]"));
74                 this.component = component;
75                 
76                 //// Component name:
77                 JLabel label = new JLabel(trans.get("RocketCompCfg.lbl.Componentname"));
78                 //// The component name.
79                 label.setToolTipText(trans.get("RocketCompCfg.ttip.Thecomponentname"));
80                 this.add(label, "split, gapright 10");
81                 
82                 componentNameField = new JTextField(15);
83                 textFieldListener = new TextFieldListener();
84                 componentNameField.addActionListener(textFieldListener);
85                 componentNameField.addFocusListener(textFieldListener);
86                 //// The component name.
87                 componentNameField.setToolTipText(trans.get("RocketCompCfg.ttip.Thecomponentname"));
88                 this.add(componentNameField, "growx, growy 0, wrap");
89                 
90
91                 tabbedPane = new JTabbedPane();
92                 this.add(tabbedPane, "growx, growy 1, wrap");
93                 
94                 //// Override and Mass and CG override options
95                 tabbedPane.addTab(trans.get("RocketCompCfg.tab.Override"), null, overrideTab(), 
96                                 trans.get("RocketCompCfg.tab.MassandCGoverride"));
97                 if (component.isMassive())
98                         //// Figure and Figure style options
99                         tabbedPane.addTab(trans.get("RocketCompCfg.tab.Figure"), null, figureTab(), 
100                                         trans.get("RocketCompCfg.tab.Figstyleopt"));
101                 //// Comment and Specify a comment for the component
102                 tabbedPane.addTab(trans.get("RocketCompCfg.tab.Comment"), null, commentTab(), 
103                                 trans.get("RocketCompCfg.tab.Specifyacomment"));
104                 
105                 addButtons();
106                 
107                 updateFields();
108         }
109         
110         
111         protected void addButtons(JButton... buttons) {
112                 if (buttonPanel != null) {
113                         this.remove(buttonPanel);
114                 }
115                 
116                 buttonPanel = new JPanel(new MigLayout("fill, ins 0"));
117                 
118                 //// Mass:
119                 massLabel = new StyledLabel(trans.get("RocketCompCfg.lbl.Mass") + " ", -1);
120                 buttonPanel.add(massLabel, "growx");
121                 
122                 for (JButton b : buttons) {
123                         buttonPanel.add(b, "right, gap para");
124                 }
125                 
126                 //// Close button
127                 JButton closeButton = new JButton(trans.get("dlg.but.close"));
128                 closeButton.addActionListener(new ActionListener() {
129                         @Override
130                         public void actionPerformed(ActionEvent arg0) {
131                                 ComponentConfigDialog.hideDialog();
132                         }
133                 });
134                 buttonPanel.add(closeButton, "right, gap 30lp");
135                 
136                 updateFields();
137                 
138                 this.add(buttonPanel, "spanx, growx");
139         }
140         
141         
142         /**
143          * Called when a change occurs, so that the fields can be updated if necessary.
144          * When overriding this method, the supermethod must always be called.
145          */
146         public void updateFields() {
147                 // Component name
148                 componentNameField.setText(component.getName());
149                 
150                 // Component color and "Use default color" checkbox
151                 if (colorButton != null && colorDefault != null) {
152                         colorButton.setIcon(new ColorIcon(getColor()));
153                         
154                         if ((component.getColor() == null) != colorDefault.isSelected())
155                                 colorDefault.setSelected(component.getColor() == null);
156                 }
157                 
158                 // Mass label
159                 if (component.isMassive()) {
160                         //// Component mass:
161                         String text = trans.get("RocketCompCfg.lbl.Componentmass") + " ";
162                         text += UnitGroup.UNITS_MASS.getDefaultUnit().toStringUnit(
163                                         component.getComponentMass());
164                         
165                         String overridetext = null;
166                         if (component.isMassOverridden()) {
167                                 //// (overridden to 
168                                 overridetext = trans.get("RocketCompCfg.lbl.overriddento")+" " + UnitGroup.UNITS_MASS.getDefaultUnit().
169                                                 toStringUnit(component.getOverrideMass()) + ")";
170                         }
171                         
172                         for (RocketComponent c = component.getParent(); c != null; c = c.getParent()) {
173                                 if (c.isMassOverridden() && c.getOverrideSubcomponents()) {
174                                         ///// (overridden by
175                                         overridetext = trans.get("RocketCompCfg.lbl.overriddenby")+" " + c.getName() + ")";
176                                 }
177                         }
178                         
179                         if (overridetext != null)
180                                 text = text + " " + overridetext;
181                         
182                         massLabel.setText(text);
183                 } else {
184                         massLabel.setText("");
185                 }
186         }
187         
188         
189         protected JPanel materialPanel(JPanel panel, Material.Type type) {
190                 ////Component material: and Component finish:
191                 return materialPanel(panel, type, trans.get("RocketCompCfg.lbl.Componentmaterial"),
192                                 trans.get("RocketCompCfg.lbl.Componentfinish"));
193         }
194         
195         protected JPanel materialPanel(JPanel panel, Material.Type type,
196                         String materialString, String finishString) {
197                 JLabel label = new JLabel(materialString);
198                 //// The component material affects the weight of the component.
199                 label.setToolTipText(trans.get("RocketCompCfg.lbl.ttip.componentmaterialaffects"));
200                 panel.add(label, "spanx 4, wrap rel");
201                 
202                 JComboBox combo = new JComboBox(new MaterialModel(panel, component, type));
203                 //// The component material affects the weight of the component.
204                 combo.setToolTipText(trans.get("RocketCompCfg.combo.ttip.componentmaterialaffects"));
205                 panel.add(combo, "spanx 4, growx, wrap paragraph");
206                 
207
208                 if (component instanceof ExternalComponent) {
209                         label = new JLabel(finishString);
210                         ////<html>The component finish affects the aerodynamic drag of the component.<br>
211                         String tip = trans.get("RocketCompCfg.lbl.longA1")
212                                         //// The value indicated is the average roughness height of the surface.
213                                         + trans.get("RocketCompCfg.lbl.longA2");
214                         label.setToolTipText(tip);
215                         panel.add(label, "spanx 4, wmin 220lp, wrap rel");
216                         
217                         combo = new JComboBox(new EnumModel<ExternalComponent.Finish>(component, "Finish"));
218                         combo.setToolTipText(tip);
219                         panel.add(combo, "spanx 4, growx, split");
220                         
221                         //// Set for all
222                         JButton button = new JButton(trans.get("RocketCompCfg.but.Setforall"));
223                         //// Set this finish for all components of the rocket.
224                         button.setToolTipText(trans.get("RocketCompCfg.but.ttip.Setforall"));
225                         button.addActionListener(new ActionListener() {
226                                 @Override
227                                 public void actionPerformed(ActionEvent e) {
228                                         Finish f = ((ExternalComponent) component).getFinish();
229                                         Rocket rocket = component.getRocket();
230                                         try {
231                                                 rocket.freeze();
232                                                 // Store previous undo description
233                                                 String desc = ComponentConfigDialog.getUndoDescription();
234                                                 ComponentConfigDialog.addUndoPosition("Set rocket finish");
235                                                 // Do changes
236                                                 Iterator<RocketComponent> iter = rocket.iterator();
237                                                 while (iter.hasNext()) {
238                                                         RocketComponent c = iter.next();
239                                                         if (c instanceof ExternalComponent) {
240                                                                 ((ExternalComponent) c).setFinish(f);
241                                                         }
242                                                 }
243                                                 // Restore undo description
244                                                 ComponentConfigDialog.addUndoPosition(desc);
245                                         } finally {
246                                                 rocket.thaw();
247                                         }
248                                 }
249                         });
250                         panel.add(button, "wrap paragraph");
251                 }
252                 
253                 return panel;
254         }
255         
256         
257         private JPanel overrideTab() {
258                 JPanel panel = new JPanel(new MigLayout("align 50% 20%, fillx, gap rel unrel",
259                                 "[][65lp::][30lp::][]", ""));
260                 //// Override the mass or center of gravity of the
261                 panel.add(new StyledLabel(trans.get("RocketCompCfg.lbl.Overridemassorcenter") + " " +
262                                 component.getComponentName() + ":", Style.BOLD), "spanx, wrap 20lp");
263                 
264                 JCheckBox check;
265                 BooleanModel bm;
266                 UnitSelector us;
267                 BasicSlider bs;
268                 
269                 ////  Mass
270                 bm = new BooleanModel(component, "MassOverridden");
271                 check = new JCheckBox(bm);
272                 //// Override mass:
273                 check.setText(trans.get("RocketCompCfg.checkbox.Overridemass"));
274                 panel.add(check, "growx 1, gapright 20lp");
275                 
276                 DoubleModel m = new DoubleModel(component, "OverrideMass", UnitGroup.UNITS_MASS, 0);
277                 
278                 JSpinner spin = new JSpinner(m.getSpinnerModel());
279                 spin.setEditor(new SpinnerEditor(spin));
280                 bm.addEnableComponent(spin, true);
281                 panel.add(spin, "growx 1");
282                 
283                 us = new UnitSelector(m);
284                 bm.addEnableComponent(us, true);
285                 panel.add(us, "growx 1");
286                 
287                 bs = new BasicSlider(m.getSliderModel(0, 0.03, 1.0));
288                 bm.addEnableComponent(bs);
289                 panel.add(bs, "growx 5, w 100lp, wrap");
290                 
291
292                 ////  CG override
293                 bm = new BooleanModel(component, "CGOverridden");
294                 check = new JCheckBox(bm);
295                 //// Override center of gravity:"
296                 check.setText(trans.get("RocketCompCfg.checkbox.Overridecenterofgrav"));
297                 panel.add(check, "growx 1, gapright 20lp");
298                 
299                 m = new DoubleModel(component, "OverrideCGX", UnitGroup.UNITS_LENGTH, 0);
300                 // Calculate suitable length for slider
301                 DoubleModel length;
302                 if (component instanceof ComponentAssembly) {
303                         double l = 0;
304                         
305                         Iterator<RocketComponent> iterator = component.iterator(false);
306                         while (iterator.hasNext()) {
307                                 RocketComponent c = iterator.next();
308                                 if (c.getRelativePosition() == RocketComponent.Position.AFTER)
309                                         l += c.getLength();
310                         }
311                         length = new DoubleModel(l);
312                 } else {
313                         length = new DoubleModel(component, "Length", UnitGroup.UNITS_LENGTH, 0);
314                 }
315                 
316                 spin = new JSpinner(m.getSpinnerModel());
317                 spin.setEditor(new SpinnerEditor(spin));
318                 bm.addEnableComponent(spin, true);
319                 panel.add(spin, "growx 1");
320                 
321                 us = new UnitSelector(m);
322                 bm.addEnableComponent(us, true);
323                 panel.add(us, "growx 1");
324                 
325                 bs = new BasicSlider(m.getSliderModel(new DoubleModel(0), length));
326                 bm.addEnableComponent(bs);
327                 panel.add(bs, "growx 5, w 100lp, wrap 35lp");
328                 
329
330                 // Override subcomponents checkbox
331                 bm = new BooleanModel(component, "OverrideSubcomponents");
332                 check = new JCheckBox(bm);
333                 //// Override mass and CG of all subcomponents
334                 check.setText(trans.get("RocketCompCfg.checkbox.OverridemassandCG"));
335                 panel.add(check, "gap para, spanx, wrap para");
336                 
337                 //// <html>The overridden mass does not include motors.<br>
338                 panel.add(new StyledLabel(trans.get("RocketCompCfg.lbl.longB1") +
339                                 //// The center of gravity is measured from the front end of the
340                                 trans.get("RocketCompCfg.lbl.longB2") +" " +
341                                 component.getComponentName().toLowerCase() + ".", -1),
342                                 "spanx, wrap, gap para, height 0::30lp");
343                 
344                 return panel;
345         }
346         
347         
348         private JPanel commentTab() {
349                 JPanel panel = new JPanel(new MigLayout("fill"));
350                 
351                 //// Comments on the
352                 panel.add(new StyledLabel(trans.get("RocketCompCfg.lbl.Commentsonthe") +" " + component.getComponentName() + ":",
353                                 Style.BOLD), "wrap");
354                 
355                 // TODO: LOW:  Changes in comment from other sources not reflected in component
356                 commentTextArea = new JTextArea(component.getComment());
357                 commentTextArea.setLineWrap(true);
358                 commentTextArea.setWrapStyleWord(true);
359                 commentTextArea.setEditable(true);
360                 GUIUtil.setTabToFocusing(commentTextArea);
361                 commentTextArea.addFocusListener(textFieldListener);
362                 
363                 panel.add(new JScrollPane(commentTextArea), "width 10px, height 10px, growx, growy");
364                 
365                 return panel;
366         }
367         
368         
369
370         private JPanel figureTab() {
371                 JPanel panel = new JPanel(new MigLayout("align 20% 20%"));
372                 
373                 //// Figure style:
374                 panel.add(new StyledLabel(trans.get("RocketCompCfg.lbl.Figurestyle"), Style.BOLD), "wrap para");
375                 
376                 //// Component color:
377                 panel.add(new JLabel(trans.get("RocketCompCfg.lbl.Componentcolor")), "gapleft para, gapright 10lp");
378                 
379                 colorButton = new JButton(new ColorIcon(getColor()));
380                 colorButton.addActionListener(new ActionListener() {
381                         @Override
382                         public void actionPerformed(ActionEvent e) {
383                                 Color c = component.getColor();
384                                 if (c == null) {
385                                         c = Prefs.getDefaultColor(component.getClass());
386                                 }
387                                 
388                                 //// Choose color
389                                 c = JColorChooser.showDialog(tabbedPane, trans.get("RocketCompCfg.lbl.Choosecolor"), c);
390                                 if (c != null) {
391                                         component.setColor(c);
392                                 }
393                         }
394                 });
395                 panel.add(colorButton, "gapright 10lp");
396                 
397                 //// Use default color
398                 colorDefault = new JCheckBox(trans.get("RocketCompCfg.checkbox.Usedefaultcolor"));
399                 if (component.getColor() == null)
400                         colorDefault.setSelected(true);
401                 colorDefault.addActionListener(new ActionListener() {
402                         @Override
403                         public void actionPerformed(ActionEvent e) {
404                                 if (colorDefault.isSelected())
405                                         component.setColor(null);
406                                 else
407                                         component.setColor(Prefs.getDefaultColor(component.getClass()));
408                         }
409                 });
410                 panel.add(colorDefault, "wrap para");
411                 
412                 //// Component line style:
413                 panel.add(new JLabel(trans.get("RocketCompCfg.lbl.Complinestyle")), "gapleft para, gapright 10lp");
414                 
415                 LineStyle[] list = new LineStyle[LineStyle.values().length + 1];
416                 System.arraycopy(LineStyle.values(), 0, list, 1, LineStyle.values().length);
417                 
418                 JComboBox combo = new JComboBox(new EnumModel<LineStyle>(component, "LineStyle",
419                                 //// Default style
420                                 list, trans.get("LineStyle.Defaultstyle")));
421                 panel.add(combo, "spanx 2, growx, wrap 50lp");
422                 
423                 //// Save as default style
424                 JButton button = new JButton(trans.get("RocketCompCfg.but.Saveasdefstyle"));
425                 button.addActionListener(new ActionListener() {
426                         @Override
427                         public void actionPerformed(ActionEvent e) {
428                                 if (component.getColor() != null) {
429                                         Prefs.setDefaultColor(component.getClass(), component.getColor());
430                                         component.setColor(null);
431                                 }
432                                 if (component.getLineStyle() != null) {
433                                         Prefs.setDefaultLineStyle(component.getClass(), component.getLineStyle());
434                                         component.setLineStyle(null);
435                                 }
436                         }
437                 });
438                 panel.add(button, "gapleft para, spanx 3, growx, wrap");
439                 
440                 return panel;
441         }
442         
443         
444         private Color getColor() {
445                 Color c = component.getColor();
446                 if (c == null) {
447                         c = Prefs.getDefaultColor(component.getClass());
448                 }
449                 return c;
450         }
451         
452         
453
454         protected JPanel shoulderTab() {
455                 JPanel panel = new JPanel(new MigLayout("fill"));
456                 JPanel sub;
457                 DoubleModel m, m2;
458                 DoubleModel m0 = new DoubleModel(0);
459                 BooleanModel bm;
460                 JCheckBox check;
461                 JSpinner spin;
462                 
463
464                 ////  Fore shoulder, not for NoseCone
465                 
466                 if (!(component instanceof NoseCone)) {
467                         sub = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::]", ""));
468                         
469                         //// Fore shoulder
470                         sub.setBorder(BorderFactory.createTitledBorder(trans.get("RocketCompCfg.border.Foreshoulder")));
471                         
472
473                         ////  Radius
474                         //// Diameter:
475                         sub.add(new JLabel(trans.get("RocketCompCfg.lbl.Diameter")));
476                         
477                         m = new DoubleModel(component, "ForeShoulderRadius", 2, UnitGroup.UNITS_LENGTH, 0);
478                         m2 = new DoubleModel(component, "ForeRadius", 2, UnitGroup.UNITS_LENGTH);
479                         
480                         spin = new JSpinner(m.getSpinnerModel());
481                         spin.setEditor(new SpinnerEditor(spin));
482                         sub.add(spin, "growx");
483                         
484                         sub.add(new UnitSelector(m), "growx");
485                         sub.add(new BasicSlider(m.getSliderModel(m0, m2)), "w 100lp, wrap");
486                         
487
488                         ////  Length:
489                         sub.add(new JLabel(trans.get("RocketCompCfg.lbl.Length")));
490                         
491                         m = new DoubleModel(component, "ForeShoulderLength", UnitGroup.UNITS_LENGTH, 0);
492                         
493                         spin = new JSpinner(m.getSpinnerModel());
494                         spin.setEditor(new SpinnerEditor(spin));
495                         sub.add(spin, "growx");
496                         
497                         sub.add(new UnitSelector(m), "growx");
498                         sub.add(new BasicSlider(m.getSliderModel(0, 0.02, 0.2)), "w 100lp, wrap");
499                         
500
501                         ////  Thickness:
502                         sub.add(new JLabel(trans.get("RocketCompCfg.lbl.Thickness")));
503                         
504                         m = new DoubleModel(component, "ForeShoulderThickness", UnitGroup.UNITS_LENGTH, 0);
505                         m2 = new DoubleModel(component, "ForeShoulderRadius", UnitGroup.UNITS_LENGTH);
506                         
507                         spin = new JSpinner(m.getSpinnerModel());
508                         spin.setEditor(new SpinnerEditor(spin));
509                         sub.add(spin, "growx");
510                         
511                         sub.add(new UnitSelector(m), "growx");
512                         sub.add(new BasicSlider(m.getSliderModel(m0, m2)), "w 100lp, wrap");
513                         
514
515                         ////  Capped
516                         bm = new BooleanModel(component, "ForeShoulderCapped");
517                         check = new JCheckBox(bm);
518                         //// End capped
519                         check.setText(trans.get("RocketCompCfg.checkbox.Endcapped"));
520                         //// Whether the end of the shoulder is capped.
521                         check.setToolTipText(trans.get("RocketCompCfg.ttip.Endcapped"));
522                         sub.add(check, "spanx");
523                         
524
525                         panel.add(sub);
526                 }
527                 
528
529                 ////  Aft shoulder
530                 sub = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::]", ""));
531                 
532                 if (component instanceof NoseCone)
533                         //// Nose cone shoulder
534                         sub.setBorder(BorderFactory.createTitledBorder(trans.get("RocketCompCfg.title.Noseconeshoulder")));
535                 else
536                         //// Aft shoulder
537                         sub.setBorder(BorderFactory.createTitledBorder(trans.get("RocketCompCfg.title.Aftshoulder")));
538                 
539
540                 ////  Radius
541                 //// Diameter:
542                 sub.add(new JLabel(trans.get("RocketCompCfg.lbl.Diameter")));
543                 
544                 m = new DoubleModel(component, "AftShoulderRadius", 2, UnitGroup.UNITS_LENGTH, 0);
545                 m2 = new DoubleModel(component, "AftRadius", 2, UnitGroup.UNITS_LENGTH);
546                 
547                 spin = new JSpinner(m.getSpinnerModel());
548                 spin.setEditor(new SpinnerEditor(spin));
549                 sub.add(spin, "growx");
550                 
551                 sub.add(new UnitSelector(m), "growx");
552                 sub.add(new BasicSlider(m.getSliderModel(m0, m2)), "w 100lp, wrap");
553                 
554
555                 ////  Length:
556                 sub.add(new JLabel(trans.get("RocketCompCfg.lbl.Length")));
557                 
558                 m = new DoubleModel(component, "AftShoulderLength", UnitGroup.UNITS_LENGTH, 0);
559                 
560                 spin = new JSpinner(m.getSpinnerModel());
561                 spin.setEditor(new SpinnerEditor(spin));
562                 sub.add(spin, "growx");
563                 
564                 sub.add(new UnitSelector(m), "growx");
565                 sub.add(new BasicSlider(m.getSliderModel(0, 0.02, 0.2)), "w 100lp, wrap");
566                 
567
568                 ////  Thickness:
569                 sub.add(new JLabel(trans.get("RocketCompCfg.lbl.Thickness")));
570                 
571                 m = new DoubleModel(component, "AftShoulderThickness", UnitGroup.UNITS_LENGTH, 0);
572                 m2 = new DoubleModel(component, "AftShoulderRadius", UnitGroup.UNITS_LENGTH);
573                 
574                 spin = new JSpinner(m.getSpinnerModel());
575                 spin.setEditor(new SpinnerEditor(spin));
576                 sub.add(spin, "growx");
577                 
578                 sub.add(new UnitSelector(m), "growx");
579                 sub.add(new BasicSlider(m.getSliderModel(m0, m2)), "w 100lp, wrap");
580                 
581
582                 ////  Capped
583                 bm = new BooleanModel(component, "AftShoulderCapped");
584                 check = new JCheckBox(bm);
585                 //// End capped
586                 check.setText(trans.get("RocketCompCfg.checkbox.Endcapped"));
587                 //// Whether the end of the shoulder is capped.
588                 check.setToolTipText(trans.get("RocketCompCfg.ttip.Endcapped"));
589                 sub.add(check, "spanx");
590                 
591
592                 panel.add(sub);
593                 
594
595                 return panel;
596         }
597         
598         
599
600
601         /*
602          * Private inner class to handle events in componentNameField.
603          */
604         private class TextFieldListener implements ActionListener, FocusListener {
605                 @Override
606                 public void actionPerformed(ActionEvent e) {
607                         setName();
608                 }
609                 
610                 @Override
611                 public void focusGained(FocusEvent e) {
612                 }
613                 
614                 @Override
615                 public void focusLost(FocusEvent e) {
616                         setName();
617                 }
618                 
619                 private void setName() {
620                         if (!component.getName().equals(componentNameField.getText())) {
621                                 component.setName(componentNameField.getText());
622                         }
623                         if (!component.getComment().equals(commentTextArea.getText())) {
624                                 component.setComment(commentTextArea.getText());
625                         }
626                 }
627         }
628         
629         
630         protected void register(Invalidatable model) {
631                 this.invalidatables.add(model);
632         }
633         
634         public void invalidateModels() {
635                 for (Invalidatable i : invalidatables) {
636                         i.invalidate();
637                 }
638         }
639         
640 }