Changeset 2220 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2009-09-30T20:00:57+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r2210 r2220 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.combineTigerTags; 5 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.completeTagCollectionForEditing; 6 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing; 4 7 import static org.openstreetmap.josm.tools.I18n.tr; 5 8 … … 30 33 import org.openstreetmap.josm.data.osm.Relation; 31 34 import org.openstreetmap.josm.data.osm.RelationMember; 32 import org.openstreetmap.josm.data.osm.Tag;33 35 import org.openstreetmap.josm.data.osm.TagCollection; 34 import org.openstreetmap.josm.data.osm.TigerUtils;35 36 import org.openstreetmap.josm.data.osm.Way; 36 37 import org.openstreetmap.josm.gui.ExtendedDialog; … … 38 39 import org.openstreetmap.josm.tools.Pair; 39 40 import org.openstreetmap.josm.tools.Shortcut; 40 41 41 /** 42 42 * Combines multiple ways into one. … … 88 88 } 89 89 90 protected static void completeTagCollectionWithMissingTags(TagCollection tc, Collection<? extends OsmPrimitive> merged) {91 for (String key: tc.getKeys()) {92 // make sure the empty value is in the tag set if a tag is not present93 // on all merged nodes94 //95 for (OsmPrimitive p: merged) {96 if (p.get(key) == null) {97 tc.add(new Tag(key)); // add a tag with key and empty value98 }99 }100 }101 // remove irrelevant tags102 //103 tc.removeByKey("created_by");104 }105 106 /**107 * Combines tags from TIGER data108 *109 * @param tc the tag collection110 */111 protected static void combineTigerTags(TagCollection tc) {112 for (String key: tc.getKeys()) {113 if (TigerUtils.isTigerTag(key)) {114 tc.setUniqueForKey(key, TigerUtils.combineTags(key, tc.getValues(key)));115 }116 }117 }118 119 protected static void completeTagCollectionForEditing(TagCollection tc) {120 for (String key: tc.getKeys()) {121 // make sure the empty value is in the tag set such that we can delete the tag122 // in the conflict dialog if necessary123 //124 tc.add(new Tag(key,""));125 }126 }127 90 128 91 public void combineWays(Collection<Way> ways) { … … 170 133 TagCollection completeWayTags = new TagCollection(wayTags); 171 134 combineTigerTags(completeWayTags); 172 completeTagCollectionWithMissingTags(completeWayTags, ways);135 normalizeTagCollectionBeforeEditing(completeWayTags, ways); 173 136 TagCollection tagsToEdit = new TagCollection(completeWayTags); 174 137 completeTagCollectionForEditing(tagsToEdit); 175 138 176 139 CombinePrimitiveResolverDialog dialog = CombinePrimitiveResolverDialog.getInstance(); 177 dialog.getTagConflictResolverModel().populate(tagsToEdit );140 dialog.getTagConflictResolverModel().populate(tagsToEdit, completeWayTags.getKeysWithMultipleValues()); 178 141 dialog.setTargetPrimitive(targetWay); 179 142 dialog.getRelationMemberConflictResolverModel().populate( -
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r2202 r2220 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.combineTigerTags; 5 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.completeTagCollectionForEditing; 6 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing; 4 7 import static org.openstreetmap.josm.tools.I18n.tr; 5 8 … … 23 26 import org.openstreetmap.josm.data.osm.Node; 24 27 import org.openstreetmap.josm.data.osm.OsmPrimitive; 25 import org.openstreetmap.josm.data.osm.Tag;26 28 import org.openstreetmap.josm.data.osm.TagCollection; 27 import org.openstreetmap.josm.data.osm.TigerUtils;28 29 import org.openstreetmap.josm.data.osm.Way; 29 30 import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference; … … 59 60 } 60 61 61 62 62 Node targetNode = selectTargetNode(selectedNodes); 63 63 Command cmd = mergeNodes(Main.main.getEditLayer(), selectedNodes, targetNode); … … 65 65 Main.main.undoRedo.add(cmd); 66 66 Main.main.getEditLayer().data.setSelected(targetNode); 67 }68 }69 70 protected static void completeTagCollectionWithMissingTags(TagCollection tc, Collection<Node> mergedNodes) {71 for (String key: tc.getKeys()) {72 // make sure the empty value is in the tag set if a tag is not present73 // on all merged nodes74 //75 for (Node n: mergedNodes) {76 if (n.get(key) == null) {77 tc.add(new Tag(key)); // add a tag with key and empty value78 }79 }80 }81 // remove irrelevant tags82 //83 tc.removeByKey("created_by");84 }85 86 protected static void completeTagCollectionForEditing(TagCollection tc) {87 for (String key: tc.getKeys()) {88 // make sure the empty value is in the tag set such that we can delete the tag89 // in the conflict dialog if necessary90 //91 tc.add(new Tag(key,""));92 }93 }94 95 /**96 * Combines tags from TIGER data97 *98 * @param tc the tag collection99 */100 protected static void combineTigerTags(TagCollection tc) {101 for (String key: tc.getKeys()) {102 if (TigerUtils.isTigerTag(key)) {103 tc.setUniqueForKey(key, TigerUtils.combineTags(key, tc.getValues(key)));104 }105 67 } 106 68 } … … 220 182 221 183 /** 222 * Merges the nodes in <code>node </code> onto one of the nodes. Uses the dataset184 * Merges the nodes in <code>nodes</code> onto one of the nodes. Uses the dataset 223 185 * managed by <code>layer</code> as reference. <code>backreferences</code> is a precomputed 224 186 * collection of all parent/child references in the dataset. … … 250 212 TagCollection nodeTags = TagCollection.unionOfAllPrimitives(nodes); 251 213 combineTigerTags(nodeTags); 252 completeTagCollectionWithMissingTags(nodeTags, nodes);214 normalizeTagCollectionBeforeEditing(nodeTags, nodes); 253 215 TagCollection nodeTagsToEdit = new TagCollection(nodeTags); 254 216 completeTagCollectionForEditing(nodeTagsToEdit); … … 257 219 // 258 220 CombinePrimitiveResolverDialog dialog = CombinePrimitiveResolverDialog.getInstance(); 259 dialog.getTagConflictResolverModel().populate(nodeTagsToEdit );221 dialog.getTagConflictResolverModel().populate(nodeTagsToEdit, nodeTags.getKeysWithMultipleValues()); 260 222 dialog.getRelationMemberConflictResolverModel().populate(relationToNodeReferences); 261 223 dialog.setTargetPrimitive(targetNode); 262 224 dialog.prepareDefaultDecisions(); 225 // conflict resolution is necessary if there are conflicts in the merged tags 226 // or if at least one of the merged nodes is referred to by a relation 227 // 263 228 if (! nodeTags.isApplicableToPrimitive() || relationToNodeReferences.size() > 1) { 264 229 dialog.setVisible(true); … … 283 248 if (wayFixCommands == null) 284 249 return null; 285 else { 286 cmds.addAll(wayFixCommands); 287 } 250 cmds.addAll(wayFixCommands); 288 251 289 252 // build the commands … … 299 262 return cmd; 300 263 } 301 302 264 303 265 /** -
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r2070 r2220 38 38 39 39 static private List<Class<? extends OsmPrimitive>> osmPrimitiveClasses; 40 {40 static { 41 41 osmPrimitiveClasses = new ArrayList<Class<? extends OsmPrimitive>>(); 42 42 osmPrimitiveClasses.add(Node.class); … … 60 60 61 61 /** 62 * Replies the subset of {@see OsmPrimitive}s of <code>type</code> from <code>superSet</code>.63 *64 * @param <T>65 * @param superSet the super set of primitives66 * @param type the type67 * @return68 */69 protected <T extends OsmPrimitive> Collection<? extends OsmPrimitive> getSubcollectionByType(Collection<? extends OsmPrimitive> superSet, Class<T> type) {70 Collection<OsmPrimitive> ret = new ArrayList<OsmPrimitive>();71 for (OsmPrimitive p : superSet) {72 if (type.isInstance(p)) {73 ret.add(p);74 }75 }76 return ret;77 }78 79 /**80 62 * Replies all primitives of type <code>type</code> in the current selection. 81 63 * … … 85 67 */ 86 68 protected <T extends OsmPrimitive> Collection<? extends OsmPrimitive> getSourcePrimitivesByType(Class<T> type) { 87 return getSubcollectionByType(Main.pasteBuffer.getSelected(), type);69 return OsmPrimitive.getFilteredList(Main.pasteBuffer.getSelected(), type); 88 70 } 89 71 … … 145 127 HashMap<OsmPrimitiveType, Integer> ret = new HashMap<OsmPrimitiveType, Integer>(); 146 128 for (Class<? extends OsmPrimitive> type: osmPrimitiveClasses) { 147 int count = getSubcollectionByType(getEditLayer().data.getSelected(), type).size();129 int count = OsmPrimitive.getFilteredList(getEditLayer().data.getSelected(), type).size(); 148 130 if (count > 0) { 149 131 ret.put(OsmPrimitiveType.from(type), count); … … 173 155 // no tags found to paste. Abort. 174 156 return; 175 176 157 177 158 if (!tc.isApplicableToPrimitive()) { … … 202 183 * <code>selection</code> 203 184 */ 204 protected <T extends OsmPrimitive> boolean hasTargetPrimitives(Collection< ? extendsOsmPrimitive> selection, Class<T> type) {205 return ! getSubcollectionByType(selection, type).isEmpty();185 protected <T extends OsmPrimitive> boolean hasTargetPrimitives(Collection<OsmPrimitive> selection, Class<T> type) { 186 return !OsmPrimitive.getFilteredList(selection, type).isEmpty(); 206 187 } 207 188 … … 212 193 * @return true if this a heterogeneous source can be pasted without conflicts to targets 213 194 */ 214 protected boolean canPasteFromHeterogeneousSourceWithoutConflict(Collection< ? extendsOsmPrimitive> targets) {195 protected boolean canPasteFromHeterogeneousSourceWithoutConflict(Collection<OsmPrimitive> targets) { 215 196 if (hasTargetPrimitives(targets, Node.class)) { 216 197 TagCollection tc = TagCollection.unionOfAllPrimitives(getSourcePrimitivesByType(Node.class)); … … 237 218 * @param targets the collection of target primitives 238 219 */ 239 protected void pasteFromHeterogeneousSource(Collection< ? extendsOsmPrimitive> targets) {220 protected void pasteFromHeterogeneousSource(Collection<OsmPrimitive> targets) { 240 221 if (canPasteFromHeterogeneousSourceWithoutConflict(targets)) { 241 222 if (hasSourceTagsByType(Node.class) && hasTargetPrimitives(targets, Node.class)) { … … 264 245 return; 265 246 if (hasSourceTagsByType(Node.class) && hasTargetPrimitives(targets, Node.class)) { 266 Command cmd = buildChangeCommand( getSubcollectionByType(targets, Node.class), dialog.getResolution(OsmPrimitiveType.NODE));247 Command cmd = buildChangeCommand(OsmPrimitive.getFilteredList(targets, Node.class), dialog.getResolution(OsmPrimitiveType.NODE)); 267 248 Main.main.undoRedo.add(cmd); 268 249 } 269 250 if (hasSourceTagsByType(Way.class) && hasTargetPrimitives(targets, Way.class)) { 270 Command cmd = buildChangeCommand( getSubcollectionByType(targets, Way.class), dialog.getResolution(OsmPrimitiveType.WAY));251 Command cmd = buildChangeCommand(OsmPrimitive.getFilteredList(targets, Way.class), dialog.getResolution(OsmPrimitiveType.WAY)); 271 252 Main.main.undoRedo.add(cmd); 272 253 } 273 254 if (hasSourceTagsByType(Relation.class) && hasTargetPrimitives(targets, Relation.class)) { 274 Command cmd = buildChangeCommand( getSubcollectionByType(targets, Relation.class), dialog.getResolution(OsmPrimitiveType.RELATION));255 Command cmd = buildChangeCommand(OsmPrimitive.getFilteredList(targets, Relation.class), dialog.getResolution(OsmPrimitiveType.RELATION)); 275 256 Main.main.undoRedo.add(cmd); 276 257 }
Note:
See TracChangeset
for help on using the changeset viewer.