Index: src/org/openstreetmap/josm/gui/DefaultNameFormatter.java =================================================================== --- src/org/openstreetmap/josm/gui/DefaultNameFormatter.java (revision 4200) +++ src/org/openstreetmap/josm/gui/DefaultNameFormatter.java (working copy) @@ -11,6 +11,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -42,6 +43,8 @@ static private DefaultNameFormatter instance; + private static final LinkedList formatHooks = new LinkedList(); + /** * Replies the unique instance of this formatter * @@ -53,6 +56,30 @@ } return instance; } + + /** + * Registers a format hook. Adds the hook at the first position of the format hooks. + * + * @param hook the format hook. Ignored if null. + */ + public static void registerFormatHook(NameFormatterHook hook) { + if (hook == null) return; + if (!formatHooks.contains(hook)) { + formatHooks.add(0,hook); + } + } + + /** + * Unregisters a format hook. Removes the hook from the list of format hooks. + * + * @param hook the format hook. Ignored if null. + */ + public static void unregisterFormatHook(NameFormatterHook hook) { + if (hook == null) return; + if (formatHooks.contains(hook)) { + formatHooks.remove(hook); + } + } /** the default list of tags which are used as naming tags in relations */ static public final String[] DEFAULT_NAMING_TAGS_FOR_RELATIONS = {"name", "ref", "restriction", "landuse", "natural", @@ -140,6 +167,14 @@ name += " (" + node.getCoor().latToString(CoordinateFormat.getDefaultFormat()) + ", " + node.getCoor().lonToString(CoordinateFormat.getDefaultFormat()) + ")"; } name = decorateNameWithId(name, node); + + for (NameFormatterHook hook: formatHooks) { + String hookResult = hook.checkFormat(node, name); + if (hookResult != null && !hookResult.isEmpty()) { + return hookResult; + } + } + return name; } @@ -216,6 +251,14 @@ name += (name.length() > 0) ? " ("+nodes+")" : nodes; } name = decorateNameWithId(name, way); + + for (NameFormatterHook hook: formatHooks) { + String hookResult = hook.checkFormat(way, name); + if (hookResult != null && !hookResult.isEmpty()) { + return hookResult; + } + } + return name; } @@ -263,6 +306,14 @@ name += ")"; } name = decorateNameWithId(name, relation); + + for (NameFormatterHook hook: formatHooks) { + String hookResult = hook.checkFormat(relation, name); + if (hookResult != null && !hookResult.isEmpty()) { + return hookResult; + } + } + return name; } @@ -355,6 +406,13 @@ if (admin_level != null) { name += "["+admin_level+"]"; } + + for (NameFormatterHook hook: formatHooks) { + String hookResult = hook.checkRelationTypeName(relation, name); + if (hookResult != null && !hookResult.isEmpty()) { + return hookResult; + } + } return name; } Index: src/org/openstreetmap/josm/gui/NameFormatterHook.java =================================================================== --- src/org/openstreetmap/josm/gui/NameFormatterHook.java (revision 0) +++ src/org/openstreetmap/josm/gui/NameFormatterHook.java (revision 0) @@ -0,0 +1,41 @@ +// License: GPL. For details, see LICENSE file. +package org.openstreetmap.josm.gui; + +import org.openstreetmap.josm.data.osm.INode; +import org.openstreetmap.josm.data.osm.IRelation; +import org.openstreetmap.josm.data.osm.IWay; + +public interface NameFormatterHook { + + /** + * Check the relation type name. Return the corrected type name if needed, null otherwise. + * @param relation The relation. + * @param defaultName The default name generated by core. + * @return The corrected type name if needed, null otherwise. + */ + public String checkRelationTypeName(IRelation relation, String defaultName); + + /** + * Check the node format. Return the corrected format if needed, null otherwise. + * @param node The node. + * @param defaultName The default name generated by core. + * @return The corrected format if needed, null otherwise. + */ + public String checkFormat(INode node, String defaultName); + + /** + * Check the way format. Return the corrected format if needed, null otherwise. + * @param way The way. + * @param defaultName The default name generated by core. + * @return The corrected format if needed, null otherwise. + */ + public String checkFormat(IWay node, String defaultName); + + /** + * Check the relation format. Return the corrected format if needed, null otherwise. + * @param relation The relation. + * @param defaultName The default name generated by core. + * @return The corrected format if needed, null otherwise. + */ + public String checkFormat(IRelation node, String defaultName); +} Index: src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java =================================================================== --- src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java (revision 4200) +++ src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java (working copy) @@ -24,7 +24,7 @@ * @author Frederik Ramm */ public class OsmPrimitivRenderer implements ListCellRenderer, TableCellRenderer { - private DefaultNameFormatter formatter = new DefaultNameFormatter(); + private DefaultNameFormatter formatter = DefaultNameFormatter.getInstance(); /** * Default list cell renderer - delegate for ListCellRenderer operation