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.tr;
|
---|
5 |
|
---|
6 | import java.util.Collection;
|
---|
7 |
|
---|
8 | import javax.swing.JLabel;
|
---|
9 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
10 | import javax.swing.tree.MutableTreeNode;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
14 | import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
|
---|
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 | public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
|
---|
29 | super();
|
---|
30 | this.osm = osm;
|
---|
31 | this.newOsm = newOsm;
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override public boolean executeCommand() {
|
---|
35 | super.executeCommand();
|
---|
36 | osm.cloneFrom(newOsm);
|
---|
37 | osm.modified = true;
|
---|
38 | return true;
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
|
---|
42 | modified.add(osm);
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override public MutableTreeNode description() {
|
---|
46 | return new DefaultMutableTreeNode(
|
---|
47 | new JLabel(tr("Change {0} {1}",
|
---|
48 | OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(),
|
---|
49 | new PrimitiveNameFormatter().getName(osm)),
|
---|
50 | ImageProvider.get(OsmPrimitiveType.from(osm)),
|
---|
51 | JLabel.HORIZONTAL));
|
---|
52 | }
|
---|
53 | }
|
---|