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

Last change on this file since 729 was 630, checked in by framm, 16 years ago
  • make commands able to fail (patch by DH)
  • add Command.getOrig() (patch by DH)
  • add RemoveRelationMemberCommand (patch by DH)
  • Property svn:eol-style set to native
File size: 1.3 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.visitor.NameVisitor;
14
15/**
16 * Command that basically replaces one OSM primitive by another of the
17 * same type.
18 *
19 * @author Imi
20 */
21public class ChangeCommand extends Command {
22
23 private final OsmPrimitive osm;
24 private final OsmPrimitive newOsm;
25
26 public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
27 this.osm = osm;
28 this.newOsm = newOsm;
29 }
30
31 @Override public boolean executeCommand() {
32 super.executeCommand();
33 osm.cloneFrom(newOsm);
34 osm.modified = true;
35 return true;
36 }
37
38 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
39 modified.add(osm);
40 }
41
42 @Override public MutableTreeNode description() {
43 NameVisitor v = new NameVisitor();
44 osm.visit(v);
45 return new DefaultMutableTreeNode(new JLabel(tr("Change")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));
46 }
47}
Note: See TracBrowser for help on using the repository browser.