1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.command;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.marktr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.util.Collection;
|
---|
8 |
|
---|
9 | import javax.swing.Icon;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
12 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
13 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
14 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Command that basically replaces one OSM primitive by another of the
|
---|
19 | * same type.
|
---|
20 | *
|
---|
21 | * @author Imi
|
---|
22 | */
|
---|
23 | public class ChangeCommand extends Command {
|
---|
24 |
|
---|
25 | private final OsmPrimitive osm;
|
---|
26 | private final OsmPrimitive newOsm;
|
---|
27 |
|
---|
28 |
|
---|
29 | public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
|
---|
30 | super();
|
---|
31 | this.osm = osm;
|
---|
32 | this.newOsm = newOsm;
|
---|
33 | }
|
---|
34 |
|
---|
35 | public ChangeCommand(OsmDataLayer layer, OsmPrimitive osm, OsmPrimitive newOsm) {
|
---|
36 | super(layer);
|
---|
37 | this.osm = osm;
|
---|
38 | this.newOsm = newOsm;
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override public boolean executeCommand() {
|
---|
42 | super.executeCommand();
|
---|
43 | osm.cloneFrom(newOsm);
|
---|
44 | osm.setModified(true);
|
---|
45 | return true;
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
|
---|
49 | modified.add(osm);
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public String getDescriptionText() {
|
---|
54 | String msg = "";
|
---|
55 | switch(OsmPrimitiveType.from(osm)) {
|
---|
56 | case NODE: msg = marktr("Change node {0}"); break;
|
---|
57 | case WAY: msg = marktr("Change way {0}"); break;
|
---|
58 | case RELATION: msg = marktr("Change relation {0}"); break;
|
---|
59 | }
|
---|
60 | return tr(msg, osm.getDisplayName(DefaultNameFormatter.getInstance()));
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public Icon getDescriptionIcon() {
|
---|
65 | return ImageProvider.get(osm.getDisplayType());
|
---|
66 | }
|
---|
67 | }
|
---|