Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / src / net / sf / openrocket / material / Material.java
index 00be68b1c3cdce191dfe53b035d13d31fc086a60..055fc336b60768060132e3399f7a5472bb377305 100644 (file)
@@ -1,5 +1,7 @@
 package net.sf.openrocket.material;
 
+import net.sf.openrocket.l10n.Translator;
+import net.sf.openrocket.startup.Application;
 import net.sf.openrocket.unit.Unit;
 import net.sf.openrocket.unit.UnitGroup;
 import net.sf.openrocket.util.MathUtil;
@@ -16,16 +18,18 @@ import net.sf.openrocket.util.MathUtil;
 
 public abstract class Material implements Comparable<Material> {
        
+       private static final Translator trans = Application.getTranslator();
+       
        public enum Type {
-               LINE("Line", UnitGroup.UNITS_DENSITY_LINE),
-               SURFACE("Surface", UnitGroup.UNITS_DENSITY_SURFACE),
-               BULK("Bulk", UnitGroup.UNITS_DENSITY_BULK);
+               LINE("Databases.materials.types.Line", UnitGroup.UNITS_DENSITY_LINE),
+               SURFACE("Databases.materials.types.Surface", UnitGroup.UNITS_DENSITY_SURFACE),
+               BULK("Databases.materials.types.Bulk", UnitGroup.UNITS_DENSITY_BULK);
                
                private final String name;
                private final UnitGroup units;
                
-               private Type(String name, UnitGroup units) {
-                       this.name = name;
+               private Type(String nameKey, UnitGroup units) {
+                       this.name = trans.get(nameKey);
                        this.units = units;
                }
                
@@ -43,7 +47,7 @@ public abstract class Material implements Comparable<Material> {
        /////  Definitions of different material types  /////
        
        public static class Line extends Material {
-               public Line(String name, double density, boolean userDefined) {
+               Line(String name, double density, boolean userDefined) {
                        super(name, density, userDefined);
                }
                
@@ -55,7 +59,7 @@ public abstract class Material implements Comparable<Material> {
        
        public static class Surface extends Material {
                
-               public Surface(String name, double density, boolean userDefined) {
+               Surface(String name, double density, boolean userDefined) {
                        super(name, density, userDefined);
                }
                
@@ -71,7 +75,7 @@ public abstract class Material implements Comparable<Material> {
        }
        
        public static class Bulk extends Material {
-               public Bulk(String name, double density, boolean userDefined) {
+               Bulk(String name, double density, boolean userDefined) {
                        super(name, density, userDefined);
                }
                
@@ -82,20 +86,26 @@ public abstract class Material implements Comparable<Material> {
        }
        
        
-
+       
        private final String name;
        private final double density;
        private final boolean userDefined;
        
        
-       public Material(String name, double density, boolean userDefined) {
+       /**
+        * Constructor for materials.
+        * 
+        * @param name ignored when defining system materials.
+        * @param key ignored when defining user materials.
+        * @param density
+        * @param userDefined true if this is a user defined material, false if it is a system material.
+        */
+       private Material(String name, double density, boolean userDefined) {
                this.name = name;
-               this.density = density;
                this.userDefined = userDefined;
+               this.density = density;
        }
        
-       
-
        public double getDensity() {
                return density;
        }
@@ -159,10 +169,15 @@ public abstract class Material implements Comparable<Material> {
        
        
        /**
-        * Return a new material of the specified type.
+        * Return a new material.  The name is used as-is, without any translation.
+        * 
+        * @param type                  the material type
+        * @param name                  the material name
+        * @param density               the material density
+        * @param userDefined   whether the material is user-defined or not
+        * @return                              the new material
         */
-       public static Material newMaterial(Type type, String name, double density,
-                       boolean userDefined) {
+       public static Material newMaterial(Type type, String name, double density, boolean userDefined) {
                switch (type) {
                case LINE:
                        return new Material.Line(name, density, userDefined);
@@ -178,7 +193,6 @@ public abstract class Material implements Comparable<Material> {
                }
        }
        
-       
        public String toStorableString() {
                return getType().name() + "|" + name.replace('|', ' ') + '|' + density;
        }