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 | import java.util.List;
|
---|
8 | import java.util.logging.Logger;
|
---|
9 |
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
12 | import javax.swing.tree.MutableTreeNode;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
17 | import org.openstreetmap.josm.data.osm.Way;
|
---|
18 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Represent a command for resolving conflicts in the node list of two
|
---|
22 | * {@see Way}s.
|
---|
23 | *
|
---|
24 | */
|
---|
25 | public class WayNodesConflictResolverCommand extends ConflictResolveCommand {
|
---|
26 |
|
---|
27 | static private final Logger logger = Logger.getLogger(WayNodesConflictResolverCommand.class.getName());
|
---|
28 |
|
---|
29 | /** the conflict to resolve */
|
---|
30 | private Conflict<Way> conflict;
|
---|
31 |
|
---|
32 | /** the list of merged nodes. This becomes the list of news of my way after the
|
---|
33 | * command is executed
|
---|
34 | */
|
---|
35 | private final List<Node> mergedNodeList;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | *
|
---|
39 | * @param my my may
|
---|
40 | * @param their their way
|
---|
41 | * @param mergedNodeList the list of merged nodes
|
---|
42 | */
|
---|
43 | public WayNodesConflictResolverCommand(Way my, Way their, List<Node> mergedNodeList) {
|
---|
44 | conflict = new Conflict<Way>(my,their);
|
---|
45 | this.mergedNodeList = mergedNodeList;
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public MutableTreeNode description() {
|
---|
50 | return new DefaultMutableTreeNode(
|
---|
51 | new JLabel(
|
---|
52 | tr("Resolve conflicts in node list of way {0}", conflict.getMy().getId()),
|
---|
53 | ImageProvider.get("data", "object"),
|
---|
54 | JLabel.HORIZONTAL
|
---|
55 | )
|
---|
56 | );
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public boolean executeCommand() {
|
---|
61 | // remember the current state of 'my' way
|
---|
62 | //
|
---|
63 | super.executeCommand();
|
---|
64 |
|
---|
65 | // replace the list of nodes of 'my' way by the list of merged
|
---|
66 | // nodes
|
---|
67 | //
|
---|
68 | for (Node n:mergedNodeList) {
|
---|
69 | if (! getLayer().data.getNodes().contains(n)) {
|
---|
70 | logger.warning(tr("Main dataset does not include node {0}", n.toString()));
|
---|
71 | }
|
---|
72 | }
|
---|
73 | conflict.getMy().setNodes(mergedNodeList);
|
---|
74 | rememberConflict(conflict);
|
---|
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 | }
|
---|