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