Changeset 16057 in josm
- Timestamp:
- 2020-03-07T15:27:23+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/tagging/presets/items
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Combo.java
r16045 r16057 37 37 if (!usage.unused()) { 38 38 for (String s : usage.values) { 39 if (!lhm.containsKey(s)) { 40 lhm.put(s, new PresetListEntry(s)); 41 } 39 presetListEntries.add(new PresetListEntry(s)); 42 40 } 43 41 } 44 if (def != null && !lhm.containsKey(def)) {45 lhm.put(def,new PresetListEntry(def));42 if (def != null) { 43 presetListEntries.add(new PresetListEntry(def)); 46 44 } 47 if (!lhm.containsKey("")) { 48 lhm.put("", new PresetListEntry("")); 49 } 45 presetListEntries.add(new PresetListEntry("")); 50 46 51 combobox = new JosmComboBox<>( lhm.values().toArray(new PresetListEntry[lhm.size()]));47 combobox = new JosmComboBox<>(presetListEntries.toArray(new PresetListEntry[0])); 52 48 component = combobox; 53 49 combobox.setRenderer(getListCellRenderer()); 54 50 combobox.setEditable(editable); 55 combobox.reinitialize( lhm.values());51 combobox.reinitialize(presetListEntries); 56 52 AutoCompletingTextField tf = new AutoCompletingTextField(); 57 53 initAutoCompletionField(tf, key); … … 70 66 if (usage.hasUniqueValue()) { 71 67 // all items have the same value (and there were no unset items) 72 originalValue = lhm.get(usage.getFirst());68 originalValue = getListEntry(usage.getFirst()); 73 69 combobox.setSelectedItem(originalValue); 74 70 } else if (def != null && usage.unused()) { … … 76 72 if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || isForceUseLastAsDefault()) { 77 73 // selected osm primitives are untagged or filling default feature is enabled 78 combobox.setSelectedItem( lhm.get(def).getDisplayValue(true));74 combobox.setSelectedItem(getListEntry(def).getDisplayValue()); 79 75 } else { 80 76 // selected osm primitives are tagged and filling default feature is disabled 81 77 combobox.setSelectedItem(""); 82 78 } 83 originalValue = lhm.get(DIFFERENT);79 originalValue = getListEntry(DIFFERENT); 84 80 } else if (usage.unused()) { 85 81 // all items were unset (and so is default) 86 originalValue = lhm.get("");82 originalValue = getListEntry(""); 87 83 if (!presetInitiallyMatches && isForceUseLastAsDefault() && LAST_VALUES.containsKey(key)) { 88 combobox.setSelectedItem( lhm.get(LAST_VALUES.get(key)));84 combobox.setSelectedItem(getListEntry(LAST_VALUES.get(key))); 89 85 } else { 90 86 combobox.setSelectedItem(originalValue); 91 87 } 92 88 } else { 93 originalValue = lhm.get(DIFFERENT);89 originalValue = getListEntry(DIFFERENT); 94 90 combobox.setSelectedItem(originalValue); 95 91 } -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java
r16053 r16057 14 14 import java.util.Collection; 15 15 import java.util.Collections; 16 import java.util.LinkedHashMap;17 16 import java.util.List; 18 import java.util.Map; 19 import java.util.Map.Entry; 17 import java.util.Objects; 20 18 import java.util.Set; 21 19 import java.util.TreeSet; 20 import java.util.concurrent.CopyOnWriteArraySet; 22 21 import java.util.stream.Collectors; 23 22 … … 98 97 99 98 protected JComponent component; 100 protected final Map<String, PresetListEntry> lhm = new LinkedHashMap<>();99 protected final Set<PresetListEntry> presetListEntries = new CopyOnWriteArraySet<>(); 101 100 private boolean initialized; 102 101 protected Usage usage; … … 253 252 return "<b>" + Utils.escapeReservedCharactersHTML(DIFFERENT) + "</b>"; 254 253 255 String displayValue = Utils.escapeReservedCharactersHTML(getDisplayValue( true));254 String displayValue = Utils.escapeReservedCharactersHTML(getDisplayValue()); 256 255 String shortDescription = getShortDescription(true); 257 256 … … 279 278 /** 280 279 * Returns the value to display. 281 * @param translated whether the text must be translated282 280 * @return the value to display 283 281 */ 284 public String getDisplayValue(boolean translated) { 285 return translated 286 ? Utils.firstNonNull(locale_display_value, tr(display_value), trc(value_context, value)) 287 : Utils.firstNonNull(display_value, value); 282 public String getDisplayValue() { 283 return Utils.firstNonNull(locale_display_value, tr(display_value), trc(value_context, value)); 288 284 } 289 285 … … 304 300 if (DIFFERENT.equals(value)) 305 301 return DIFFERENT; 306 String displayValue = getDisplayValue( true);302 String displayValue = getDisplayValue(); 307 303 return displayValue != null ? displayValue.replaceAll("<.*>", "") : ""; // remove additional markup, e.g. <br> 304 } 305 306 @Override 307 public boolean equals(Object o) { 308 if (this == o) return true; 309 if (o == null || getClass() != o.getClass()) return false; 310 PresetListEntry that = (PresetListEntry) o; 311 return Objects.equals(value, that.value); 312 } 313 314 @Override 315 public int hashCode() { 316 return Objects.hash(value); 308 317 } 309 318 310 319 @Override 311 320 public int compareTo(PresetListEntry o) { 312 return AlphanumComparator.getInstance().compare(this.getDisplayValue( true), o.getDisplayValue(true));321 return AlphanumComparator.getInstance().compare(this.getDisplayValue(), o.getDisplayValue()); 313 322 } 314 323 } … … 355 364 public Collection<String> getValues() { 356 365 initListEntries(); 357 return lhm.keySet();366 return presetListEntries.stream().map(x -> x.value).collect(Collectors.toSet()); 358 367 } 359 368 … … 364 373 public Collection<String> getDisplayValues() { 365 374 initListEntries(); 366 return lhm.values().stream().map(x -> x.getDisplayValue(true)).collect(Collectors.toList());375 return presetListEntries.stream().map(PresetListEntry::getDisplayValue).collect(Collectors.toList()); 367 376 } 368 377 … … 374 383 usage = determineTextUsage(sel, key); 375 384 if (!usage.hasUniqueValue() && !usage.unused()) { 376 lhm.put(DIFFERENT,new PresetListEntry(DIFFERENT));385 presetListEntries.add(new PresetListEntry(DIFFERENT)); 377 386 } 378 387 … … 389 398 private void initListEntries() { 390 399 if (initialized) { 391 lhm.remove(DIFFERENT); // possibly added in #addToPanel400 presetListEntries.remove(new PresetListEntry(DIFFERENT)); // possibly added in #addToPanel 392 401 return; 393 } else if ( lhm.isEmpty()) {402 } else if (presetListEntries.isEmpty()) { 394 403 initListEntriesFromAttributes(); 395 404 } else { … … 409 418 key, text, "short_descriptions", "list_entry")); 410 419 } 411 for (PresetListEntry e : lhm.values()) {420 for (PresetListEntry e : presetListEntries) { 412 421 if (e.value_context == null) { 413 422 e.value_context = values_context; … … 493 502 } 494 503 495 for (PresetListEntry i : entries) { 496 lhm.put(i.value, i); 497 } 504 addListEntries(entries); 498 505 } 499 506 … … 509 516 510 517 if (display != null) { 511 for ( Entry<String, PresetListEntry> entry : lhm.entrySet()) {512 String k = entry. getValue().toString();518 for (PresetListEntry entry : presetListEntries) { 519 String k = entry.toString(); 513 520 if (k.equals(display)) { 514 value = entry. getKey();521 value = entry.value; 515 522 break; 516 523 } … … 560 567 */ 561 568 public void addListEntry(PresetListEntry e) { 562 lhm.put(e.value,e);569 presetListEntries.add(e); 563 570 } 564 571 … … 573 580 } 574 581 582 protected PresetListEntry getListEntry(String value) { 583 return presetListEntries.stream().filter(e -> Objects.equals(e.value, value)).findFirst().orElse(null); 584 } 585 575 586 protected ListCellRenderer<PresetListEntry> getListCellRenderer() { 576 587 return RENDERER; -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/MultiSelect.java
r16045 r16057 26 26 @Override 27 27 protected void addToPanelAnchor(JPanel p, String def, boolean presetInitiallyMatches) { 28 list = new ConcatenatingJList(delimiter, lhm.values().toArray(new PresetListEntry[lhm.size()]));28 list = new ConcatenatingJList(delimiter, presetListEntries.toArray(new PresetListEntry[0])); 29 29 component = list; 30 30 ListCellRenderer<PresetListEntry> renderer = getListCellRenderer();
Note:
See TracChangeset
for help on using the changeset viewer.