Add factory method which constructs a user material which uses a localizable key.
[debian/openrocket] / core / src / net / sf / openrocket / material / Material.java
index f52acf51df97664c53e6425bac569f306188eda2..912e85cc076f63afdeed7a5cc1f4ab61dab1098c 100644 (file)
@@ -215,6 +215,26 @@ public abstract class Material implements Comparable<Material> {
                }
        }
        
+       /**
+        * Return a new user defined material of the specified type and localizable key.
+        */
+       public static Material newUserMaterialWithKey(Type type, String key, double density) {
+               switch (type) {
+               case LINE:
+                       return new Material.Line(null, key, density, true);
+                       
+               case SURFACE:
+                       return new Material.Surface(null, key, density, true);
+                       
+               case BULK:
+                       return new Material.Bulk(null, key, density, true);
+                       
+               default:
+                       throw new IllegalArgumentException("Unknown material type: " + type);
+               }
+       }
+       
+       
        
        public String toStorableString() {
                return getType().name() + "|" + key + "|" + name.replace('|', ' ') + '|' + density;