source: josm/trunk/src/org/openstreetmap/josm/command/ChangeCommand.java@ 6396

Last change on this file since 6396 was 6380, checked in by Don-vip, 10 years ago

update license/copyright information

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.util.Collection;
8
9import javax.swing.Icon;
10
11import org.openstreetmap.josm.data.osm.OsmPrimitive;
12import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
13import org.openstreetmap.josm.data.osm.Way;
14import org.openstreetmap.josm.gui.DefaultNameFormatter;
15import org.openstreetmap.josm.gui.layer.OsmDataLayer;
16import org.openstreetmap.josm.tools.CheckParameterUtil;
17import org.openstreetmap.josm.tools.ImageProvider;
18
19/**
20 * Command that basically replaces one OSM primitive by another of the same type.
21 *
22 * @since 93
23 */
24public class ChangeCommand extends Command {
25
26 private final OsmPrimitive osm;
27 private final OsmPrimitive newOsm;
28
29 public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
30 super();
31 this.osm = osm;
32 this.newOsm = newOsm;
33 sanityChecks();
34 }
35
36 public ChangeCommand(OsmDataLayer layer, OsmPrimitive osm, OsmPrimitive newOsm) {
37 super(layer);
38 this.osm = osm;
39 this.newOsm = newOsm;
40 sanityChecks();
41 }
42
43 private void sanityChecks() {
44 CheckParameterUtil.ensureParameterNotNull(osm, "osm");
45 CheckParameterUtil.ensureParameterNotNull(newOsm, "newOsm");
46 if (newOsm instanceof Way && ((Way)newOsm).getNodesCount() == 0) {
47 // Do not allow to create empty ways (see #7465)
48 throw new IllegalArgumentException(tr("New way {0} has 0 nodes", newOsm));
49 }
50 }
51
52 @Override
53 public boolean executeCommand() {
54 super.executeCommand();
55 osm.cloneFrom(newOsm);
56 osm.setModified(true);
57 return true;
58 }
59
60 @Override
61 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
62 modified.add(osm);
63 }
64
65 @Override
66 public String getDescriptionText() {
67 String msg = "";
68 switch(OsmPrimitiveType.from(osm)) {
69 case NODE: msg = marktr("Change node {0}"); break;
70 case WAY: msg = marktr("Change way {0}"); break;
71 case RELATION: msg = marktr("Change relation {0}"); break;
72 }
73 return tr(msg, osm.getDisplayName(DefaultNameFormatter.getInstance()));
74 }
75
76 @Override
77 public Icon getDescriptionIcon() {
78 return ImageProvider.get(osm.getDisplayType());
79 }
80}
Note: See TracBrowser for help on using the repository browser.