Changeset 4209 in josm


Ignore:
Timestamp:
Jul 7, 2011 11:10:48 AM (23 months ago)
Author:
bastiK
Message:

#6535 - Allow plugins to modify default name formatter (patch by Don-vip)

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java

    r4144 r4209  
    1212import java.util.Comparator; 
    1313import java.util.HashSet; 
     14import java.util.LinkedList; 
    1415import java.util.List; 
    1516import java.util.Set; 
     
    4344    static private DefaultNameFormatter instance; 
    4445 
     46    private static final LinkedList<NameFormatterHook> formatHooks = new LinkedList<NameFormatterHook>(); 
     47 
    4548    /** 
    4649     * Replies the unique instance of this formatter 
     
    5356        } 
    5457        return instance; 
     58    } 
     59     
     60    /** 
     61     * Registers a format hook. Adds the hook at the first position of the format hooks. 
     62     * (for plugins) 
     63     * 
     64     * @param hook the format hook. Ignored if null. 
     65     */ 
     66    public static void registerFormatHook(NameFormatterHook hook) { 
     67        if (hook == null) return; 
     68        if (!formatHooks.contains(hook)) { 
     69            formatHooks.add(0,hook); 
     70        } 
     71    } 
     72 
     73    /** 
     74     * Unregisters a format hook. Removes the hook from the list of format hooks. 
     75     * 
     76     * @param hook the format hook. Ignored if null. 
     77     */ 
     78    public static void unregisterFormatHook(NameFormatterHook hook) { 
     79        if (hook == null) return; 
     80        if (formatHooks.contains(hook)) { 
     81            formatHooks.remove(hook); 
     82        } 
    5583    } 
    5684 
     
    141169        } 
    142170        name = decorateNameWithId(name, node); 
     171 
     172        for (NameFormatterHook hook: formatHooks) { 
     173            String hookResult = hook.checkFormat(node, name); 
     174            if (hookResult != null) { 
     175                return hookResult; 
     176            } 
     177        } 
     178 
    143179        return name; 
    144180    } 
     
    217253        } 
    218254        name = decorateNameWithId(name, way); 
     255         
     256        for (NameFormatterHook hook: formatHooks) { 
     257            String hookResult = hook.checkFormat(way, name); 
     258            if (hookResult != null) { 
     259                return hookResult; 
     260            } 
     261        } 
     262 
    219263        return name; 
    220264    } 
     
    264308        } 
    265309        name = decorateNameWithId(name, relation); 
     310 
     311        for (NameFormatterHook hook: formatHooks) { 
     312            String hookResult = hook.checkFormat(relation, name); 
     313            if (hookResult != null) { 
     314                return hookResult; 
     315            } 
     316        } 
     317 
    266318        return name; 
    267319    } 
     
    355407        if (admin_level != null) { 
    356408            name += "["+admin_level+"]"; 
     409        } 
     410         
     411        for (NameFormatterHook hook: formatHooks) { 
     412            String hookResult = hook.checkRelationTypeName(relation, name); 
     413            if (hookResult != null) { 
     414                return hookResult; 
     415            } 
    357416        } 
    358417 
  • trunk/src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java

    r3844 r4209  
    2525 */ 
    2626public class OsmPrimitivRenderer implements ListCellRenderer, TableCellRenderer { 
    27     private DefaultNameFormatter formatter = new DefaultNameFormatter(); 
     27    private DefaultNameFormatter formatter = DefaultNameFormatter.getInstance(); 
    2828 
    2929    /** 
Note: See TracChangeset for help on using the changeset viewer.