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

Last change on this file since 8342 was 8342, checked in by Don-vip, 9 years ago

code style - Close curly brace and the next "else", "catch" and "finally" keywords should be located on the same line

  • 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 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 repaint();
77 }
78 }
79
80 /**
81 * Refreshes the tile sources
82 * @since 6364
83 */
84 public final void refreshTileSources() {
85 if (pnlSlippyMapBBoxChooser != null) {
86 pnlSlippyMapBBoxChooser.refreshTileSources();
87 }
88 }
89}
Note: See TracBrowser for help on using the repository browser.