Changeset 2946 in josm


Ignore:
Timestamp:
Feb 6, 2010 5:37:52 PM (3 years ago)
Author:
bastiK
Message:

autocompletion: Always add the preset keys/values to the autocompletion list.
Does not apply to the Properties dialog, because it has a seperate implementation of the autocompletion feature.

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java

    r2888 r2946  
    135135                        for (FileImporter importer : ExtensionFileFilter.importers) { 
    136136                            if (importer.acceptFile(f)) { 
    137                                 map.add(importer, f); 
     137                                map.put(importer, f); 
    138138                                continue FILES; 
    139139                            } 
     
    146146                for (FileImporter importer : ims) { 
    147147                    //System.err.println("Using "+importer.getClass().getName()); 
    148                     List<File> files = map.get(importer); 
     148                    List<File> files = new ArrayList<File>(map.get(importer)); 
    149149                    //System.err.println("for files: "+files); 
    150150                    importData(importer, files); 
  • trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java

    r2745 r2946  
    2121import org.openstreetmap.josm.gui.tagging.TaggingPresetMenu; 
    2222import org.openstreetmap.josm.gui.tagging.TaggingPresetSeparator; 
     23import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 
    2324import org.openstreetmap.josm.tools.GBC; 
    2425 
     
    8788        else 
    8889        { 
     90            AutoCompletionCache.cachePresets(taggingPresets); 
    8991            HashMap<TaggingPresetMenu,JMenu> submenus = new HashMap<TaggingPresetMenu,JMenu>(); 
    9092            for (final TaggingPreset p : taggingPresets) 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagCellEditor.java

    r2711 r2946  
    6262        // add the list of keys in the current data set 
    6363        // 
    64         for (String key : acCache.getKeys()) { 
    65             autoCompletionList.add( 
    66                     new AutoCompletionListItem(key, AutoCompletionItemPritority.IS_IN_DATASET) 
    67             ); 
    68         } 
     64        acCache.populateWithKeys(autoCompletionList, true); 
    6965 
    7066        // remove the keys already present in the current tag model 
     
    9187            return; 
    9288        } 
    93         autoCompletionList.clear(); 
    94         for (String value : acCache.getValues(forKey)) { 
    95             autoCompletionList.add( 
    96                     new AutoCompletionListItem(value, AutoCompletionItemPritority.IS_IN_DATASET) 
    97             ); 
    98         } 
     89        acCache.populateWithTagValues(autoCompletionList, forKey, false); 
    9990    } 
    10091 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r2905 r2946  
    8282            if (layer == null) return; 
    8383            AutoCompletionList list  = new AutoCompletionList(); 
    84             List<String> values = AutoCompletionCache.getCacheForLayer(Main.main.getEditLayer()).getValues(key); 
    85             list.add(values,AutoCompletionItemPritority.IS_IN_DATASET); 
     84            AutoCompletionCache.getCacheForLayer(Main.main.getEditLayer()).populateWithTagValues(list, key, false); 
    8685            field.setAutoCompletionList(list); 
    8786        } 
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java

    r2621 r2946  
    1010 
    1111import org.openstreetmap.josm.data.osm.OsmPrimitive; 
     12import org.openstreetmap.josm.data.osm.OsmUtils; 
    1213import org.openstreetmap.josm.data.osm.Relation; 
    1314import org.openstreetmap.josm.data.osm.RelationMember; 
     
    1516import org.openstreetmap.josm.gui.layer.Layer; 
    1617import org.openstreetmap.josm.gui.layer.OsmDataLayer; 
     18import org.openstreetmap.josm.gui.tagging.TaggingPreset; 
     19import org.openstreetmap.josm.tools.MultiMap; 
    1720 
    1821/** 
     
    6770    } 
    6871 
    69     /** the cached tags give by a tag key and a list of values for this tag*/ 
    70     private HashMap<String, Set<String>> tagCache; 
     72    /** the cached tags given by a tag key and a list of values for this tag */ 
     73    private MultiMap<String, String> tagCache; 
     74    /**  the layer this cache is built for */ 
     75    private OsmDataLayer layer; 
     76    /** the same as tagCache but for the preset keys and values */ 
     77    private static MultiMap<String, String> presetTagCache = new MultiMap<String, String>(); 
    7178    /** the cached list of member roles */ 
    7279    private  Set<String> roleCache; 
    73     /**  the layer this cache is built for */ 
    74     private OsmDataLayer layer; 
    7580 
    7681    /** 
     
    7883     */ 
    7984    public AutoCompletionCache(OsmDataLayer layer) { 
    80         tagCache = new HashMap<String, Set<String>>(); 
     85        tagCache = new MultiMap<String, String>(); 
    8186        roleCache = new HashSet<String>(); 
    8287        this.layer = layer; 
     
    8590    public AutoCompletionCache() { 
    8691        this(null); 
    87     } 
    88  
    89     /** 
    90      * make sure, <code>key</code> is in the cache 
    91      * 
    92      * @param key  the key 
    93      */ 
    94     protected void cacheKey(String key) { 
    95         if (tagCache.containsKey(key)) 
    96             return; 
    97         tagCache.put(key, new HashSet<String>()); 
    98     } 
    99  
    100     /** 
    101      * make sure, value is one of the auto completion values allowed for key 
    102      * 
    103      * @param key the key 
    104      * @param value the value 
    105      */ 
    106     protected void cacheValue(String key, String value) { 
    107         cacheKey(key); 
    108         tagCache.get(key).add(value); 
    10992    } 
    11093 
     
    118101        for (String key: primitive.keySet()) { 
    119102            String value = primitive.get(key); 
    120             cacheValue(key, value); 
     103            tagCache.put(key, value); 
    121104        } 
    122105    } 
     
    141124     */ 
    142125    public void initFromDataSet() { 
    143         tagCache = new HashMap<String, Set<String>>(); 
     126        tagCache = new MultiMap<String, String>(); 
    144127        if (layer == null) 
    145128            return; 
     
    157140 
    158141    /** 
     142     * Initialize the cache for presets. This is done only once. 
     143     */ 
     144    public static void cachePresets(Collection<TaggingPreset> presets) { 
     145        for (final TaggingPreset p : presets) { 
     146            for (TaggingPreset.Item item : p.data) { 
     147                if (item instanceof TaggingPreset.Check) { 
     148                    TaggingPreset.Check ch = (TaggingPreset.Check) item; 
     149                    presetTagCache.put(ch.key, OsmUtils.falseval); 
     150                    presetTagCache.put(ch.key, OsmUtils.trueval); 
     151                } else if (item instanceof TaggingPreset.Combo) { 
     152                    TaggingPreset.Combo co = (TaggingPreset.Combo) item; 
     153                    for (String value : co.values.split(",")) { 
     154                        presetTagCache.put(co.key, value); 
     155                    } 
     156                } else if (item instanceof TaggingPreset.Key) { 
     157                    TaggingPreset.Key ky = (TaggingPreset.Key) item; 
     158                    presetTagCache.put(ky.key, ky.value); 
     159                } else if (item instanceof TaggingPreset.Text) { 
     160                    TaggingPreset.Text tt = (TaggingPreset.Text) item; 
     161                    presetTagCache.putVoid(tt.key); 
     162                    if (tt.default_ != null && !tt.default_.equals("")) { 
     163                        presetTagCache.put(tt.key, tt.default_); 
     164                    } 
     165                } 
     166            } 
     167        } 
     168    } 
     169     
     170    /** 
    159171     * replies the keys held by the cache 
    160172     * 
    161173     * @return the list of keys held by the cache 
    162174     */ 
    163     public List<String> getKeys() { 
     175    protected List<String> getDataKeys() { 
    164176        return new ArrayList<String>(tagCache.keySet()); 
     177    } 
     178 
     179    protected List<String> getPresetKeys() { 
     180        return new ArrayList<String>(presetTagCache.keySet()); 
    165181    } 
    166182 
     
    172188     * @return the list of auto completion values 
    173189     */ 
    174     public List<String> getValues(String key) { 
    175         if (!tagCache.containsKey(key)) 
    176             return new ArrayList<String>(); 
    177         return new ArrayList<String>(tagCache.get(key)); 
     190    protected List<String> getDataValues(String key) { 
     191        return new ArrayList<String>(tagCache.getValues(key)); 
     192    } 
     193 
     194    protected static List<String> getPresetValues(String key) { 
     195        return new ArrayList<String>(presetTagCache.getValues(key)); 
    178196    } 
    179197 
     
    211229            list.clear(); 
    212230        } 
    213         list.add(getValues(key), AutoCompletionItemPritority.IS_IN_DATASET); 
     231        list.add(getDataValues(key), AutoCompletionItemPritority.IS_IN_DATASET); 
     232        list.add(getPresetValues(key), AutoCompletionItemPritority.IS_IN_STANDARD); 
    214233    } 
    215234 
     
    226245            list.clear(); 
    227246        } 
    228         list.add(tagCache.keySet(), AutoCompletionItemPritority.IS_IN_DATASET); 
     247        list.add(getDataKeys(), AutoCompletionItemPritority.IS_IN_DATASET); 
     248        list.add(getPresetKeys(), AutoCompletionItemPritority.IS_IN_STANDARD); 
    229249    } 
    230250} 
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionItemPritority.java

    r2512 r2946  
    44public enum AutoCompletionItemPritority implements Comparable<AutoCompletionItemPritority> { 
    55 
    6     /** indicates that a value is in the current selection */ 
     6    /** Indicates that a value is in the current selection. */ 
    77    IS_IN_SELECTION, 
    88 
    9     /** indicates that this is a standard value, i.e. a standard tag name 
    10      *  or a standard value for a given tag name 
     9    /** 
     10     * Indicates, that the value is standard and it is found in the data. 
     11     * This has higher priority than some arbitrary standard value that is 
     12     * usually not used by the user. 
     13     */ 
     14    IS_IN_STANDARD_AND_IN_DATASET, 
     15 
     16    /** 
     17     * Indicates that this is a standard value, i.e. a standard tag name 
     18     * or a standard value for a given tag name (from the presets). 
    1119     */ 
    1220    IS_IN_STANDARD, 
    1321 
    1422    /** 
    15      * indicates that this is an arbitrary value from the data set, i.e. 
    16      * the value of a tag name=xxx 
     23     * Indicates that this is an arbitrary value from the data set, i.e. 
     24     * the value of a tag name=*. 
    1725     */ 
    1826    IS_IN_DATASET, 
    1927 
    20     /** unknown priority. This is the lowest priority. */ 
     28    /** Unknown priority. This is the lowest priority. */ 
    2129    UNKNOWN 
    2230} 
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java

    r2512 r2946  
    157157        } else { 
    158158            // new item already exists. Update priority if necessary 
    159             // 
    160             if (toadd.getPriority().compareTo(item.getPriority()) < 0) { 
    161                 item.setPriority(toadd.getPriority()); 
     159 
     160            // If it is both in the dataset and in the presets, update the priority. 
     161            final AutoCompletionItemPritority IS_IN_DATASET = AutoCompletionItemPritority.IS_IN_DATASET; 
     162            final AutoCompletionItemPritority IS_IN_STANDARD = AutoCompletionItemPritority.IS_IN_STANDARD; 
     163            if ((toadd.getPriority() == IS_IN_STANDARD && item.getPriority() == IS_IN_DATASET) || 
     164                (toadd.getPriority() == IS_IN_DATASET && item.getPriority() == IS_IN_STANDARD)) { 
     165 
     166                item.setPriority(AutoCompletionItemPritority.IS_IN_STANDARD_AND_IN_DATASET); 
     167            } else { 
     168                if (toadd.getPriority().compareTo(item.getPriority()) < 0) { 
     169                    item.setPriority(toadd.getPriority()); 
     170                } 
    162171            } 
    163172        } 
  • trunk/src/org/openstreetmap/josm/tools/MultiMap.java

    r2702 r2946  
    22package org.openstreetmap.josm.tools; 
    33 
    4 import java.util.ArrayList; 
     4import java.util.LinkedHashSet; 
    55import java.util.List; 
    66import java.util.HashMap; 
    77 
    88/** 
    9  * Maps keys to a list of values. Partial implementation. Extend if you need more! 
     9 * Maps keys to ordered sets of values. 
    1010 */ 
    11 public class MultiMap<A, B> extends HashMap<A, List<B>> { 
    12     public void add(A key, B value) { 
    13         List<B> vals = get(key); 
     11public class MultiMap<A, B> extends HashMap<A, LinkedHashSet<B>> { 
     12    /** 
     13     * Map a key to a value. Can be called multiple times with the same key, but different value. 
     14     */ 
     15    public void put(A key, B value) { 
     16        LinkedHashSet<B> vals = get(key); 
    1417        if (vals == null) { 
    15             vals = new ArrayList<B>(); 
     18            vals = new LinkedHashSet<B>(); 
    1619            put(key, vals); 
    1720        } 
    1821        vals.add(value); 
    1922    } 
     23     
     24    /** 
     25     * Put a key that maps to nothing. 
     26     */ 
     27    public void putVoid(A key) { 
     28        if (containsKey(key)) 
     29            return; 
     30        put(key, new LinkedHashSet<B>()); 
     31    } 
     32 
     33    /** 
     34     * Returns a list of values for the given key 
     35     * or an empty list, if it maps to nothing. 
     36     */ 
     37    public LinkedHashSet<B> getValues(A key) { 
     38        if (!containsKey(key)) 
     39            return new LinkedHashSet<B>(); 
     40        return get(key); 
     41    } 
    2042} 
Note: See TracChangeset for help on using the changeset viewer.