source: josm/src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java@ 6

Last change on this file since 6 was 6, checked in by imi, 19 years ago
  • pretty preferrences menu
  • drawing double circles on double position hit
  • mergeNodes option
File size: 1.9 KB
Line 
1package org.openstreetmap.josm.actions.mapmode;
2
3import java.awt.Rectangle;
4import java.awt.event.KeyEvent;
5
6import org.openstreetmap.josm.data.GeoPoint;
7import org.openstreetmap.josm.gui.MapFrame;
8import org.openstreetmap.josm.gui.MapView;
9import org.openstreetmap.josm.gui.SelectionManager;
10import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded;
11
12/**
13 * Enable the zoom mode within the MapFrame.
14 *
15 * Holding down the left mouse button select a rectangle with the same aspect
16 * ratio than the current map view.
17 * Holding down left and right let the user move the former selected rectangle.
18 * Releasing the left button zoom to the selection.
19 *
20 * Rectangle selections with either height or width smaller than 3 pixels
21 * are ignored.
22 *
23 * @author imi
24 */
25public class ZoomAction extends MapMode implements SelectionEnded {
26
27 /**
28 * Shortcut to the mapview.
29 */
30 private final MapView mv;
31 /**
32 * Manager that manages the selection rectangle with the aspect ratio of the
33 * MapView.
34 */
35 private final SelectionManager selectionManager;
36
37
38 /**
39 * Construct a ZoomAction without a label.
40 * @param mapFrame The MapFrame, whose zoom mode should be enabled.
41 */
42 public ZoomAction(MapFrame mapFrame) {
43 super("Zoom", "zoom", "Zoom in by dragging", KeyEvent.VK_Z, mapFrame);
44 mv = mapFrame.mapView;
45 selectionManager = new SelectionManager(this, true, mv);
46 }
47
48 /**
49 * Zoom to the rectangle on the map.
50 */
51 public void selectionEnded(Rectangle r, int modifier) {
52 if (r.width >= 3 && r.height >= 3) {
53 double scale = mv.getScale() * r.getWidth()/mv.getWidth();
54 GeoPoint newCenter = mv.getPoint(r.x+r.width/2, r.y+r.height/2, false);
55 mv.zoomTo(newCenter, scale);
56 }
57 }
58
59 @Override
60 public void registerListener(MapView mapView) {
61 selectionManager.register(mapView);
62 }
63
64 @Override
65 public void unregisterListener(MapView mapView) {
66 selectionManager.unregister(mapView);
67 }
68}
Note: See TracBrowser for help on using the repository browser.