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

Last change on this file since 1195 was 1195, checked in by stoecker, 15 years ago

fixed relation handling, applied language patches

  • Property svn:eol-style set to native
File size: 2.6 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;
15import org.openstreetmap.josm.tools.Shortcut;
16
17/**
18 * Enable the zoom mode within the MapFrame.
19 *
20 * Holding down the left mouse button select a rectangle with the same aspect
21 * ratio than the current map view.
22 * Holding down left and right let the user move the former selected rectangle.
23 * Releasing the left button zoom to the selection.
24 *
25 * Rectangle selections with either height or width smaller than 3 pixels
26 * are ignored.
27 *
28 * @author imi
29 */
30public class ZoomAction extends MapMode implements SelectionEnded {
31
32 /**
33 * Shortcut to the mapview.
34 */
35 private final MapView mv;
36 /**
37 * Manager that manages the selection rectangle with the aspect ratio of the
38 * MapView.
39 */
40 private final SelectionManager selectionManager;
41
42
43 /**
44 * Construct a ZoomAction without a label.
45 * @param mapFrame The MapFrame, whose zoom mode should be enabled.
46 */
47 public ZoomAction(MapFrame mapFrame) {
48 super(tr("Zoom"), "zoom", tr("Zoom and move map"),
49 Shortcut.registerShortcut("mapmode:zoom", tr("Mode: {0}", tr("Zoom")), KeyEvent.VK_Z, Shortcut.GROUP_EDIT),
50 mapFrame, ImageProvider.getCursor("normal", "zoom"));
51 mv = mapFrame.mapView;
52 selectionManager = new SelectionManager(this, true, mv);
53 }
54
55 /**
56 * Zoom to the rectangle on the map.
57 */
58 public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) {
59 if (r.width >= 3 && r.height >= 3) {
60 double scale = mv.getScale() * r.getWidth()/mv.getWidth();
61 EastNorth newCenter = mv.getEastNorth(r.x+r.width/2, r.y+r.height/2);
62 mv.zoomTo(newCenter, scale);
63 }
64 }
65
66 @Override public void enterMode() {
67 super.enterMode();
68 selectionManager.register(mv);
69 }
70
71 @Override public void exitMode() {
72 super.exitMode();
73 selectionManager.unregister(mv);
74 }
75
76 @Override public String getModeHelpText() {
77 return tr("Zoom by dragging or Ctrl+. or Ctrl+,; move with Ctrl+up, left, down, right; move zoom with right button");
78 }
79}
Note: See TracBrowser for help on using the repository browser.