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 */
|
---|
25 | private Conflict<Node> conflict;
|
---|
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 | */
|
---|
37 | public CoordinateConflictResolveCommand(Node my, Node their, MergeDecisionType decision) {
|
---|
38 | this.conflict = new Conflict<Node>(my,their);
|
---|
39 | this.decision = decision;
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | public MutableTreeNode description() {
|
---|
45 | return new DefaultMutableTreeNode(
|
---|
46 | new JLabel(
|
---|
47 | tr("Resolve conflicts in coordinates in {0}",conflict.getMy().getId()),
|
---|
48 | ImageProvider.get("data", "object"),
|
---|
49 | JLabel.HORIZONTAL
|
---|
50 | )
|
---|
51 | );
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public boolean executeCommand() {
|
---|
56 | // remember the current state of modified primitives, i.e. of
|
---|
57 | // OSM primitive 'my'
|
---|
58 | //
|
---|
59 | super.executeCommand();
|
---|
60 |
|
---|
61 | if (decision.equals(MergeDecisionType.KEEP_MINE)) {
|
---|
62 | // do nothing
|
---|
63 | } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
|
---|
64 | Node my = conflict.getMy();
|
---|
65 | Node their = conflict.getTheir();
|
---|
66 | my.setCoor(their.getCoor());
|
---|
67 | } else
|
---|
68 | // should not happen
|
---|
69 | throw new IllegalStateException(tr("Cannot resolve undecided conflict."));
|
---|
70 |
|
---|
71 | // remember the layer this command was applied to
|
---|
72 | //
|
---|
73 | rememberConflict(conflict);
|
---|
74 |
|
---|
75 | return true;
|
---|
76 | }
|
---|
77 |
|
---|
78 | @Override
|
---|
79 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
80 | Collection<OsmPrimitive> added) {
|
---|
81 | modified.add(conflict.getMy());
|
---|
82 | }
|
---|
83 | }
|
---|