source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/MinimapDialog.java@ 10784

Last change on this file since 10784 was 10784, checked in by simon04, 8 years ago

see #11823 - Delay minimap initialization until first use

This does no longer cause the JCSCacheManager to be initialized when creating the MapFrame.

File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.beans.PropertyChangeEvent;
7import java.beans.PropertyChangeListener;
8import java.util.Collections;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.Bounds;
12import org.openstreetmap.josm.gui.MapView;
13import org.openstreetmap.josm.gui.NavigatableComponent;
14import org.openstreetmap.josm.gui.bbox.BBoxChooser;
15import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
16
17/**
18 * A small map of the current edit location implemented as {@link ToggleDialog}.
19 */
20public class MinimapDialog extends ToggleDialog implements NavigatableComponent.ZoomChangeListener, PropertyChangeListener {
21
22 private SlippyMapBBoxChooser slippyMap;
23 private boolean skipEvents;
24
25 /**
26 * Constructs a new {@code MinimapDialog}.
27 */
28 public MinimapDialog() {
29 super(tr("Mini map"), "minimap", tr("Displays a small map of the current edit location"), null, 150);
30 }
31
32 private synchronized void initialize() {
33 if (slippyMap != null) {
34 return;
35 }
36 slippyMap = new SlippyMapBBoxChooser();
37 createLayout(slippyMap, false, Collections.emptyList());
38 slippyMap.setSizeButtonVisible(false);
39 slippyMap.addPropertyChangeListener(BBoxChooser.BBOX_PROP, this);
40 }
41
42 @Override
43 public void showDialog() {
44 initialize();
45 NavigatableComponent.addZoomChangeListener(this);
46 super.showDialog();
47 }
48
49 @Override
50 public void hideDialog() {
51 NavigatableComponent.removeZoomChangeListener(this);
52 super.hideDialog();
53 }
54
55 @Override
56 public void zoomChanged() {
57 if (Main.isDisplayingMapView() && !skipEvents) {
58 MapView mv = Main.map.mapView;
59 final Bounds currentBounds = new Bounds(
60 mv.getLatLon(0, mv.getHeight()),
61 mv.getLatLon(mv.getWidth(), 0)
62 );
63 skipEvents = true;
64 slippyMap.setBoundingBox(currentBounds);
65 slippyMap.zoomOut(); // to give a better overview
66 skipEvents = false;
67 }
68 }
69
70 @Override
71 public void propertyChange(PropertyChangeEvent evt) {
72 if (!skipEvents) {
73 skipEvents = true;
74 Main.map.mapView.zoomTo(slippyMap.getBoundingBox());
75 skipEvents = false;
76 }
77 }
78}
Note: See TracBrowser for help on using the repository browser.