001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.download; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.Dimension; 007import java.awt.Toolkit; 008import java.beans.PropertyChangeEvent; 009import java.beans.PropertyChangeListener; 010 011import javax.swing.JPanel; 012 013import org.openstreetmap.josm.data.Bounds; 014import org.openstreetmap.josm.gui.bbox.BBoxChooser; 015import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; 016 017/** 018 * JComponent that displays the slippy map tiles 019 * 020 * @author Tim Haussmann 021 * 022 */ 023public class SlippyMapChooser extends JPanel implements DownloadSelection, PropertyChangeListener { 024 025 private DownloadDialog iGui; 026 private SlippyMapBBoxChooser pnlSlippyMapBBoxChooser; 027 // standard dimension 028 private Dimension iDownloadDialogDimension; 029 030 /** 031 * Create the chooser component. 032 */ 033 public SlippyMapChooser() { 034 pnlSlippyMapBBoxChooser = new SlippyMapBBoxChooser(); 035 pnlSlippyMapBBoxChooser.addPropertyChangeListener(this); 036 } 037 038 @Override 039 public void addGui(final DownloadDialog gui) { 040 iGui = gui; 041 iGui.addDownloadAreaSelector(pnlSlippyMapBBoxChooser, tr("Slippy map")); 042 } 043 044 @Override 045 public void setDownloadArea(Bounds area) { 046 pnlSlippyMapBBoxChooser.setBoundingBox(area); 047 repaint(); 048 } 049 050 @Override 051 public void propertyChange(PropertyChangeEvent evt) { 052 if (evt.getPropertyName().equals(BBoxChooser.BBOX_PROP)) { 053 if (iGui != null) { 054 iGui.boundingBoxChanged((Bounds)evt.getNewValue(), this); 055 } 056 } else if(evt.getPropertyName().equals(SlippyMapBBoxChooser.RESIZE_PROP)) { 057 int w, h; 058 059 // retrieve the size of the display 060 Dimension iScreenSize = Toolkit.getDefaultToolkit().getScreenSize(); 061 062 // enlarge 063 if(iDownloadDialogDimension == null) { 064 // make the each dimension 90% of the absolute display size 065 w = iScreenSize.width * 90 / 100; 066 h = iScreenSize.height * 90 / 100; 067 iDownloadDialogDimension = iGui.getSize(); 068 } 069 // shrink 070 else { 071 // set the size back to the initial dimensions 072 w = iDownloadDialogDimension.width; 073 h = iDownloadDialogDimension.height; 074 iDownloadDialogDimension = null; 075 } 076 077 // resize and center the DownloadDialog 078 iGui.setBounds((iScreenSize.width - w) / 2, (iScreenSize.height - h) / 2, w, h); 079 repaint(); 080 } 081 } 082 083 /** 084 * Refreshes the tile sources 085 * @since 6364 086 */ 087 public final void refreshTileSources() { 088 if (pnlSlippyMapBBoxChooser != null) { 089 pnlSlippyMapBBoxChooser.refreshTileSources(); 090 } 091 } 092}