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

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