Changeset 1169 in josm for trunk/src/org/openstreetmap/josm/command/MoveCommand.java
- Timestamp:
- 2008-12-23T15:07:05+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/MoveCommand.java
r655 r1169 26 26 * MoveCommand moves a set of OsmPrimitives along the map. It can be moved again 27 27 * to collect several MoveCommands into one command. 28 * 28 * 29 29 * @author imi 30 30 */ 31 31 public class MoveCommand extends Command { 32 33 34 35 36 37 * x difference movement. Coordinates are in northern/eastern 38 39 40 41 * y difference movement. Coordinates are in northern/eastern 42 43 32 /** 33 * The objects that should be moved. 34 */ 35 public Collection<Node> objects = new LinkedList<Node>(); 36 /** 37 * x difference movement. Coordinates are in northern/eastern 38 */ 39 private double x; 40 /** 41 * y difference movement. Coordinates are in northern/eastern 42 */ 43 private double y; 44 44 45 /** 46 * Small helper for holding the interesting part of the old data state of the 47 * objects. 48 */ 49 public static class OldState { 50 LatLon latlon; 51 EastNorth eastNorth; 52 boolean modified; 53 } 54 55 /** 56 * List of all old states of the objects. 57 */ 58 private List<OldState> oldState = new LinkedList<OldState>(); 45 /** 46 * Small helper for holding the interesting part of the old data state of the 47 * objects. 48 */ 49 public static class OldState { 50 LatLon latlon; 51 EastNorth eastNorth; 52 boolean modified; 53 } 59 54 60 61 public MoveCommand(OsmPrimitive osm, double x, double y) { 62 this(Collections.singleton(osm), x, y); 63 } 64 /** 65 * Create a MoveCommand and assign the initial object set and movement vector. 66 */ 67 public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) { 68 this.x = x; 69 this.y = y; 70 this.objects = AllNodesVisitor.getAllNodes(objects); 71 for (Node n : this.objects) { 72 OldState os = new OldState(); 73 os.eastNorth = n.eastNorth; 74 os.latlon = n.coor; 75 os.modified = n.modified; 76 oldState.add(os); 77 } 78 } 55 /** 56 * List of all old states of the objects. 57 */ 58 private List<OldState> oldState = new LinkedList<OldState>(); 79 59 80 /**81 * Move the same set of objects again by the specified vector. The vectors82 * are added together and so the resulting will be moved to the previous83 * vector plus this one.84 *85 * The move is immediately executed and any undo will undo both vectors to86 * the original position the objects had before first moving.87 */88 public void moveAgain(double x, double y) {89 for (Node n : objects) {90 n.eastNorth = new EastNorth(n.eastNorth.east()+x, n.eastNorth.north()+y);91 n.coor = Main.proj.eastNorth2latlon(n.eastNorth);92 }93 this.x += x;94 this.y += y;95 }96 97 @Override public boolean executeCommand() {98 for (Node n : objects) {99 n.eastNorth = new EastNorth(n.eastNorth.east()+x, n.eastNorth.north()+y);100 n.coor = Main.proj.eastNorth2latlon(n.eastNorth);101 n.modified = true;102 }103 return true;104 }105 60 106 @Override public void undoCommand() { 107 Iterator<OldState> it = oldState.iterator(); 108 for (Node n : objects) { 109 OldState os = it.next(); 110 n.eastNorth = os.eastNorth; 111 n.coor = os.latlon; 112 n.modified = os.modified; 113 } 114 } 61 public MoveCommand(OsmPrimitive osm, double x, double y) { 62 this(Collections.singleton(osm), x, y); 63 } 64 /** 65 * Create a MoveCommand and assign the initial object set and movement vector. 66 */ 67 public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) { 68 this.x = x; 69 this.y = y; 70 this.objects = AllNodesVisitor.getAllNodes(objects); 71 for (Node n : this.objects) { 72 OldState os = new OldState(); 73 os.eastNorth = n.eastNorth; 74 os.latlon = n.coor; 75 os.modified = n.modified; 76 oldState.add(os); 77 } 78 } 115 79 116 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 117 for (OsmPrimitive osm : objects) 118 modified.add(osm); 119 } 80 /** 81 * Move the same set of objects again by the specified vector. The vectors 82 * are added together and so the resulting will be moved to the previous 83 * vector plus this one. 84 * 85 * The move is immediately executed and any undo will undo both vectors to 86 * the original position the objects had before first moving. 87 */ 88 public void moveAgain(double x, double y) { 89 for (Node n : objects) { 90 n.eastNorth = new EastNorth(n.eastNorth.east()+x, n.eastNorth.north()+y); 91 n.coor = Main.proj.eastNorth2latlon(n.eastNorth); 92 } 93 this.x += x; 94 this.y += y; 95 } 120 96 121 @Override public MutableTreeNode description() { 122 return new DefaultMutableTreeNode(new JLabel(tr("Move")+" "+objects.size()+" "+trn("node","nodes",objects.size()), ImageProvider.get("data", "node"), JLabel.HORIZONTAL)); 97 @Override public boolean executeCommand() { 98 for (Node n : objects) { 99 n.eastNorth = new EastNorth(n.eastNorth.east()+x, n.eastNorth.north()+y); 100 n.coor = Main.proj.eastNorth2latlon(n.eastNorth); 101 n.modified = true; 102 } 103 return true; 104 } 105 106 @Override public void undoCommand() { 107 Iterator<OldState> it = oldState.iterator(); 108 for (Node n : objects) { 109 OldState os = it.next(); 110 n.eastNorth = os.eastNorth; 111 n.coor = os.latlon; 112 n.modified = os.modified; 113 } 114 } 115 116 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 117 for (OsmPrimitive osm : objects) 118 modified.add(osm); 119 } 120 121 @Override public MutableTreeNode description() { 122 return new DefaultMutableTreeNode(new JLabel(tr("Move")+" "+objects.size()+" "+trn("node","nodes",objects.size()), ImageProvider.get("data", "node"), JLabel.HORIZONTAL)); 123 123 } 124 124 }
Note:
See TracChangeset
for help on using the changeset viewer.