| 1 | Index: DefaultNameFormatter.java
|
|---|
| 2 | ===================================================================
|
|---|
| 3 | --- DefaultNameFormatter.java (revision 4195)
|
|---|
| 4 | +++ DefaultNameFormatter.java (working copy)
|
|---|
| 5 | @@ -8,9 +8,11 @@
|
|---|
| 6 |
|
|---|
| 7 | import java.util.ArrayList;
|
|---|
| 8 | import java.util.Arrays;
|
|---|
| 9 | +import java.util.Collection;
|
|---|
| 10 | import java.util.Collections;
|
|---|
| 11 | import java.util.Comparator;
|
|---|
| 12 | import java.util.HashSet;
|
|---|
| 13 | +import java.util.Iterator;
|
|---|
| 14 | import java.util.List;
|
|---|
| 15 | import java.util.Set;
|
|---|
| 16 |
|
|---|
| 17 | @@ -33,6 +35,8 @@
|
|---|
| 18 | import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
|
|---|
| 19 | import org.openstreetmap.josm.data.osm.history.HistoryRelation;
|
|---|
| 20 | import org.openstreetmap.josm.data.osm.history.HistoryWay;
|
|---|
| 21 | +import org.openstreetmap.josm.data.preferences.StringProperty;
|
|---|
| 22 | +import org.openstreetmap.josm.plugins.PluginHandler;
|
|---|
| 23 |
|
|---|
| 24 | /**
|
|---|
| 25 | * This is the default implementation of a {@see NameFormatter} for names of {@see OsmPrimitive}s.
|
|---|
| 26 | @@ -42,6 +46,8 @@
|
|---|
| 27 |
|
|---|
| 28 | static private DefaultNameFormatter instance;
|
|---|
| 29 |
|
|---|
| 30 | + public static final StringProperty PREF_KEY_FORMATTER_CLASS_NAME = new StringProperty("gui.formatter-class-name", null);
|
|---|
| 31 | +
|
|---|
| 32 | /**
|
|---|
| 33 | * Replies the unique instance of this formatter
|
|---|
| 34 | *
|
|---|
| 35 | @@ -49,7 +55,37 @@
|
|---|
| 36 | */
|
|---|
| 37 | static public DefaultNameFormatter getInstance() {
|
|---|
| 38 | if (instance == null) {
|
|---|
| 39 | - instance = new DefaultNameFormatter();
|
|---|
| 40 | + final String formatterClassName = PREF_KEY_FORMATTER_CLASS_NAME.get();
|
|---|
| 41 | + final Collection<ClassLoader> classLoaders = PluginHandler.getResourceClassLoaders();
|
|---|
| 42 | +
|
|---|
| 43 | + Class<?> formatterClass = null;
|
|---|
| 44 | +
|
|---|
| 45 | + // Find the preferred class in the right ClassLoader
|
|---|
| 46 | + for (Iterator<ClassLoader> i = classLoaders.iterator(); i.hasNext() && formatterClass == null; ) {
|
|---|
| 47 | + try {
|
|---|
| 48 | + formatterClass = Class.forName(formatterClassName, true, i.next());
|
|---|
| 49 | + } catch (ClassNotFoundException e) {
|
|---|
| 50 | + // Do nothing and try next ClassLoader
|
|---|
| 51 | + }
|
|---|
| 52 | + }
|
|---|
| 53 | +
|
|---|
| 54 | + // If found, instantiate the preffered Name formatter
|
|---|
| 55 | + if (formatterClass != null) {
|
|---|
| 56 | + try {
|
|---|
| 57 | + instance = (DefaultNameFormatter) formatterClass.newInstance();
|
|---|
| 58 | + } catch (InstantiationException e) {
|
|---|
| 59 | + e.printStackTrace();
|
|---|
| 60 | + } catch (IllegalAccessException e) {
|
|---|
| 61 | + e.printStackTrace();
|
|---|
| 62 | + } catch (ClassCastException e) {
|
|---|
| 63 | + e.printStackTrace();
|
|---|
| 64 | + }
|
|---|
| 65 | + }
|
|---|
| 66 | +
|
|---|
| 67 | + // If not found, or if something went wrong, create the default name formatter
|
|---|
| 68 | + if (instance == null) {
|
|---|
| 69 | + instance = new DefaultNameFormatter();
|
|---|
| 70 | + }
|
|---|
| 71 | }
|
|---|
| 72 | return instance;
|
|---|
| 73 | }
|
|---|
| 74 | @@ -331,7 +367,7 @@
|
|---|
| 75 | return s.substring(0, i);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | - private String getRelationTypeName(IRelation relation) {
|
|---|
| 79 | + protected String getRelationTypeName(IRelation relation) {
|
|---|
| 80 | String name = trc("Relation type", relation.get("type"));
|
|---|
| 81 | if (name == null) {
|
|---|
| 82 | name = (relation.get("public_transport") != null) ? tr("public transport") : null;
|
|---|