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

Last change on this file since 6380 was 6380, checked in by Don-vip, 10 years ago

update license/copyright information

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