Changeset 2758 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-01-07T18:20:47+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r2711 r2758 28 28 public class AutoScaleAction extends JosmAction { 29 29 30 public static final String[] MODES = { marktr("data"), marktr("layer"), marktr("selection"), marktr("conflict"), marktr("download") }; 30 public static final String[] MODES = { 31 marktr("data"), 32 marktr("layer"), 33 marktr("selection"), 34 marktr("conflict"), 35 marktr("download"), 36 marktr("previous"), 37 marktr("next")}; 31 38 32 39 /** … … 81 88 shortcut = KeyEvent.VK_5; 82 89 } 90 if (mode.equals("previous")) { 91 shortcut = KeyEvent.VK_8; 92 } 93 if (mode.equals("next")) { 94 shortcut = KeyEvent.VK_9; 95 } 83 96 84 97 return shortcut; … … 99 112 } else if (mode.equals("conflict")) { 100 113 putValue("help", ht("/Action/ZoomToConflict")); 101 } else if (mode.equals("download")) {114 } else if (mode.equals("download")) { 102 115 putValue("help", ht("/Action/ZoomToDownload")); 116 } else if (mode.equals("previous")) { 117 putValue("help", ht("/Action/ZoomPrevious")); 118 } else if (mode.equals("next")) { 119 putValue("help", ht("/Action/ZoomNext")); 103 120 } 104 121 } … … 106 123 public void autoScale() { 107 124 if (Main.map != null) { 108 BoundingXYVisitor bbox = getBoundingBox(); 109 if (bbox != null && bbox.getBounds() != null) { 110 Main.map.mapView.recalculateCenterScale(bbox); 125 if (mode.equals("previous")) { 126 Main.map.mapView.zoomPrevious(); 127 } else if (mode.equals("next")) { 128 Main.map.mapView.zoomNext(); 129 } else { 130 BoundingXYVisitor bbox = getBoundingBox(); 131 if (bbox != null && bbox.getBounds() != null) { 132 Main.map.mapView.recalculateCenterScale(bbox); 133 } 111 134 } 112 135 } -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r2578 r2758 8 8 import java.util.Collection; 9 9 import java.util.Collections; 10 import java.util.Date; 10 11 import java.util.HashSet; 11 12 import java.util.LinkedList; … … 205 206 */ 206 207 private void zoomTo(EastNorth newCenter, double newScale) { 207 boolean rep = false;208 209 208 Bounds b = getProjection().getWorldBoundsLatLon(); 210 209 CachedLatLon cl = new CachedLatLon(newCenter); … … 219 218 newCenter = new CachedLatLon(lat, lon).getEastNorth(); 220 219 } 221 if (!newCenter.equals(center)) {222 EastNorth oldCenter = center;223 center = newCenter;224 rep = true;225 firePropertyChange("center", oldCenter, newCenter);226 }227 228 220 int width = getWidth()/2; 229 221 int height = getHeight()/2; … … 250 242 } 251 243 } 244 245 if (!newCenter.equals(center) || (scale != newScale)) { 246 pushZoomUndo(center, scale); 247 zoomNoUndoTo(newCenter, newScale); 248 } 249 } 250 251 /** 252 * Zoom to the given coordinate without adding to the zoom undo buffer. 253 * @param newCenter The center x-value (easting) to zoom to. 254 * @param scale The scale to use. 255 */ 256 private void zoomNoUndoTo(EastNorth newCenter, double newScale) { 257 if (!newCenter.equals(center)) { 258 EastNorth oldCenter = center; 259 center = newCenter; 260 firePropertyChange("center", oldCenter, newCenter); 261 } 252 262 if (scale != newScale) { 253 263 double oldScale = scale; 254 264 scale = newScale; 255 rep = true;256 265 firePropertyChange("scale", oldScale, newScale); 257 266 } 258 267 259 if(rep) { 260 repaint(); 261 } 268 repaint(); 262 269 } 263 270 … … 313 320 zoomTo(new ProjectionBounds(getProjection().latlon2eastNorth(box.getMin()), 314 321 getProjection().latlon2eastNorth(box.getMax()))); 322 } 323 324 private class ZoomData { 325 LatLon center; 326 double scale; 327 328 public ZoomData(EastNorth center, double scale) { 329 this.center = new CachedLatLon(center); 330 this.scale = scale; 331 } 332 333 public EastNorth getCenterEastNorth() { 334 return getProjection().latlon2eastNorth(center); 335 } 336 337 public double getScale() { 338 return scale; 339 } 340 } 341 342 private LinkedList<ZoomData> zoomUndoBuffer = new LinkedList<ZoomData>(); 343 private LinkedList<ZoomData> zoomRedoBuffer = new LinkedList<ZoomData>(); 344 private Date zoomTimestamp = new Date(); 345 346 private void pushZoomUndo(EastNorth center, double scale) { 347 Date now = new Date(); 348 if ((now.getTime() - zoomTimestamp.getTime()) > (Main.pref.getDouble("zoom.delay", 1.0) * 1000)) { 349 zoomUndoBuffer.push(new ZoomData(center, scale)); 350 zoomRedoBuffer.clear(); 351 } 352 zoomTimestamp = now; 353 } 354 355 public void zoomPrevious() { 356 if (!zoomUndoBuffer.isEmpty()) { 357 ZoomData zoom = zoomUndoBuffer.pop(); 358 zoomRedoBuffer.push(new ZoomData(center, scale)); 359 zoomNoUndoTo(zoom.getCenterEastNorth(), zoom.getScale()); 360 } 361 } 362 363 public void zoomNext() { 364 if (!zoomRedoBuffer.isEmpty()) { 365 ZoomData zoom = zoomRedoBuffer.pop(); 366 zoomUndoBuffer.push(new ZoomData(center, scale)); 367 zoomNoUndoTo(zoom.getCenterEastNorth(), zoom.getScale()); 368 } 315 369 } 316 370
Note:
See TracChangeset
for help on using the changeset viewer.