source: josm/src/org/openstreetmap/josm/command/MoveCommand.java@ 23

Last change on this file since 23 was 23, checked in by imi, 19 years ago
  • added commands to support undo later
  • added Edit-Layer concept
  • painting of deleted objects
File size: 1.8 KB
Line 
1package org.openstreetmap.josm.command;
2
3import java.awt.Component;
4import java.util.Collection;
5
6import javax.swing.JLabel;
7
8import org.openstreetmap.josm.data.osm.Node;
9import org.openstreetmap.josm.data.osm.OsmPrimitive;
10import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor;
11
12/**
13 * MoveCommand moves a set of OsmPrimitives along the map. It can be moved again
14 * to collect several MoveCommands into one command.
15 *
16 * @author imi
17 */
18public class MoveCommand implements Command {
19
20 /**
21 * The objects that should be moved.
22 */
23 private Collection<OsmPrimitive> objects;
24 /**
25 * x difference movement. Coordinates are in northern/eastern
26 */
27 private double x;
28 /**
29 * y difference movement. Coordinates are in northern/eastern
30 */
31 private double y;
32
33 /**
34 * Create a MoveCommand and assign the initial object set and movement vector.
35 */
36 public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) {
37 this.objects = objects;
38 this.x = x;
39 this.y = y;
40 }
41
42 /**
43 * Move the objects additional to the current movement.
44 */
45 public void move(double x, double y) {
46 this.x += x;
47 this.y += y;
48 }
49
50 public void executeCommand() {
51 AllNodesVisitor visitor = new AllNodesVisitor();
52 for (OsmPrimitive osm : objects)
53 osm.visit(visitor);
54 for (Node n : visitor.nodes) {
55 n.coor.x += x;
56 n.coor.y += y;
57 }
58 }
59
60 public Component commandDescription() {
61 String xstr = Math.abs(x) + (x < 0 ? "W" : "E");
62 String ystr = Math.abs(y) + (y < 0 ? "S" : "N");
63 return new JLabel("Move "+objects.size()+" primitives "+xstr+" "+ystr);
64 }
65
66 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
67 if (modified != null)
68 for (OsmPrimitive osm : objects)
69 if (!modified.contains(osm))
70 modified.add(osm);
71 }
72}
Note: See TracBrowser for help on using the repository browser.