Ticket #8987: core.diff
| File core.diff, 10.5 KB (added by , 13 years ago) |
|---|
-
src/org/openstreetmap/josm/command/Command.java
15 15 import javax.swing.JPanel; 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.coor.EastNorth; 19 import org.openstreetmap.josm.data.coor.LatLon; 18 20 import org.openstreetmap.josm.data.osm.Node; 19 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 22 import org.openstreetmap.josm.data.osm.PrimitiveData; … … 53 55 } 54 56 } 55 57 58 /** 59 * Small helper for holding the interesting part of the old data state of the 60 * objects. 61 */ 62 public static class OldNodeState { 63 64 final LatLon latlon; 65 final EastNorth eastNorth; // cached EastNorth to be used for applying exact displacement 66 final boolean modified; 67 68 public OldNodeState(Node node){ 69 latlon = node.getCoor(); 70 eastNorth = node.getEastNorth(); 71 modified = node.isModified(); 72 } 73 } 74 56 75 /** the map of OsmPrimitives in the original state to OsmPrimitives in cloned state */ 57 76 private Map<OsmPrimitive, PrimitiveData> cloneMap = new HashMap<OsmPrimitive, PrimitiveData>(); 58 77 -
src/org/openstreetmap/josm/command/MoveCommand.java
8 8 import java.util.Iterator; 9 9 import java.util.LinkedList; 10 10 import java.util.List; 11 11 12 import javax.swing.Icon; 12 13 13 14 import org.openstreetmap.josm.data.coor.EastNorth; … … 47 48 private double backupY; 48 49 49 50 /** 50 * Small helper for holding the interesting part of the old data state of the51 * objects.52 */53 public static class OldState {54 LatLon latlon;55 EastNorth en; // cached EastNorth to be used for applying exact displacenment56 boolean modified;57 }58 59 /**60 51 * List of all old states of the objects. 61 52 */ 62 private List<Old State> oldState = new LinkedList<OldState>();53 private List<OldNodeState> oldState = new LinkedList<OldNodeState>(); 63 54 64 55 public MoveCommand(OsmPrimitive osm, double x, double y) { 65 56 this(Collections.singleton(osm), x, y); … … 84 75 this.y = y; 85 76 this.nodes = AllNodesVisitor.getAllNodes(objects); 86 77 for (Node n : this.nodes) { 87 OldState os = new OldState(); 88 os.latlon = new LatLon(n.getCoor()); 89 os.en = n.getEastNorth(); 90 os.modified = n.isModified(); 91 oldState.add(os); 78 oldState.add(new OldNodeState(n)); 92 79 } 93 80 } 94 81 95 public MoveCommand(Collection<OsmPrimitive> objects, EastNorth start, EastNorth end) {96 this(objects, end.getX()-start.getX(), end.getY()-start.getY());97 startEN = start;98 }82 public MoveCommand(Collection<OsmPrimitive> objects, EastNorth start, EastNorth end) { 83 this(objects, end.getX()-start.getX(), end.getY()-start.getY()); 84 startEN = start; 85 } 99 86 100 public MoveCommand(OsmPrimitive p, EastNorth start, EastNorth end) {101 this(Collections.singleton(p), end.getX()-start.getX(), end.getY()-start.getY());102 startEN = start;103 }87 public MoveCommand(OsmPrimitive p, EastNorth start, EastNorth end) { 88 this(Collections.singleton(p), end.getX()-start.getX(), end.getY()-start.getY()); 89 startEN = start; 90 } 104 91 105 92 /** 106 93 * Move the same set of objects again by the specified vector. The vectors … … 134 121 updateCoordinates(); 135 122 } 136 123 137 /**124 /** 138 125 * Changes base point of movement 139 126 * @param newDraggedStartPoint - new starting point after movement (where user clicks to start new drag) 140 127 */ 141 128 public void changeStartPoint(EastNorth newDraggedStartPoint) { 142 129 startEN = new EastNorth(newDraggedStartPoint.getX()-x, newDraggedStartPoint.getY()-y); 143 }130 } 144 131 145 132 /** 146 133 * Save curent displacement to restore in case of some problems … … 160 147 } 161 148 162 149 private void updateCoordinates() { 163 Iterator<Old State> it = oldState.iterator();150 Iterator<OldNodeState> it = oldState.iterator(); 164 151 for (Node n : nodes) { 165 Old State os = it.next();166 n.setEastNorth(os.e n.add(x, y));152 OldNodeState os = it.next(); 153 n.setEastNorth(os.eastNorth.add(x, y)); 167 154 } 168 155 } 169 156 … … 182 169 } 183 170 184 171 @Override public void undoCommand() { 185 Iterator<Old State> it = oldState.iterator();172 Iterator<OldNodeState> it = oldState.iterator(); 186 173 for (Node n : nodes) { 187 Old State os = it.next();174 OldNodeState os = it.next(); 188 175 n.setCoor(os.latlon); 189 176 n.setModified(os.modified); 190 177 } -
src/org/openstreetmap/josm/command/TransformNodesCommand.java
11 11 import javax.swing.Icon; 12 12 13 13 import org.openstreetmap.josm.data.coor.EastNorth; 14 import org.openstreetmap.josm.data.coor.LatLon;15 14 import org.openstreetmap.josm.data.osm.Node; 16 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 16 import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; … … 29 28 */ 30 29 protected Collection<Node> nodes = new LinkedList<Node>(); 31 30 32 /**33 * Small helper for holding the interesting part of the old data state of the34 * nodes.35 */36 public static class OldState {37 LatLon latlon;38 EastNorth eastNorth;39 boolean modified;40 }41 31 42 32 /** 43 33 * List of all old states of the nodes. 44 34 */ 45 protected Map<Node, Old State> oldStates = new HashMap<Node, OldState>();35 protected Map<Node, OldNodeState> oldStates = new HashMap<Node, OldNodeState>(); 46 36 47 37 /** 48 38 * Stores the state of the nodes before the command. 49 39 */ 50 40 protected void storeOldState() { 51 41 for (Node n : this.nodes) { 52 OldState os = new OldState(); 53 os.latlon = new LatLon(n.getCoor()); 54 os.eastNorth = n.getEastNorth(); 55 os.modified = n.isModified(); 56 oldStates.put(n, os); 42 oldStates.put(n, new OldNodeState(n)); 57 43 } 58 44 } 59 45 … … 106 92 @Override 107 93 public void undoCommand() { 108 94 for (Node n : nodes) { 109 Old State os = oldStates.get(n);95 OldNodeState os = oldStates.get(n); 110 96 n.setCoor(os.latlon); 111 97 n.setModified(os.modified); 112 98 } -
src/org/openstreetmap/josm/data/coor/EastNorth.java
8 8 * 9 9 * @author Imi 10 10 */ 11 public class EastNorth extends Coordinate implements Cloneable{11 public class EastNorth extends Coordinate { 12 12 13 13 public EastNorth(double east, double north) { 14 14 super(east,north); … … 36 36 37 37 public EastNorth interpolate(EastNorth en2, double proportion) { 38 38 return new EastNorth(this.x + proportion * (en2.x - this.x), 39 this.y + proportion * (en2.y - this.y));39 this.y + proportion * (en2.y - this.y)); 40 40 } 41 41 42 42 public EastNorth getCenter(EastNorth en2) { … … 53 53 public double distance(final EastNorth en) { 54 54 return super.distance(en); 55 55 } 56 56 57 57 /** 58 58 * Returns the square of the euclidean distance from this {@code EastNorth} to a specified {@code EastNorth}. 59 59 * … … 73 73 public double length(){ 74 74 return Math.sqrt(x*x + y*y); 75 75 } 76 76 77 77 /** 78 78 * Returns the heading, in radians, that you have to use to get from 79 79 * this EastNorth to another. Heading is mapped into [0, 2pi) … … 83 83 */ 84 84 public double heading(EastNorth other) { 85 85 double hd = Math.atan2(other.east() - east(), other.north() - north()); 86 if(hd < 0) hd = 2 * Math.PI + hd; 86 if(hd < 0) { 87 hd = 2 * Math.PI + hd; 88 } 87 89 return hd; 88 90 } 89 91 … … 129 131 public boolean equalsEpsilon(EastNorth other, double e) { 130 132 return (Math.abs(x - other.x) < e && Math.abs(y - other.y) < e); 131 133 } 132 133 @Override134 public EastNorth clone() throws CloneNotSupportedException {135 return (EastNorth) super.clone();136 }137 134 } -
src/org/openstreetmap/josm/data/coor/LatLon.java
25 25 * 26 26 * @author Imi 27 27 */ 28 public class LatLon extends Coordinate implements Cloneable{28 public class LatLon extends Coordinate { 29 29 30 30 /** 31 31 * Minimum difference in location to not be represented as the same position. … … 157 157 super(lon, lat); 158 158 } 159 159 160 p ublicLatLon(LatLon coor) {160 protected LatLon(LatLon coor) { 161 161 super(coor.lon(), coor.lat()); 162 162 } 163 163 … … 221 221 } 222 222 223 223 /** 224 * Check if this is contained in given area or area is null. 224 * Check if this is contained in given area or area is null. 225 225 * 226 226 * @param a Area 227 * @return <code>true</code> if this is contained in given area or area is null. 227 * @return <code>true</code> if this is contained in given area or area is null. 228 228 */ 229 229 public boolean isIn(Area a) { 230 230 return a == null || a.contains(x, y); … … 305 305 public double distance(final LatLon ll) { 306 306 return super.distance(ll); 307 307 } 308 308 309 309 /** 310 310 * Returns the square of the euclidean distance from this {@code LatLon} to a specified {@code LatLon}. 311 311 * … … 316 316 public double distanceSq(final LatLon ll) { 317 317 return super.distanceSq(ll); 318 318 } 319 319 320 320 @Override public String toString() { 321 321 return "LatLon[lat="+lat()+",lon="+lon()+"]"; 322 322 } … … 394 394 return false; 395 395 return true; 396 396 } 397 398 @Override399 public LatLon clone() throws CloneNotSupportedException {400 return (LatLon) super.clone();401 }402 397 }
