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 |
|
---|
9 | import javax.swing.JLabel;
|
---|
10 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
11 | import javax.swing.tree.MutableTreeNode;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.data.osm.Node;
|
---|
15 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
16 | import org.openstreetmap.josm.data.osm.Way;
|
---|
17 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Represent a command for resolving conflicts in the node list of two
|
---|
21 | * {@see Way}s.
|
---|
22 | *
|
---|
23 | */
|
---|
24 | public class WayNodesConflictResolverCommand extends Command {
|
---|
25 |
|
---|
26 | /** my way */
|
---|
27 | private final Way my;
|
---|
28 | /** their way */
|
---|
29 | private final Way their;
|
---|
30 | /** the list of merged nodes. This becomes the list of news of my way after the
|
---|
31 | * command is executed
|
---|
32 | */
|
---|
33 | private final List<Node> mergedNodeList;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | *
|
---|
37 | * @param my my may
|
---|
38 | * @param their their way
|
---|
39 | * @param mergedNodeList the list of merged nodes
|
---|
40 | */
|
---|
41 | public WayNodesConflictResolverCommand(Way my, Way their, List<Node> mergedNodeList) {
|
---|
42 | this.my = my;
|
---|
43 | this.their = their;
|
---|
44 | this.mergedNodeList = mergedNodeList;
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public MutableTreeNode description() {
|
---|
50 | return new DefaultMutableTreeNode(
|
---|
51 | new JLabel(
|
---|
52 | tr("Resolve conflicts in node list of of way {0}", my.id),
|
---|
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 | my.nodes.clear();
|
---|
69 | for (int i=0; i<mergedNodeList.size();i++) {
|
---|
70 | Node n = mergedNodeList.get(i);
|
---|
71 | my.nodes.add(n);
|
---|
72 | if (! Main.ds.nodes.contains(n)) {
|
---|
73 | System.out.println("Main.ds doesn't include node " + n.toString());
|
---|
74 | }
|
---|
75 | }
|
---|
76 | return true;
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Override
|
---|
80 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
81 | Collection<OsmPrimitive> added) {
|
---|
82 | modified.add(my);
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override
|
---|
86 | public void undoCommand() {
|
---|
87 | // restore the former state
|
---|
88 | //
|
---|
89 | super.undoCommand();
|
---|
90 |
|
---|
91 | // restore a conflict if necessary
|
---|
92 | //
|
---|
93 | if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
|
---|
94 | Main.map.conflictDialog.addConflict(my, their);
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|