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

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