001 // This code has been adapted and copied from code that has been written by Immanuel Scholz and others for JOSM.
002 // License: GPL. Copyright 2007 by Tim Haussmann
003 package org.openstreetmap.josm.gui.download;
004
005 import static org.openstreetmap.josm.tools.I18n.tr;
006
007 import java.awt.Dimension;
008 import java.awt.Graphics;
009 import java.awt.Toolkit;
010
011 import java.beans.PropertyChangeEvent;
012 import java.beans.PropertyChangeListener;
013
014 import javax.swing.JPanel;
015
016 import org.openstreetmap.josm.data.Bounds;
017 import org.openstreetmap.josm.gui.bbox.BBoxChooser;
018 import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
019
020 /**
021 * JComponent that displays the slippy map tiles
022 *
023 * @author Tim Haussmann
024 *
025 */
026 public class SlippyMapChooser extends JPanel implements DownloadSelection, PropertyChangeListener{
027
028 private DownloadDialog iGui;
029 private SlippyMapBBoxChooser pnlSlippyMapBBoxChooser;
030 // standard dimension
031 private Dimension iDownloadDialogDimension;
032
033 /**
034 * Create the chooser component.
035 */
036 public SlippyMapChooser() {
037 pnlSlippyMapBBoxChooser = new SlippyMapBBoxChooser();
038 pnlSlippyMapBBoxChooser.addPropertyChangeListener(this);
039 }
040
041 public void addGui(final DownloadDialog gui) {
042 iGui = gui;
043 iGui.addDownloadAreaSelector(pnlSlippyMapBBoxChooser, tr("Slippy map"));
044 }
045
046 public void setDownloadArea(Bounds area) {
047 pnlSlippyMapBBoxChooser.setBoundingBox(area);
048 repaint();
049 }
050
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 }