updates for 0.9.4
[debian/openrocket] / src / net / sf / openrocket / material / Material.java
index 93db63aa0d106e836f7d37175e2ccd64fc0a8a00..8febc9480432cefa785ebc2c1b5a262ef51f9e7f 100644 (file)
@@ -17,21 +17,33 @@ import net.sf.openrocket.util.MathUtil;
 public abstract class Material implements Comparable<Material> {
 
        public enum Type {
-               LINE,
-               SURFACE,
-               BULK
+               LINE("Line", UnitGroup.UNITS_DENSITY_LINE),
+               SURFACE("Surface", UnitGroup.UNITS_DENSITY_SURFACE),
+               BULK("Bulk", UnitGroup.UNITS_DENSITY_BULK);
+               
+               private final String name;
+               private final UnitGroup units;
+               private Type(String name, UnitGroup units) {
+                       this.name = name;
+                       this.units = units;
+               }
+               public UnitGroup getUnitGroup() {
+                       return units;
+               }
+               @Override
+               public String toString() {
+                       return name;
+               }
        }
        
+       
+       /////  Definitions of different material types  /////
+       
        public static class Line extends Material {
                public Line(String name, double density, boolean userDefined) {
                        super(name, density, userDefined);
                }
 
-               @Override
-               public UnitGroup getUnitGroup() {
-                       return UnitGroup.UNITS_DENSITY_LINE;
-               }
-
                @Override
                public Type getType() {
                        return Type.LINE;
@@ -44,11 +56,6 @@ public abstract class Material implements Comparable<Material> {
                        super(name, density, userDefined);
                }
                
-               @Override
-               public UnitGroup getUnitGroup() {
-                       return UnitGroup.UNITS_DENSITY_SURFACE;
-               }
-
                @Override
                public Type getType() {
                        return Type.SURFACE;
@@ -65,11 +72,6 @@ public abstract class Material implements Comparable<Material> {
                        super(name, density, userDefined);
                }
 
-               @Override
-               public UnitGroup getUnitGroup() {
-                       return UnitGroup.UNITS_DENSITY_BULK;
-               }
-
                @Override
                public Type getType() {
                        return Type.BULK;
@@ -107,12 +109,11 @@ public abstract class Material implements Comparable<Material> {
                return userDefined;
        }
        
-       public abstract UnitGroup getUnitGroup();
        public abstract Type getType();
        
        @Override
        public String toString() {
-               return getName(getUnitGroup().getDefaultUnit());
+               return this.getName(this.getType().getUnitGroup().getDefaultUnit());
        }