1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions.mapmode;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Rectangle;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.Main;
|
---|
10 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
11 | import org.openstreetmap.josm.gui.MapView;
|
---|
12 | import org.openstreetmap.josm.gui.SelectionManager;
|
---|
13 | import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded;
|
---|
14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
15 | import 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 | */
|
---|
30 | public class ZoomAction extends MapMode implements SelectionEnded {
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Manager that manages the selection rectangle with the aspect ratio of the
|
---|
34 | * MapView.
|
---|
35 | */
|
---|
36 | private final SelectionManager selectionManager;
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Construct a ZoomAction without a label.
|
---|
40 | * @param mapFrame The MapFrame, whose zoom mode should be enabled.
|
---|
41 | */
|
---|
42 | public ZoomAction(MapFrame mapFrame) {
|
---|
43 | super(tr("Zoom"), "zoom", tr("Zoom and move map"),
|
---|
44 | Shortcut.registerShortcut("mapmode:zoom", tr("Mode: {0}", tr("Zoom")), KeyEvent.VK_Z, Shortcut.GROUP_EDIT),
|
---|
45 | mapFrame, ImageProvider.getCursor("normal", "zoom"));
|
---|
46 | selectionManager = new SelectionManager(this, true, mapFrame.mapView);
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Zoom to the rectangle on the map.
|
---|
51 | */
|
---|
52 | public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) {
|
---|
53 | if (r.width >= 3 && r.height >= 3 && Main.isDisplayingMapView()) {
|
---|
54 | MapView mv = Main.map.mapView;
|
---|
55 | mv.zoomToFactor(mv.getEastNorth(r.x+r.width/2, r.y+r.height/2), r.getWidth()/mv.getWidth());
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override public void enterMode() {
|
---|
60 | super.enterMode();
|
---|
61 | selectionManager.register(Main.map.mapView);
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override public void exitMode() {
|
---|
65 | super.exitMode();
|
---|
66 | selectionManager.unregister(Main.map.mapView);
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Override public String getModeHelpText() {
|
---|
70 | return tr("Zoom by dragging or Ctrl+. or Ctrl+,; move with Ctrl+up, left, down, right; move zoom with right button");
|
---|
71 | }
|
---|
72 | }
|
---|