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

Last change on this file since 3965 was 3262, checked in by bastiK, 14 years ago

extended command list dialog; added inspection panel

  • Property svn:eol-style set to native
File size: 1.9 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;
10
11import org.openstreetmap.josm.data.osm.OsmPrimitive;
12import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
13import org.openstreetmap.josm.gui.DefaultNameFormatter;
14import org.openstreetmap.josm.gui.layer.OsmDataLayer;
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
29 public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
30 super();
31 this.osm = osm;
32 this.newOsm = newOsm;
33 }
34
35 public ChangeCommand(OsmDataLayer layer, OsmPrimitive osm, OsmPrimitive newOsm) {
36 super(layer);
37 this.osm = osm;
38 this.newOsm = newOsm;
39 }
40
41 @Override public boolean executeCommand() {
42 super.executeCommand();
43 osm.cloneFrom(newOsm);
44 osm.setModified(true);
45 return true;
46 }
47
48 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
49 modified.add(osm);
50 }
51
52 @Override public JLabel getDescription() {
53 String msg = "";
54 switch(OsmPrimitiveType.from(osm)) {
55 case NODE: msg = marktr("Change node {0}"); break;
56 case WAY: msg = marktr("Change way {0}"); break;
57 case RELATION: msg = marktr("Change relation {0}"); break;
58 }
59 return new JLabel(tr(msg,
60 osm.getDisplayName(DefaultNameFormatter.getInstance())),
61 ImageProvider.get(OsmPrimitiveType.from(osm)),
62 JLabel.HORIZONTAL);
63 }
64}
Note: See TracBrowser for help on using the repository browser.