Ticket #6306: 6306_v2.patch
File 6306_v2.patch, 5.7 KB (added by , 14 years ago) |
---|
-
src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java
2 2 package org.openstreetmap.josm.gui.tagging.ac; 3 3 4 4 import java.util.ArrayList; 5 import java.util.Arrays; 5 6 import java.util.Collection; 6 7 import java.util.Collections; 7 8 import java.util.HashSet; … … 242 243 * tag keys 243 244 * 244 245 * @param list the list to populate 245 * @param append true to add the keys to the list; false, to replace the keys246 * in the list by the keys in the cache247 246 */ 248 247 public void populateWithKeys(AutoCompletionList list) { 249 248 list.add(getPresetKeys(), AutoCompletionItemPritority.IS_IN_STANDARD); … … 256 255 * 257 256 * @param list the list to populate 258 257 * @param key the tag key 259 * @param append true to add the values to the list; false, to replace the values260 * in the list by the tag values261 258 */ 262 259 public void populateWithTagValues(AutoCompletionList list, String key) { 263 list.add(getPresetValues(key), AutoCompletionItemPritority.IS_IN_STANDARD); 264 list.add(getDataValues(key), AutoCompletionItemPritority.IS_IN_DATASET); 260 populateWithTagValues(list, Arrays.asList(key)); 265 261 } 266 262 263 /** 264 * Populates the an {@see AutoCompletionList} with the currently cached 265 * values for some given tags 266 * 267 * @param list the list to populate 268 * @param key the tag keys 269 */ 270 public void populateWithTagValues(AutoCompletionList list, List<String> keys) { 271 for (String key : keys) { 272 list.add(getPresetValues(key), AutoCompletionItemPritority.IS_IN_STANDARD); 273 list.add(getDataValues(key), AutoCompletionItemPritority.IS_IN_DATASET); 274 } 275 } 276 277 /** 278 * Returns the currently cached tag keys. 279 * @return a list of tag keys 280 */ 267 281 public List<AutoCompletionListItem> getKeys() { 268 282 AutoCompletionList list = new AutoCompletionList(); 269 283 populateWithKeys(list); 270 return new ArrayList<AutoCompletionListItem>(list.getList());284 return list.getList(); 271 285 } 272 286 287 /** 288 * Returns the currently cached tag values for a given tag key. 289 * @param key the tag key 290 * @return a list of tag values 291 */ 273 292 public List<AutoCompletionListItem> getValues(String key) { 293 return getValues(Arrays.asList(key)); 294 } 295 296 /** 297 * Returns the currently cached tag values for a given list of tag keys. 298 * @param keys the tag keys 299 * @return a list of tag values 300 */ 301 public List<AutoCompletionListItem> getValues(List<String> keys) { 274 302 AutoCompletionList list = new AutoCompletionList(); 275 populateWithTagValues(list, key );276 return new ArrayList<AutoCompletionListItem>(list.getList());303 populateWithTagValues(list, keys); 304 return list.getList(); 277 305 } 278 306 279 307 /********************************************************* -
src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java
257 257 return filtered.get(idx); 258 258 } 259 259 260 List<AutoCompletionListItem> getList() { 260 ArrayList<AutoCompletionListItem> getList() { 261 return list; 262 } 263 264 List<AutoCompletionListItem> getUnmodifiableList() { 261 265 return Collections.unmodifiableList(list); 262 266 } 263 267 -
src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
22 22 import java.net.URI; 23 23 import java.net.URLEncoder; 24 24 import java.util.ArrayList; 25 import java.util.Arrays; 25 26 import java.util.Collection; 26 27 import java.util.Collections; 27 28 import java.util.Comparator; … … 248 249 }); 249 250 values.setEditable(true); 250 251 251 List<AutoCompletionListItem> valueList = autocomplete.getValues( key);252 List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key)); 252 253 Collections.sort(valueList, defaultACItemComparator); 253 254 254 255 values.setPossibleACItems(valueList); … … 368 369 } 369 370 370 371 /** 372 * For a given key k, return a list of keys which are used as keys for 373 * auto-completing values to increase the search space. 374 * @param key the key k 375 * @return a list of keys 376 */ 377 static List<String> getAutocompletionKeys(String key) { 378 if ("name".equals(key) || "addr:street".equals(key)) { 379 return Arrays.asList("addr:street", "name"); 380 } else { 381 return Arrays.asList(key); 382 } 383 } 384 385 /** 371 386 * This simply fires up an relation editor for the relation shown; everything else 372 387 * is the editor's business. 373 388 * … … 477 492 @Override public void focusGained(FocusEvent e) { 478 493 String key = keys.getEditor().getItem().toString(); 479 494 480 List<AutoCompletionListItem> valueList = autocomplete.getValues( key);495 List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key)); 481 496 Collections.sort(valueList, defaultACItemComparator); 482 497 483 498 values.setPossibleACItems(valueList);