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

Last change on this file since 1937 was 1814, checked in by Gubaer, 15 years ago

removed dependencies to Main.ds, removed Main.ds
removed AddVisitor, NameVisitor, DeleteVisitor - unnecessary double dispatching for these simple cases

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collection;
7
8import javax.swing.JLabel;
9import javax.swing.tree.DefaultMutableTreeNode;
10import javax.swing.tree.MutableTreeNode;
11
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
14import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
15import 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 */
23public 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}
Note: See TracBrowser for help on using the repository browser.