Changeset 2972 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-02-13T16:19:56+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/UndeletePrimitivesCommand.java
r2844 r2972 6 6 import java.util.ArrayList; 7 7 import java.util.Collection; 8 import java.util.Collections; 8 9 import java.util.List; 9 import java.util. logging.Logger;10 import java.util.ListIterator; 10 11 11 12 import javax.swing.JLabel; … … 13 14 import javax.swing.tree.MutableTreeNode; 14 15 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.Node; 15 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.data.osm.Relation; 20 import org.openstreetmap.josm.data.osm.RelationMember; 21 import org.openstreetmap.josm.data.osm.Way; 16 22 import org.openstreetmap.josm.tools.ImageProvider; 17 23 … … 23 29 */ 24 30 public class UndeletePrimitivesCommand extends ConflictResolveCommand { 25 static private final Logger logger = Logger.getLogger(UndeletePrimitivesCommand.class.getName());31 //static private final Logger logger = Logger.getLogger(UndeletePrimitivesCommand.class.getName()); 26 32 27 33 /** the node to undelete */ 28 34 private final List<OsmPrimitive> toUndelete = new ArrayList<OsmPrimitive>(); 35 /** primitives that replaced undeleted primitives */ 36 private final List<OsmPrimitive> replacedPrimitives = new ArrayList<OsmPrimitive>(); 29 37 30 38 /** … … 51 59 */ 52 60 public UndeletePrimitivesCommand(Collection<OsmPrimitive> toUndelete) { 53 this();54 61 this.toUndelete.addAll(toUndelete); 55 62 } … … 70 77 super.executeCommand(); 71 78 79 replacedPrimitives.clear(); 72 80 for(OsmPrimitive primitive: toUndelete) { 73 81 if(getLayer().getConflicts().hasConflictForMy(primitive)) { … … 75 83 getLayer().getConflicts().remove(primitive); 76 84 } 77 primitive.clearOsmId(); 85 OsmPrimitive prim; 86 switch (primitive.getType()) { 87 case NODE: 88 prim = new Node((Node)primitive, true); 89 break; 90 case WAY: 91 prim = new Way((Way)primitive, true); 92 break; 93 case RELATION: 94 prim = new Relation((Relation)primitive, true); 95 break; 96 default: 97 throw new AssertionError(); 98 } 99 replacedPrimitives.add(prim); 100 replacePrimitive(getLayer().data, primitive, prim); 78 101 } 79 102 return true; 103 } 104 105 private void replacePrimitive(DataSet dataSet, OsmPrimitive oldPrim, OsmPrimitive newPrim) { 106 dataSet.addPrimitive(newPrim); 107 for (OsmPrimitive referrer: oldPrim.getReferrers()) { 108 if (referrer instanceof Way) { 109 Way w = (Way)referrer; 110 List<Node> nodes = w.getNodes(); 111 Collections.replaceAll(nodes, (Node)oldPrim, (Node)newPrim); 112 w.setNodes(nodes); 113 w.setModified(true); 114 } else if (referrer instanceof Relation) { 115 Relation r = (Relation)referrer; 116 List<RelationMember> members = r.getMembers(); 117 ListIterator<RelationMember> it = members.listIterator(); 118 while (it.hasNext()) { 119 RelationMember rm = it.next(); 120 if (rm.getMember() == oldPrim) { 121 it.set(new RelationMember(rm.getRole(), newPrim)); 122 } 123 } 124 r.setMembers(members); 125 r.setModified(true); 126 } 127 } 128 dataSet.removePrimitive(oldPrim); 129 } 130 131 @Override 132 public void undoCommand() { 133 for (int i=0; i<toUndelete.size(); i++) { 134 replacePrimitive(getLayer().data, replacedPrimitives.get(i), toUndelete.get(i)); 135 } 136 super.undoCommand(); 80 137 } 81 138 … … 83 140 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 84 141 Collection<OsmPrimitive> added) { 85 modified.addAll(toUndelete);86 142 } 87 143 }
Note:
See TracChangeset
for help on using the changeset viewer.