1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command.conflict;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.Collection;
|
---|
7 | import java.util.Objects;
|
---|
8 |
|
---|
9 | import javax.swing.Icon;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
12 | import org.openstreetmap.josm.data.osm.Node;
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
14 | import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Represents the resolution of a conflict between the coordinates of two {@link Node}s.
|
---|
19 | *
|
---|
20 | */
|
---|
21 | public class CoordinateConflictResolveCommand extends ConflictResolveCommand {
|
---|
22 |
|
---|
23 | /** the conflict to resolve */
|
---|
24 | private final Conflict<? extends OsmPrimitive> conflict;
|
---|
25 |
|
---|
26 | /** the merge decision */
|
---|
27 | private final MergeDecisionType decision;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * constructor for coordinate conflict
|
---|
31 | *
|
---|
32 | * @param conflict the conflict data set
|
---|
33 | * @param decision the merge decision
|
---|
34 | */
|
---|
35 | public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
|
---|
36 | super(conflict.getMy().getDataSet());
|
---|
37 | this.conflict = conflict;
|
---|
38 | this.decision = decision;
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public String getDescriptionText() {
|
---|
43 | return tr("Resolve conflicts in coordinates in {0}", conflict.getMy().getId());
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public Icon getDescriptionIcon() {
|
---|
48 | return ImageProvider.get("data", "object");
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public boolean executeCommand() {
|
---|
53 | // remember the current state of modified primitives, i.e. of OSM primitive 'my'
|
---|
54 | super.executeCommand();
|
---|
55 |
|
---|
56 | if (decision.equals(MergeDecisionType.KEEP_MINE)) {
|
---|
57 | // do nothing
|
---|
58 | } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
|
---|
59 | Node my = (Node) conflict.getMy();
|
---|
60 | Node their = (Node) conflict.getTheir();
|
---|
61 | my.setCoor(their.getCoor());
|
---|
62 | } else
|
---|
63 | // should not happen
|
---|
64 | throw new IllegalStateException(tr("Cannot resolve undecided conflict."));
|
---|
65 |
|
---|
66 | // remember the layer this command was applied to
|
---|
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 |
|
---|
78 | @Override
|
---|
79 | public int hashCode() {
|
---|
80 | return Objects.hash(super.hashCode(), conflict, decision);
|
---|
81 | }
|
---|
82 |
|
---|
83 | @Override
|
---|
84 | public boolean equals(Object obj) {
|
---|
85 | if (this == obj) return true;
|
---|
86 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
87 | if (!super.equals(obj)) return false;
|
---|
88 | CoordinateConflictResolveCommand that = (CoordinateConflictResolveCommand) obj;
|
---|
89 | return decision == that.decision && Objects.equals(conflict, that.conflict);
|
---|
90 | }
|
---|
91 | }
|
---|