[298] | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
[343] | 2 | package org.openstreetmap.josm.command;
|
---|
| 3 |
|
---|
[1989] | 4 | import static org.openstreetmap.josm.tools.I18n.marktr;
|
---|
[343] | 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 6 |
|
---|
| 7 | import java.util.Collection;
|
---|
| 8 |
|
---|
| 9 | import javax.swing.JLabel;
|
---|
| 10 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
| 11 | import javax.swing.tree.MutableTreeNode;
|
---|
| 12 |
|
---|
| 13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
[1814] | 14 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
[1990] | 15 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
[1814] | 16 | import 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 | */
|
---|
| 24 | public 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 | }
|
---|