Index: DefaultNameFormatter.java =================================================================== --- DefaultNameFormatter.java (revision 4195) +++ DefaultNameFormatter.java (working copy) @@ -8,9 +8,11 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -33,6 +35,8 @@ import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; import org.openstreetmap.josm.data.osm.history.HistoryRelation; import org.openstreetmap.josm.data.osm.history.HistoryWay; +import org.openstreetmap.josm.data.preferences.StringProperty; +import org.openstreetmap.josm.plugins.PluginHandler; /** * This is the default implementation of a {@see NameFormatter} for names of {@see OsmPrimitive}s. @@ -42,6 +46,8 @@ static private DefaultNameFormatter instance; + public static final StringProperty PREF_KEY_FORMATTER_CLASS_NAME = new StringProperty("gui.formatter-class-name", null); + /** * Replies the unique instance of this formatter * @@ -49,7 +55,37 @@ */ static public DefaultNameFormatter getInstance() { if (instance == null) { - instance = new DefaultNameFormatter(); + final String formatterClassName = PREF_KEY_FORMATTER_CLASS_NAME.get(); + final Collection classLoaders = PluginHandler.getResourceClassLoaders(); + + Class formatterClass = null; + + // Find the preferred class in the right ClassLoader + for (Iterator i = classLoaders.iterator(); i.hasNext() && formatterClass == null; ) { + try { + formatterClass = Class.forName(formatterClassName, true, i.next()); + } catch (ClassNotFoundException e) { + // Do nothing and try next ClassLoader + } + } + + // If found, instantiate the preffered Name formatter + if (formatterClass != null) { + try { + instance = (DefaultNameFormatter) formatterClass.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (ClassCastException e) { + e.printStackTrace(); + } + } + + // If not found, or if something went wrong, create the default name formatter + if (instance == null) { + instance = new DefaultNameFormatter(); + } } return instance; } @@ -331,7 +367,7 @@ return s.substring(0, i); } - private String getRelationTypeName(IRelation relation) { + protected String getRelationTypeName(IRelation relation) { String name = trc("Relation type", relation.get("type")); if (name == null) { name = (relation.get("public_transport") != null) ? tr("public transport") : null;