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

Revision 5077, 1.9 KB checked in by xeen, 2 months ago (diff)

Bring area icon to most (all?) places in core. Fixes #6318 (related: #7036)

  • Property svn:eol-style set to native
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.Icon;
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
53    public String getDescriptionText() {
54        String msg = "";
55        switch(OsmPrimitiveType.from(osm)) {
56        case NODE: msg = marktr("Change node {0}"); break;
57        case WAY: msg = marktr("Change way {0}"); break;
58        case RELATION: msg = marktr("Change relation {0}"); break;
59        }
60        return tr(msg, osm.getDisplayName(DefaultNameFormatter.getInstance()));
61    }
62
63    @Override
64    public Icon getDescriptionIcon() {
65        return ImageProvider.get(osm.getDisplayType());
66    }
67}
Note: See TracBrowser for help on using the repository browser.