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

Last change on this file since 2163 was 2025, checked in by Gubaer, 15 years ago

new: improved dialog for uploading/saving modified layers on exit
new: improved dialog for uploading/saving modified layers if layers are deleted
new: new progress monitor which can delegate rendering to any Swing component
more setters/getters for properties in OSM data classes (fields are @deprecated); started to update references in the code base

  • 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;
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.tools.ImageProvider;
17
18/**
19 * Command that basically replaces one OSM primitive by another of the
20 * same type.
21 *
22 * @author Imi
23 */
24public class ChangeCommand extends Command {
25
26 private final OsmPrimitive osm;
27 private final OsmPrimitive newOsm;
28
29 public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
30 super();
31 this.osm = osm;
32 this.newOsm = newOsm;
33 }
34
35 @Override public boolean executeCommand() {
36 super.executeCommand();
37 osm.cloneFrom(newOsm);
38 osm.setModified(true);
39 return true;
40 }
41
42 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
43 modified.add(osm);
44 }
45
46 @Override public MutableTreeNode description() {
47 String msg = "";
48 switch(OsmPrimitiveType.from(osm)) {
49 case NODE: msg = marktr("Change node {0}"); break;
50 case WAY: msg = marktr("Change way {0}"); break;
51 case RELATION: msg = marktr("Change relation {0}"); break;
52 }
53 return new DefaultMutableTreeNode(
54 new JLabel(tr(msg,
55 osm.getDisplayName(DefaultNameFormatter.getInstance()),
56 ImageProvider.get(OsmPrimitiveType.from(osm)),
57 JLabel.HORIZONTAL)));
58 }
59}
Note: See TracBrowser for help on using the repository browser.