source: josm/trunk/src/org/openstreetmap/josm/gui/download/SlippyMapChooser.java@ 17318

Last change on this file since 17318 was 16920, checked in by simon04, 4 years ago

fix #7638 - Download dialog: add status bar with lat/lon of mouse cursor and selected download area (for experts)

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.download;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Dimension;
7import java.beans.PropertyChangeEvent;
8import java.beans.PropertyChangeListener;
9
10import javax.swing.ActionMap;
11
12import org.openstreetmap.josm.data.Bounds;
13import org.openstreetmap.josm.data.coor.ILatLon;
14import org.openstreetmap.josm.gui.bbox.BBoxChooser;
15import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
16import org.openstreetmap.josm.gui.util.GuiHelper;
17
18/**
19 * JComponent that displays the slippy map tiles.
20 *
21 * @author Tim Haussmann
22 * @since 1390
23 */
24public class SlippyMapChooser implements DownloadSelection, PropertyChangeListener {
25
26 private DownloadDialog iGui;
27 private final SlippyMapBBoxChooser pnlSlippyMapBBoxChooser;
28 // standard dimension
29 private Dimension iDownloadDialogDimension;
30
31 /**
32 * Create the chooser component.
33 */
34 public SlippyMapChooser() {
35 pnlSlippyMapBBoxChooser = new SlippyMapBBoxChooser();
36 pnlSlippyMapBBoxChooser.addPropertyChangeListener(this);
37 }
38
39 @Override
40 public void addGui(final DownloadDialog gui) {
41 iGui = gui;
42 iGui.addDownloadAreaSelector(pnlSlippyMapBBoxChooser, tr("Slippy map"));
43 }
44
45 @Override
46 public void setDownloadArea(Bounds area) {
47 pnlSlippyMapBBoxChooser.setBoundingBox(area);
48 }
49
50 @Override
51 public void propertyChange(PropertyChangeEvent evt) {
52 if (evt.getPropertyName().equals(BBoxChooser.BBOX_PROP)) {
53 if (iGui != null) {
54 iGui.boundingBoxChanged((Bounds) evt.getNewValue(), this);
55 }
56 } else if (evt.getPropertyName().equals(SlippyMapBBoxChooser.RESIZE_PROP)) {
57 int w, h;
58
59 // retrieve the size of the display
60 Dimension iScreenSize = GuiHelper.getScreenSize();
61
62 if (iDownloadDialogDimension == null) {
63 // enlarge: make the each dimension 90% of the absolute display size
64 w = iScreenSize.width * 90 / 100;
65 h = iScreenSize.height * 90 / 100;
66 iDownloadDialogDimension = iGui.getSize();
67 } else {
68 // shrink: set the size back to the initial dimensions
69 w = iDownloadDialogDimension.width;
70 h = iDownloadDialogDimension.height;
71 iDownloadDialogDimension = null;
72 }
73
74 // resize and center the DownloadDialog
75 iGui.setBounds((iScreenSize.width - w) / 2, (iScreenSize.height - h) / 2, w, h);
76 } else if (evt.getPropertyName().equals(SlippyMapBBoxChooser.CURSOR_COORDINATE_PROP)) {
77 iGui.mapCursorChanged((ILatLon) evt.getNewValue());
78 }
79 }
80
81 /**
82 * Refreshes the tile sources
83 * @since 6364
84 */
85 public final void refreshTileSources() {
86 if (pnlSlippyMapBBoxChooser != null) {
87 pnlSlippyMapBBoxChooser.refreshTileSources();
88 }
89 }
90
91 /**
92 * Returns the action map of the underlying navigation component.
93 * @return the action map of the underlying navigation component
94 * @since 8932
95 */
96 public final ActionMap getNavigationComponentActionMap() {
97 return pnlSlippyMapBBoxChooser.getActionMap();
98 }
99}
Note: See TracBrowser for help on using the repository browser.