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

Last change on this file since 2692 was 2512, checked in by stoecker, 14 years ago

i18n updated, fixed files to reduce problems when applying patches, fix #4017

  • Property svn:eol-style set to native
File size: 2.5 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.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;
14import org.openstreetmap.josm.tools.Shortcut;
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 * 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 and move map"),
47 Shortcut.registerShortcut("mapmode:zoom", tr("Mode: {0}", tr("Zoom")), KeyEvent.VK_Z, Shortcut.GROUP_EDIT),
48 mapFrame, ImageProvider.getCursor("normal", "zoom"));
49 mv = mapFrame.mapView;
50 selectionManager = new SelectionManager(this, true, mv);
51 }
52
53 /**
54 * Zoom to the rectangle on the map.
55 */
56 public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) {
57 if (r.width >= 3 && r.height >= 3) {
58 mv.zoomToFactor(mv.getEastNorth(r.x+r.width/2, r.y+r.height/2), r.getWidth()/mv.getWidth());
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
72 @Override public String getModeHelpText() {
73 return tr("Zoom by dragging or Ctrl+. or Ctrl+,; move with Ctrl+up, left, down, right; move zoom with right button");
74 }
75}
Note: See TracBrowser for help on using the repository browser.