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

Last change on this file since 2405 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
RevLine 
[298]1// License: GPL. Copyright 2007 by Immanuel Scholz and others
[343]2package org.openstreetmap.josm.command;
3
[1989]4import static org.openstreetmap.josm.tools.I18n.marktr;
[343]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;
[1814]14import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
[1990]15import org.openstreetmap.josm.gui.DefaultNameFormatter;
[1814]16import org.openstreetmap.josm.tools.ImageProvider;
[343]17
18/**
[1169]19 * Command that basically replaces one OSM primitive by another of the
[343]20 * same type.
[1169]21 *
[343]22 * @author Imi
23 */
24public class ChangeCommand extends Command {
25
[1169]26 private final OsmPrimitive osm;
27 private final OsmPrimitive newOsm;
[343]28
[1169]29 public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
[1750]30 super();
[1169]31 this.osm = osm;
32 this.newOsm = newOsm;
[343]33 }
34
[1169]35 @Override public boolean executeCommand() {
36 super.executeCommand();
37 osm.cloneFrom(newOsm);
[2025]38 osm.setModified(true);
[1169]39 return true;
[343]40 }
41
[1169]42 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
43 modified.add(osm);
[343]44 }
45
[1169]46 @Override public MutableTreeNode description() {
[1989]47 String msg = "";
48 switch(OsmPrimitiveType.from(osm)) {
[2025]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;
[1989]52 }
[1814]53 return new DefaultMutableTreeNode(
[1989]54 new JLabel(tr(msg,
[1990]55 osm.getDisplayName(DefaultNameFormatter.getInstance()),
[1814]56 ImageProvider.get(OsmPrimitiveType.from(osm)),
[1990]57 JLabel.HORIZONTAL)));
[343]58 }
59}
Note: See TracBrowser for help on using the repository browser.