create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / gui / preset / MaterialModel.java
index a80e6847e0e975777c54765ed42e754786ca4d84..f51f2146bc8e6a7efbaad0bd94ee62e34baffe73 100644 (file)
@@ -6,10 +6,12 @@ import net.sf.openrocket.database.Databases;
 import net.sf.openrocket.gui.dialogs.CustomMaterialDialog;
 import net.sf.openrocket.l10n.Translator;
 import net.sf.openrocket.material.Material;
+import net.sf.openrocket.preset.loader.MaterialHolder;
 import net.sf.openrocket.startup.Application;
 
-import javax.swing.*;
-import java.awt.*;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.SwingUtilities;
+import java.awt.Component;
 
 /**
  * A material model specifically for presets.
@@ -22,9 +24,20 @@ public class MaterialModel extends DefaultComboBoxModel implements DatabaseListe
 
     private static final Translator trans = Application.getTranslator();
 
+    private Material.Type type;
+
     private Component parent;
-    public MaterialModel(Component theParent, Material.Type type) {
+
+    public MaterialModel(Component theParent, Material.Type theType, Database<Material> materials) {
         parent = theParent;
+        type = theType;
+        database = materials;
+        database.addDatabaseListener(this);
+    }
+
+    public MaterialModel(Component theParent, Material.Type theType) {
+        parent = theParent;
+        type = theType;
 
         switch (type) {
             case LINE:
@@ -59,9 +72,7 @@ public class MaterialModel extends DefaultComboBoxModel implements DatabaseListe
             SwingUtilities.invokeLater(new Runnable() {
                 @Override
                 public void run() {
-                    CustomMaterialDialog dialog = new CustomMaterialDialog(
-                            SwingUtilities.getWindowAncestor(parent),
-                            (Material) getSelectedItem(), true,
+                    CustomMaterialDialog dialog = new CustomMaterialDialog(SwingUtilities.getWindowAncestor(parent), (Material) getSelectedItem(), true,
                             //// Define custom material
                             trans.get("MaterialModel.title.Defcustmat"));
 
@@ -117,4 +128,11 @@ public class MaterialModel extends DefaultComboBoxModel implements DatabaseListe
         this.fireContentsChanged(this, 0, database.size());
     }
 
+    public Material.Type getType() {
+        return type;
+    }
+
+    public void removeListener() {
+        database.removeChangeListener(this);
+    }
 }