Changeset 15835 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-02-10T22:58:04+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r15834 r15835 89 89 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; 90 90 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 91 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;92 91 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 93 92 import org.openstreetmap.josm.gui.util.GuiHelper; … … 96 95 import org.openstreetmap.josm.io.XmlWriter; 97 96 import org.openstreetmap.josm.tools.GBC; 97 import org.openstreetmap.josm.tools.ImageProvider; 98 98 import org.openstreetmap.josm.tools.Logging; 99 99 import org.openstreetmap.josm.tools.PlatformManager; … … 501 501 addFocusAdapter(autocomplete, usedValuesAwareComparator); 502 502 503 addUpdateIconListener(); 504 503 505 setContent(mainPanel, false); 504 506 … … 517 519 @Override 518 520 public void performTagEdit() { 519 String value = Utils.removeWhiteSpaces(values.getEditor().getItem().toString());521 String value = values.getEditItem(); 520 522 value = Normalizer.normalize(value, Normalizer.Form.NFC); 521 523 if (value.isEmpty()) { 522 524 value = null; // delete the key 523 525 } 524 String newkey = Utils.removeWhiteSpaces(keys.getEditor().getItem().toString());526 String newkey = keys.getEditItem(); 525 527 newkey = Normalizer.normalize(newkey, Normalizer.Form.NFC); 526 528 if (newkey.isEmpty()) { … … 610 612 } 611 613 keys.setFixedLocale(PROPERTY_FIX_TAG_LOCALE.get()); 614 updateOkButtonIcon(); 612 615 } 613 616 super.setVisible(visible); … … 672 675 } 673 676 674 private Optional<ImageIcon> findIcon(Tag tag) { 675 // Find and display icon 676 ImageIcon icon = MapPaintStyles.getNodeIcon(tag, false); // Filters deprecated icon 677 if (icon != null) { 678 return Optional.of(icon); 679 } 680 // If no icon found in map style look at presets 681 return TaggingPresets.getMatchingPresets(null, tag.getKeys(), false).stream() 682 .map(TaggingPreset::getIcon) 677 protected void addUpdateIconListener() { 678 keys.addActionListener(ignore -> updateOkButtonIcon()); 679 values.addActionListener(ignore -> updateOkButtonIcon()); 680 } 681 682 private void updateOkButtonIcon() { 683 if (buttons.isEmpty()) { 684 return; 685 } 686 final Tag tag = new Tag(keys.getSelectedOrEditItem(), values.getSelectedOrEditItem()); 687 buttons.get(0).setIcon(findIcon(tag) 688 .orElse(ImageProvider.get("ok", ImageProvider.ImageSizes.LARGEICON))); 689 } 690 691 protected Optional<ImageIcon> findIcon(Tag tag) { 692 final Optional<ImageIcon> taggingPresetIcon = TaggingPresets.getMatchingPresets(null, tag.getKeys(), false).stream() 693 .map(preset -> preset.getIcon(Action.LARGE_ICON_KEY)) 683 694 .filter(Objects::nonNull) 684 695 .findFirst(); 696 // Java 9: use Optional.or 697 return taggingPresetIcon.isPresent() ? taggingPresetIcon : Optional.ofNullable(MapPaintStyles.getNodeIcon(tag, false)); 685 698 } 686 699 … … 755 768 // fire focus event in advance or otherwise the popup list will be too small at first 756 769 focus.focusGained(null); 770 771 addUpdateIconListener(); 757 772 758 773 // Add tag on Shift-Enter … … 1078 1093 */ 1079 1094 public final void performTagAdding() { 1080 String key = Utils.removeWhiteSpaces(keys.getEditor().getItem().toString());1081 String value = Utils.removeWhiteSpaces(values.getEditor().getItem().toString());1095 String key = keys.getEditItem(); 1096 String value = values.getEditItem(); 1082 1097 if (key.isEmpty() || value.isEmpty()) 1083 1098 return; -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java
r15567 r15835 33 33 import org.openstreetmap.josm.spi.preferences.Config; 34 34 import org.openstreetmap.josm.tools.Logging; 35 import org.openstreetmap.josm.tools.Utils; 35 36 36 37 /** … … 386 387 387 388 /** 389 * Returns the edited item with whitespaces removed 390 * @return the edited item with whitespaces removed 391 * @since 15835 392 */ 393 public String getEditItem() { 394 return Utils.removeWhiteSpaces(getEditor().getItem().toString()); 395 } 396 397 /** 398 * Returns the selected item or the edited item as string 399 * @return the selected item or the edited item as string 400 * @see #getSelectedItem() 401 * @see #getEditItem() 402 * @since 15835 403 */ 404 public String getSelectedOrEditItem() { 405 final Object selectedItem = getSelectedItem(); 406 if (selectedItem instanceof AutoCompletionItem) { 407 return ((AutoCompletionItem) selectedItem).getValue(); 408 } else if (selectedItem instanceof String) { 409 return (String) selectedItem; 410 } else { 411 return getEditItem(); 412 } 413 } 414 415 /** 388 416 * ListCellRenderer for AutoCompletingComboBox 389 417 * renders an AutoCompletionListItem by showing only the string value part
Note:
See TracChangeset
for help on using the changeset viewer.