| 1 | ### Eclipse Workspace Patch 1.0
|
|---|
| 2 | #P JOSM
|
|---|
| 3 | Index: src/org/openstreetmap/josm/gui/download/SlippyMapChooser.java
|
|---|
| 4 | ===================================================================
|
|---|
| 5 | --- src/org/openstreetmap/josm/gui/download/SlippyMapChooser.java (revision 1413)
|
|---|
| 6 | +++ src/org/openstreetmap/josm/gui/download/SlippyMapChooser.java (working copy)
|
|---|
| 7 | @@ -10,9 +10,8 @@
|
|---|
| 8 | import java.awt.Dimension;
|
|---|
| 9 | import java.awt.Graphics;
|
|---|
| 10 | import java.awt.Point;
|
|---|
| 11 | +import java.awt.Rectangle;
|
|---|
| 12 | import java.awt.Toolkit;
|
|---|
| 13 | -import java.awt.event.ComponentEvent;
|
|---|
| 14 | -import java.awt.event.ComponentListener;
|
|---|
| 15 | import java.awt.geom.Point2D;
|
|---|
| 16 | import java.util.Vector;
|
|---|
| 17 |
|
|---|
| 18 | @@ -26,13 +25,10 @@
|
|---|
| 19 | import org.openstreetmap.gui.jmapviewer.OsmMercator;
|
|---|
| 20 | import org.openstreetmap.gui.jmapviewer.OsmTileLoader;
|
|---|
| 21 | import org.openstreetmap.gui.jmapviewer.OsmTileSource;
|
|---|
| 22 | -import org.openstreetmap.gui.jmapviewer.OsmTileSource.CycleMap;
|
|---|
| 23 | import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker;
|
|---|
| 24 | import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
|
|---|
| 25 | import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
|
|---|
| 26 | import org.openstreetmap.josm.Main;
|
|---|
| 27 | -import org.openstreetmap.josm.gui.download.DownloadDialog;
|
|---|
| 28 | -import org.openstreetmap.josm.gui.download.DownloadSelection;
|
|---|
| 29 |
|
|---|
| 30 | /**
|
|---|
| 31 | * JComponent that displays the slippy map tiles
|
|---|
| 32 | @@ -40,7 +36,7 @@
|
|---|
| 33 | * @author Tim Haussmann
|
|---|
| 34 | *
|
|---|
| 35 | */
|
|---|
| 36 | -public class SlippyMapChooser extends JMapViewer implements DownloadSelection, ComponentListener {
|
|---|
| 37 | +public class SlippyMapChooser extends JMapViewer implements DownloadSelection {
|
|---|
| 38 |
|
|---|
| 39 | private DownloadDialog iGui;
|
|---|
| 40 |
|
|---|
| 41 | @@ -57,11 +53,11 @@
|
|---|
| 42 | // screen size
|
|---|
| 43 | private Dimension iScreenSize;
|
|---|
| 44 |
|
|---|
| 45 | - private TileSource[] sources = { new OsmTileSource.Mapnik(), new OsmTileSource.TilesAtHome(),new OsmTileSource.CycleMap()};
|
|---|
| 46 | + private TileSource[] sources = { new OsmTileSource.Mapnik(), new OsmTileSource.TilesAtHome(),
|
|---|
| 47 | + new OsmTileSource.CycleMap() };
|
|---|
| 48 | TileLoader cachedLoader;
|
|---|
| 49 | TileLoader uncachedLoader;
|
|---|
| 50 | JPanel slipyyMapTabPanel;
|
|---|
| 51 | - boolean firstShown = true;
|
|---|
| 52 |
|
|---|
| 53 | /**
|
|---|
| 54 | * Create the chooser component.
|
|---|
| 55 | @@ -73,25 +69,26 @@
|
|---|
| 56 | setZoomContolsVisible(false);
|
|---|
| 57 | setMapMarkerVisible(false);
|
|---|
| 58 | setMinimumSize(new Dimension(350, 350 / 2));
|
|---|
| 59 | + // We need to set an initial size - this prevents a wrong zoom selection for
|
|---|
| 60 | + // the area before the component has been displayed the first time
|
|---|
| 61 | + setBounds(new Rectangle(getMinimumSize()));
|
|---|
| 62 | setFileCacheEnabled(Main.pref.getBoolean("slippy_map_chooser.file_cache", true));
|
|---|
| 63 | - setMaxTilesInmemory(Main.pref.getInteger("slippy_map_chooser.max_tiles", 1000));
|
|---|
| 64 | - addComponentListener(this);
|
|---|
| 65 | + setMaxTilesInMemory(Main.pref.getInteger("slippy_map_chooser.max_tiles", 1000));
|
|---|
| 66 |
|
|---|
| 67 | String mapStyle = Main.pref.get("slippy_map_chooser.mapstyle", "mapnik");
|
|---|
| 68 | - if(mapStyle.equals("osmarender")) {
|
|---|
| 69 | + if (mapStyle.equals("osmarender")) {
|
|---|
| 70 | iSourceButton.setMapStyle(SourceButton.OSMARENDER);
|
|---|
| 71 | this.setTileSource(sources[1]);
|
|---|
| 72 | - }else if(mapStyle.equals("cyclemap")){
|
|---|
| 73 | - iSourceButton.setMapStyle(SourceButton.CYCLEMAP);
|
|---|
| 74 | - this.setTileSource(sources[2]);
|
|---|
| 75 | - }
|
|---|
| 76 | - else {
|
|---|
| 77 | - if(!mapStyle.equals("mapnik"))
|
|---|
| 78 | + } else if (mapStyle.equals("cyclemap")) {
|
|---|
| 79 | + iSourceButton.setMapStyle(SourceButton.CYCLEMAP);
|
|---|
| 80 | + this.setTileSource(sources[2]);
|
|---|
| 81 | + } else {
|
|---|
| 82 | + if (!mapStyle.equals("mapnik"))
|
|---|
| 83 | Main.pref.put("slippy_map_chooser.mapstyle", "mapnik");
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | - public void setMaxTilesInmemory(int tiles) {
|
|---|
| 88 | + public void setMaxTilesInMemory(int tiles) {
|
|---|
| 89 | ((MemoryTileCache) getTileCache()).setCacheSize(tiles);
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | @@ -108,10 +105,8 @@
|
|---|
| 93 | slipyyMapTabPanel.setLayout(new BorderLayout());
|
|---|
| 94 | slipyyMapTabPanel.add(this, BorderLayout.CENTER);
|
|---|
| 95 | slipyyMapTabPanel.add(new JLabel((tr("Zoom: Mousewheel or double click. "
|
|---|
| 96 | - + "Move map: Hold right mousebutton and move mouse. Select: Click."))),
|
|---|
| 97 | - BorderLayout.SOUTH);
|
|---|
| 98 | + + "Move map: Hold right mousebutton and move mouse. Select: Click."))), BorderLayout.SOUTH);
|
|---|
| 99 | iGui.tabpane.add(slipyyMapTabPanel, tr("Slippy map"));
|
|---|
| 100 | - iGui.tabpane.addComponentListener(this);
|
|---|
| 101 | new OsmMapControl(this, slipyyMapTabPanel, iSizeButton, iSourceButton);
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | @@ -223,9 +218,8 @@
|
|---|
| 105 | */
|
|---|
| 106 | public void resizeSlippyMap() {
|
|---|
| 107 | if (iScreenSize == null) {
|
|---|
| 108 | - Component c =
|
|---|
| 109 | - iGui.getParent().getParent().getParent().getParent().getParent().getParent()
|
|---|
| 110 | - .getParent().getParent().getParent();
|
|---|
| 111 | + Component c = iGui.getParent().getParent().getParent().getParent().getParent().getParent().getParent()
|
|---|
| 112 | + .getParent().getParent();
|
|---|
| 113 | // remember the initial set screen dimensions
|
|---|
| 114 | iDownloadDialogDimension = c.getSize();
|
|---|
| 115 | // retrive the size of the display
|
|---|
| 116 | @@ -233,9 +227,8 @@
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | // resize
|
|---|
| 120 | - Component co =
|
|---|
| 121 | - iGui.getParent().getParent().getParent().getParent().getParent().getParent()
|
|---|
| 122 | - .getParent().getParent().getParent();
|
|---|
| 123 | + Component co = iGui.getParent().getParent().getParent().getParent().getParent().getParent().getParent()
|
|---|
| 124 | + .getParent().getParent();
|
|---|
| 125 | Dimension currentDimension = co.getSize();
|
|---|
| 126 |
|
|---|
| 127 | // enlarge
|
|---|
| 128 | @@ -265,31 +258,13 @@
|
|---|
| 129 | if (mapSource == SourceButton.MAPNIK) {
|
|---|
| 130 | this.setTileSource(sources[0]);
|
|---|
| 131 | Main.pref.put("slippy_map_chooser.mapstyle", "mapnik");
|
|---|
| 132 | - }else if (mapSource == SourceButton.CYCLEMAP) {
|
|---|
| 133 | + } else if (mapSource == SourceButton.CYCLEMAP) {
|
|---|
| 134 | this.setTileSource(sources[2]);
|
|---|
| 135 | Main.pref.put("slippy_map_chooser.mapstyle", "cyclemap");
|
|---|
| 136 | - }else {
|
|---|
| 137 | + } else {
|
|---|
| 138 | this.setTileSource(sources[1]);
|
|---|
| 139 | Main.pref.put("slippy_map_chooser.mapstyle", "osmarender");
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | - public void componentHidden(ComponentEvent e) {
|
|---|
| 144 | - }
|
|---|
| 145 | -
|
|---|
| 146 | - public void componentMoved(ComponentEvent e) {
|
|---|
| 147 | - }
|
|---|
| 148 | -
|
|---|
| 149 | - public void componentShown(ComponentEvent e) {
|
|---|
| 150 | - }
|
|---|
| 151 | -
|
|---|
| 152 | - public void componentResized(ComponentEvent e) {
|
|---|
| 153 | - if (!this.equals(e.getSource()) || getHeight() == 0 || getWidth() == 0)
|
|---|
| 154 | - return;
|
|---|
| 155 | - firstShown = false;
|
|---|
| 156 | - // The bounding box has to be set after SlippyMapChooser's size has been
|
|---|
| 157 | - // finally set - otherwise the zoom level will be totally wrong (too wide)
|
|---|
| 158 | - boundingBoxChanged(iGui);
|
|---|
| 159 | - }
|
|---|
| 160 | -
|
|---|
| 161 | }
|
|---|