From 13f30acd78c356b00ab2c8107f92f04fda0966cb Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Fri, 13 Apr 2012 19:37:16 +0000 Subject: [PATCH] Move the preset drop down into RocketComponentConfig materials section. Only display it if the component has a non-null getPresetType(). git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@556 180e2498-e6e9-4542-8430-84ac67f01cd8 --- .../gui/configdialog/BodyTubeConfig.java | 18 ----------------- .../gui/configdialog/NoseConeConfig.java | 13 ------------ .../configdialog/RocketComponentConfig.java | 20 ++++++++++++++++++- 3 files changed, 19 insertions(+), 32 deletions(-) diff --git a/core/src/net/sf/openrocket/gui/configdialog/BodyTubeConfig.java b/core/src/net/sf/openrocket/gui/configdialog/BodyTubeConfig.java index 53d4049a..b6ff3bdd 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/BodyTubeConfig.java +++ b/core/src/net/sf/openrocket/gui/configdialog/BodyTubeConfig.java @@ -27,8 +27,6 @@ public class BodyTubeConfig extends RocketComponentConfig { private MotorConfig motorConfigPane = null; private DoubleModel maxLength; - private JComboBox presetComboBox; - private PresetModel presetModel; private static final Translator trans = Application.getTranslator(); public BodyTubeConfig(OpenRocketDocument d, RocketComponent c) { @@ -38,15 +36,6 @@ public class BodyTubeConfig extends RocketComponentConfig { - //// Body tube template - // FIXME: Move to proper location - panel.add(new JLabel(trans.get("PresetModel.lbl.select"))); - presetModel = new PresetModel( this, component); - ((ComponentPresetDatabase)Application.getComponentPresetDao()).addDatabaseListener(presetModel); - presetComboBox = new JComboBox(presetModel); - presetComboBox.setEditable(false); - panel.add(presetComboBox, "wrap para"); - //// Body tube length panel.add(new JLabel(trans.get("BodyTubecfg.lbl.Bodytubelength"))); @@ -136,11 +125,4 @@ public class BodyTubeConfig extends RocketComponentConfig { motorConfigPane.updateFields(); } - @Override - public void invalidateModels() { - super.invalidateModels(); - ((ComponentPresetDatabase)Application.getComponentPresetDao()).removeChangeListener(presetModel); - } - - } diff --git a/core/src/net/sf/openrocket/gui/configdialog/NoseConeConfig.java b/core/src/net/sf/openrocket/gui/configdialog/NoseConeConfig.java index 78d02f8f..b1b8d55a 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/NoseConeConfig.java +++ b/core/src/net/sf/openrocket/gui/configdialog/NoseConeConfig.java @@ -35,9 +35,6 @@ public class NoseConeConfig extends RocketComponentConfig { private DescriptionArea description; - private JComboBox presetComboBox; - private PresetModel presetModel; - private JLabel shapeLabel; private JSpinner shapeSpinner; private JSlider shapeSlider; @@ -52,16 +49,6 @@ public class NoseConeConfig extends RocketComponentConfig { DoubleModel m; JPanel panel = new JPanel(new MigLayout("", "[][65lp::][30lp::]")); - - // FIXME: Move to proper location - panel.add(new JLabel(trans.get("PresetModel.lbl.select"))); - presetModel = new PresetModel( this, component); - ((ComponentPresetDatabase)Application.getComponentPresetDao()).addDatabaseListener(presetModel); - presetComboBox = new JComboBox(presetModel); - presetComboBox.setEditable(false); - panel.add(presetComboBox, "wrap para"); - - //// Shape selection //// Nose cone shape: panel.add(new JLabel(trans.get("NoseConeCfg.lbl.Noseconeshape"))); diff --git a/core/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java b/core/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java index 2a782d15..02643543 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java +++ b/core/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java @@ -25,12 +25,14 @@ import javax.swing.JTextArea; import javax.swing.JTextField; import net.miginfocom.swing.MigLayout; +import net.sf.openrocket.database.ComponentPresetDatabase; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.gui.SpinnerEditor; import net.sf.openrocket.gui.adaptors.BooleanModel; import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.adaptors.EnumModel; import net.sf.openrocket.gui.adaptors.MaterialModel; +import net.sf.openrocket.gui.adaptors.PresetModel; import net.sf.openrocket.gui.components.BasicSlider; import net.sf.openrocket.gui.components.ColorIcon; import net.sf.openrocket.gui.components.StyledLabel; @@ -61,7 +63,9 @@ public class RocketComponentConfig extends JPanel { private final List invalidatables = new ArrayList(); - + private JComboBox presetComboBox; + private PresetModel presetModel; + protected final JTextField componentNameField; protected JTextArea commentTextArea; private final TextFieldListener textFieldListener; @@ -198,6 +202,18 @@ public class RocketComponentConfig extends JPanel { protected JPanel materialPanel(JPanel panel, Material.Type type, String materialString, String finishString) { + + if ( component.getPresetType() != null ) { + //// Body tube template + // FIXME: Move to proper location + panel.add(new JLabel(trans.get("PresetModel.lbl.select"))); + presetModel = new PresetModel( this, component); + ((ComponentPresetDatabase)Application.getComponentPresetDao()).addDatabaseListener(presetModel); + presetComboBox = new JComboBox(presetModel); + presetComboBox.setEditable(false); + panel.add(presetComboBox, "wrap para"); + } + JLabel label = new JLabel(materialString); //// The component material affects the weight of the component. label.setToolTipText(trans.get("RocketCompCfg.lbl.ttip.componentmaterialaffects")); @@ -636,6 +652,8 @@ public class RocketComponentConfig extends JPanel { for (Invalidatable i : invalidatables) { i.invalidate(); } + ((ComponentPresetDatabase)Application.getComponentPresetDao()).removeChangeListener(presetModel); + } } \ No newline at end of file -- 2.39.5