Changeset 5418 in josm for trunk/src/org/openstreetmap/josm/command
- Timestamp:
- 2012-08-10T21:01:12+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/MoveCommand.java
r4918 r5418 33 33 private Collection<Node> nodes = new LinkedList<Node>(); 34 34 /** 35 * Starting position, base command point, current (mouse-drag) position = startEN + (x,y) = 36 */ 37 private EastNorth startEN; 38 39 /** 35 40 * x difference movement. Coordinates are in northern/eastern 36 41 */ … … 40 45 */ 41 46 private double y; 47 48 private double backupX; 49 private double backupY; 42 50 43 51 /** … … 47 55 public static class OldState { 48 56 LatLon latlon; 57 EastNorth en; // cached EastNorth to be used for applying exact displacenment 49 58 boolean modified; 50 59 } … … 66 75 this(objects, offset.getX(), offset.getY()); 67 76 } 68 77 69 78 /** 70 79 * Create a MoveCommand and assign the initial object set and movement vector. … … 72 81 public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) { 73 82 super(); 83 startEN = null; 84 saveCheckpoint(); // (0,0) displacement will be saved 74 85 this.x = x; 75 86 this.y = y; … … 78 89 OldState os = new OldState(); 79 90 os.latlon = new LatLon(n.getCoor()); 91 os.en = n.getEastNorth(); 80 92 os.modified = n.isModified(); 81 93 oldState.add(os); … … 83 95 } 84 96 97 public MoveCommand(Collection<OsmPrimitive> objects, EastNorth start, EastNorth end) { 98 this(objects, end.getX()-start.getX(), end.getY()-start.getY()); 99 startEN = start; 100 } 101 102 public MoveCommand(OsmPrimitive p, EastNorth start, EastNorth end) { 103 this(Collections.singleton(p), end.getX()-start.getX(), end.getY()-start.getY()); 104 startEN = start; 105 } 106 85 107 /** 86 108 * Move the same set of objects again by the specified vector. The vectors … … 102 124 moveAgain(x - this.x, y - this.y); 103 125 } 126 127 /** 128 * Change the displacement vector to have endpoint @param currentEN 129 * starting point is startEN 130 */ 131 public void applyVectorTo(EastNorth currentEN) { 132 if (startEN == null) 133 return; 134 x = currentEN.getX() - startEN.getX(); 135 y = currentEN.getY() - startEN.getY(); 136 updateCoordinates(); 137 } 138 139 /** 140 * Changes base point of movement 141 * @param newDraggedStartPoint - new starting point after movement (where user clicks to start new drag) 142 */ 143 public void changeStartPoint(EastNorth newDraggedStartPoint) { 144 startEN = new EastNorth(newDraggedStartPoint.getX()-x, newDraggedStartPoint.getY()-y); 145 } 146 147 /** 148 * Save curent displacement to restore in case of some problems 149 */ 150 public void saveCheckpoint() { 151 backupX = x; 152 backupY = y; 153 } 154 155 /** 156 * Restore old displacement in case of some problems 157 */ 158 public void resetToCheckpoint() { 159 x = backupX; 160 y = backupY; 161 updateCoordinates(); 162 } 163 164 private void updateCoordinates() { 165 Iterator<OldState> it = oldState.iterator(); 166 for (Node n : nodes) { 167 OldState os = it.next(); 168 n.setEastNorth(os.en.add(x, y)); 169 } 170 } 104 171 105 172 @Override public boolean executeCommand() {
Note:
See TracChangeset
for help on using the changeset viewer.