Changeset 2946 in josm for trunk/src/org
- Timestamp:
- 2010-02-06T17:37:52+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java
r2888 r2946 135 135 for (FileImporter importer : ExtensionFileFilter.importers) { 136 136 if (importer.acceptFile(f)) { 137 map. add(importer, f);137 map.put(importer, f); 138 138 continue FILES; 139 139 } … … 146 146 for (FileImporter importer : ims) { 147 147 //System.err.println("Using "+importer.getClass().getName()); 148 List<File> files = map.get(importer);148 List<File> files = new ArrayList<File>(map.get(importer)); 149 149 //System.err.println("for files: "+files); 150 150 importData(importer, files); -
trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java
r2745 r2946 21 21 import org.openstreetmap.josm.gui.tagging.TaggingPresetMenu; 22 22 import org.openstreetmap.josm.gui.tagging.TaggingPresetSeparator; 23 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 23 24 import org.openstreetmap.josm.tools.GBC; 24 25 … … 87 88 else 88 89 { 90 AutoCompletionCache.cachePresets(taggingPresets); 89 91 HashMap<TaggingPresetMenu,JMenu> submenus = new HashMap<TaggingPresetMenu,JMenu>(); 90 92 for (final TaggingPreset p : taggingPresets) -
trunk/src/org/openstreetmap/josm/gui/tagging/TagCellEditor.java
r2711 r2946 62 62 // add the list of keys in the current data set 63 63 // 64 for (String key : acCache.getKeys()) { 65 autoCompletionList.add( 66 new AutoCompletionListItem(key, AutoCompletionItemPritority.IS_IN_DATASET) 67 ); 68 } 64 acCache.populateWithKeys(autoCompletionList, true); 69 65 70 66 // remove the keys already present in the current tag model … … 91 87 return; 92 88 } 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); 99 90 } 100 91 -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r2905 r2946 82 82 if (layer == null) return; 83 83 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); 86 85 field.setAutoCompletionList(list); 87 86 } -
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 } -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionItemPritority.java
r2512 r2946 4 4 public enum AutoCompletionItemPritority implements Comparable<AutoCompletionItemPritority> { 5 5 6 /** indicates that a value is in the current selection*/6 /** Indicates that a value is in the current selection. */ 7 7 IS_IN_SELECTION, 8 8 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). 11 19 */ 12 20 IS_IN_STANDARD, 13 21 14 22 /** 15 * indicates that this is an arbitrary value from the data set, i.e.16 * the value of a tag name= xxx23 * Indicates that this is an arbitrary value from the data set, i.e. 24 * the value of a tag name=*. 17 25 */ 18 26 IS_IN_DATASET, 19 27 20 /** unknown priority. This is the lowest priority. */28 /** Unknown priority. This is the lowest priority. */ 21 29 UNKNOWN 22 30 } -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java
r2512 r2946 157 157 } else { 158 158 // 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 } 162 171 } 163 172 } -
trunk/src/org/openstreetmap/josm/tools/MultiMap.java
r2702 r2946 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.util. ArrayList;4 import java.util.LinkedHashSet; 5 5 import java.util.List; 6 6 import java.util.HashMap; 7 7 8 8 /** 9 * Maps keys to a list of values. Partial implementation. Extend if you need more!9 * Maps keys to ordered sets of values. 10 10 */ 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); 11 public 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); 14 17 if (vals == null) { 15 vals = new ArrayList<B>();18 vals = new LinkedHashSet<B>(); 16 19 put(key, vals); 17 20 } 18 21 vals.add(value); 19 22 } 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 } 20 42 }
Note:
See TracChangeset
for help on using the changeset viewer.