When creating a new user material from an existing material (ie, key), make certain to use the name associated with the material because the key might not be localizable.

This commit is contained in:
Kevin Ruland 2012-08-04 08:37:39 +00:00
parent f9c450c79c
commit a373126c41
3 changed files with 73 additions and 63 deletions

View File

@ -198,8 +198,13 @@ public class Databases {
// 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 ( key != null && m.getKey().equals(key) ) {
// Exact match
if ( MathUtil.equals(m.getDensity(), density) ) {
return m;
}
// Custom material with standard name
return Material.newUserMaterialWithKey(type, key, m.getName(), density);
}
if (m.getName().equalsIgnoreCase(name) && MathUtil.equals(m.getDensity(), density)) {
bestMatch = m;

View File

@ -161,7 +161,12 @@ public class CustomMaterialDialog extends JDialog {
density = this.density.getValue();
return Material.newUserMaterial(type, name, density);
// If the name has not changed from the original name and we started with a system material.
if ( name.equals( originalMaterial.getName()) ) {
return Material.newUserMaterialWithKey(type, originalMaterial.getKey(), originalMaterial.getName(), density);
} else {
return Material.newUserMaterial(type, name, density);
}
}

View File

@ -218,16 +218,16 @@ public abstract class Material implements Comparable<Material> {
/**
* Return a new user defined material of the specified type and localizable key.
*/
public static Material newUserMaterialWithKey(Type type, String key, double density) {
public static Material newUserMaterialWithKey(Type type, String key, String name, double density) {
switch (type) {
case LINE:
return new Material.Line(null, key, density, true);
return new Material.Line(name, key, density, true);
case SURFACE:
return new Material.Surface(null, key, density, true);
return new Material.Surface(name, key, density, true);
case BULK:
return new Material.Bulk(null, key, density, true);
return new Material.Bulk(name, key, density, true);
default:
throw new IllegalArgumentException("Unknown material type: " + type);