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

Last change on this file since 3173 was 3152, checked in by Gubaer, 14 years ago

SplitWayAction slightly refactored, going to need this somewhere else

  • Property svn:eol-style set to native
File size: 2.1 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.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.util.Collection;
8
9import javax.swing.JLabel;
10import javax.swing.tree.DefaultMutableTreeNode;
11import javax.swing.tree.MutableTreeNode;
12
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
15import org.openstreetmap.josm.gui.DefaultNameFormatter;
16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
17import org.openstreetmap.josm.tools.ImageProvider;
18
19/**
20 * Command that basically replaces one OSM primitive by another of the
21 * same type.
22 *
23 * @author Imi
24 */
25public class ChangeCommand extends Command {
26
27 private final OsmPrimitive osm;
28 private final OsmPrimitive newOsm;
29
30
31 public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
32 super();
33 this.osm = osm;
34 this.newOsm = newOsm;
35 }
36
37 public ChangeCommand(OsmDataLayer layer, OsmPrimitive osm, OsmPrimitive newOsm) {
38 super(layer);
39 this.osm = osm;
40 this.newOsm = newOsm;
41 }
42
43 @Override public boolean executeCommand() {
44 super.executeCommand();
45 osm.cloneFrom(newOsm);
46 osm.setModified(true);
47 return true;
48 }
49
50 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
51 modified.add(osm);
52 }
53
54 @Override public MutableTreeNode description() {
55 String msg = "";
56 switch(OsmPrimitiveType.from(osm)) {
57 case NODE: msg = marktr("Change node {0}"); break;
58 case WAY: msg = marktr("Change way {0}"); break;
59 case RELATION: msg = marktr("Change relation {0}"); break;
60 }
61 return new DefaultMutableTreeNode(
62 new JLabel(tr(msg,
63 osm.getDisplayName(DefaultNameFormatter.getInstance()),
64 ImageProvider.get(OsmPrimitiveType.from(osm)),
65 JLabel.HORIZONTAL)));
66 }
67}
Note: See TracBrowser for help on using the repository browser.