Changeset 29118 in osm
- Timestamp:
- 2012-12-26T03:25:48+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/UnGlueRelationAction.java
r28028 r29118 5 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 import static org.openstreetmap.josm.tools.I18n.trn;8 7 8 import java.awt.event.ActionEvent; 9 9 import java.awt.event.KeyEvent; 10 import java.awt.event.ActionEvent;11 12 10 import java.util.Collection; 13 import java.util.Collections;14 11 import java.util.LinkedList; 15 12 import java.util.List; … … 17 14 import org.openstreetmap.josm.Main; 18 15 import org.openstreetmap.josm.actions.JosmAction; 19 import org.openstreetmap.josm.tools.Shortcut;20 16 import org.openstreetmap.josm.command.AddCommand; 21 import org.openstreetmap.josm.command.ChangeCommand;22 17 import org.openstreetmap.josm.command.Command; 23 18 import org.openstreetmap.josm.command.SequenceCommand; 24 19 import org.openstreetmap.josm.data.osm.Node; 25 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 26 22 import org.openstreetmap.josm.data.osm.Relation; 27 23 import org.openstreetmap.josm.data.osm.RelationMember; 28 24 import org.openstreetmap.josm.data.osm.Way; 25 import org.openstreetmap.josm.gui.DefaultNameFormatter; 26 import org.openstreetmap.josm.tools.Shortcut; 29 27 30 28 /** … … 72 70 newPrimitives.add(newp); 73 71 cmds.add(new AddCommand(newp)); 74 cmds.add(new Change Command(relation, changeRelationMember(relation, p, newp)));72 cmds.add(new ChangeRelationMemberCommand(relation, p, newp)); 75 73 } else { 76 74 first = false; … … 93 91 /** 94 92 * Change member in relation to another one 95 * @param relation96 * @param orginalMember member to change97 * @param newMember98 * @return new relation were change is made99 93 */ 100 private Relation changeRelationMember(Relation relation, OsmPrimitive orginalMember, OsmPrimitive newMember) { 101 LinkedList<RelationMember> newrms = new LinkedList<RelationMember>(); 102 for (RelationMember rm : relation.getMembers()) { 103 if (rm.getMember() == orginalMember) { 104 newrms.add(new RelationMember(rm.getRole(),newMember)); 105 } else { 106 newrms.add(rm); 94 private class ChangeRelationMemberCommand extends Command { 95 96 private final Relation relation; 97 private final OsmPrimitive oldMember; 98 private final OsmPrimitive newMember; 99 100 public ChangeRelationMemberCommand(Relation relation, OsmPrimitive oldMember, OsmPrimitive newMember) { 101 this.relation = relation; 102 this.oldMember = oldMember; 103 this.newMember = newMember; 104 } 105 106 private boolean replaceMembers(OsmPrimitive oldP, OsmPrimitive newP) { 107 if (relation == null || oldMember == null || newMember == null) { 108 return false; 107 109 } 110 LinkedList<RelationMember> newrms = new LinkedList<RelationMember>(); 111 for (RelationMember rm : relation.getMembers()) { 112 if (rm.getMember() == oldP) { 113 newrms.add(new RelationMember(rm.getRole(), newP)); 114 } else { 115 newrms.add(rm); 116 } 117 } 118 relation.setMembers(newrms); 119 return true; 108 120 } 109 Relation newRelation = new Relation(relation); 110 newRelation.setMembers(newrms); 111 return newRelation; 121 122 @Override 123 public boolean executeCommand() { 124 return replaceMembers(oldMember, newMember); 125 } 126 127 @Override 128 public void fillModifiedData(Collection<OsmPrimitive> modified, 129 Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 130 modified.add(relation); 131 } 132 133 @Override 134 public void undoCommand() { 135 replaceMembers(newMember, oldMember); 136 } 137 138 @Override 139 public String getDescriptionText() { 140 return tr("Change relation member for {0} {1}", 141 OsmPrimitiveType.from(relation), 142 relation.getDisplayName(DefaultNameFormatter.getInstance())); 143 } 112 144 } 113 145
Note:
See TracChangeset
for help on using the changeset viewer.