Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / src / net / sf / openrocket / database / Databases.java
index 8be3574dbdf4fee19f525c4d3c9084413c805963..853790bf8c0826b0307f25054e75d0887271e63e 100644 (file)
@@ -1,7 +1,9 @@
 package net.sf.openrocket.database;
 
+import net.sf.openrocket.l10n.Translator;
 import net.sf.openrocket.logging.LogHelper;
 import net.sf.openrocket.material.Material;
+import net.sf.openrocket.material.Material.Type;
 import net.sf.openrocket.material.MaterialStorage;
 import net.sf.openrocket.startup.Application;
 import net.sf.openrocket.util.MathUtil;
@@ -14,6 +16,8 @@ import net.sf.openrocket.util.MathUtil;
  */
 public class Databases {
        private static final LogHelper log = Application.getLogger();
+       private static final Translator trans = Application.getTranslator();
+       
        
        /* Static implementations of specific databases: */
        
@@ -35,65 +39,53 @@ public class Databases {
        static {
                
                // Add default materials
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Acrylic", 1190));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Aluminum", 2700));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Balsa", 170));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Basswood", 500));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Birch", 670));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Brass", 8600));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Cardboard", 680));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Carbonfiber", 1780));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Cork", 240));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"DepronXPS", 40));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Fiberglass", 1850));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Kraftphenolic", 950));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Maple", 755));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Paperoffice", 820));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Pine", 530));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Plywoodbirch", 630));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"PolycarbonateLexan", 1200));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Polystyrene", 1050));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"PVC", 1390));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Spruce", 450));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Steel", 7850));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"StyrofoamgenericEPS", 20));
-               //              BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Styrofoam (Blue foam, XPS)", 32));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"StyrofoamBluefoamXPS", 32));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Titanium", 4500));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"Quantumtubing", 1050));
-               BULK_MATERIAL.add(Material.newSystemMaterial(Material.Type.BULK,"BlueTube", 1300));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Acrylic", 1190));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Aluminum", 2700));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Balsa", 170));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Basswood", 500));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Birch", 670));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Brass", 8600));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Cardboard", 680));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Carbon fiber", 1780));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Cork", 240));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Depron (XPS)", 40));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Fiberglass", 1850));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Kraft phenolic", 950));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Maple", 755));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Paper (office)", 820));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Pine", 530));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Plywood (birch)", 630));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Polycarbonate (Lexan)", 1200));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Polystyrene", 1050));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "PVC", 1390));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Spruce", 450));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Steel", 7850));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Styrofoam (generic EPS)", 20));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Styrofoam \"Blue foam\" (XPS)", 32));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Titanium", 4500));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Quantum tubing", 1050));
+               BULK_MATERIAL.add(newMaterial(Material.Type.BULK, "Blue tube", 1300));
                
-               SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Ripstopnylon", 0.067));
-               SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Mylar", 0.021));
-               SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Polyethylenethin", 0.015));
-               SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Polyethyleneheavy", 0.040));
-               SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Silk", 0.060));
-               SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Paperoffice", 0.080));
-               SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Cellophane", 0.018));
-               SURFACE_MATERIAL.add(Material.newSystemMaterial(Material.Type.SURFACE,"Crepepaper", 0.025));
+               SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Ripstop nylon", 0.067));
+               SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Mylar", 0.021));
+               SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Polyethylene (thin)", 0.015));
+               SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Polyethylene (heavy)", 0.040));
+               SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Silk", 0.060));
+               SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Paper (office)", 0.080));
+               SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Cellophane", 0.018));
+               SURFACE_MATERIAL.add(newMaterial(Material.Type.SURFACE, "Cr\u00eape paper", 0.025));
                
