Ignore:
Timestamp:
04.09.2009 10:49:53 (3 years ago)
Author:
Gubaer
Message:

Improved auto completion
fixed #2729: Auto completion with numbers sometimes annoying (only fixed in presets, relation editor, not in property dialog)
fixed #2320: Preset dialog for house numbers should have autocompletion (auto completion now supported in all preset dialogs)

Location:
trunk/src/org/openstreetmap/josm/gui/tagging/ac
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java

    r1930 r2048  
    1 package org.openstreetmap.josm.gui.dialogs.relation.ac; 
     1package org.openstreetmap.josm.gui.tagging.ac; 
    22 
    33import java.util.ArrayList; 
     
    55import java.util.Collections; 
    66import java.util.HashMap; 
     7import java.util.HashSet; 
     8import java.util.LinkedList; 
    79import java.util.List; 
     10import java.util.Set; 
    811import java.util.logging.Logger; 
    912 
     
    6770 
    6871 
    69     /** the cache */ 
    70     private HashMap<String, ArrayList<String>> cache; 
    71     private  ArrayList<String> roleCache; 
     72    /** the cached tags give by a tag key and a list of values for this tag*/ 
     73    private HashMap<String, Set<String>> tagCache; 
     74    /** the cached list of member roles */ 
     75    private  Set<String> roleCache; 
     76    /** the cache of all tag values */ 
     77    private  Set<String> allTagValues; 
     78    /**  the layer this cache is built for */ 
    7279    private OsmDataLayer layer; 
    7380 
     81 
    7482    /** 
    7583     * constructor 
    7684     */ 
    7785    public AutoCompletionCache(OsmDataLayer layer) { 
    78         cache = new HashMap<String, ArrayList<String>>(); 
    79         roleCache = new ArrayList<String>(); 
     86        tagCache = new HashMap<String, Set<String>>(); 
     87        roleCache = new HashSet<String>(); 
     88        allTagValues = new HashSet<String>(); 
    8089        this.layer = layer; 
    8190    } 
     
    91100     */ 
    92101    protected void cacheKey(String key) { 
    93         if (cache.containsKey(key)) 
     102        if (tagCache.containsKey(key)) 
    94103            return; 
    95         else { 
    96             cache.put(key, new ArrayList<String>()); 
    97         } 
     104        tagCache.put(key, new HashSet<String>()); 
    98105    } 
    99106 
     
    106113    protected void cacheValue(String key, String value) { 
    107114        cacheKey(key); 
    108         ArrayList<String> values = cache.get(key); 
    109         if (!values.contains(value)) { 
    110             values.add(value); 
    111         } 
     115        tagCache.get(key).add(value); 
     116        allTagValues.add(value); 
    112117    } 
    113118 
     
    143148     * 
    144149     */ 
    145     public void initFromJOSMDataset() { 
    146         cache = new HashMap<String, ArrayList<String>>(); 
     150    public void initFromDataSet() { 
     151        tagCache = new HashMap<String, Set<String>>(); 
    147152        if (layer == null) 
    148153            return; 
     
    152157        } 
    153158        for (Relation relation : layer.data.relations) { 
    154             if (relation.incomplete || relation.deleted) { 
     159            if (relation.incomplete || relation.isDeleted()) { 
    155160                continue; 
    156161            } 
    157162            cacheRelationMemberRoles(relation); 
    158             Collections.sort(roleCache); 
    159163        } 
    160164    } 
     
    166170     */ 
    167171    public List<String> getKeys() { 
    168         return new ArrayList<String>(cache.keySet()); 
     172        return new ArrayList<String>(tagCache.keySet()); 
    169173    } 
    170174 
     
    177181     */ 
    178182    public List<String> getValues(String key) { 
    179         if (!cache.containsKey(key)) 
     183        if (!tagCache.containsKey(key)) 
    180184            return new ArrayList<String>(); 
    181         return cache.get(key); 
     185        return new ArrayList<String>(tagCache.get(key)); 
    182186    } 
    183187 
     
    188192     */ 
    189193    public List<String> getMemberRoles() { 
    190         return roleCache; 
     194        return new ArrayList<String>(roleCache); 
    191195    } 
    192196 
     
    199203    public void populateWithMemberRoles(AutoCompletionList list) { 
    200204        list.clear(); 
    201         for (String role: roleCache) { 
    202             list.add(new AutoCompletionListItem(role, AutoCompletionItemPritority.IS_IN_DATASET)); 
    203         } 
     205        list.add(roleCache, AutoCompletionItemPritority.IS_IN_DATASET); 
     206    } 
     207 
     208    /** 
     209     * Populates the an {@see AutoCompletionList} with the currently cached 
     210     * values for a tag 
     211     * 
     212     * @param list the list to populate 
     213     * @param key the tag key 
     214     * @param append true to add the values to the list; false, to replace the values 
     215     * in the list by the tag values 
     216     */ 
     217    public void populateWithTagValues(AutoCompletionList list, String key, boolean append) { 
     218        if (!append) { 
     219            list.clear(); 
     220        } 
     221        list.add(getValues(key), AutoCompletionItemPritority.IS_IN_DATASET); 
     222    } 
     223 
     224    /** 
     225     * Populates the an {@see AutoCompletionList} with the currently cached 
     226     * tag keys 
     227     * 
     228     * @param list the list to populate 
     229     * @param append true to add the keys to the list; false, to replace the keys 
     230     * in the list by the keys in the cache 
     231     */ 
     232    public void populateWithKeys(AutoCompletionList list, boolean append) { 
     233        if (!append) { 
     234            list.clear(); 
     235        } 
     236        list.add(tagCache.keySet(), AutoCompletionItemPritority.IS_IN_DATASET); 
     237    } 
     238 
     239 
     240    /** 
     241     * Populates the an {@see AutoCompletionList} with the currently cached 
     242     * tag values 
     243     * 
     244     * @param list the list to populate 
     245     * @param append true to add the keys to the list; false, to replace the keys 
     246     * in the list by the keys in the cache 
     247     */ 
     248    public void populateWithValues(AutoCompletionList list, boolean append) { 
     249        if (!append) { 
     250            list.clear(); 
     251        } 
     252        list.add(this.allTagValues, AutoCompletionItemPritority.IS_IN_DATASET); 
    204253    } 
    205254} 
Note: See TracChangeset for help on using the changeset viewer.