Changeset 9939 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r9877 r9939 35 35 import java.util.HashMap; 36 36 import java.util.Iterator; 37 import java.util.LinkedHashMap;38 import java.util.LinkedList;39 37 import java.util.List; 40 38 import java.util.Map; … … 70 68 import org.openstreetmap.josm.data.osm.Tag; 71 69 import org.openstreetmap.josm.data.preferences.BooleanProperty; 70 import org.openstreetmap.josm.data.preferences.CollectionProperty; 72 71 import org.openstreetmap.josm.data.preferences.EnumProperty; 73 72 import org.openstreetmap.josm.data.preferences.IntegerProperty; … … 125 124 public static final IntegerProperty PROPERTY_RECENT_TAGS_NUMBER = new IntegerProperty("properties.recently-added-tags", 126 125 DEFAULT_LRU_TAGS_NUMBER); 126 /** The preference storage of recent tags */ 127 public static final CollectionProperty COLLECTION_PROPERTY = new CollectionProperty("properties.recent-tags", 128 Collections.<String>emptyList()); 127 129 128 130 /** … … 156 158 "properties.refresh-recently-added-tags", RefreshRecent.class, RefreshRecent.STATUS); 157 159 158 // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html) 159 private final Map<Tag, Void> recentTags = new LinkedHashMap<Tag, Void>(MAX_LRU_TAGS_NUMBER+1, 1.1f, true) { 160 @Override 161 protected boolean removeEldestEntry(Map.Entry<Tag, Void> eldest) { 162 return size() > MAX_LRU_TAGS_NUMBER; 163 } 164 }; 160 final RecentTagCollection recentTags = new RecentTagCollection(MAX_LRU_TAGS_NUMBER); 165 161 166 162 // Copy of recently added tags, used to cache initial status … … 291 287 public void loadTagsIfNeeded() { 292 288 if (PROPERTY_REMEMBER_TAGS.get() && recentTags.isEmpty()) { 293 recentTags.clear(); 294 Collection<String> c = Main.pref.getCollection("properties.recent-tags"); 295 Iterator<String> it = c.iterator(); 296 while (it.hasNext()) { 297 String key = it.next(); 298 String value = it.next(); 299 recentTags.put(new Tag(key, value), null); 300 } 289 recentTags.loadFromPreference(COLLECTION_PROPERTY); 301 290 } 302 291 } … … 307 296 public void saveTagsIfNeeded() { 308 297 if (PROPERTY_REMEMBER_TAGS.get() && !recentTags.isEmpty()) { 309 List<String> c = new ArrayList<>(recentTags.size()*2); 310 for (Tag t: recentTags.keySet()) { 311 c.add(t.getKey()); 312 c.add(t.getValue()); 313 } 314 Main.pref.putCollection("properties.recent-tags", c); 298 recentTags.saveToPreference(COLLECTION_PROPERTY); 315 299 } 316 300 } … … 320 304 */ 321 305 private void cacheRecentTags() { 322 tags = new LinkedList<>(recentTags.keySet());306 tags = recentTags.toList(); 323 307 } 324 308 … … 857 841 // This implies to iterate in descending order, as the oldest elements will only be removed after we reach the maximum 858 842 // number and not the number of tags to show. 859 // However, as Set does not allow to iterate in descending order, we need to copy its elements into a List we can access860 // in reverse order.861 843 for (int i = tags.size()-1; i >= 0 && count < tagsToShow; i--) { 862 844 final Tag t = tags.get(i); … … 995 977 lastAddKey = key; 996 978 lastAddValue = value; 997 recentTags. put(new Tag(key, value), null);979 recentTags.add(new Tag(key, value)); 998 980 valueCount.put(key, new TreeMap<String, Integer>()); 999 981 AutoCompletionManager.rememberUserInput(key, value, false);
Note:
See TracChangeset
for help on using the changeset viewer.