001 // License: GPL. For details, see LICENSE file.
002 package org.openstreetmap.josm.command;
003
004 import static org.openstreetmap.josm.tools.I18n.tr;
005
006 import java.util.Collection;
007 import javax.swing.Icon;
008
009 import org.openstreetmap.josm.data.conflict.Conflict;
010 import org.openstreetmap.josm.data.osm.Node;
011 import org.openstreetmap.josm.data.osm.OsmPrimitive;
012 import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
013 import org.openstreetmap.josm.tools.ImageProvider;
014
015 /**
016 * Represents a the resolution of a conflict between the coordinates of two {@link Node}s
017 *
018 */
019 public class CoordinateConflictResolveCommand extends ConflictResolveCommand {
020
021 /** the conflict to resolve */
022 private Conflict<? extends OsmPrimitive> conflict;
023
024 /** the merge decision */
025 private final MergeDecisionType decision;
026
027 /**
028 * constructor
029 *
030 * @param my my node
031 * @param their their node
032 * @param decision the merge decision
033 */
034 public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
035 this.conflict = conflict;
036 this.decision = decision;
037 }
038
039 @Override
040 public String getDescriptionText() {
041 return tr("Resolve conflicts in coordinates in {0}", conflict.getMy().getId());
042 }
043
044 @Override
045 public Icon getDescriptionIcon() {
046 return ImageProvider.get("data", "object");
047 }
048
049 @Override
050 public boolean executeCommand() {
051 // remember the current state of modified primitives, i.e. of
052 // OSM primitive 'my'
053 //
054 super.executeCommand();
055
056 if (decision.equals(MergeDecisionType.KEEP_MINE)) {
057 // do nothing
058 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
059 Node my = (Node)conflict.getMy();
060 Node their = (Node)conflict.getTheir();
061 my.setCoor(their.getCoor());
062 } else
063 // should not happen
064 throw new IllegalStateException(tr("Cannot resolve undecided conflict."));
065
066 // remember the layer this command was applied to
067 //
068 rememberConflict(conflict);
069
070 return true;
071 }
072
073 @Override
074 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
075 Collection<OsmPrimitive> added) {
076 modified.add(conflict.getMy());
077 }
078 }