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

Last change on this file since 6590 was 6380, checked in by Don-vip, 11 years ago

update license/copyright information

  • Property svn:eol-style set to native
File size: 2.8 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.awt.Toolkit;
8import java.beans.PropertyChangeEvent;
9import java.beans.PropertyChangeListener;
10
11import javax.swing.JPanel;
12
13import org.openstreetmap.josm.data.Bounds;
14import org.openstreetmap.josm.gui.bbox.BBoxChooser;
15import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
16
17/**
18 * JComponent that displays the slippy map tiles
19 *
20 * @author Tim Haussmann
21 *
22 */
23public class SlippyMapChooser extends JPanel implements DownloadSelection, PropertyChangeListener {
24
25 private DownloadDialog iGui;
26 private SlippyMapBBoxChooser pnlSlippyMapBBoxChooser;
27 // standard dimension
28 private Dimension iDownloadDialogDimension;
29
30 /**
31 * Create the chooser component.
32 */
33 public SlippyMapChooser() {
34 pnlSlippyMapBBoxChooser = new SlippyMapBBoxChooser();
35 pnlSlippyMapBBoxChooser.addPropertyChangeListener(this);
36 }
37
38 @Override
39 public void addGui(final DownloadDialog gui) {
40 iGui = gui;
41 iGui.addDownloadAreaSelector(pnlSlippyMapBBoxChooser, tr("Slippy map"));
42 }
43
44 @Override
45 public void setDownloadArea(Bounds area) {
46 pnlSlippyMapBBoxChooser.setBoundingBox(area);
47 repaint();
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 = Toolkit.getDefaultToolkit().getScreenSize();
61
62 // enlarge
63 if(iDownloadDialogDimension == null) {
64 // 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 }
69 // shrink
70 else {
71 // set the size back to the initial dimensions
72 w = iDownloadDialogDimension.width;
73 h = iDownloadDialogDimension.height;
74 iDownloadDialogDimension = null;
75 }
76
77 // resize and center the DownloadDialog
78 iGui.setBounds((iScreenSize.width - w) / 2, (iScreenSize.height - h) / 2, w, h);
79 repaint();
80 }
81 }
82
83 /**
84 * Refreshes the tile sources
85 * @since 6364
86 */
87 public final void refreshTileSources() {
88 if (pnlSlippyMapBBoxChooser != null) {
89 pnlSlippyMapBBoxChooser.refreshTileSources();
90 }
91 }
92}
Note: See TracBrowser for help on using the repository browser.