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;
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;
}
///// 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);
}
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);
}
}
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);
}
}
-
+
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;
}
/**
- * 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);
}
}
-
public String toStorableString() {
return getType().name() + "|" + name.replace('|', ' ') + '|' + density;
}