Changeset 2946 in josm for trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java
- Timestamp:
- 06.02.2010 17:37:52 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java
r2621 r2946 10 10 11 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 import org.openstreetmap.josm.data.osm.OsmUtils; 12 13 import org.openstreetmap.josm.data.osm.Relation; 13 14 import org.openstreetmap.josm.data.osm.RelationMember; … … 15 16 import org.openstreetmap.josm.gui.layer.Layer; 16 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 18 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 19 import org.openstreetmap.josm.tools.MultiMap; 17 20 18 21 /** … … 67 70 } 68 71 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>(); 71 78 /** the cached list of member roles */ 72 79 private Set<String> roleCache; 73 /** the layer this cache is built for */74 private OsmDataLayer layer;75 80 76 81 /** … … 78 83 */ 79 84 public AutoCompletionCache(OsmDataLayer layer) { 80 tagCache = new HashMap<String, Set<String>>();85 tagCache = new MultiMap<String, String>(); 81 86 roleCache = new HashSet<String>(); 82 87 this.layer = layer; … … 85 90 public AutoCompletionCache() { 86 91 this(null); 87 }88 89 /**90 * make sure, <code>key</code> is in the cache91 *92 * @param key the key93 */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 key102 *103 * @param key the key104 * @param value the value105 */106 protected void cacheValue(String key, String value) {107 cacheKey(key);108 tagCache.get(key).add(value);109 92 } 110 93 … … 118 101 for (String key: primitive.keySet()) { 119 102 String value = primitive.get(key); 120 cacheValue(key, value);103 tagCache.put(key, value); 121 104 } 122 105 } … … 141 124 */ 142 125 public void initFromDataSet() { 143 tagCache = new HashMap<String, Set<String>>();126 tagCache = new MultiMap<String, String>(); 144 127 if (layer == null) 145 128 return; … … 157 140 158 141 /** 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 /** 159 171 * replies the keys held by the cache 160 172 * 161 173 * @return the list of keys held by the cache 162 174 */ 163 p ublic List<String> getKeys() {175 protected List<String> getDataKeys() { 164 176 return new ArrayList<String>(tagCache.keySet()); 177 } 178 179 protected List<String> getPresetKeys() { 180 return new ArrayList<String>(presetTagCache.keySet()); 165 181 } 166 182 … … 172 188 * @return the list of auto completion values 173 189 */ 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)); 178 196 } 179 197 … … 211 229 list.clear(); 212 230 } 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); 214 233 } 215 234 … … 226 245 list.clear(); 227 246 } 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); 229 249 } 230 250 }
Note: See TracChangeset
for help on using the changeset viewer.
