X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Fmaterial%2FMaterial.java;h=93db63aa0d106e836f7d37175e2ccd64fc0a8a00;hb=84086eec3f20c7af0c4817548de4e8296c7674f8;hp=f59885da900a38d93ce9146e3dc3ee90ee3bc350;hpb=720d4935bc6bec453e6478ad5227356c626610a2;p=debian%2Fopenrocket diff --git a/src/net/sf/openrocket/material/Material.java b/src/net/sf/openrocket/material/Material.java index f59885da..93db63aa 100644 --- a/src/net/sf/openrocket/material/Material.java +++ b/src/net/sf/openrocket/material/Material.java @@ -23,8 +23,8 @@ public abstract class Material implements Comparable { } public static class Line extends Material { - public Line(String name, double density) { - super(name, density); + public Line(String name, double density, boolean userDefined) { + super(name, density, userDefined); } @Override @@ -40,8 +40,8 @@ public abstract class Material implements Comparable { public static class Surface extends Material { - public Surface(String name, double density) { - super(name, density); + public Surface(String name, double density, boolean userDefined) { + super(name, density, userDefined); } @Override @@ -61,8 +61,8 @@ public abstract class Material implements Comparable { } public static class Bulk extends Material { - public Bulk(String name, double density) { - super(name, density); + public Bulk(String name, double density, boolean userDefined) { + super(name, density, userDefined); } @Override @@ -80,11 +80,13 @@ public abstract class Material implements Comparable { private final String name; private final double density; + private final boolean userDefined; - public Material(String name, double density) { + public Material(String name, double density, boolean userDefined) { this.name = name; this.density = density; + this.userDefined = userDefined; } @@ -101,6 +103,10 @@ public abstract class Material implements Comparable { return name + " (" + u.toStringUnit(density) + ")"; } + public boolean isUserDefined() { + return userDefined; + } + public abstract UnitGroup getUnitGroup(); public abstract Type getType(); @@ -148,17 +154,20 @@ public abstract class Material implements Comparable { } - - public static Material newMaterial(Type type, String name, double density) { + /** + * Return a new material of the specified type. + */ + public static Material newMaterial(Type type, String name, double density, + boolean userDefined) { switch (type) { case LINE: - return new Material.Line(name, density); + return new Material.Line(name, density, userDefined); case SURFACE: - return new Material.Surface(name, density); + return new Material.Surface(name, density, userDefined); case BULK: - return new Material.Bulk(name, density); + return new Material.Bulk(name, density, userDefined); default: throw new IllegalArgumentException("Unknown material type: "+type); @@ -170,7 +179,19 @@ public abstract class Material implements Comparable { return getType().name() + "|" + name.replace('|', ' ') + '|' + density; } - public static Material fromStorableString(String str) { + + /** + * Return a material defined by the provided string. + * + * @param str the material storage string. + * @param userDefined whether the created material is user-defined. + * @return a new Material object. + * @throws IllegalArgumentException if str is invalid or null. + */ + public static Material fromStorableString(String str, boolean userDefined) { + if (str == null) + throw new IllegalArgumentException("Material string is null"); + String[] split = str.split("\\|",3); if (split.length < 3) throw new IllegalArgumentException("Illegal material string: "+str); @@ -195,13 +216,13 @@ public abstract class Material implements Comparable { switch (type) { case BULK: - return new Material.Bulk(name, density); + return new Material.Bulk(name, density, userDefined); case SURFACE: - return new Material.Surface(name, density); + return new Material.Surface(name, density, userDefined); case LINE: - return new Material.Line(name, density); + return new Material.Line(name, density, userDefined); default: throw new IllegalArgumentException("Illegal material string: "+str);