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.JLabel;
|
---|
10 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
11 | import javax.swing.tree.MutableTreeNode;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
14 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
15 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
16 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Command that basically replaces one OSM primitive by another of the
|
---|
20 | * same type.
|
---|
21 | *
|
---|
22 | * @author Imi
|
---|
23 | */
|
---|
24 | public 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 | }
|
---|
34 |
|
---|
35 | @Override public boolean executeCommand() {
|
---|
36 | super.executeCommand();
|
---|
37 | osm.cloneFrom(newOsm);
|
---|
38 | osm.setModified(true);
|
---|
39 | return true;
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
|
---|
43 | modified.add(osm);
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override public MutableTreeNode description() {
|
---|
47 | String msg = "";
|
---|
48 | switch(OsmPrimitiveType.from(osm)) {
|
---|
49 | case NODE: msg = marktr("Change node {0}"); break;
|
---|
50 | case WAY: msg = marktr("Change way {0}"); break;
|
---|
51 | case RELATION: msg = marktr("Change relation {0}"); break;
|
---|
52 | }
|
---|
53 | return new DefaultMutableTreeNode(
|
---|
54 | new JLabel(tr(msg,
|
---|
55 | osm.getDisplayName(DefaultNameFormatter.getInstance()),
|
---|
56 | ImageProvider.get(OsmPrimitiveType.from(osm)),
|
---|
57 | JLabel.HORIZONTAL)));
|
---|
58 | }
|
---|
59 | }
|
---|