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