1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.download;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Dimension;
|
---|
7 | import java.beans.PropertyChangeEvent;
|
---|
8 | import java.beans.PropertyChangeListener;
|
---|
9 |
|
---|
10 | import javax.swing.ActionMap;
|
---|
11 | import javax.swing.JPanel;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.data.Bounds;
|
---|
14 | import org.openstreetmap.josm.gui.bbox.BBoxChooser;
|
---|
15 | import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
|
---|
16 | import 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 | */
|
---|
24 | public class SlippyMapChooser extends JPanel 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 | repaint();
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
53 | if (evt.getPropertyName().equals(BBoxChooser.BBOX_PROP)) {
|
---|
54 | if (iGui != null) {
|
---|
55 | iGui.boundingBoxChanged((Bounds) evt.getNewValue(), this);
|
---|
56 | }
|
---|
57 | } else if (evt.getPropertyName().equals(SlippyMapBBoxChooser.RESIZE_PROP)) {
|
---|
58 | int w, h;
|
---|
59 |
|
---|
60 | // retrieve the size of the display
|
---|
61 | Dimension iScreenSize = GuiHelper.getScreenSize();
|
---|
62 |
|
---|
63 | if (iDownloadDialogDimension == null) {
|
---|
64 | // enlarge: make the each dimension 90% of the absolute display size
|
---|
65 | w = iScreenSize.width * 90 / 100;
|
---|
66 | h = iScreenSize.height * 90 / 100;
|
---|
67 | iDownloadDialogDimension = iGui.getSize();
|
---|
68 | } else {
|
---|
69 | // shrink: set the size back to the initial dimensions
|
---|
70 | w = iDownloadDialogDimension.width;
|
---|
71 | h = iDownloadDialogDimension.height;
|
---|
72 | iDownloadDialogDimension = null;
|
---|
73 | }
|
---|
74 |
|
---|
75 | // resize and center the DownloadDialog
|
---|
76 | iGui.setBounds((iScreenSize.width - w) / 2, (iScreenSize.height - h) / 2, w, h);
|
---|
77 | repaint();
|
---|
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 | }
|
---|