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

Revision 5152, 2.5 KB checked in by simon04, 7 weeks ago (diff)

see #3910 - original patch by Oliver Raupach - add lasso selection mode

  • Property svn:eol-style set to native
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;
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    public void selectionEnded(Rectangle r, MouseEvent e) {
54        if (r.width >= 3 && r.height >= 3 && Main.isDisplayingMapView()) {
55            MapView mv = Main.map.mapView;
56            mv.zoomToFactor(mv.getEastNorth(r.x+r.width/2, r.y+r.height/2), r.getWidth()/mv.getWidth());
57        }
58    }
59
60    @Override public void enterMode() {
61        super.enterMode();
62        selectionManager.register(Main.map.mapView, false);
63    }
64
65    @Override public void exitMode() {
66        super.exitMode();
67        selectionManager.unregister(Main.map.mapView);
68    }
69
70    @Override public String getModeHelpText() {
71        return tr("Zoom by dragging or Ctrl+. or Ctrl+,; move with Ctrl+up, left, down, right; move zoom with right button");
72    }
73}
Note: See TracBrowser for help on using the repository browser.