Changeset 1428 in josm for trunk/src


Ignore:
Timestamp:
2009-02-19T18:13:30+01:00 (16 years ago)
Author:
stoecker
Message:

fixed #2159. Patch by Jan Peter Stotz

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/download/SlippyMapChooser.java

    r1390 r1428  
    1111import java.awt.Graphics;
    1212import java.awt.Point;
     13import java.awt.Rectangle;
    1314import java.awt.Toolkit;
    14 import java.awt.event.ComponentEvent;
    15 import java.awt.event.ComponentListener;
    1615import java.awt.geom.Point2D;
    1716import java.util.Vector;
     
    2726import org.openstreetmap.gui.jmapviewer.OsmTileLoader;
    2827import org.openstreetmap.gui.jmapviewer.OsmTileSource;
    29 import org.openstreetmap.gui.jmapviewer.OsmTileSource.CycleMap;
    3028import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker;
    3129import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
    3230import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    3331import org.openstreetmap.josm.Main;
    34 import org.openstreetmap.josm.gui.download.DownloadDialog;
    35 import org.openstreetmap.josm.gui.download.DownloadSelection;
    3632
    3733/**
     
    4137 *
    4238 */
    43 public class SlippyMapChooser extends JMapViewer implements DownloadSelection, ComponentListener {
     39public class SlippyMapChooser extends JMapViewer implements DownloadSelection {
    4440
    4541    private DownloadDialog iGui;
     
    5854    private Dimension iScreenSize;
    5955
    60     private TileSource[] sources = { new OsmTileSource.Mapnik(), new OsmTileSource.TilesAtHome(),new OsmTileSource.CycleMap()};
     56    private TileSource[] sources = { new OsmTileSource.Mapnik(), new OsmTileSource.TilesAtHome(),
     57            new OsmTileSource.CycleMap() };
    6158    TileLoader cachedLoader;
    6259    TileLoader uncachedLoader;
    6360    JPanel slipyyMapTabPanel;
    64     boolean firstShown = true;
    6561
    6662    /**
     
    7470        setMapMarkerVisible(false);
    7571        setMinimumSize(new Dimension(350, 350 / 2));
     72        // We need to set an initial size - this prevents a wrong zoom selection for
     73        // the area before the component has been displayed the first time   
     74        setBounds(new Rectangle(getMinimumSize()));
    7675        setFileCacheEnabled(Main.pref.getBoolean("slippy_map_chooser.file_cache", true));
    77         setMaxTilesInmemory(Main.pref.getInteger("slippy_map_chooser.max_tiles", 1000));
    78         addComponentListener(this);
     76        setMaxTilesInMemory(Main.pref.getInteger("slippy_map_chooser.max_tiles", 1000));
    7977
    8078        String mapStyle = Main.pref.get("slippy_map_chooser.mapstyle", "mapnik");
    81         if(mapStyle.equals("osmarender")) {
     79        if (mapStyle.equals("osmarender")) {
    8280            iSourceButton.setMapStyle(SourceButton.OSMARENDER);
    8381            this.setTileSource(sources[1]);
    84         }else if(mapStyle.equals("cyclemap")){
    85                  iSourceButton.setMapStyle(SourceButton.CYCLEMAP);
    86              this.setTileSource(sources[2]);
    87         }
    88         else {
    89             if(!mapStyle.equals("mapnik"))
     82        } else if (mapStyle.equals("cyclemap")) {
     83            iSourceButton.setMapStyle(SourceButton.CYCLEMAP);
     84            this.setTileSource(sources[2]);
     85        } else {
     86            if (!mapStyle.equals("mapnik"))
    9087                Main.pref.put("slippy_map_chooser.mapstyle", "mapnik");
    9188        }
    9289    }
    9390
    94     public void setMaxTilesInmemory(int tiles) {
     91    public void setMaxTilesInMemory(int tiles) {
    9592        ((MemoryTileCache) getTileCache()).setCacheSize(tiles);
    9693    }
     
    109106        slipyyMapTabPanel.add(this, BorderLayout.CENTER);
    110107        slipyyMapTabPanel.add(new JLabel((tr("Zoom: Mousewheel or double click.   "
    111                 + "Move map: Hold right mousebutton and move mouse.   Select: Click."))),
    112                 BorderLayout.SOUTH);
     108                + "Move map: Hold right mousebutton and move mouse.   Select: Click."))), BorderLayout.SOUTH);
    113109        iGui.tabpane.add(slipyyMapTabPanel, tr("Slippy map"));
    114         iGui.tabpane.addComponentListener(this);
    115110        new OsmMapControl(this, slipyyMapTabPanel, iSizeButton, iSourceButton);
    116111    }
     
    224219    public void resizeSlippyMap() {
    225220        if (iScreenSize == null) {
    226             Component c =
    227                     iGui.getParent().getParent().getParent().getParent().getParent().getParent()
    228                             .getParent().getParent().getParent();
     221            Component c = iGui.getParent().getParent().getParent().getParent().getParent().getParent().getParent()
     222                    .getParent().getParent();
    229223            // remember the initial set screen dimensions
    230224            iDownloadDialogDimension = c.getSize();
     
    234228
    235229        // resize
    236         Component co =
    237                 iGui.getParent().getParent().getParent().getParent().getParent().getParent()
    238                         .getParent().getParent().getParent();
     230        Component co = iGui.getParent().getParent().getParent().getParent().getParent().getParent().getParent()
     231                .getParent().getParent();
    239232        Dimension currentDimension = co.getSize();
    240233
     
    266259            this.setTileSource(sources[0]);
    267260            Main.pref.put("slippy_map_chooser.mapstyle", "mapnik");
    268         }else if (mapSource == SourceButton.CYCLEMAP) {
     261        } else if (mapSource == SourceButton.CYCLEMAP) {
    269262            this.setTileSource(sources[2]);
    270263            Main.pref.put("slippy_map_chooser.mapstyle", "cyclemap");
    271         }else {
     264        } else {
    272265            this.setTileSource(sources[1]);
    273266            Main.pref.put("slippy_map_chooser.mapstyle", "osmarender");
     
    275268    }
    276269
    277     public void componentHidden(ComponentEvent e) {
    278     }
    279 
    280     public void componentMoved(ComponentEvent e) {
    281     }
    282 
    283     public void componentShown(ComponentEvent e) {
    284     }
    285 
    286     public void componentResized(ComponentEvent e) {
    287         if (!this.equals(e.getSource()) || getHeight() == 0 || getWidth() == 0)
    288             return;
    289         firstShown = false;
    290         // The bounding box has to be set after SlippyMapChooser's size has been
    291         // finally set - otherwise the zoom level will be totally wrong (too wide)
    292         boundingBoxChanged(iGui);
    293     }
    294 
    295270}
Note: See TracChangeset for help on using the changeset viewer.