[2512] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.command;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.util.Collection;
|
---|
| 7 |
|
---|
| 8 | import javax.swing.JLabel;
|
---|
| 9 |
|
---|
| 10 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
| 11 | import org.openstreetmap.josm.data.osm.Node;
|
---|
| 12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
| 13 | import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
|
---|
| 14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * Represents a the resolution of a conflict between the coordinates of two {@see Node}s
|
---|
| 18 | *
|
---|
| 19 | */
|
---|
| 20 | public class CoordinateConflictResolveCommand extends ConflictResolveCommand {
|
---|
| 21 |
|
---|
| 22 | /** the conflict to resolve */
|
---|
[3034] | 23 | private Conflict<? extends OsmPrimitive> conflict;
|
---|
[2512] | 24 |
|
---|
| 25 | /** the merge decision */
|
---|
| 26 | private final MergeDecisionType decision;
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * constructor
|
---|
| 30 | *
|
---|
| 31 | * @param my my node
|
---|
| 32 | * @param their their node
|
---|
| 33 | * @param decision the merge decision
|
---|
| 34 | */
|
---|
[3034] | 35 | public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
|
---|
| 36 | this.conflict = conflict;
|
---|
[2512] | 37 | this.decision = decision;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[3262] | 40 | @Override public JLabel getDescription() {
|
---|
| 41 | return new JLabel(
|
---|
[2512] | 42 | tr("Resolve conflicts in coordinates in {0}",conflict.getMy().getId()),
|
---|
| 43 | ImageProvider.get("data", "object"),
|
---|
| 44 | JLabel.HORIZONTAL
|
---|
| 45 | );
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | @Override
|
---|
| 49 | public boolean executeCommand() {
|
---|
| 50 | // remember the current state of modified primitives, i.e. of
|
---|
| 51 | // OSM primitive 'my'
|
---|
| 52 | //
|
---|
| 53 | super.executeCommand();
|
---|
| 54 |
|
---|
| 55 | if (decision.equals(MergeDecisionType.KEEP_MINE)) {
|
---|
| 56 | // do nothing
|
---|
| 57 | } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
|
---|
[3034] | 58 | Node my = (Node)conflict.getMy();
|
---|
| 59 | Node their = (Node)conflict.getTheir();
|
---|
[2512] | 60 | my.setCoor(their.getCoor());
|
---|
| 61 | } else
|
---|
| 62 | // should not happen
|
---|
| 63 | throw new IllegalStateException(tr("Cannot resolve undecided conflict."));
|
---|
| 64 |
|
---|
| 65 | // remember the layer this command was applied to
|
---|
| 66 | //
|
---|
| 67 | rememberConflict(conflict);
|
---|
| 68 |
|
---|
| 69 | return true;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | @Override
|
---|
| 73 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
| 74 | Collection<OsmPrimitive> added) {
|
---|
| 75 | modified.add(conflict.getMy());
|
---|
| 76 | }
|
---|
| 77 | }
|
---|