Changeset 34768 in osm
- Timestamp:
- 2018-12-07T16:20:47+01:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/build.xml
r34454 r34768 5 5 <property name="commit.message" value="[josm_utilsplugin2]: select boundary by double-click; multitagger table highlights"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="14 153"/>7 <property name="plugin.main.version" value="14518"/> 8 8 9 9 <property name="plugin.author" value="Kalle Lampila, Upliner, Zverik, akks, joshdoe and others"/> -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagBufferAction.java
r34454 r34768 8 8 import java.util.ArrayList; 9 9 import java.util.Collection; 10 import java.util.HashMap;11 10 import java.util.HashSet; 12 11 import java.util.List; 13 import java.util.Map;14 12 import java.util.Set; 15 import java.util.function.Predicate;16 13 17 14 import org.openstreetmap.josm.actions.JosmAction; … … 21 18 import org.openstreetmap.josm.data.UndoRedoHandler; 22 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 import org.openstreetmap.josm.data.osm.Tag; 21 import org.openstreetmap.josm.data.osm.TagCollection; 23 22 import org.openstreetmap.josm.tools.Shortcut; 24 23 import org.openstreetmap.josm.tools.SubclassFilteredCollection; … … 31 30 public class TagBufferAction extends JosmAction { 32 31 private static final String TITLE = tr("Copy tags from previous selection"); 33 private static final Predicate<OsmPrimitive> IS_TAGGED_PREDICATE = object -> object.isTagged(); 34 private Map<String, String> tags = new HashMap<>(); 35 private Map<String, String> currentTags = new HashMap<>(); 36 private Set<OsmPrimitive> selectionBuf = new HashSet<>(); 37 32 private static final TagCollection EmptyTags = new TagCollection(); 33 private final Set<OsmPrimitive> selectionBuf = new HashSet<>(); 34 private TagCollection tagsToPaste = EmptyTags; 38 35 /** 39 36 * Constructs a new {@code TagBufferAction}. … … 51 48 public void actionPerformed(ActionEvent e) { 52 49 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 53 if (selection.isEmpty() )50 if (selection.isEmpty() || tagsToPaste.isEmpty()) 54 51 return; 55 52 56 53 List<Command> commands = new ArrayList<>(); 57 for (String key : tags.keySet()) { 58 String value = tags.get(key); 54 for (Tag tag : tagsToPaste) { 59 55 boolean foundNew = false; 60 56 for (OsmPrimitive p : selection) { 61 if (!p.has Key(key) || !p.get(key).equals(value)) {57 if (!p.hasTag(tag.getKey(), tag.getValue())) { 62 58 foundNew = true; 63 59 break; … … 65 61 } 66 62 if (foundNew) 67 commands.add(new ChangePropertyCommand(selection, key, value));63 commands.add(new ChangePropertyCommand(selection, tag.getKey(), tag.getValue())); 68 64 } 69 65 … … 76 72 if (getLayerManager().getEditDataSet() == null) { 77 73 setEnabled(false); 78 if (selectionBuf != null)79 selectionBuf.clear();74 selectionBuf.clear(); 75 tagsToPaste = EmptyTags; 80 76 } else 81 77 updateEnabledState(getLayerManager().getEditDataSet().getSelected()); … … 84 80 @Override 85 81 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 86 // selection changed => check if selection is completely different from before 87 boolean foundOld = false; 88 if (selection != null) { 89 for (OsmPrimitive p : selectionBuf) { 90 if (selection.contains(p)) { 91 foundOld = true; 92 break; 93 } 94 } 95 selectionBuf.clear(); 96 selectionBuf.addAll(selection); 97 } else { 98 foundOld = selectionBuf.isEmpty(); 99 selectionBuf.clear(); 100 } 101 if (!foundOld) { 102 // selection has completely changed, remember tags 103 tags.clear(); 104 tags.putAll(currentTags); 105 } 106 if (getLayerManager().getEditDataSet() != null) 107 rememberSelectionTags(); 82 TagCollection oldTags = getCommonTags(selectionBuf); 83 if (!oldTags.isEmpty()) { 84 tagsToPaste = new TagCollection(oldTags); 85 } 86 selectionBuf.clear(); 87 selectionBuf.addAll(selection); 108 88 109 setEnabled( selection != null && !selection.isEmpty() && !tags.isEmpty());89 setEnabled(!selection.isEmpty() && !tagsToPaste.isEmpty()); 110 90 } 111 91 112 private void rememberSelectionTags() { 113 // Fix #8350 - only care about tagged objects 114 final Collection<OsmPrimitive> selectedTaggedObjects = SubclassFilteredCollection.filter( 115 getLayerManager().getEditDataSet().getSelected(), IS_TAGGED_PREDICATE); 116 if (!selectedTaggedObjects.isEmpty()) { 117 currentTags.clear(); 118 Set<String> bad = new HashSet<>(); 119 for (OsmPrimitive p : selectedTaggedObjects) { 120 if (currentTags.isEmpty()) { 121 for (String key : p.keySet()) { 122 currentTags.put(key, p.get(key)); 123 } 124 } else { 125 for (String key : p.keySet()) { 126 if (!currentTags.containsKey(key) || !currentTags.get(key).equals(p.get(key))) 127 bad.add(key); 128 } 129 for (String key : currentTags.keySet()) { 130 if (!p.hasKey(key)) 131 bad.add(key); 132 } 133 } 134 } 135 for (String key : bad) { 136 currentTags.remove(key); 137 } 138 } 92 /** 93 * Find those tags which appear in all primitives of the selection 94 * @param selection the selection 95 */ 96 private static TagCollection getCommonTags(Set<OsmPrimitive> selection) { 97 if (selection.isEmpty()) 98 return EmptyTags; 99 // // Fix #8350 - only care about tagged objects 100 return TagCollection.commonToAllPrimitives(SubclassFilteredCollection.filter(selection, p -> p.isTagged())); 139 101 } 140 102 }
Note:
See TracChangeset
for help on using the changeset viewer.