-               //// Thread (heavy-duty)
-               LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Threadheavy-duty", 0.0003));
-               //// Elastic cord (round 2mm, 1/16 in)
-               LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordround2mm", 0.0018));
-               //// Elastic cord (flat  6mm, 1/4 in)
-               LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat6mm", 0.0043));
-               //// Elastic cord (flat 12mm, 1/2 in)
-               LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat12mm", 0.008));
-               //// Elastic cord (flat 19mm, 3/4 in)
-               LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat19mm", 0.0012));
-               //// Elastic cord (flat 25mm, 1 in)
-               LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Elasticcordflat25mm", 0.0016));
-               //// Braided nylon (2 mm, 1/16 in)
-               LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Braidednylon2mm", 0.001));
-               //// Braided nylon (3 mm, 1/8 in)
-               LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Braidednylon3mm", 0.0035));
-               //// Tubular nylon (11 mm, 7/16 in)
-               LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Tubularnylon11mm", 0.013));
-               //// Tubular nylon (14 mm, 9/16 in)
-               LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Tubularnylon14mm", 0.016));
-               //// Tubular nylon (25 mm, 1 in)
-               LINE_MATERIAL.add(Material.newSystemMaterial(Material.Type.LINE,"Tubularnylon25mm", 0.029));
+               LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Thread (heavy-duty)", 0.0003));
+               LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Elastic cord (round 2 mm, 1/16 in)", 0.0018));
+               LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Elastic cord (flat 6 mm, 1/4 in)", 0.0043));
+               LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Elastic cord (flat 12 mm, 1/2 in)", 0.008));
+               LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Elastic cord (flat 19 mm, 3/4 in)", 0.0012));
+               LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Elastic cord (flat 25 mm, 1 in)", 0.0016));
+               LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Braided nylon (2 mm, 1/16 in)", 0.001));
+               LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Braided nylon (3 mm, 1/8 in)", 0.0035));
+               LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Tubular nylon (11 mm, 7/16 in)", 0.013));
+               LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Tubular nylon (14 mm, 9/16 in)", 0.016));
+               LINE_MATERIAL.add(newMaterial(Material.Type.LINE, "Tubular nylon (25 mm, 1 in)", 0.029));
                
                
                // Add user-defined materials
@@ -124,6 +116,14 @@ public class Databases {
        }
        
        
+       private static Material newMaterial(Type type, String baseName, double density) {
+               String name = trans.get("material", baseName);
+               return Material.newMaterial(type, name, density, false);
+       }
+       
+       
+       
+       
        /*
         * Used just for ensuring initialization of the class.
         */
@@ -131,16 +131,18 @@ public class Databases {
                
        }
        
-       
        /**
         * Find a material from the database with the specified type and name.  Returns
         * <code>null</code> if the specified material could not be found.
+        * <p>
+        * This method will attempt to localize the material name to the current locale, or use
+        * the provided name if unable to do so.
         * 
-        * @param type  the material type.
-        * @param name  the material name in the database.
-        * @return              the material, or <code>null</code> if not found.
+        * @param type          the material type.
+        * @param baseName      the material base name in the database.
+        * @return                      the material, or <code>null</code> if not found.
         */
-       public static Material findMaterial(Material.Type type, String name) {
+       public static Material findMaterial(Material.Type type, String baseName) {
                Database<Material> db;
                switch (type) {
                case BULK:
@@ -156,6 +158,8 @@ public class Databases {
                        throw new IllegalArgumentException("Illegal material type: " + type);
                }
                
+               String name = trans.get("material", baseName);
+               
                for (Material m : db) {
                        if (m.getName().equalsIgnoreCase(name)) {
                                return m;
@@ -168,13 +172,16 @@ public class Databases {
        /**
         * Find a material from the database or return a new user defined material if the specified
         * material with the specified density is not found.
+        * <p>
+        * This method will attempt to localize the material name to the current locale, or use
+        * the provided name if unable to do so.
         * 
         * @param type                  the material type.
-        * @param name                  the material name.
+        * @param baseName                      the base name of the material.
         * @param density               the density of the material.
         * @return                              the material object from the database or a new material.
         */
-       public static Material findMaterial(Material.Type type, String key, String name, double density) {
+       public static Material findMaterial(Material.Type type, String baseName, double density) {
                Database<Material> db;
                switch (type) {
                case BULK:
@@ -190,26 +197,14 @@ public class Databases {
                        throw new IllegalArgumentException("Illegal material type: " + type);
                }
                
-               Material bestMatch = null;
+               String name = trans.get("material", baseName);
                
-               // Alter the search mechanism to handle older specifications.
-               // If a key is specified, then we match on key, if one is found.
-               // Otherwise we return the material which matches on name.
-               // this requires us to loop through the entire db at least once to look for the key.
                for (Material m : db) {
-                       // perfect match based on key.
-                       if ( key != null && m.getKey().equals(key) && MathUtil.equals(m.getDensity(), density) ) {
-                               return m;
-                       }
                        if (m.getName().equalsIgnoreCase(name) && MathUtil.equals(m.getDensity(), density)) {
-                               bestMatch = m;
+                               return m;
                        }
                }
-               if ( bestMatch != null ) {
-                       return bestMatch;
-               }
-               return Material.newUserMaterial(type, name, density);
+               return Material.newMaterial(type, name, density, true);
        }
        
-       
 }