source: josm/trunk/src/org/openstreetmap/josm/command/WayNodesConflictResolverCommand.java@ 3172

Last change on this file since 3172 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collection;
7import java.util.List;
8import java.util.logging.Logger;
9
10import javax.swing.JLabel;
11import javax.swing.tree.DefaultMutableTreeNode;
12import javax.swing.tree.MutableTreeNode;
13
14import org.openstreetmap.josm.data.conflict.Conflict;
15import org.openstreetmap.josm.data.osm.Node;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.Way;
18import 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 */
25public 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 @SuppressWarnings("unchecked")
44 public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
45 this.conflict = (Conflict<Way>) conflict;
46 this.mergedNodeList = mergedNodeList;
47 }
48
49 @Override
50 public MutableTreeNode description() {
51 return new DefaultMutableTreeNode(
52 new JLabel(
53 tr("Resolve conflicts in node list of way {0}", conflict.getMy().getId()),
54 ImageProvider.get("data", "object"),
55 JLabel.HORIZONTAL
56 )
57 );
58 }
59
60 @Override
61 public boolean executeCommand() {
62 // remember the current state of 'my' way
63 //
64 super.executeCommand();
65
66 // replace the list of nodes of 'my' way by the list of merged
67 // nodes
68 //
69 for (Node n:mergedNodeList) {
70 if (! getLayer().data.getNodes().contains(n)) {
71 logger.warning(tr("Main dataset does not include node {0}", n.toString()));
72 }
73 }
74 conflict.getMy().setNodes(mergedNodeList);
75 rememberConflict(conflict);
76 return true;
77 }
78
79 @Override
80 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
81 Collection<OsmPrimitive> added) {
82 modified.add(conflict.getMy());
83 }
84}
Note: See TracBrowser for help on using the repository browser.