├── .gitignore ├── src ├── splash │ └── splash.png ├── org │ └── openstreetmap │ │ ├── gui │ │ └── jmapviewer │ │ │ ├── images │ │ │ ├── plus.png │ │ │ ├── error.png │ │ │ ├── minus.png │ │ │ └── hourglass.png │ │ │ ├── interfaces │ │ │ ├── TileLoaderListener.java │ │ │ ├── TileLoader.java │ │ │ ├── MapMarker.java │ │ │ ├── TileCache.java │ │ │ └── TileSource.java │ │ │ ├── JMapController.java │ │ │ ├── OsmTileSource.java │ │ │ ├── MapMarkerDot.java │ │ │ ├── JTileDownloaderTileSourceWrapper.java │ │ │ ├── OsmTileLoader.java │ │ │ ├── OsmMercator.java │ │ │ ├── Demo.java │ │ │ ├── JobDispatcher.java │ │ │ ├── DefaultMapController.java │ │ │ ├── MemoryTileCache.java │ │ │ ├── Tile.java │ │ │ └── JTileDownloaderTileLoader.java │ │ └── fma │ │ └── jtiledownloader │ │ ├── config │ │ ├── DownloadConfigurationSaverIf.java │ │ ├── DownloadConfiguration.java │ │ ├── DownloadConfigurationGPX.java │ │ ├── DownloadConfigurationUrlSquare.java │ │ ├── DownloadConfigurationBBoxXY.java │ │ └── DownloadConfigurationBBoxLatLon.java │ │ ├── tilelist │ │ ├── TileList.java │ │ ├── TileListSimple.java │ │ ├── TileListCommon.java │ │ ├── TileListBBoxLatLon.java │ │ └── TileListUrlSquare.java │ │ ├── LogFormatter.java │ │ ├── datatypes │ │ ├── ThunderforestTileProvider.java │ │ ├── RotatingTileProvider.java │ │ ├── MapnikTileProvider.java │ │ ├── YDirectory.java │ │ ├── OsmFrTileProvider.java │ │ ├── TileDownloadError.java │ │ ├── UpdateTileList.java │ │ ├── TileProviderIf.java │ │ ├── Tile.java │ │ ├── TileDownloadResult.java │ │ ├── GenericTileProvider.java │ │ ├── TileComparatorFactory.java │ │ └── DownloadJob.java │ │ ├── views │ │ ├── main │ │ │ ├── slippymap │ │ │ │ └── SlippyMapChooserWindow.java │ │ │ ├── UpdateTilesTableModel.java │ │ │ ├── inputpanel │ │ │ │ └── InputPanel.java │ │ │ ├── InfoPanel.java │ │ │ ├── NetworkPanel.java │ │ │ └── JTileDownloaderMainView.java │ │ ├── progressbar │ │ │ └── TilePreviewViewComponent.java │ │ └── errortilelist │ │ │ ├── ErrorTileListViewTableModel.java │ │ │ └── ErrorTileListView.java │ │ ├── Constants.java │ │ ├── TileProviderList.java │ │ ├── listener │ │ └── TileDownloaderListener.java │ │ ├── network │ │ └── ProxyConnection.java │ │ ├── JTileDownloaderStart.java │ │ ├── TileListExporter.java │ │ ├── Util.java │ │ └── cmdline │ │ └── JTileDownloaderCommandLine.java └── logging.properties ├── jar ├── JTileDownloader-dev.jar ├── JTileDownloader-0-2-0.jar ├── JTileDownloader-0-3-0.jar ├── JTileDownloader-0-4-0.jar ├── jTileDownloader-0-5-0.jar ├── jTileDownloader-0-6-0.jar ├── jTileDownloader-0-6-1.jar ├── jTileDownloader-0-6-2.jar └── JTileDownloader-dev.jnlp ├── release ├── JTileDownloader-0-2-0.zip ├── JTileDownloader-0-3-0.zip ├── JTileDownloader-0-4-0.zip ├── jTileDownloader-0-5-0.zip ├── jTileDownloader-0-6-0.zip ├── jTileDownloader-0-6-1.zip ├── jTileDownloader-0-6-2.zip ├── jTileDownloader-src-0-5-0.zip ├── jTileDownloader-src-0-6-0.zip ├── jTileDownloader-src-0-6-1.zip └── jTileDownloader-src-0-6-2.zip ├── doc └── screenshot │ ├── JTileDownloader_Network.png │ ├── JTileDownloader_Options.png │ ├── JTileDownloader_MainView.png │ ├── JTileDownloader_UpdateTiles.png │ └── JTileDownloader_MainView_BBoxLatLon.png ├── .classpath ├── .project ├── application.properties ├── README.md └── .settings └── org.eclipse.jdt.ui.prefs /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | tiles/ 3 | nbproject/ 4 | appConfig.xml 5 | bin/ 6 | doc/api/ 7 | -------------------------------------------------------------------------------- /src/splash/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/src/splash/splash.png -------------------------------------------------------------------------------- /jar/JTileDownloader-dev.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/jar/JTileDownloader-dev.jar -------------------------------------------------------------------------------- /jar/JTileDownloader-0-2-0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/jar/JTileDownloader-0-2-0.jar -------------------------------------------------------------------------------- /jar/JTileDownloader-0-3-0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/jar/JTileDownloader-0-3-0.jar -------------------------------------------------------------------------------- /jar/JTileDownloader-0-4-0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/jar/JTileDownloader-0-4-0.jar -------------------------------------------------------------------------------- /jar/jTileDownloader-0-5-0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/jar/jTileDownloader-0-5-0.jar -------------------------------------------------------------------------------- /jar/jTileDownloader-0-6-0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/jar/jTileDownloader-0-6-0.jar -------------------------------------------------------------------------------- /jar/jTileDownloader-0-6-1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/jar/jTileDownloader-0-6-1.jar -------------------------------------------------------------------------------- /jar/jTileDownloader-0-6-2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/jar/jTileDownloader-0-6-2.jar -------------------------------------------------------------------------------- /release/JTileDownloader-0-2-0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/release/JTileDownloader-0-2-0.zip -------------------------------------------------------------------------------- /release/JTileDownloader-0-3-0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/release/JTileDownloader-0-3-0.zip -------------------------------------------------------------------------------- /release/JTileDownloader-0-4-0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/release/JTileDownloader-0-4-0.zip -------------------------------------------------------------------------------- /release/jTileDownloader-0-5-0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/release/jTileDownloader-0-5-0.zip -------------------------------------------------------------------------------- /release/jTileDownloader-0-6-0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/release/jTileDownloader-0-6-0.zip -------------------------------------------------------------------------------- /release/jTileDownloader-0-6-1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/release/jTileDownloader-0-6-1.zip -------------------------------------------------------------------------------- /release/jTileDownloader-0-6-2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/release/jTileDownloader-0-6-2.zip -------------------------------------------------------------------------------- /release/jTileDownloader-src-0-5-0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/release/jTileDownloader-src-0-5-0.zip -------------------------------------------------------------------------------- /release/jTileDownloader-src-0-6-0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/release/jTileDownloader-src-0-6-0.zip -------------------------------------------------------------------------------- /release/jTileDownloader-src-0-6-1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/release/jTileDownloader-src-0-6-1.zip -------------------------------------------------------------------------------- /release/jTileDownloader-src-0-6-2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/release/jTileDownloader-src-0-6-2.zip -------------------------------------------------------------------------------- /doc/screenshot/JTileDownloader_Network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/doc/screenshot/JTileDownloader_Network.png -------------------------------------------------------------------------------- /doc/screenshot/JTileDownloader_Options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/doc/screenshot/JTileDownloader_Options.png -------------------------------------------------------------------------------- /doc/screenshot/JTileDownloader_MainView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/doc/screenshot/JTileDownloader_MainView.png -------------------------------------------------------------------------------- /doc/screenshot/JTileDownloader_UpdateTiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/doc/screenshot/JTileDownloader_UpdateTiles.png -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/images/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/src/org/openstreetmap/gui/jmapviewer/images/plus.png -------------------------------------------------------------------------------- /doc/screenshot/JTileDownloader_MainView_BBoxLatLon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/doc/screenshot/JTileDownloader_MainView_BBoxLatLon.png -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/images/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/src/org/openstreetmap/gui/jmapviewer/images/error.png -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/images/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/src/org/openstreetmap/gui/jmapviewer/images/minus.png -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/images/hourglass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zverik/JTileDownloader/main/src/org/openstreetmap/gui/jmapviewer/images/hourglass.png -------------------------------------------------------------------------------- /src/logging.properties: -------------------------------------------------------------------------------- 1 | handlers=java.util.logging.ConsoleHandler 2 | java.util.logging.ConsoleHandler.level=INFO 3 | java.util.logging.ConsoleHandler.formatter=org.openstreetmap.fma.jtiledownloader.LogFormatter -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | JTileDownloader 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /application.properties: -------------------------------------------------------------------------------- 1 | # Target directory of sources 2 | source.dir=src 3 | 4 | # Directory where to find the .class-files 5 | bin.dir=bin 6 | 7 | # Directory where to store the javadoc 8 | doc.dir=doc/api 9 | 10 | # Main-Class 11 | main.class=org.openstreetmap.fma.jtiledownloader.JTileDownloaderStart 12 | 13 | # debug settings 14 | build.debug=true 15 | build.debuglevel=lines,vars,source 16 | 17 | # version information 18 | # - Constants.VERSION 19 | version=0-6-2 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JTileDownloader 2 | 3 | Slightly revived and updated repository of JTileDownloader, 4 | a very old tool to download all tiles in a bounding box. 5 | Its user agent is banned on OSM tile servers, so you would need 6 | to recompile to use it. 7 | 8 | Please always make sure that you agree and stick to the policies 9 | of the tile-providers before downloading! 10 | 11 | Please take a look at the 12 | [Tile usage policy](https://wiki.openstreetmap.org/index.php/Tile_usage_policy) 13 | of OpenStreetMap. 14 | 15 | Copyright © 2008-2020, Friedrich Maier, Sven Strickroth, Ilya Zverev 16 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/interfaces/TileLoaderListener.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer.interfaces; 2 | 3 | import org.openstreetmap.gui.jmapviewer.Tile; 4 | 5 | //License: GPL. Copyright 2008 by Jan Peter Stotz 6 | 7 | public interface TileLoaderListener { 8 | 9 | /** 10 | * Will be called if a new {@link Tile} has been loaded successfully. 11 | * Loaded can mean downloaded or loaded from file cache. 12 | * 13 | * @param tile 14 | */ 15 | public void tileLoadingFinished(Tile tile, boolean success); 16 | 17 | public TileCache getTileCache(); 18 | } 19 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/interfaces/TileLoader.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer.interfaces; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | /** 6 | * Interface for implementing a tile loader. Tiles are usually loaded via HTTP 7 | * or from a file. 8 | * 9 | * @author Jan Peter Stotz 10 | */ 11 | public interface TileLoader { 12 | 13 | /** 14 | * A typical {@link #createTileLoaderJob(org.openstreetmap.gui.jmapviewer.interfaces.TileSource, int, int, int) } implementation 15 | * should create and return a new {@link Runnable} instance that performs the 16 | * load action. 17 | * 18 | * @param tileLayerSource 19 | * @param tilex 20 | * @param tiley 21 | * @param zoom 22 | * @return {@link Runnable} implementation that performs the desired load 23 | * action. 24 | */ 25 | public Runnable createTileLoaderJob(TileSource tileLayerSource, int tilex, int tiley, int zoom); 26 | } 27 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/interfaces/MapMarker.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer.interfaces; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | import java.awt.Graphics; 6 | import java.awt.Point; 7 | 8 | import org.openstreetmap.gui.jmapviewer.JMapViewer; 9 | 10 | /** 11 | * Interface to be implemented by all elements that can be displayed on the map. 12 | * 13 | * @author Jan Peter Stotz 14 | * @see JMapViewer#addMapMarker(MapMarker) 15 | * @see JMapViewer#getMapMarkerList() 16 | */ 17 | public interface MapMarker { 18 | 19 | /** 20 | * @return Latitude of the map marker position 21 | */ 22 | public double getLat(); 23 | 24 | /** 25 | * @return Longitude of the map marker position 26 | */ 27 | public double getLon(); 28 | 29 | /** 30 | * Paints the map marker on the map. The position specifies the 31 | * coordinates within g 32 | * 33 | * @param g 34 | * @param position 35 | */ 36 | public void paint(Graphics g, Point position); 37 | } 38 | -------------------------------------------------------------------------------- /jar/JTileDownloader-dev.jnlp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JTileDownloader 5 | OpenStreetMap 6 | 7 | Java Tile Downloader for OpenStreetMap 8 | JTileDownloader 9 | JTileDownloader 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/config/DownloadConfigurationSaverIf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Sven Strickroth 3 | * 4 | * This file is part of JTileDownloader. 5 | * 6 | * JTileDownloader is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * JTileDownloader is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy (see file COPYING.txt) of the GNU 17 | * General Public License along with JTileDownloader. 18 | * If not, see . 19 | */ 20 | 21 | package org.openstreetmap.fma.jtiledownloader.config; 22 | 23 | /** 24 | * 25 | */ 26 | public interface DownloadConfigurationSaverIf 27 | { 28 | public void saveDownloadConfig(DownloadConfiguration config); 29 | 30 | public void loadDownloadConfig(DownloadConfiguration config); 31 | } 32 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/JMapController.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | import java.awt.event.MouseListener; 6 | import java.awt.event.MouseMotionListener; 7 | import java.awt.event.MouseWheelListener; 8 | 9 | /** 10 | * Abstract base class for all mouse controller implementations. For 11 | * implementing your own controller create a class that derives from this one 12 | * and implements one or more of the following interfaces: 13 | *
    14 | *
  • {@link MouseListener}
  • 15 | *
  • {@link MouseMotionListener}
  • 16 | *
  • {@link MouseWheelListener}
  • 17 | *
18 | * 19 | * @author Jan Peter Stotz 20 | */ 21 | public abstract class JMapController { 22 | 23 | protected JMapViewer map; 24 | 25 | public JMapController(JMapViewer map) { 26 | this.map = map; 27 | } 28 | 29 | public void addListeners() { 30 | if (this instanceof MouseListener) 31 | map.addMouseListener((MouseListener) this); 32 | if (this instanceof MouseWheelListener) 33 | map.addMouseWheelListener((MouseWheelListener) this); 34 | if (this instanceof MouseMotionListener) 35 | map.addMouseMotionListener((MouseMotionListener) this); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/tilelist/TileList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.tilelist; 23 | 24 | import java.util.ArrayList; 25 | 26 | import org.openstreetmap.fma.jtiledownloader.datatypes.Tile; 27 | 28 | public interface TileList 29 | { 30 | 31 | /** 32 | * @return {@link ArrayList} containing Tiles 33 | */ 34 | public abstract ArrayList getTileListToDownload(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/OsmTileSource.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer; 2 | 3 | import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 4 | 5 | public class OsmTileSource { 6 | 7 | public static final String MAP_MAPNIK = "https://tile.openstreetmap.org"; 8 | 9 | protected static abstract class AbstractOsmTileSource implements TileSource { 10 | 11 | public int getMaxZoom() { 12 | return 18; 13 | } 14 | 15 | public int getMinZoom() { 16 | return 0; 17 | } 18 | 19 | public String getTileUrl(int zoom, int tilex, int tiley) { 20 | return "/" + zoom + "/" + tilex + "/" + tiley + ".png"; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return getName(); 26 | } 27 | 28 | public String getTileType() { 29 | return "png"; 30 | } 31 | 32 | } 33 | 34 | public static class Mapnik extends AbstractOsmTileSource { 35 | 36 | public static String NAME = "Mapnik"; 37 | 38 | public String getName() { 39 | return NAME; 40 | } 41 | 42 | @Override 43 | public String getTileUrl(int zoom, int tilex, int tiley) { 44 | return MAP_MAPNIK + super.getTileUrl(zoom, tilex, tiley); 45 | } 46 | 47 | public TileUpdate getTileUpdate() { 48 | return TileUpdate.IfNoneMatch; 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/LogFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package org.openstreetmap.fma.jtiledownloader; 6 | 7 | import java.io.PrintWriter; 8 | import java.io.StringWriter; 9 | import java.text.SimpleDateFormat; 10 | import java.util.Date; 11 | import java.util.logging.Formatter; 12 | import java.util.logging.LogRecord; 13 | 14 | /** 15 | * Simple and clean log formatter. 16 | * 17 | * @author zverik 18 | */ 19 | public final class LogFormatter extends Formatter { 20 | 21 | private final String LINE_SEPARATOR = System.getProperty("line.separator"); 22 | 23 | @Override 24 | public String format(LogRecord record) { 25 | StringBuilder sb = new StringBuilder(); 26 | 27 | sb.append(new SimpleDateFormat("HH:mm").format(new Date(record.getMillis()))) 28 | .append(" ").append(record.getLevel().getLocalizedName()).append(": ") 29 | .append(formatMessage(record)) 30 | .append(LINE_SEPARATOR); 31 | 32 | if (record.getThrown() != null) { 33 | try { 34 | StringWriter sw = new StringWriter(); 35 | PrintWriter pw = new PrintWriter(sw); 36 | record.getThrown().printStackTrace(pw); 37 | pw.close(); 38 | sb.append(sw.toString()); 39 | } catch (Exception ex) { 40 | // ignore 41 | } 42 | } 43 | 44 | return sb.toString(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/ThunderforestTileProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Sven Strickroth 3 | * 4 | * This file is part of JTileDownloader. 5 | * 6 | * JTileDownloader is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * JTileDownloader is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy (see file COPYING.txt) of the GNU 17 | * General Public License along with JTileDownloader. 18 | * If not, see . 19 | */ 20 | 21 | package org.openstreetmap.fma.jtiledownloader.datatypes; 22 | 23 | /** 24 | * Thunderforest (OpenCycleMap) Tile Provider 25 | */ 26 | public class ThunderforestTileProvider 27 | extends RotatingTileProvider 28 | { 29 | private final static String[] SUBDOMAINS = { "a", "b", "c" }; 30 | 31 | public ThunderforestTileProvider( String name, String url ) 32 | { 33 | this.url = "https://{0}." + url; 34 | this.name = name; 35 | } 36 | 37 | @Override 38 | protected String[] getSubDomains() 39 | { 40 | return SUBDOMAINS; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/views/main/slippymap/SlippyMapChooserWindow.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.fma.jtiledownloader.views.main.slippymap; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | // Adapted for JTileDownloader by Sven Strickroth , 2009 - 2010 6 | 7 | import java.awt.BorderLayout; 8 | 9 | import javax.swing.JFrame; 10 | import javax.swing.WindowConstants; 11 | 12 | import org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf; 13 | import org.openstreetmap.fma.jtiledownloader.views.main.inputpanel.BBoxLatLonPanel; 14 | import org.openstreetmap.gui.jmapviewer.JMapViewer; 15 | 16 | /** 17 | * 18 | * Demonstrates the usage of {@link JMapViewer} 19 | * 20 | * @author Jan Peter Stotz 21 | * 22 | */ 23 | public class SlippyMapChooserWindow 24 | extends JFrame 25 | { 26 | 27 | private SlippyMapChooser map = null; 28 | private static final long serialVersionUID = 1L; 29 | 30 | public SlippyMapChooserWindow(BBoxLatLonPanel bboxlatlonpanel, TileProviderIf tileProvider, String tileDirectory) 31 | { 32 | super("Slippy Map Chooser"); 33 | setSize(400, 400); 34 | map = new SlippyMapChooser(bboxlatlonpanel, tileDirectory, tileProvider); 35 | setLayout(new BorderLayout()); 36 | setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 37 | add(map, BorderLayout.CENTER); 38 | } 39 | 40 | public SlippyMapChooser getSlippyMapChooser() 41 | { 42 | return map; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader; 23 | 24 | public class Constants 25 | { 26 | public static final String USER_AGENT = "JTileDownloader"; 27 | public static final String VERSION = "0.6.2"; 28 | 29 | public static final double EARTH_CIRC_POLE = 40.007863 * Math.pow(10, 6); 30 | public static final double EARTH_CIRC_EQUATOR = 40.075016 * Math.pow(10, 6); 31 | public static final double MIN_LON = -180; 32 | public static final double MAX_LON = 180; 33 | public static final double MIN_LAT = -85.0511; 34 | public static final double MAX_LAT = 85.0511; 35 | } 36 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/interfaces/TileCache.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer.interfaces; 2 | 3 | import org.openstreetmap.gui.jmapviewer.JMapViewer; 4 | import org.openstreetmap.gui.jmapviewer.Tile; 5 | 6 | //License: GPL. Copyright 2008 by Jan Peter Stotz 7 | 8 | /** 9 | * Implement this interface for creating your custom tile cache for 10 | * {@link JMapViewer}. 11 | * 12 | * @author Jan Peter Stotz 13 | */ 14 | public interface TileCache { 15 | 16 | /** 17 | * Retrieves a tile from the cache if present, otherwise null 18 | * will be returned. 19 | * 20 | * @param source 21 | * @param x 22 | * tile number on the x axis of the tile to be retrieved 23 | * @param y 24 | * tile number on the y axis of the tile to be retrieved 25 | * @param z 26 | * zoom level of the tile to be retrieved 27 | * @return the requested tile or null if the tile is not 28 | * present in the cache 29 | */ 30 | public Tile getTile(TileSource source, int x, int y, int z); 31 | 32 | /** 33 | * Adds a tile to the cache. How long after adding a tile can be retrieved 34 | * via {@link #getTile(TileSource, int, int, int)} is unspecified and depends on the 35 | * implementation. 36 | * 37 | * @param tile 38 | */ 39 | public void addTile(Tile tile); 40 | 41 | /** 42 | * @return the number of tiles hold by the cache 43 | */ 44 | public int getTileCount(); 45 | } 46 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/MapMarkerDot.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | import java.awt.Color; 6 | import java.awt.Graphics; 7 | import java.awt.Point; 8 | 9 | import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker; 10 | 11 | /** 12 | * A simple implementation of the {@link MapMarker} interface. Each map marker 13 | * is painted as a circle with a black border line and filled with a specified 14 | * color. 15 | * 16 | * @author Jan Peter Stotz 17 | * 18 | */ 19 | public class MapMarkerDot implements MapMarker { 20 | 21 | double lat; 22 | double lon; 23 | Color color; 24 | 25 | public MapMarkerDot(double lat, double lon) { 26 | this(Color.YELLOW, lat, lon); 27 | } 28 | 29 | public MapMarkerDot(Color color, double lat, double lon) { 30 | super(); 31 | this.color = color; 32 | this.lat = lat; 33 | this.lon = lon; 34 | } 35 | 36 | public double getLat() { 37 | return lat; 38 | } 39 | 40 | public double getLon() { 41 | return lon; 42 | } 43 | 44 | public void paint(Graphics g, Point position) { 45 | int size_h = 5; 46 | int size = size_h * 2; 47 | g.setColor(color); 48 | g.fillOval(position.x - size_h, position.y - size_h, size, size); 49 | g.setColor(Color.BLACK); 50 | g.drawOval(position.x - size_h, position.y - size_h, size, size); 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "MapMarker at " + lat + " " + lon; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/RotatingTileProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Sven Strickroth 3 | * 4 | * Based on: 5 | * OsmTileSource.java from JMapViewer. 6 | * 7 | * This file is part of JTileDownloader. 8 | * 9 | * JTileDownloader is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * JTileDownloader is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy (see file COPYING.txt) of the GNU 20 | * General Public License along with JTileDownloader. 21 | * If not, see . 22 | */ 23 | 24 | package org.openstreetmap.fma.jtiledownloader.datatypes; 25 | 26 | import java.text.MessageFormat; 27 | 28 | /** 29 | * Rotating TileProvider 30 | */ 31 | public abstract class RotatingTileProvider 32 | extends GenericTileProvider 33 | { 34 | 35 | private int serverNumber = -1; 36 | 37 | protected abstract String[] getSubDomains(); 38 | 39 | /** 40 | * @see org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf#getTileServerUrl() 41 | */ 42 | @Override 43 | public String getTileServerUrl() 44 | { 45 | serverNumber = (serverNumber + 1) % getSubDomains().length; 46 | return MessageFormat.format(url, new Object[] { getSubDomains()[serverNumber] }); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/MapnikTileProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Sven Strickroth 3 | * 4 | * This file is part of JTileDownloader. 5 | * 6 | * JTileDownloader is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * JTileDownloader is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy (see file COPYING.txt) of the GNU 17 | * General Public License along with JTileDownloader. 18 | * If not, see . 19 | */ 20 | 21 | package org.openstreetmap.fma.jtiledownloader.datatypes; 22 | 23 | /** 24 | * Mapnik Tile Provider 25 | */ 26 | public class MapnikTileProvider 27 | extends RotatingTileProvider 28 | { 29 | private final static String[] SUBDOMAINS = { "a", "b", "c" }; 30 | 31 | public MapnikTileProvider() 32 | { 33 | url = "https://{0}.tile.openstreetmap.org/"; 34 | } 35 | 36 | @Override 37 | protected String[] getSubDomains() 38 | { 39 | return SUBDOMAINS; 40 | } 41 | 42 | /** 43 | * @see org.openstreetmap.fma.jtiledownloader.datatypes.GenericTileProvider#getName() 44 | */ 45 | @Override 46 | public String getName() 47 | { 48 | return "Mapnik"; 49 | } 50 | 51 | @Override 52 | public int getMaxZoom() 53 | { 54 | return 12; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/YDirectory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.datatypes; 23 | 24 | public class YDirectory 25 | { 26 | private Tile[] _tiles; 27 | private String _name; 28 | 29 | /** 30 | * Setter for tiles 31 | * @param tiles the tiles to set 32 | */ 33 | public void setTiles(Tile[] tiles) 34 | { 35 | _tiles = tiles; 36 | } 37 | 38 | /** 39 | * Getter for tiles 40 | * @return the tiles 41 | */ 42 | public Tile[] getTiles() 43 | { 44 | return _tiles; 45 | } 46 | 47 | /** 48 | * Setter for name 49 | * @param name the name to set 50 | */ 51 | public void setName(String name) 52 | { 53 | _name = name; 54 | } 55 | 56 | /** 57 | * Getter for name 58 | * @return the name 59 | */ 60 | public String getName() 61 | { 62 | return _name; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/OsmFrTileProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Sven Strickroth 3 | * 4 | * This file is part of JTileDownloader. 5 | * 6 | * JTileDownloader is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * JTileDownloader is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy (see file COPYING.txt) of the GNU 17 | * General Public License along with JTileDownloader. 18 | * If not, see . 19 | */ 20 | 21 | package org.openstreetmap.fma.jtiledownloader.datatypes; 22 | 23 | /** 24 | * openstreetmap.fr Tile Provider 25 | */ 26 | public class OsmFrTileProvider 27 | extends RotatingTileProvider 28 | { 29 | private final static String[] SUBDOMAINS = { "a", "b", "c" }; 30 | 31 | public OsmFrTileProvider() 32 | { 33 | url = "https://{0}.tile.openstreetmap.fr/osmfr/"; 34 | } 35 | 36 | @Override 37 | protected String[] getSubDomains() 38 | { 39 | return SUBDOMAINS; 40 | } 41 | 42 | /** 43 | * @see org.openstreetmap.fma.jtiledownloader.datatypes.GenericTileProvider#getName() 44 | */ 45 | @Override 46 | public String getName() 47 | { 48 | return "openstreetmap.fr"; 49 | } 50 | 51 | /** 52 | * @see org.openstreetmap.fma.jtiledownloader.datatypes.GenericTileProvider#getMaxZoom() 53 | */ 54 | @Override 55 | public int getMaxZoom() 56 | { 57 | return 20; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/tilelist/TileListSimple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.tilelist; 23 | 24 | import java.util.ArrayList; 25 | 26 | import org.openstreetmap.fma.jtiledownloader.datatypes.Tile; 27 | 28 | public class TileListSimple 29 | implements TileList 30 | { 31 | 32 | ArrayList _tileList; 33 | 34 | /** 35 | * @see org.openstreetmap.fma.jtiledownloader.tilelist.TileList#getTileListToDownload() 36 | */ 37 | public ArrayList getTileListToDownload() 38 | { 39 | return _tileList; 40 | } 41 | 42 | public void addTile(Tile tile) 43 | { 44 | if (_tileList == null) 45 | { 46 | _tileList = new ArrayList(); 47 | } 48 | 49 | _tileList.add(tile); 50 | } 51 | 52 | /** 53 | * @return the number of tiles 54 | */ 55 | public int getElementCount() 56 | { 57 | return _tileList == null ? 0 : _tileList.size(); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/TileDownloadError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | package org.openstreetmap.fma.jtiledownloader.datatypes; 22 | 23 | public class TileDownloadError 24 | { 25 | private Tile _tile; 26 | private TileDownloadResult result = new TileDownloadResult(); 27 | 28 | /** 29 | * Setter for tile 30 | * @param tile the tile to set 31 | */ 32 | public void setTile(Tile tile) 33 | { 34 | _tile = tile; 35 | } 36 | 37 | /** 38 | * Getter for tile 39 | * @return the tile 40 | */ 41 | public Tile getTile() 42 | { 43 | return _tile; 44 | } 45 | 46 | /** 47 | * Setter for result 48 | * @param result the result to set 49 | */ 50 | public void setResult(TileDownloadResult result) 51 | { 52 | this.result = result; 53 | } 54 | 55 | /** 56 | * Getter for result 57 | * @return the result 58 | */ 59 | public TileDownloadResult getResult() 60 | { 61 | return result; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/config/DownloadConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Sven Strickroth 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.config; 23 | 24 | import java.util.Properties; 25 | 26 | import java.util.logging.Logger; 27 | import org.openstreetmap.fma.jtiledownloader.datatypes.DownloadJob; 28 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileList; 29 | 30 | public abstract class DownloadConfiguration 31 | { 32 | private static final Logger log = Logger.getLogger(DownloadConfiguration.class.getName()); 33 | 34 | public static final String TYPE = "Type"; 35 | 36 | abstract public void save(Properties prop); 37 | 38 | abstract public void load(Properties prop); 39 | 40 | protected void setTemplateProperty(Properties prop, String key, String value) 41 | { 42 | log.config("setting property " + key + " to value " + value); 43 | prop.setProperty(key, value); 44 | } 45 | 46 | /** 47 | * Getter for type 48 | * @return the type 49 | */ 50 | public abstract String getType(); 51 | 52 | public abstract TileList getTileList(DownloadJob downloadJob); 53 | } 54 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/views/progressbar/TilePreviewViewComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.views.progressbar; 23 | 24 | import java.awt.Graphics; 25 | import java.awt.Image; 26 | import java.awt.Toolkit; 27 | 28 | import javax.swing.JComponent; 29 | 30 | public class TilePreviewViewComponent 31 | extends JComponent 32 | { 33 | private static final long serialVersionUID = 1L; 34 | private Image image; 35 | 36 | /** 37 | * 38 | */ 39 | public TilePreviewViewComponent() 40 | { 41 | super(); 42 | setDoubleBuffered(true); 43 | } 44 | 45 | @Override 46 | protected void paintComponent(Graphics g) 47 | { 48 | if (image != null) 49 | { 50 | g.drawImage(image, 0, 0, this); 51 | } 52 | } 53 | 54 | public void setImage(String filePathName) 55 | { 56 | image = Toolkit.getDefaultToolkit().createImage(filePathName); 57 | if (image != null) 58 | { 59 | repaint(); 60 | } 61 | } 62 | 63 | /** 64 | * @see javax.swing.JComponent#update(java.awt.Graphics) 65 | */ 66 | @Override 67 | public void update(Graphics g) 68 | { 69 | paint(g); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/TileProviderList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 - 2010, Sven Strickroth 3 | * Copyright 2008, Friedrich Maier 4 | * 5 | * This file is part of JTileDownloader. 6 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 7 | * 8 | * JTileDownloader is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * JTileDownloader is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy (see file COPYING.txt) of the GNU 19 | * General Public License along with JTileDownloader. 20 | * If not, see . 21 | */ 22 | 23 | package org.openstreetmap.fma.jtiledownloader; 24 | 25 | import org.openstreetmap.fma.jtiledownloader.datatypes.*; 26 | 27 | public class TileProviderList 28 | { 29 | private TileProviderIf[] tileProviders; 30 | 31 | /** 32 | * Sets up the tileProviderList 33 | */ 34 | public TileProviderList() 35 | { 36 | super(); 37 | tileProviders = new TileProviderIf[] { 38 | new MapnikTileProvider(), 39 | new ThunderforestTileProvider("OpenCycleMap", "tile.opencyclemap.org/cycle/"), 40 | new ThunderforestTileProvider("Thunderforest Transport", "tile2.opencyclemap.org/transport/"), 41 | new ThunderforestTileProvider("Thunderforest Landscape", "tile3.opencyclemap.org/landscape/"), 42 | new ThunderforestTileProvider("Thunderforest Outdoors", "tile.thunderforest.com/outdoors/"), 43 | new GenericTileProvider("OpenStreetBrowser (Europe)", "https://www.openstreetbrowser.org/tiles/base/"), 44 | new GenericTileProvider("OpenPisteMap", "https://openpistemap.org/tiles/contours/"), 45 | new OsmFrTileProvider() 46 | }; 47 | } 48 | 49 | public TileProviderIf[] getTileProviderList() 50 | { 51 | return tileProviders.clone(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/listener/TileDownloaderListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | package org.openstreetmap.fma.jtiledownloader.listener; 22 | 23 | import java.util.ArrayList; 24 | 25 | import org.openstreetmap.fma.jtiledownloader.datatypes.Tile; 26 | import org.openstreetmap.fma.jtiledownloader.datatypes.TileDownloadError; 27 | 28 | public interface TileDownloaderListener 29 | { 30 | /** 31 | * @param actCount 32 | * @param maxCount 33 | * @param path 34 | * @param updatedTile 35 | */ 36 | void downloadedTile(int actCount, int maxCount, String path, int updatedCount, boolean updatedTile); 37 | 38 | /** 39 | * @param errorCount 40 | * @param errorTileList 41 | * @param updatedTileCount 42 | */ 43 | void downloadComplete(int errorCount, ArrayList errorTileList, int updatedTileCount); 44 | 45 | /** 46 | * @param actCount 47 | * @param maxCount 48 | */ 49 | void downloadStopped(int actCount, int maxCount); 50 | 51 | /** 52 | * @param actCount 53 | * @param maxCount 54 | */ 55 | void downloadPaused(int actCount, int maxCount); 56 | 57 | /** 58 | * @param message 59 | */ 60 | void setInfo(String message); 61 | 62 | /** 63 | * @param actCount 64 | * @param maxCount 65 | * @param tile 66 | */ 67 | void errorOccured(int actCount, int maxCount, Tile tile); 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/UpdateTileList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.datatypes; 23 | 24 | import java.util.ArrayList; 25 | 26 | public class UpdateTileList 27 | { 28 | private int _zoomLevel; 29 | private ArrayList _yDirectory; 30 | 31 | public void addYDirectory(YDirectory yDirectory) 32 | { 33 | if (_yDirectory == null) 34 | { 35 | _yDirectory = new ArrayList(); 36 | } 37 | _yDirectory.add(yDirectory); 38 | } 39 | 40 | /** 41 | * Getter for yDirectory 42 | * @return the yDirectory 43 | */ 44 | public final ArrayList getYDirectory() 45 | { 46 | return _yDirectory; 47 | } 48 | 49 | public int getFileCount() 50 | { 51 | if (_yDirectory == null) 52 | { 53 | return 0; 54 | } 55 | 56 | int count = 0; 57 | for (int index = 0; index < _yDirectory.size(); index++) 58 | { 59 | YDirectory yDir = _yDirectory.get(index); 60 | if (yDir.getTiles() != null) 61 | { 62 | count += yDir.getTiles().length; 63 | } 64 | } 65 | 66 | return count; 67 | } 68 | 69 | /** 70 | * Setter for zoomLevel 71 | * @param zoomLevel the zoomLevel to set 72 | */ 73 | public void setZoomLevel(int zoomLevel) 74 | { 75 | _zoomLevel = zoomLevel; 76 | } 77 | 78 | /** 79 | * Getter for zoomLevel 80 | * @return the zoomLevel 81 | */ 82 | public int getZoomLevel() 83 | { 84 | return _zoomLevel; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/views/main/UpdateTilesTableModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.views.main; 23 | 24 | import java.util.ArrayList; 25 | 26 | import javax.swing.table.AbstractTableModel; 27 | 28 | import org.openstreetmap.fma.jtiledownloader.datatypes.UpdateTileList; 29 | 30 | public class UpdateTilesTableModel 31 | extends AbstractTableModel 32 | { 33 | private static final long serialVersionUID = 1L; 34 | private ArrayList _data; 35 | 36 | /** 37 | * @param updateTileList 38 | */ 39 | public UpdateTilesTableModel(ArrayList updateTileList) 40 | { 41 | if (updateTileList == null || updateTileList.isEmpty()) 42 | { 43 | return; 44 | } 45 | 46 | _data = new ArrayList(); 47 | int count = 0; 48 | 49 | for (UpdateTileList utl : updateTileList) 50 | { 51 | count++; 52 | ArrayList rowData = new ArrayList(); 53 | rowData.add(utl.getZoomLevel()); 54 | rowData.add(Integer.toString(utl.getFileCount())); 55 | _data.add(rowData); 56 | } 57 | } 58 | 59 | /** 60 | * @see javax.swing.table.TableModel#getColumnCount() 61 | */ 62 | public int getColumnCount() 63 | { 64 | return 2; 65 | } 66 | 67 | /** 68 | * @see javax.swing.table.TableModel#getRowCount() 69 | */ 70 | public int getRowCount() 71 | { 72 | return _data == null ? 0 : _data.size(); 73 | } 74 | 75 | /** 76 | * @see javax.swing.table.TableModel#getValueAt(int, int) 77 | */ 78 | public Object getValueAt(int row, int column) 79 | { 80 | ArrayList rowData = _data == null ? null : _data.get(row); 81 | return rowData == null ? null : rowData.get(column); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/views/errortilelist/ErrorTileListViewTableModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.views.errortilelist; 23 | 24 | import java.util.ArrayList; 25 | import javax.swing.table.AbstractTableModel; 26 | 27 | import org.openstreetmap.fma.jtiledownloader.datatypes.TileDownloadError; 28 | 29 | public class ErrorTileListViewTableModel 30 | extends AbstractTableModel 31 | { 32 | private static final long serialVersionUID = 1L; 33 | private ArrayList _data; 34 | 35 | /** 36 | * @param errorTileList 37 | */ 38 | public ErrorTileListViewTableModel(ArrayList errorTileList) 39 | { 40 | _data = new ArrayList(); 41 | int count = 0; 42 | for (TileDownloadError tde : errorTileList) 43 | { 44 | ArrayList rowData = new ArrayList(); 45 | rowData.add(Integer.toString(++count)); 46 | rowData.add(tde.getTile()); 47 | rowData.add(tde.getResult().getMessage()); 48 | _data.add(rowData); 49 | } 50 | 51 | } 52 | 53 | /** 54 | * @see javax.swing.table.TableModel#getColumnCount() 55 | */ 56 | public int getColumnCount() 57 | { 58 | return 3; 59 | } 60 | 61 | /** 62 | * @see javax.swing.table.TableModel#getRowCount() 63 | */ 64 | public int getRowCount() 65 | { 66 | return _data == null ? 0 : _data.size(); 67 | } 68 | 69 | /** 70 | * @see javax.swing.table.TableModel#getValueAt(int, int) 71 | */ 72 | public Object getValueAt(int row, int column) 73 | { 74 | if (_data == null) 75 | { 76 | return null; 77 | } 78 | 79 | ArrayList rowData = (ArrayList) _data.get(row); 80 | 81 | return rowData == null ? null : rowData.get(column); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/tilelist/TileListCommon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * 6 | * JTileDownloader is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * JTileDownloader is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy (see file COPYING.txt) of the GNU 17 | * General Public License along with JTileDownloader. 18 | * If not, see . 19 | */ 20 | 21 | package org.openstreetmap.fma.jtiledownloader.tilelist; 22 | 23 | import org.openstreetmap.fma.jtiledownloader.Constants; 24 | 25 | /** 26 | * 27 | */ 28 | public abstract class TileListCommon 29 | implements TileList 30 | { 31 | private int[] _downloadZoomLevels; 32 | 33 | /** 34 | * @param lat 35 | * @param zoomLevel 36 | * @return tileY 37 | */ 38 | protected final int calculateTileY(double lat, int zoomLevel) 39 | { 40 | if (lat < Constants.MIN_LAT) 41 | { 42 | lat = Constants.MIN_LAT; 43 | } 44 | if (lat > Constants.MAX_LAT) 45 | { 46 | lat = Constants.MAX_LAT; 47 | } 48 | int y = (int) Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * (1 << zoomLevel)); 49 | return y; 50 | } 51 | 52 | /** 53 | * @param lon 54 | * @param zoomLevel 55 | * @return tileX 56 | */ 57 | protected final int calculateTileX(double lon, int zoomLevel) 58 | { 59 | if (lon < Constants.MIN_LON) 60 | { 61 | lon = Constants.MIN_LON; 62 | } 63 | if (lon > Constants.MAX_LON) 64 | { 65 | lon = Constants.MAX_LON; 66 | } 67 | 68 | int x = (int) Math.floor((lon + 180) / 360 * (1 << zoomLevel)); 69 | return x; 70 | } 71 | 72 | /** 73 | * Getter for downloadZoomLevel 74 | * @return the downloadZoomLevel 75 | */ 76 | public final int[] getDownloadZoomLevels() 77 | { 78 | return _downloadZoomLevels.clone(); 79 | } 80 | 81 | /** 82 | * Setter for downloadZoomLevel 83 | * @param downloadZoomLevel the downloadZoomLevel to set 84 | */ 85 | public final void setDownloadZoomLevels(int[] downloadZoomLevel) 86 | { 87 | _downloadZoomLevels = downloadZoomLevel.clone(); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/TileProviderIf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Sven Strickroth 3 | * 4 | * Based on: 5 | * TileSource.java from Jan Peter Stotz (JMapViewer) 6 | * 7 | * This file is part of JTileDownloader. 8 | * 9 | * JTileDownloader is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * JTileDownloader is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy (see file COPYING.txt) of the GNU 20 | * General Public License along with JTileDownloader. 21 | * If not, see . 22 | */ 23 | 24 | package org.openstreetmap.fma.jtiledownloader.datatypes; 25 | 26 | /** 27 | * TileProvider interface 28 | */ 29 | public interface TileProviderIf 30 | { 31 | 32 | /** 33 | * Specifies the maximum zoom value. The number of zoom levels is [0.. 34 | * {@link #getMaxZoom()}]. 35 | * 36 | * @return maximum zoom value 37 | */ 38 | public int getMaxZoom(); 39 | 40 | /** 41 | * Specifies the minimum zoom value. This value is usually 0. 42 | * Only for maps that cover a certain region up to a limited zoom level 43 | * this method should return a value different than 0. 44 | * 45 | * @return minimum zoom value - usually 0 46 | */ 47 | public int getMinZoom(); 48 | 49 | /** 50 | * A tile layer name has to be unique and has to consist only of characters 51 | * valid for filenames. 52 | * 53 | * @return Name of the tile layer 54 | */ 55 | public String getName(); 56 | 57 | /** 58 | * Returns the tile server url 59 | * @return the tile server url 60 | */ 61 | public String getTileServerUrl(); 62 | 63 | /** 64 | * Constructs the tile url. 65 | * @param tile the tile 66 | * @return fully qualified url for downloading the specified tile image 67 | */ 68 | public String getTileUrl(Tile tile); 69 | 70 | /** 71 | * Constructs the relative tile-image filename 72 | * @param tile 73 | * @return the relative path and filename of the image file 74 | */ 75 | public String getTileFilename(Tile tile); 76 | 77 | /** 78 | * Specifies the tile image type. For tiles rendered by Mapnik or 79 | * Osmarenderer this is usually "png". 80 | * 81 | * @return file extension of the tile image type 82 | */ 83 | public String getTileType(); 84 | } 85 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/views/main/inputpanel/InputPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * 6 | * JTileDownloader is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * JTileDownloader is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy (see file COPYING.txt) of the GNU 17 | * General Public License along with JTileDownloader. 18 | * If not, see . 19 | */ 20 | 21 | package org.openstreetmap.fma.jtiledownloader.views.main.inputpanel; 22 | 23 | import javax.swing.JPanel; 24 | 25 | import org.openstreetmap.fma.jtiledownloader.Util; 26 | import org.openstreetmap.fma.jtiledownloader.config.DownloadConfigurationSaverIf; 27 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileList; 28 | import org.openstreetmap.fma.jtiledownloader.views.main.MainPanel; 29 | 30 | /** 31 | * 32 | */ 33 | public abstract class InputPanel 34 | extends JPanel 35 | { 36 | 37 | private static final long serialVersionUID = 1L; 38 | protected final MainPanel _mainPanel; 39 | 40 | /** 41 | * Returns the name/title for the input panel 42 | * @return name of the panel 43 | */ 44 | public abstract String getInputName(); 45 | 46 | public boolean isDownloadOkay() 47 | { 48 | return true; 49 | } 50 | 51 | /** 52 | * @param mainPanel 53 | */ 54 | public InputPanel(MainPanel mainPanel) 55 | { 56 | super(); 57 | _mainPanel = mainPanel; 58 | } 59 | 60 | /** 61 | * Getter for downloadZoomLevel 62 | * @return the downloadZoomLevel 63 | */ 64 | public final int[] getDownloadZoomLevel() 65 | { 66 | return Util.getOutputZoomLevelArray(_mainPanel.getSelectedTileProvider(), _mainPanel.getOutputZoomLevelString()); 67 | } 68 | 69 | public abstract void updateAll(); 70 | 71 | public abstract int getNumberOfTilesToDownload(); 72 | 73 | public abstract TileList getTileList(); 74 | 75 | public abstract String getJobType(); 76 | 77 | public abstract void loadConfig(DownloadConfigurationSaverIf configurationSave); 78 | 79 | public abstract void saveConfig(DownloadConfigurationSaverIf configurationSave); 80 | 81 | public void updateNumberOfTiles() 82 | { 83 | int numberOfTiles = 0; 84 | numberOfTiles = getNumberOfTilesToDownload(); 85 | _mainPanel.setNumberOfTiles(numberOfTiles); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/network/ProxyConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.network; 23 | 24 | import java.net.Authenticator; 25 | import java.net.PasswordAuthentication; 26 | import java.util.logging.Logger; 27 | 28 | public class ProxyConnection 29 | { 30 | private static final Logger log = Logger.getLogger(ProxyConnection.class.getName()); 31 | 32 | private ProxyConnection(String host, int port) 33 | { 34 | setProxyData(host, port); 35 | } 36 | 37 | private ProxyConnection(String host, int port, String username, String passwort) 38 | { 39 | setProxyData(host, port); 40 | log.fine("Authenticator.setDefault..."); 41 | Authenticator.setDefault(new ProxyAuth(username, passwort)); 42 | } 43 | 44 | public static void setProxyData(String host, int port) 45 | { 46 | System.getProperties().put("http.proxySet", "true"); 47 | log.config("http.proxyHost = " + host); 48 | System.getProperties().put("http.proxyHost", host); 49 | log.config("http.proxyPort = " + port); 50 | System.getProperties().put("http.proxyPort", String.valueOf(port)); 51 | } 52 | 53 | public static void setProxyData(String host, int port, String username, String password ) { 54 | setProxyData(host, port); 55 | log.fine("Authenticator.setDefault..."); 56 | Authenticator.setDefault(new ProxyAuth(username, password)); 57 | } 58 | 59 | static private class ProxyAuth 60 | extends Authenticator 61 | { 62 | private String _username; 63 | private String _password; 64 | 65 | public ProxyAuth(String username, String passwort) 66 | { 67 | _username = username; 68 | _password = passwort; 69 | } 70 | 71 | @Override 72 | protected PasswordAuthentication getPasswordAuthentication() 73 | { 74 | // log.config("user " + _username + ", pw " + _password); 75 | return (new PasswordAuthentication(_username, _password.toCharArray())); 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/JTileDownloaderTileSourceWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Sven Strickroth 3 | * 4 | * This file is part of JTileDownloader. 5 | * 6 | * JTileDownloader is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * JTileDownloader is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy (see file COPYING.txt) of the GNU 17 | * General Public License along with JTileDownloader. 18 | * If not, see . 19 | */ 20 | 21 | package org.openstreetmap.gui.jmapviewer; 22 | 23 | import org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf; 24 | import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 25 | 26 | /** 27 | * 28 | */ 29 | public class JTileDownloaderTileSourceWrapper 30 | implements TileSource 31 | { 32 | 33 | private TileProviderIf tileProvider = null; 34 | 35 | public JTileDownloaderTileSourceWrapper(TileProviderIf tileProvider) 36 | { 37 | this.tileProvider = tileProvider; 38 | } 39 | 40 | /** 41 | * @see org.openstreetmap.gui.jmapviewer.interfaces.TileSource#getMaxZoom() 42 | * {@inheritDoc} 43 | */ 44 | public int getMaxZoom() 45 | { 46 | return tileProvider.getMaxZoom(); 47 | } 48 | 49 | /** 50 | * @see org.openstreetmap.gui.jmapviewer.interfaces.TileSource#getMinZoom() 51 | * {@inheritDoc} 52 | */ 53 | public int getMinZoom() 54 | { 55 | return tileProvider.getMinZoom(); 56 | } 57 | 58 | /** 59 | * @see org.openstreetmap.gui.jmapviewer.interfaces.TileSource#getName() 60 | * {@inheritDoc} 61 | */ 62 | public String getName() 63 | { 64 | return tileProvider.getName(); 65 | } 66 | 67 | /** 68 | * @see org.openstreetmap.gui.jmapviewer.interfaces.TileSource#getTileType() 69 | * {@inheritDoc} 70 | */ 71 | public String getTileType() 72 | { 73 | return tileProvider.getTileType(); 74 | } 75 | 76 | /** 77 | * @see org.openstreetmap.gui.jmapviewer.interfaces.TileSource#getTileUpdate() 78 | * {@inheritDoc} 79 | */ 80 | public TileUpdate getTileUpdate() 81 | { 82 | return TileUpdate.None; 83 | } 84 | 85 | /** 86 | * @see org.openstreetmap.gui.jmapviewer.interfaces.TileSource#getTileUrl(int, int, int) 87 | * {@inheritDoc} 88 | */ 89 | public String getTileUrl(int zoom, int tilex, int tiley) 90 | { 91 | return tileProvider.getTileUrl(new org.openstreetmap.fma.jtiledownloader.datatypes.Tile(tilex, tiley, zoom)); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/Tile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Sven Strickroth 3 | * 4 | * This file is part of JTileDownloader. 5 | * 6 | * JTileDownloader is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * JTileDownloader is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy (see file COPYING.txt) of the GNU 17 | * General Public License along with JTileDownloader. 18 | * If not, see . 19 | */ 20 | 21 | package org.openstreetmap.fma.jtiledownloader.datatypes; 22 | 23 | import java.io.File; 24 | 25 | /** 26 | * Tile 27 | */ 28 | public class Tile 29 | { 30 | private int x; 31 | private int y; 32 | private int z; 33 | 34 | /** 35 | * @param x 36 | * @param y 37 | * @param z 38 | */ 39 | public Tile(int x, int y, int z) 40 | { 41 | this.x = x; 42 | this.y = y; 43 | this.z = z; 44 | } 45 | 46 | /** 47 | * Getter for x 48 | * @return the x 49 | */ 50 | public int getX() 51 | { 52 | return x; 53 | } 54 | 55 | /** 56 | * Getter for y 57 | * @return the y 58 | */ 59 | public int getY() 60 | { 61 | return y; 62 | } 63 | 64 | /** 65 | * Getter for z 66 | * @return the z 67 | */ 68 | public int getZ() 69 | { 70 | return z; 71 | } 72 | 73 | /** 74 | * Returns the relative path of a tile 75 | * @return relative tile-image path 76 | */ 77 | public String getPath() 78 | { 79 | return z + File.separator + x; 80 | } 81 | 82 | /** 83 | * @see java.lang.Object#toString() 84 | */ 85 | @Override 86 | public String toString() 87 | { 88 | return z + "/" + x + "/" + y; 89 | } 90 | 91 | @Override 92 | public int hashCode() { 93 | int hash = 5; 94 | hash = 17 * hash + this.x; 95 | hash = 17 * hash + this.y; 96 | hash = 17 * hash + this.z; 97 | return hash; 98 | } 99 | 100 | @Override 101 | public boolean equals(Object obj) { 102 | if (obj == null) { 103 | return false; 104 | } 105 | if (getClass() != obj.getClass()) { 106 | return false; 107 | } 108 | final Tile other = (Tile) obj; 109 | if (this.x != other.x) { 110 | return false; 111 | } 112 | if (this.y != other.y) { 113 | return false; 114 | } 115 | if (this.z != other.z) { 116 | return false; 117 | } 118 | return true; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/JTileDownloaderStart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader; 23 | 24 | import java.util.HashMap; 25 | 26 | import java.util.logging.LogManager; 27 | import javax.swing.SwingUtilities; 28 | import javax.swing.UIManager; 29 | 30 | import org.openstreetmap.fma.jtiledownloader.cmdline.JTileDownloaderCommandLine; 31 | import org.openstreetmap.fma.jtiledownloader.views.main.JTileDownloaderMainView; 32 | 33 | public class JTileDownloaderStart 34 | { 35 | /** 36 | * 37 | */ 38 | private static final String CMDLINE_DL = "DL"; 39 | 40 | public static void main(String[] args) 41 | { 42 | try { 43 | LogManager.getLogManager().readConfiguration(JTileDownloaderStart.class.getClassLoader().getResourceAsStream("logging.properties")); 44 | } catch( Exception e ) { /* oh well... */ } 45 | // get command line arguments 46 | HashMap arguments = new HashMap(); 47 | if (args != null && args.length > 0) 48 | { 49 | for (String arg : args) 50 | { 51 | String[] parts = arg.split("="); 52 | if (parts != null && parts.length == 2) 53 | { 54 | String key = parts[0].toUpperCase(); 55 | String value = parts[1]; 56 | arguments.put(key, value); 57 | } 58 | } 59 | } 60 | 61 | if (arguments.containsKey(CMDLINE_DL)) 62 | { 63 | JTileDownloaderCommandLine tileDownloaderCommandLine = new JTileDownloaderCommandLine(arguments); 64 | tileDownloaderCommandLine.start(); 65 | } 66 | else 67 | { 68 | SwingUtilities.invokeLater(new Runnable() { 69 | public void run() 70 | { 71 | try 72 | { 73 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 74 | } 75 | catch (Exception e) 76 | { 77 | } 78 | new JTileDownloaderMainView().setVisible(true); 79 | } 80 | }); 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer.interfaces; 2 | 3 | import org.openstreetmap.gui.jmapviewer.JMapViewer; 4 | 5 | //License: GPL. Copyright 2008 by Jan Peter Stotz 6 | 7 | /** 8 | * 9 | * @author Jan Peter Stotz 10 | */ 11 | public interface TileSource { 12 | 13 | /** 14 | * Specifies the different mechanisms for detecting updated tiles 15 | * respectively only download newer tiles than those stored locally. 16 | * 17 | *
    18 | *
  • {@link #IfNoneMatch} Server provides ETag header entry for all tiles 19 | * and supports conditional download via If-None-Match 20 | * header entry.
  • 21 | *
  • {@link #ETag} Server provides ETag header entry for all tiles but 22 | * does not support conditional download via 23 | * If-None-Match header entry.
  • 24 | *
  • {@link #IfModifiedSince} Server provides Last-Modified header entry 25 | * for all tiles and supports conditional download via 26 | * If-Modified-Since header entry.
  • 27 | *
  • {@link #LastModified} Server provides Last-Modified header entry for 28 | * all tiles but does not support conditional download via 29 | * If-Modified-Since header entry.
  • 30 | *
  • {@link #None} The server does not support any of the listed 31 | * mechanisms.
  • 32 | *
33 | * 34 | */ 35 | public enum TileUpdate { 36 | IfNoneMatch, ETag, IfModifiedSince, LastModified, None 37 | } 38 | 39 | /** 40 | * Specifies the maximum zoom value. The number of zoom levels is [0.. 41 | * {@link #getMaxZoom()}]. 42 | * 43 | * @return maximum zoom value that has to be smaller or equal to 44 | * {@link JMapViewer#MAX_ZOOM} 45 | */ 46 | public int getMaxZoom(); 47 | 48 | /** 49 | * Specifies the minimum zoom value. This value is usually 0. 50 | * Only for maps that cover a certain region up to a limited zoom level 51 | * this method should return a value different than 0. 52 | * 53 | * @return minimum zoom value - usually 0 54 | */ 55 | public int getMinZoom(); 56 | 57 | /** 58 | * @return The supported tile update mechanism 59 | * @see TileUpdate 60 | */ 61 | public TileUpdate getTileUpdate(); 62 | 63 | /** 64 | * A tile layer name has to be unique and has to consist only of characters 65 | * valid for filenames. 66 | * 67 | * @return Name of the tile layer 68 | */ 69 | public String getName(); 70 | 71 | /** 72 | * Constructs the tile url. 73 | * 74 | * @param zoom 75 | * @param tilex 76 | * @param tiley 77 | * @return fully qualified url for downloading the specified tile image 78 | */ 79 | public String getTileUrl(int zoom, int tilex, int tiley); 80 | 81 | /** 82 | * Specifies the tile image type. For tiles rendered by Mapnik or 83 | * Osmarenderer this is usually "png". 84 | * 85 | * @return file extension of the tile image type 86 | */ 87 | public String getTileType(); 88 | } 89 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/TileDownloadResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | package org.openstreetmap.fma.jtiledownloader.datatypes; 22 | 23 | public class TileDownloadResult 24 | { 25 | public static final int CODE_OK = 0; 26 | public static final String MSG_OK = "OK"; 27 | 28 | public static final int CODE_FILENOTFOUND = 1; 29 | public static final String MSG_FILENOTFOUND = "File not found"; 30 | 31 | public static final int CODE_MALFORMED_URL_EXECPTION = 2; 32 | public static final String MSG_MALFORMED_URL_EXECPTION = "MalformedURLException"; 33 | 34 | public static final int CODE_UNKNOWN_HOST_EXECPTION = 3; 35 | public static final String MSG_UNKNOWN_HOST_EXECPTION = "Unknown Host"; 36 | 37 | public static final int CODE_HTTP_500 = 500; 38 | public static final String MSG_HTTP_500 = "Http 500 Error"; 39 | 40 | public static final int CODE_UNKNOWN_ERROR = 9999; 41 | public static final String MSG_UNKNOWN_ERROR = "Not specified"; 42 | 43 | private int _code = CODE_OK; 44 | private String _message = ""; 45 | private boolean _updatedTile = false; 46 | 47 | /** 48 | * Setter for code 49 | * @param code the code to set 50 | */ 51 | public void setCode(int code) 52 | { 53 | _code = code; 54 | } 55 | 56 | /** 57 | * Getter for code 58 | * @return the code 59 | */ 60 | public int getCode() 61 | { 62 | return _code; 63 | } 64 | 65 | /** 66 | * Setter for message 67 | * @param message the message to set 68 | */ 69 | public void setMessage(String message) 70 | { 71 | _message = message; 72 | } 73 | 74 | /** 75 | * Getter for message 76 | * @return the message 77 | */ 78 | public String getMessage() 79 | { 80 | return _message; 81 | } 82 | 83 | /** 84 | * Setter for updatedTile 85 | * @param updatedTile the updatedTile to set 86 | */ 87 | public void setUpdatedTile(boolean updatedTile) 88 | { 89 | _updatedTile = updatedTile; 90 | } 91 | 92 | /** 93 | * Getter for updatedTile 94 | * @return the updatedTile 95 | */ 96 | public boolean isUpdatedTile() 97 | { 98 | return _updatedTile; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/tilelist/TileListBBoxLatLon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.tilelist; 23 | 24 | import java.util.logging.Logger; 25 | 26 | public class TileListBBoxLatLon 27 | extends TileListCommonBBox 28 | { 29 | private static final Logger log = Logger.getLogger(TileListBBoxLatLon.class.getName()); 30 | private double _minLat; 31 | private double _minLon; 32 | private double _maxLat; 33 | private double _maxLon; 34 | 35 | public void calculateTileValuesXY() 36 | { 37 | 38 | log.fine("calculate tile values for (BBoxLatLon):"); 39 | 40 | log.fine("minLat=" + _minLat); 41 | log.fine("minLon=" + _minLon); 42 | log.fine("maxLat=" + _maxLat); 43 | log.fine("maxLon=" + _maxLon); 44 | 45 | calculateTileValuesXY(_minLat, _minLon, _maxLat, _maxLon); 46 | } 47 | 48 | /** 49 | * Getter for minLat 50 | * @return the minLat 51 | */ 52 | public final double getMinLat() 53 | { 54 | return _minLat; 55 | } 56 | 57 | /** 58 | * Setter for minLat 59 | * @param minLat the minLat to set 60 | */ 61 | public final void setMinLat(double minLat) 62 | { 63 | _minLat = minLat; 64 | } 65 | 66 | /** 67 | * Getter for minLon 68 | * @return the minLon 69 | */ 70 | public final double getMinLon() 71 | { 72 | return _minLon; 73 | } 74 | 75 | /** 76 | * Setter for minLon 77 | * @param minLon the minLon to set 78 | */ 79 | public final void setMinLon(double minLon) 80 | { 81 | _minLon = minLon; 82 | } 83 | 84 | /** 85 | * Getter for maxLat 86 | * @return the maxLat 87 | */ 88 | public final double getMaxLat() 89 | { 90 | return _maxLat; 91 | } 92 | 93 | /** 94 | * Setter for maxLat 95 | * @param maxLat the maxLat to set 96 | */ 97 | public final void setMaxLat(double maxLat) 98 | { 99 | _maxLat = maxLat; 100 | } 101 | 102 | /** 103 | * Getter for maxLon 104 | * @return the maxLon 105 | */ 106 | public final double getMaxLon() 107 | { 108 | return _maxLon; 109 | } 110 | 111 | /** 112 | * Setter for maxLon 113 | * @param maxLon the maxLon to set 114 | */ 115 | public final void setMaxLon(double maxLon) 116 | { 117 | _maxLon = maxLon; 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/GenericTileProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Sven Strickroth 3 | * 4 | * This file is part of JTileDownloader. 5 | * 6 | * JTileDownloader is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * JTileDownloader is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy (see file COPYING.txt) of the GNU 17 | * General Public License along with JTileDownloader. 18 | * If not, see . 19 | */ 20 | 21 | package org.openstreetmap.fma.jtiledownloader.datatypes; 22 | 23 | import java.io.File; 24 | 25 | /** 26 | * Generic TileProvider 27 | */ 28 | public class GenericTileProvider 29 | implements TileProviderIf 30 | { 31 | protected String name; 32 | protected String url; 33 | 34 | protected GenericTileProvider() 35 | {} 36 | 37 | /** 38 | * @param url 39 | */ 40 | public GenericTileProvider(String url) 41 | { 42 | if (!url.endsWith("/")) 43 | { 44 | url = url + "/"; 45 | } 46 | this.name = url; 47 | this.url = url; 48 | } 49 | 50 | /** 51 | * @param name 52 | * @param url 53 | */ 54 | public GenericTileProvider(String name, String url) 55 | { 56 | this.name = name; 57 | this.url = url; 58 | } 59 | 60 | /** 61 | * @see org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf#getMaxZoom() 62 | */ 63 | public int getMaxZoom() 64 | { 65 | return 18; 66 | } 67 | 68 | /** 69 | * @see org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf#getMinZoom() 70 | */ 71 | public int getMinZoom() 72 | { 73 | return 0; 74 | } 75 | 76 | /** 77 | * @see org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf#getName() 78 | */ 79 | public String getName() 80 | { 81 | return name; 82 | } 83 | 84 | /** 85 | * @see org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf#getTileType() 86 | */ 87 | public String getTileType() 88 | { 89 | return "png"; 90 | } 91 | 92 | /** 93 | * @see org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf#getTileUrl(Tile) 94 | */ 95 | public String getTileUrl(Tile tile) 96 | { 97 | return getTileServerUrl() + tile.getZ() + "/" + tile.getX() + "/" + tile.getY() + "." + getTileType(); 98 | } 99 | 100 | /** 101 | * @see org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf#getTileServerUrl() 102 | */ 103 | public String getTileServerUrl() 104 | { 105 | return url; 106 | } 107 | 108 | /** 109 | * @see org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf#getTileFilename(org.openstreetmap.fma.jtiledownloader.datatypes.Tile) 110 | */ 111 | public String getTileFilename(Tile tile) 112 | { 113 | return tile.getZ() + File.separator + tile.getX() + File.separator + tile.getY() + "." + getTileType(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.net.HttpURLConnection; 8 | import java.net.URL; 9 | 10 | import java.util.logging.Logger; 11 | import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; 12 | import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 13 | import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 14 | import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 15 | 16 | /** 17 | * A {@link TileLoader} implementation that loads tiles from OSM via HTTP. 18 | * 19 | * @author Jan Peter Stotz 20 | */ 21 | public class OsmTileLoader implements TileLoader { 22 | 23 | private static final Logger log = Logger.getLogger(OsmTileLoader.class.getName()); 24 | 25 | /** 26 | * Holds the used user agent used for HTTP requests. If this field is 27 | * null, the default Java user agent is used. 28 | */ 29 | public static String USER_AGENT = "JMapViewer"; 30 | public static String ACCEPT = "text/html, image/png, image/jpeg, image/gif, */*"; 31 | 32 | protected TileLoaderListener listener; 33 | 34 | public OsmTileLoader(TileLoaderListener listener) { 35 | this.listener = listener; 36 | } 37 | 38 | public Runnable createTileLoaderJob(final TileSource source, final int tilex, final int tiley, final int zoom) { 39 | return new Runnable() { 40 | 41 | InputStream input = null; 42 | 43 | public void run() { 44 | TileCache cache = listener.getTileCache(); 45 | Tile tile; 46 | synchronized (cache) { 47 | tile = cache.getTile(source, tilex, tiley, zoom); 48 | if (tile == null || tile.isLoaded() || tile.loading) 49 | return; 50 | tile.loading = true; 51 | } 52 | try { 53 | // Thread.sleep(500); 54 | input = loadTileFromOsm(tile).getInputStream(); 55 | tile.loadImage(input); 56 | tile.setLoaded(true); 57 | listener.tileLoadingFinished(tile, true); 58 | input.close(); 59 | input = null; 60 | } catch (Exception e) { 61 | tile.setImage(Tile.ERROR_IMAGE); 62 | listener.tileLoadingFinished(tile, false); 63 | if (input == null) 64 | log.warning("failed loading " + zoom + "/" + tilex + "/" + tiley + " " + e.getMessage()); 65 | } finally { 66 | tile.loading = false; 67 | tile.setLoaded(true); 68 | } 69 | } 70 | 71 | }; 72 | } 73 | 74 | protected HttpURLConnection loadTileFromOsm(Tile tile) throws IOException { 75 | URL url; 76 | url = new URL(tile.getUrl()); 77 | HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); 78 | prepareHttpUrlConnection(urlConn); 79 | urlConn.setReadTimeout(30000); // 30 seconds read timeout 80 | return urlConn; 81 | } 82 | 83 | protected void prepareHttpUrlConnection(HttpURLConnection urlConn) { 84 | if (USER_AGENT != null) 85 | urlConn.setRequestProperty("User-agent", USER_AGENT); 86 | urlConn.setRequestProperty("Accept", ACCEPT); 87 | } 88 | 89 | @Override 90 | public String toString() { 91 | return getClass().getSimpleName(); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/OsmMercator.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer; 2 | 3 | // License: GPL. Copyright 2007 by Tim Haussmann 4 | 5 | /** 6 | * This class implements the Mercator Projection as it is used by Openstreetmap 7 | * (and google). It provides methods to translate coordinates from 'map space' 8 | * into latitude and longitude (on the WGS84 ellipsoid) and vice versa. Map 9 | * space is measured in pixels. The origin of the map space is the top left 10 | * corner. The map space origin (0,0) has latitude ~85 and longitude -180 11 | * 12 | * @author Tim Haussmann 13 | * 14 | */ 15 | 16 | public class OsmMercator { 17 | 18 | private static int TILE_SIZE = 256; 19 | public static final double MAX_LAT = 85.05112877980659; 20 | public static final double MIN_LAT = -85.05112877980659; 21 | 22 | public static double radius(int aZoomlevel) { 23 | return (TILE_SIZE * (1 << aZoomlevel)) / (2.0 * Math.PI); 24 | } 25 | 26 | /** 27 | * Returns the absolut number of pixels in y or x, defined as: 2^Zoomlevel * 28 | * TILE_WIDTH where TILE_WIDTH is the width of a tile in pixels 29 | * 30 | * @param aZoomlevel 31 | */ 32 | public static int getMaxPixels(int aZoomlevel) { 33 | return TILE_SIZE * (1 << aZoomlevel); 34 | } 35 | 36 | public static int falseEasting(int aZoomlevel) { 37 | return getMaxPixels(aZoomlevel) / 2; 38 | } 39 | 40 | public static int falseNorthing(int aZoomlevel) { 41 | return (-1 * getMaxPixels(aZoomlevel) / 2); 42 | } 43 | 44 | /** 45 | * Transform longitude to pixelspace 46 | * 47 | * @param aLongitude 48 | * [-180..180] 49 | * @return [0..2^Zoomlevel*TILE_SIZE[ 50 | */ 51 | public static int LonToX(double aLongitude, int aZoomlevel) { 52 | double longitude = Math.toRadians(aLongitude); 53 | int x = (int) ((radius(aZoomlevel) * longitude) + falseEasting(aZoomlevel)); 54 | x = Math.min(x, getMaxPixels(aZoomlevel) - 1); 55 | return x; 56 | } 57 | 58 | /** 59 | * Transforms latitude to pixelspace 60 | * 61 | * @param aLat 62 | * [-90...90] 63 | * @return [0..2^Zoomlevel*TILE_SIZE[ 64 | */ 65 | public static int LatToY(double aLat, int aZoomlevel) { 66 | if (aLat < MIN_LAT) 67 | aLat = MIN_LAT; 68 | else if (aLat > MAX_LAT) 69 | aLat = MAX_LAT; 70 | double latitude = Math.toRadians(aLat); 71 | int y = (int) (-1 72 | * (radius(aZoomlevel) / 2.0 * Math.log((1.0 + Math.sin(latitude)) / (1.0 - Math.sin(latitude)))) - falseNorthing(aZoomlevel)); 73 | y = Math.min(y, getMaxPixels(aZoomlevel) - 1); 74 | return y; 75 | } 76 | 77 | /** 78 | * Transforms pixel coordinate X to longitude 79 | * 80 | * @param aX 81 | * [0..2^Zoomlevel*TILE_WIDTH[ 82 | * @return ]-180..180[ 83 | */ 84 | public static double XToLon(int aX, int aZoomlevel) { 85 | aX -= falseEasting(aZoomlevel); 86 | double longRadians = aX / radius(aZoomlevel); 87 | double longDegrees = Math.toDegrees(longRadians); 88 | return longDegrees; 89 | } 90 | 91 | /** 92 | * Transforms pixel coordinate Y to latitude 93 | * 94 | * @param aY 95 | * [0..2^Zoomlevel*TILE_WIDTH[ 96 | * @return [MIN_LAT..MAX_LAT] is about [-85..85] 97 | */ 98 | public static double YToLat(int aY, int aZoomlevel) { 99 | aY += falseNorthing(aZoomlevel); 100 | double latitude = (Math.PI / 2) - (2 * Math.atan(Math.exp(-1.0 * aY / radius(aZoomlevel)))); 101 | return -1 * Math.toDegrees(latitude); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/tilelist/TileListUrlSquare.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.tilelist; 23 | 24 | import java.util.logging.Level; 25 | import java.util.logging.Logger; 26 | import org.openstreetmap.fma.jtiledownloader.Constants; 27 | 28 | public class TileListUrlSquare 29 | extends TileListCommonBBox 30 | { 31 | private static final Logger log = Logger.getLogger(TileListUrlSquare.class.getName()); 32 | private int _radius; // radius in m 33 | private double _latitude; 34 | private double _longitude; 35 | 36 | public void calculateTileValuesXY() 37 | { 38 | 39 | log.log(Level.FINE, "calculate tile values for (UrlSquare:) lat {0}, lon {1}, radius {2}", new Object[]{_latitude, _longitude, _radius}); 40 | 41 | if (_radius > 6370000 * 2 * 4) 42 | { 43 | _radius = 6370000 * 2 * 4; 44 | } 45 | 46 | double minLat = _latitude - 360 * (_radius / Constants.EARTH_CIRC_POLE); 47 | double minLon = _longitude - 360 * (_radius / (Constants.EARTH_CIRC_EQUATOR * Math.cos(_longitude * Math.PI / 180))); 48 | double maxLat = _latitude + 360 * (_radius / Constants.EARTH_CIRC_POLE); 49 | double maxLon = _longitude + 360 * (_radius / (Constants.EARTH_CIRC_EQUATOR * Math.cos(_longitude * Math.PI / 180))); 50 | 51 | log.log(Level.FINE, "minLat={0}", minLat); 52 | log.log(Level.FINE, "minLon={0}", minLon); 53 | log.log(Level.FINE, "maxLat={0}", maxLat); 54 | log.log(Level.FINE, "maxLon={0}", maxLon); 55 | 56 | calculateTileValuesXY(minLat, minLon, maxLat, maxLon); 57 | 58 | } 59 | 60 | /** 61 | * Getter for radius 62 | * @return the radius 63 | */ 64 | protected final int getRadius() 65 | { 66 | return _radius; 67 | } 68 | 69 | /** 70 | * Setter for radius in meter 71 | * @param radius the radius to set 72 | */ 73 | public final void setRadius(int radius) 74 | { 75 | _radius = radius; 76 | } 77 | 78 | /** 79 | * Getter for latitude 80 | * @return the latitude 81 | */ 82 | public final double getLatitude() 83 | { 84 | return _latitude; 85 | } 86 | 87 | /** 88 | * Setter for latitude 89 | * @param latitude the latitude to set 90 | */ 91 | public final void setLatitude(double latitude) 92 | { 93 | _latitude = latitude; 94 | } 95 | 96 | /** 97 | * Getter for longitude 98 | * @return the longitude 99 | */ 100 | public final double getLongitude() 101 | { 102 | return _longitude; 103 | } 104 | 105 | /** 106 | * Setter for longitude 107 | * @param longitude the longitude to set 108 | */ 109 | public final void setLongitude(double longitude) 110 | { 111 | _longitude = longitude; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/config/DownloadConfigurationGPX.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.config; 23 | 24 | import java.util.Properties; 25 | 26 | import org.openstreetmap.fma.jtiledownloader.Util; 27 | import org.openstreetmap.fma.jtiledownloader.datatypes.DownloadJob; 28 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileList; 29 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileListCommonGPX; 30 | 31 | public class DownloadConfigurationGPX 32 | extends DownloadConfiguration 33 | { 34 | 35 | private String _gpxFile = ""; 36 | private int _corridor = 0; 37 | 38 | private static final String GPX_FILE = "GpxFile"; 39 | private static final String CORRIDOR = "Corridor"; 40 | 41 | public static final String ID = "GPX"; 42 | 43 | @Override 44 | public void save(Properties prop) 45 | { 46 | setTemplateProperty(prop, TYPE, ID); 47 | 48 | setTemplateProperty(prop, GPX_FILE, _gpxFile); 49 | setTemplateProperty(prop, CORRIDOR, String.valueOf(_corridor)); 50 | } 51 | 52 | @Override 53 | public void load(Properties prop) 54 | { 55 | _gpxFile = prop.getProperty(GPX_FILE, ""); 56 | _corridor = Integer.parseInt(prop.getProperty(CORRIDOR, "0")); 57 | } 58 | 59 | /** 60 | * Getter for gpxFile 61 | * @return the gpxFile 62 | */ 63 | public final String getGpxFile() 64 | { 65 | return _gpxFile; 66 | } 67 | 68 | /** 69 | * Setter for gpxFile 70 | * @param gpxFile the gpxFile to set 71 | */ 72 | public final void setGpxFile(String gpxFile) 73 | { 74 | _gpxFile = gpxFile; 75 | } 76 | 77 | /** 78 | * Getter for corridor 79 | * @return the corridor 80 | */ 81 | public final int getCorridor() 82 | { 83 | return _corridor; 84 | } 85 | 86 | /** 87 | * Setter for corridor 88 | * @param corridor the corridor to set 89 | */ 90 | public final void setCorridor(int corridor) 91 | { 92 | _corridor = corridor; 93 | } 94 | 95 | /** 96 | * @see org.openstreetmap.fma.jtiledownloader.config.DownloadConfiguration#getType() 97 | */ 98 | @Override 99 | public String getType() 100 | { 101 | return ID; 102 | } 103 | 104 | /** 105 | * @see org.openstreetmap.fma.jtiledownloader.config.DownloadConfiguration#getTileList(DownloadJob) 106 | */ 107 | @Override 108 | public TileList getTileList(DownloadJob downloadJob) 109 | { 110 | TileListCommonGPX tileList = new TileListCommonGPX(); 111 | 112 | tileList.setDownloadZoomLevels(Util.getOutputZoomLevelArray(downloadJob.getTileProvider(), downloadJob.getOutputZoomLevels())); 113 | 114 | String gpxFile = getGpxFile(); 115 | int corridor = getCorridor(); 116 | 117 | tileList.updateList(gpxFile, corridor); 118 | 119 | return tileList; 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/config/DownloadConfigurationUrlSquare.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.config; 23 | 24 | import java.util.Properties; 25 | 26 | import org.openstreetmap.fma.jtiledownloader.Util; 27 | import org.openstreetmap.fma.jtiledownloader.datatypes.DownloadJob; 28 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileList; 29 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileListUrlSquare; 30 | 31 | public class DownloadConfigurationUrlSquare 32 | extends DownloadConfiguration 33 | { 34 | 35 | private String _pasteUrl = ""; 36 | private int _radius = 5; 37 | 38 | private static final String PASTE_URL = "PasteUrl"; 39 | private static final String RADIUS = "Radius"; 40 | 41 | public static final String ID = "UrlSquare"; 42 | 43 | @Override 44 | public void save(Properties prop) 45 | { 46 | setTemplateProperty(prop, TYPE, ID); 47 | 48 | setTemplateProperty(prop, PASTE_URL, _pasteUrl); 49 | setTemplateProperty(prop, RADIUS, String.valueOf(_radius)); 50 | } 51 | 52 | @Override 53 | public void load(Properties prop) 54 | { 55 | _pasteUrl = prop.getProperty(PASTE_URL, ""); 56 | _radius = Integer.parseInt(prop.getProperty(RADIUS, "5")); 57 | } 58 | 59 | /** 60 | * Getter for pasteUrl 61 | * @return the pasteUrl 62 | */ 63 | public final String getPasteUrl() 64 | { 65 | return _pasteUrl; 66 | } 67 | 68 | /** 69 | * Setter for pasteUrl 70 | * @param pasteUrl the pasteUrl to set 71 | */ 72 | public final void setPasteUrl(String pasteUrl) 73 | { 74 | _pasteUrl = pasteUrl; 75 | } 76 | 77 | /** 78 | * Getter for radius 79 | * @return the radius 80 | */ 81 | public final int getRadius() 82 | { 83 | return _radius; 84 | } 85 | 86 | /** 87 | * Setter for radius 88 | * @param radius the radius to set 89 | */ 90 | public final void setRadius(int radius) 91 | { 92 | _radius = radius; 93 | } 94 | 95 | /** 96 | * @see org.openstreetmap.fma.jtiledownloader.config.DownloadConfiguration#getType() 97 | */ 98 | @Override 99 | public String getType() 100 | { 101 | return ID; 102 | } 103 | 104 | /** 105 | * @see org.openstreetmap.fma.jtiledownloader.config.DownloadConfiguration#getTileList(DownloadJob) 106 | */ 107 | @Override 108 | public TileList getTileList(DownloadJob downloadJob) 109 | { 110 | TileListUrlSquare tileList = new TileListUrlSquare(); 111 | 112 | String url = getPasteUrl(); 113 | if (url == null || url.length() == 0) 114 | { 115 | throw new RuntimeException("invalid URL"); 116 | } 117 | 118 | tileList.setDownloadZoomLevels(Util.getOutputZoomLevelArray(downloadJob.getTileProvider(), downloadJob.getOutputZoomLevels())); 119 | 120 | Util.parsePasteUrl(url, tileList); 121 | tileList.setRadius(getRadius() * 1000); 122 | 123 | tileList.calculateTileValuesXY(); 124 | 125 | return tileList; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/TileListExporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * Copyright 2009, Sven Strickroth 4 | * 5 | * This file is part of JTileDownloader. 6 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 7 | * 8 | * JTileDownloader is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * JTileDownloader is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy (see file COPYING.txt) of the GNU 19 | * General Public License along with JTileDownloader. 20 | * If not, see . 21 | */ 22 | 23 | package org.openstreetmap.fma.jtiledownloader; 24 | 25 | import java.io.BufferedWriter; 26 | import java.io.File; 27 | import java.io.FileWriter; 28 | import java.io.IOException; 29 | import java.util.ArrayList; 30 | 31 | import java.util.Collections; 32 | import java.util.logging.Logger; 33 | import org.openstreetmap.fma.jtiledownloader.config.AppConfiguration; 34 | import org.openstreetmap.fma.jtiledownloader.datatypes.Tile; 35 | import org.openstreetmap.fma.jtiledownloader.datatypes.TileComparatorFactory; 36 | import org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf; 37 | 38 | public class TileListExporter 39 | { 40 | private static final Logger log = Logger.getLogger(TileListExporter.class.getName()); 41 | private ArrayList _tilesToDownload; 42 | private final String _downloadPathBase; 43 | private TileProviderIf _tileProvider; 44 | 45 | /** 46 | * @param downloadPathBase 47 | * @param tilesToDownload 48 | * @param tileProvider 49 | */ 50 | public TileListExporter(String downloadPathBase, ArrayList tilesToDownload, TileProviderIf tileProvider) 51 | { 52 | super(); 53 | _downloadPathBase = downloadPathBase; 54 | _tilesToDownload = tilesToDownload; 55 | _tileProvider = tileProvider; 56 | } 57 | 58 | public void doExport() 59 | { 60 | int tileSortingPolicy = AppConfiguration.getInstance().getTileSortingPolicy(); 61 | if (tileSortingPolicy > 0) { 62 | Collections.sort(_tilesToDownload, TileComparatorFactory.getComparator(tileSortingPolicy)); 63 | } 64 | 65 | String exportFile = _downloadPathBase + File.separator + "export.txt"; 66 | 67 | //check directories 68 | 69 | File testDir = new File(_downloadPathBase); 70 | if (!testDir.exists()) 71 | { 72 | log.info("Creating directory " + testDir.getPath()); 73 | testDir.mkdirs(); 74 | } 75 | 76 | // check if export file exists 77 | File exportFileTest = new File(exportFile); 78 | if (exportFileTest.exists()) 79 | { 80 | exportFileTest.delete(); 81 | } 82 | 83 | BufferedWriter fileWriter; 84 | try 85 | { 86 | fileWriter = new BufferedWriter(new FileWriter(exportFile)); 87 | 88 | int count = 0; 89 | for (Tile tileToDownload : _tilesToDownload) 90 | { 91 | doSingleExport(tileToDownload, fileWriter); 92 | count++; 93 | } 94 | 95 | fileWriter.close(); 96 | } 97 | catch (IOException e) 98 | { 99 | log.warning("Failed to save tile: " + e.getLocalizedMessage()); 100 | } 101 | } 102 | 103 | private void doSingleExport(Tile tileToDownload, BufferedWriter fileWriter) throws IOException 104 | { 105 | fileWriter.write(_tileProvider.getTileUrl(tileToDownload)); 106 | fileWriter.newLine(); 107 | log.fine("added url " + tileToDownload); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/TileComparatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011, Ilya Zverev 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.datatypes; 23 | 24 | import java.util.Collections; 25 | import java.util.Comparator; 26 | import java.util.List; 27 | import org.openstreetmap.fma.jtiledownloader.config.AppConfiguration; 28 | 29 | /** 30 | * This class compares two tiles in three possible ways: 31 | *
    32 | *
  1. Simply by order, z -> x -> y. 33 | *
  2. By quad-tiles, z -> (quad x) -> (quad y) -> x -> y. 34 | *
  3. By quad-tiles recursively (not supported yet — I have no idea how). 35 | *
36 | * 37 | * @author zverik 38 | */ 39 | public class TileComparatorFactory { 40 | public static final int COMPARE_DONT = 0; 41 | public static final int COMPARE_SIMPLE = 1; 42 | public static final int COMPARE_QUAD = 2; 43 | public static final int COMPARE_RECURSIVE = 3; 44 | public static final int COMPARE_COUNT = 3; 45 | 46 | private static Comparator[] comparators = new Comparator[] { 47 | new SimpleComparator(), 48 | new SimpleComparator(), 49 | new QuadComparator(), 50 | new RecursiveComparator() 51 | }; 52 | 53 | public static Comparator getComparator( int type ) { 54 | return comparators[type]; 55 | } 56 | 57 | public static void sortTileList( List tileList ) { 58 | int tileSortingPolicy = AppConfiguration.getInstance().getTileSortingPolicy(); 59 | if (tileSortingPolicy > 0) { 60 | Collections.sort(tileList, TileComparatorFactory.getComparator(tileSortingPolicy)); 61 | } 62 | } 63 | 64 | private static class SimpleComparator implements Comparator { 65 | public int compare(Tile t1, Tile t2) { 66 | int r = Integer.valueOf(t1.getZ()).compareTo(Integer.valueOf(t2.getZ())); 67 | if( r == 0 ) { 68 | r = Integer.valueOf(t1.getX()).compareTo(Integer.valueOf(t2.getX())); 69 | if( r == 0 ) 70 | r = Integer.valueOf(t1.getY()).compareTo(Integer.valueOf(t2.getY())); 71 | } 72 | return r; 73 | } 74 | } 75 | 76 | private static class QuadComparator implements Comparator { 77 | public int compare(Tile t1, Tile t2) { 78 | int r = Integer.valueOf(t1.getZ()).compareTo(Integer.valueOf(t2.getZ())); 79 | if( r == 0 ) { 80 | r = Integer.valueOf(t1.getX() >> 3).compareTo(Integer.valueOf(t2.getX() >> 3)); 81 | if( r == 0 ) { 82 | r = Integer.valueOf(t1.getY() >> 3).compareTo(Integer.valueOf(t2.getY() >> 3)); 83 | if( r == 0 ) { 84 | r = Integer.valueOf(t1.getX()).compareTo(Integer.valueOf(t2.getX())); 85 | if (r == 0) { 86 | r = Integer.valueOf(t1.getY()).compareTo(Integer.valueOf(t2.getY())); 87 | } 88 | } 89 | } 90 | } 91 | return r; 92 | } 93 | } 94 | 95 | private static class RecursiveComparator implements Comparator { 96 | public int compare(Tile t1, Tile t2) { 97 | throw new UnsupportedOperationException("Not supported yet."); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Sven Strickroth 3 | * 4 | * parsePasteUrl by: 5 | * Copyright 2008, Friedrich Maier 6 | * 7 | * This file is part of JTileDownloader. 8 | * 9 | * JTileDownloader is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * JTileDownloader is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy (see file COPYING.txt) of the GNU 20 | * General Public License along with JTileDownloader. 21 | * If not, see . 22 | */ 23 | 24 | package org.openstreetmap.fma.jtiledownloader; 25 | 26 | import java.util.LinkedList; 27 | 28 | import org.openstreetmap.fma.jtiledownloader.datatypes.GenericTileProvider; 29 | import org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf; 30 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileListUrlSquare; 31 | 32 | /** 33 | * Class with helper methods 34 | */ 35 | public class Util 36 | { 37 | /** 38 | * Returns valid array of zoomlevels to download 39 | * @param selectedTileProvider 40 | * @param zoomLevelString 41 | * @return int[] zoomlevels 42 | */ 43 | public static int[] getOutputZoomLevelArray(TileProviderIf selectedTileProvider, String zoomLevelString) 44 | { 45 | int minZoom = selectedTileProvider == null ? 0 : selectedTileProvider.getMinZoom(); 46 | int maxZoom = selectedTileProvider == null ? 20 : selectedTileProvider.getMaxZoom(); 47 | LinkedList zoomLevels = new LinkedList(); 48 | for (String zoomLevel : zoomLevelString.split(",")) 49 | { 50 | int z1, z2; 51 | int p = zoomLevel.indexOf('-'); 52 | if( p > 0 ) { 53 | z1 = Integer.parseInt(zoomLevel.substring(0, p).trim()); 54 | z2 = Integer.parseInt(zoomLevel.substring(p + 1).trim()); 55 | } else { 56 | z1 = Integer.parseInt(zoomLevel.trim()); 57 | z2 = z1; 58 | } 59 | for( int selectedZoom = z1; selectedZoom <= z2; selectedZoom ++ ) { 60 | if (selectedZoom <= maxZoom && selectedZoom >= minZoom) 61 | { 62 | if (!zoomLevels.contains(selectedZoom)) 63 | { 64 | zoomLevels.add(selectedZoom); 65 | } 66 | } 67 | } 68 | } 69 | int[] parsedLevels = new int[zoomLevels.size()]; 70 | for (int i = 0; i < zoomLevels.size(); i++) 71 | { 72 | parsedLevels[i] = zoomLevels.get(i); 73 | } 74 | return parsedLevels; 75 | } 76 | 77 | /** 78 | * @param tileServer 79 | * @return tileProvider 80 | */ 81 | public static TileProviderIf getTileProvider(String tileServer) 82 | { 83 | TileProviderIf[] _tileProviders = new TileProviderList().getTileProviderList(); 84 | for (TileProviderIf tileProvider : _tileProviders) 85 | { 86 | if (tileProvider.getName().equalsIgnoreCase(tileServer)) 87 | { 88 | return tileProvider; 89 | } 90 | } 91 | return new GenericTileProvider(tileServer); 92 | } 93 | 94 | public static void parsePasteUrl(String url, TileListUrlSquare tileList) 95 | { 96 | //String pasteUrl = "http://www.openstreetmap.org/?lat=48.256&lon=13.0434&zoom=12&layers=0B0FT"; 97 | if (url == null || url.length() == 0) 98 | { 99 | tileList.setLatitude(0); 100 | tileList.setLongitude(0); 101 | return; 102 | } 103 | 104 | try { 105 | int posLat = url.indexOf("lat="); 106 | String lat = url.substring(posLat); 107 | int posLon = url.indexOf("lon="); 108 | String lon = url.substring(posLon); 109 | 110 | int posAnd = lat.indexOf("&"); 111 | lat = lat.substring(4, posAnd).replace(',', '.'); 112 | posAnd = lon.indexOf("&"); 113 | lon = lon.substring(4, posAnd).replace(',', '.'); 114 | 115 | if( lat.length() > 0 && lon.length() > 0 ) { 116 | tileList.setLatitude(Double.parseDouble(lat)); 117 | tileList.setLongitude(Double.parseDouble(lon)); 118 | } 119 | } catch( NumberFormatException e ) { 120 | tileList.setLatitude(0); 121 | tileList.setLongitude(0); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/config/DownloadConfigurationBBoxXY.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.config; 23 | 24 | import java.util.Properties; 25 | 26 | import org.openstreetmap.fma.jtiledownloader.Util; 27 | import org.openstreetmap.fma.jtiledownloader.datatypes.DownloadJob; 28 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileList; 29 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileListCommonBBox; 30 | 31 | public class DownloadConfigurationBBoxXY 32 | extends DownloadConfiguration 33 | { 34 | 35 | private int _minX = 0; 36 | private int _minY = 0; 37 | private int _maxX = 0; 38 | private int _maxY = 0; 39 | 40 | private static final String MIN_X = "MinX"; 41 | private static final String MIN_Y = "MinY"; 42 | private static final String MAX_X = "MaxX"; 43 | private static final String MAX_Y = "MaxY"; 44 | 45 | public static final String ID = "BBoxXY"; 46 | 47 | @Override 48 | public void save(Properties prop) 49 | { 50 | setTemplateProperty(prop, TYPE, ID); 51 | 52 | setTemplateProperty(prop, MIN_X, String.valueOf(_minX)); 53 | setTemplateProperty(prop, MIN_Y, String.valueOf(_minY)); 54 | setTemplateProperty(prop, MAX_X, String.valueOf(_maxX)); 55 | setTemplateProperty(prop, MAX_Y, String.valueOf(_maxY)); 56 | } 57 | 58 | @Override 59 | public void load(Properties prop) 60 | { 61 | _minX = Integer.parseInt(prop.getProperty(MIN_X, "0")); 62 | _minY = Integer.parseInt(prop.getProperty(MIN_Y, "0")); 63 | _maxX = Integer.parseInt(prop.getProperty(MAX_X, "0")); 64 | _maxY = Integer.parseInt(prop.getProperty(MAX_Y, "0")); 65 | } 66 | 67 | /** 68 | * Getter for minX 69 | * @return the minX 70 | */ 71 | public final int getMinX() 72 | { 73 | return _minX; 74 | } 75 | 76 | /** 77 | * Setter for minX 78 | * @param minX the minX to set 79 | */ 80 | public final void setMinX(int minX) 81 | { 82 | _minX = minX; 83 | } 84 | 85 | /** 86 | * Getter for minY 87 | * @return the minY 88 | */ 89 | public final int getMinY() 90 | { 91 | return _minY; 92 | } 93 | 94 | /** 95 | * Setter for minY 96 | * @param minY the minY to set 97 | */ 98 | public final void setMinY(int minY) 99 | { 100 | _minY = minY; 101 | } 102 | 103 | /** 104 | * Getter for maxX 105 | * @return the maxX 106 | */ 107 | public final int getMaxX() 108 | { 109 | return _maxX; 110 | } 111 | 112 | /** 113 | * Setter for maxX 114 | * @param maxX the maxX to set 115 | */ 116 | public final void setMaxX(int maxX) 117 | { 118 | _maxX = maxX; 119 | } 120 | 121 | /** 122 | * Getter for maxY 123 | * @return the maxY 124 | */ 125 | public final int getMaxY() 126 | { 127 | return _maxY; 128 | } 129 | 130 | /** 131 | * Setter for maxY 132 | * @param maxY the maxY to set 133 | */ 134 | public final void setMaxY(int maxY) 135 | { 136 | _maxY = maxY; 137 | } 138 | 139 | /** 140 | * @see org.openstreetmap.fma.jtiledownloader.config.DownloadConfiguration#getType() 141 | */ 142 | @Override 143 | public String getType() 144 | { 145 | return ID; 146 | } 147 | 148 | /** 149 | * @see org.openstreetmap.fma.jtiledownloader.config.DownloadConfiguration#getTileList(DownloadJob) 150 | */ 151 | @Override 152 | public TileList getTileList(DownloadJob downloadJob) 153 | { 154 | TileListCommonBBox tileList = new TileListCommonBBox(); 155 | 156 | tileList.setDownloadZoomLevels(Util.getOutputZoomLevelArray(downloadJob.getTileProvider(), downloadJob.getOutputZoomLevels())); 157 | 158 | tileList.initXTopLeft(getMinX()); 159 | tileList.initYTopLeft(getMinY()); 160 | tileList.initXBottomRight(getMaxX()); 161 | tileList.initYBottomRight(getMaxY()); 162 | 163 | return tileList; 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/views/main/InfoPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.views.main; 23 | 24 | import java.awt.BorderLayout; 25 | 26 | import javax.swing.JPanel; 27 | import javax.swing.JScrollPane; 28 | import javax.swing.JTextArea; 29 | 30 | import org.openstreetmap.fma.jtiledownloader.Constants; 31 | import org.openstreetmap.fma.jtiledownloader.TileProviderList; 32 | import org.openstreetmap.fma.jtiledownloader.datatypes.TileProviderIf; 33 | 34 | public class InfoPanel 35 | extends JPanel 36 | { 37 | private static final long serialVersionUID = 1L; 38 | 39 | private JTextArea _textInfo = new JTextArea(); 40 | 41 | /** 42 | * 43 | */ 44 | public InfoPanel() 45 | { 46 | super(); 47 | 48 | createPanel(); 49 | initializePanel(); 50 | 51 | } 52 | 53 | /** 54 | */ 55 | private void createPanel() 56 | { 57 | 58 | JScrollPane scrollPane = new JScrollPane(_textInfo); 59 | 60 | // GridBagConstraints constraints = new GridBagConstraints(); 61 | // // constraints.gridwidth = GridBagConstraints.REMAINDER; 62 | // constraints.fill = GridBagConstraints.BOTH; 63 | // constraints.insets = new Insets(5, 5, 0, 5); 64 | // constraints.weightx = 1; 65 | // constraints.weighty = 1; 66 | 67 | // setLayout(new GridBagLayout()); 68 | setLayout(new BorderLayout()); 69 | 70 | // add(scrollPane, constraints); 71 | add(scrollPane, BorderLayout.CENTER); 72 | 73 | } 74 | 75 | /** 76 | * 77 | */ 78 | private void initializePanel() 79 | { 80 | _textInfo.setEditable(false); 81 | _textInfo.setLineWrap(true); 82 | _textInfo.setWrapStyleWord(true); 83 | _textInfo.setRows(10); 84 | 85 | _textInfo.setText("JTileDownloader Version " + Constants.VERSION + "\n"); 86 | _textInfo.append("----------------------------------------\n"); 87 | _textInfo.append("JTileDownloader Copyright (C) 2008 Friedrich Maier\n"); 88 | _textInfo.append("This program comes with ABSOLUTELY NO WARRANTY.\n"); 89 | _textInfo.append("This is free software, and you are welcome to redistribute\n"); 90 | _textInfo.append("it under certain conditions\n"); 91 | _textInfo.append("See file COPYING.txt and README.txt for details.\n"); 92 | _textInfo.append("GPLv3 see \n"); 93 | _textInfo.append("----------------------------------------\n"); 94 | _textInfo.append("Project Homepage:\n"); 95 | _textInfo.append("http://wiki.openstreetmap.org/index.php/JTileDownloader\n"); 96 | _textInfo.append("----------------------------------------\n"); 97 | _textInfo.append("\n"); 98 | _textInfo.append("Please always make sure that you agree and stick to the policies of the tile-providers before downloading!"); 99 | _textInfo.append("\n"); 100 | _textInfo.append("Downloaded data (tiles) based http://www.openstreetmap.org"); 101 | _textInfo.append("see http://wiki.openstreetmap.org/index.php/OpenStreetMap_License\n"); 102 | _textInfo.append("\n"); 103 | _textInfo.append("Plase take also a look at the 'Tile usage policy'\nhttp://wiki.openstreetmap.org/index.php/Tile_usage_policy\n"); 104 | _textInfo.append("\n"); 105 | _textInfo.append("----------------------------------------\n"); 106 | _textInfo.append("Predefined tile servers are:\n"); 107 | TileProviderIf[] tileServerList = new TileProviderList().getTileProviderList(); 108 | for (TileProviderIf element : tileServerList) 109 | { 110 | _textInfo.append(element.getName() + "\n"); 111 | _textInfo.append(element.getTileServerUrl() + "\n"); 112 | } 113 | 114 | _textInfo.append("----------------------------------------\n"); 115 | _textInfo.append("Source code of this program is available at:\n"); 116 | _textInfo.append("http://svn.openstreetmap.org/applications/utils/downloading/JTileDownloader/\n"); 117 | 118 | _textInfo.setCaretPosition(0); 119 | 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/Demo.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | import java.awt.BorderLayout; 6 | import java.awt.event.ActionEvent; 7 | import java.awt.event.ActionListener; 8 | import java.awt.event.ItemEvent; 9 | import java.awt.event.ItemListener; 10 | 11 | import javax.swing.JButton; 12 | import javax.swing.JCheckBox; 13 | import javax.swing.JComboBox; 14 | import javax.swing.JFrame; 15 | import javax.swing.JLabel; 16 | import javax.swing.JPanel; 17 | 18 | import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 19 | import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 20 | 21 | /** 22 | * 23 | * Demonstrates the usage of {@link JMapViewer} 24 | * 25 | * @author Jan Peter Stotz 26 | * 27 | */ 28 | public class Demo extends JFrame { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | public Demo() { 33 | super("JMapViewer Demo"); 34 | setSize(400, 400); 35 | final JMapViewer map = new JMapViewer(); 36 | // final JMapViewer map = new JMapViewer(new MemoryTileCache(),4); 37 | // map.setTileLoader(new OsmFileCacheTileLoader(map)); 38 | // new DefaultMapController(map); 39 | setLayout(new BorderLayout()); 40 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 41 | setExtendedState(JFrame.MAXIMIZED_BOTH); 42 | JPanel panel = new JPanel(); 43 | JPanel helpPanel = new JPanel(); 44 | add(panel, BorderLayout.NORTH); 45 | add(helpPanel, BorderLayout.SOUTH); 46 | JLabel helpLabel = new JLabel("Use right mouse button to move,\n " 47 | + "left double click or mouse wheel to zoom."); 48 | helpPanel.add(helpLabel); 49 | JButton button = new JButton("setDisplayToFitMapMarkers"); 50 | button.addActionListener(new ActionListener() { 51 | 52 | public void actionPerformed(ActionEvent e) { 53 | map.setDisplayToFitMapMarkers(); 54 | } 55 | }); 56 | JComboBox tileSourceSelector = new JComboBox(new TileSource[] { new OsmTileSource.Mapnik() }); 57 | tileSourceSelector.addItemListener(new ItemListener() { 58 | public void itemStateChanged(ItemEvent e) { 59 | map.setTileSource((TileSource) e.getItem()); 60 | } 61 | }); 62 | JComboBox tileLoaderSelector = new JComboBox(new TileLoader[] { new OsmFileCacheTileLoader(map), 63 | new OsmTileLoader(map) }); 64 | tileLoaderSelector.addItemListener(new ItemListener() { 65 | public void itemStateChanged(ItemEvent e) { 66 | map.setTileLoader((TileLoader) e.getItem()); 67 | } 68 | }); 69 | map.setTileLoader((TileLoader) tileLoaderSelector.getSelectedItem()); 70 | panel.add(tileSourceSelector); 71 | panel.add(tileLoaderSelector); 72 | final JCheckBox showMapMarker = new JCheckBox("Map markers visible"); 73 | showMapMarker.setSelected(map.getMapMarkersVisible()); 74 | showMapMarker.addActionListener(new ActionListener() { 75 | 76 | public void actionPerformed(ActionEvent e) { 77 | map.setMapMarkerVisible(showMapMarker.isSelected()); 78 | } 79 | }); 80 | panel.add(showMapMarker); 81 | final JCheckBox showTileGrid = new JCheckBox("Tile grid visible"); 82 | showTileGrid.setSelected(map.isTileGridVisible()); 83 | showTileGrid.addActionListener(new ActionListener() { 84 | 85 | public void actionPerformed(ActionEvent e) { 86 | map.setTileGridVisible(showTileGrid.isSelected()); 87 | } 88 | }); 89 | panel.add(showTileGrid); 90 | final JCheckBox showZoomControls = new JCheckBox("Show zoom controls"); 91 | showZoomControls.setSelected(map.getZoomContolsVisible()); 92 | showZoomControls.addActionListener(new ActionListener() { 93 | 94 | public void actionPerformed(ActionEvent e) { 95 | map.setZoomContolsVisible(showZoomControls.isSelected()); 96 | } 97 | }); 98 | panel.add(showZoomControls); 99 | panel.add(button); 100 | add(map, BorderLayout.CENTER); 101 | 102 | // 103 | map.addMapMarker(new MapMarkerDot(49.814284999, 8.642065999)); 104 | map.addMapMarker(new MapMarkerDot(49.91, 8.24)); 105 | map.addMapMarker(new MapMarkerDot(49.71, 8.64)); 106 | map.addMapMarker(new MapMarkerDot(48.71, -1)); 107 | map.addMapMarker(new MapMarkerDot(49.8588, 8.643)); 108 | 109 | // map.setDisplayPositionByLatLon(49.807, 8.6, 11); 110 | // map.setTileGridVisible(true); 111 | } 112 | 113 | /** 114 | * @param args 115 | */ 116 | public static void main(String[] args) { 117 | // java.util.Properties systemProperties = System.getProperties(); 118 | // systemProperties.setProperty("http.proxyHost", "localhost"); 119 | // systemProperties.setProperty("http.proxyPort", "8008"); 120 | new Demo().setVisible(true); 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/JobDispatcher.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | import java.util.concurrent.BlockingQueue; 6 | import java.util.concurrent.LinkedBlockingQueue; 7 | import java.util.concurrent.TimeUnit; 8 | import java.util.logging.Level; 9 | import java.util.logging.Logger; 10 | 11 | /** 12 | * A generic class that processes a list of {@link Runnable} one-by-one using 13 | * one or more {@link Thread}-instances. The number of instances varies between 14 | * 1 and {@link #WORKER_THREAD_MAX_COUNT} (default: 8). If an instance is idle 15 | * more than {@link #WORKER_THREAD_TIMEOUT} seconds (default: 30), the instance 16 | * ends itself. 17 | * 18 | * @author Jan Peter Stotz 19 | */ 20 | public class JobDispatcher { 21 | 22 | private static final Logger log = Logger.getLogger(JobDispatcher.class.getName()); 23 | private static JobDispatcher instance; 24 | 25 | /** 26 | * @return the singelton instance of the {@link JobDispatcher} 27 | */ 28 | public static JobDispatcher getInstance() { 29 | // for speed reasons we check if the instance has been created 30 | // one time before we enter the synchronized section... 31 | if (instance != null) 32 | return instance; 33 | synchronized (JobDispatcher.class) { 34 | // ... and for thread safety reasons one time inside the 35 | // synchronized section. 36 | if (instance != null) 37 | return instance; 38 | new JobDispatcher(); 39 | return instance; 40 | } 41 | } 42 | 43 | private JobDispatcher() { 44 | instance = this; 45 | addWorkerThread().firstThread = true; 46 | } 47 | 48 | protected BlockingQueue jobQueue = new LinkedBlockingQueue(); 49 | 50 | public static int WORKER_THREAD_MAX_COUNT = 8; 51 | 52 | /** 53 | * Specifies the time span in seconds that a worker thread waits for new 54 | * jobs to perform. If the time span has elapsed the worker thread 55 | * terminates itself. Only the first worker thread works differently, it 56 | * ignores the timeout and will never terminate itself. 57 | */ 58 | public static int WORKER_THREAD_TIMEOUT = 30; 59 | 60 | /** 61 | * Total number of worker threads currently idle or active 62 | */ 63 | protected int workerThreadCount = 0; 64 | 65 | /** 66 | * Number of worker threads currently idle 67 | */ 68 | protected int workerThreadIdleCount = 0; 69 | 70 | /** 71 | * Just an id for identifying an worker thread instance 72 | */ 73 | protected int workerThreadId = 0; 74 | 75 | /** 76 | * Removes all jobs from the queue that are currently not being processed. 77 | */ 78 | public void cancelOutstandingJobs() { 79 | jobQueue.clear(); 80 | } 81 | 82 | public void addJob(Runnable job) { 83 | try { 84 | jobQueue.put(job); 85 | if (workerThreadIdleCount == 0 && workerThreadCount < WORKER_THREAD_MAX_COUNT) 86 | addWorkerThread(); 87 | } catch (InterruptedException e) { 88 | } 89 | } 90 | 91 | protected JobThread addWorkerThread() { 92 | JobThread jobThread = new JobThread(++workerThreadId); 93 | synchronized (this) { 94 | workerThreadCount++; 95 | } 96 | return jobThread; 97 | } 98 | 99 | protected class JobThread extends Thread { 100 | 101 | Runnable job; 102 | boolean firstThread = false; 103 | 104 | public JobThread(int threadId) { 105 | super("OSMJobThread " + threadId); 106 | setDaemon(true); 107 | job = null; 108 | start(); 109 | } 110 | 111 | @Override 112 | public void run() { 113 | executeJobs(); 114 | synchronized (instance) { 115 | workerThreadCount--; 116 | } 117 | } 118 | 119 | protected void executeJobs() { 120 | while (!isInterrupted()) { 121 | try { 122 | synchronized (instance) { 123 | workerThreadIdleCount++; 124 | } 125 | if (firstThread) 126 | job = jobQueue.take(); 127 | else 128 | job = jobQueue.poll(WORKER_THREAD_TIMEOUT, TimeUnit.SECONDS); 129 | } catch (InterruptedException e1) { 130 | return; 131 | } finally { 132 | synchronized (instance) { 133 | workerThreadIdleCount--; 134 | } 135 | } 136 | if (job == null) 137 | return; 138 | try { 139 | job.run(); 140 | job = null; 141 | } catch (Exception e) { 142 | log.log(Level.SEVERE, "Error running job", e); 143 | } 144 | } 145 | } 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | import java.awt.Point; 6 | import java.awt.event.MouseEvent; 7 | import java.awt.event.MouseListener; 8 | import java.awt.event.MouseMotionListener; 9 | import java.awt.event.MouseWheelEvent; 10 | import java.awt.event.MouseWheelListener; 11 | 12 | /** 13 | * Default map controller which implements map moving by pressing the right 14 | * mouse button and zooming by double click or by mouse wheel. 15 | * 16 | * @author Jan Peter Stotz 17 | * 18 | */ 19 | public class DefaultMapController extends JMapController implements MouseListener, MouseMotionListener, 20 | MouseWheelListener { 21 | 22 | private static final int MOUSE_BUTTONS_MASK = MouseEvent.BUTTON3_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK 23 | | MouseEvent.BUTTON2_DOWN_MASK; 24 | 25 | public DefaultMapController(JMapViewer map) { 26 | super(map); 27 | } 28 | 29 | private Point lastDragPoint; 30 | 31 | private boolean isMoving = false; 32 | 33 | private boolean movementEnabled = true; 34 | 35 | private int movementMouseButton = MouseEvent.BUTTON3; 36 | private int movementMouseButtonMask = MouseEvent.BUTTON3_DOWN_MASK; 37 | 38 | private boolean wheelZoomEnabled = true; 39 | private boolean doubleClickZoomEnabled = true; 40 | 41 | public void mouseDragged(MouseEvent e) { 42 | if (!movementEnabled || !isMoving) 43 | return; 44 | // Is only the selected mouse button pressed? 45 | if ((e.getModifiersEx() & MOUSE_BUTTONS_MASK) == movementMouseButtonMask) { 46 | Point p = e.getPoint(); 47 | if (lastDragPoint != null) { 48 | int diffx = lastDragPoint.x - p.x; 49 | int diffy = lastDragPoint.y - p.y; 50 | map.moveMap(diffx, diffy); 51 | } 52 | lastDragPoint = p; 53 | } 54 | } 55 | 56 | public void mouseClicked(MouseEvent e) { 57 | if (doubleClickZoomEnabled && e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) 58 | map.zoomIn(e.getPoint()); 59 | } 60 | 61 | public void mousePressed(MouseEvent e) { 62 | if (e.getButton() == movementMouseButton) { 63 | lastDragPoint = null; 64 | isMoving = true; 65 | } 66 | } 67 | 68 | public void mouseReleased(MouseEvent e) { 69 | if (e.getButton() == movementMouseButton) { 70 | lastDragPoint = null; 71 | isMoving = false; 72 | } 73 | } 74 | 75 | public void mouseWheelMoved(MouseWheelEvent e) { 76 | if (wheelZoomEnabled) 77 | map.setZoom(map.getZoom() - e.getWheelRotation(), e.getPoint()); 78 | } 79 | 80 | public boolean isMovementEnabled() { 81 | return movementEnabled; 82 | } 83 | 84 | /** 85 | * Enables or disables that the map pane can be moved using the mouse. 86 | * 87 | * @param movementEnabled 88 | */ 89 | public void setMovementEnabled(boolean movementEnabled) { 90 | this.movementEnabled = movementEnabled; 91 | } 92 | 93 | public int getMovementMouseButton() { 94 | return movementMouseButton; 95 | } 96 | 97 | /** 98 | * Sets the mouse button that is used for moving the map. Possible values 99 | * are: 100 | *
    101 | *
  • {@link MouseEvent#BUTTON1} (left mouse button)
  • 102 | *
  • {@link MouseEvent#BUTTON2} (middle mouse button)
  • 103 | *
  • {@link MouseEvent#BUTTON3} (right mouse button)
  • 104 | *
105 | * 106 | * @param movementMouseButton 107 | */ 108 | public void setMovementMouseButton(int movementMouseButton) { 109 | this.movementMouseButton = movementMouseButton; 110 | switch (movementMouseButton) { 111 | case MouseEvent.BUTTON1: 112 | movementMouseButtonMask = MouseEvent.BUTTON1_DOWN_MASK; 113 | break; 114 | case MouseEvent.BUTTON2: 115 | movementMouseButtonMask = MouseEvent.BUTTON2_DOWN_MASK; 116 | break; 117 | case MouseEvent.BUTTON3: 118 | movementMouseButtonMask = MouseEvent.BUTTON3_DOWN_MASK; 119 | break; 120 | default: 121 | throw new RuntimeException("Unsupported button"); 122 | } 123 | } 124 | 125 | public boolean isWheelZoomEnabled() { 126 | return wheelZoomEnabled; 127 | } 128 | 129 | public void setWheelZoomEnabled(boolean wheelZoomEnabled) { 130 | this.wheelZoomEnabled = wheelZoomEnabled; 131 | } 132 | 133 | public boolean isDoubleClickZoomEnabled() { 134 | return doubleClickZoomEnabled; 135 | } 136 | 137 | public void setDoubleClickZoomEnabled(boolean doubleClickZoomEnabled) { 138 | this.doubleClickZoomEnabled = doubleClickZoomEnabled; 139 | } 140 | 141 | public void mouseEntered(MouseEvent e) { 142 | } 143 | 144 | public void mouseExited(MouseEvent e) { 145 | } 146 | 147 | public void mouseMoved(MouseEvent e) { 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/config/DownloadConfigurationBBoxLatLon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.config; 23 | 24 | import java.util.Properties; 25 | 26 | import org.openstreetmap.fma.jtiledownloader.Util; 27 | import org.openstreetmap.fma.jtiledownloader.datatypes.DownloadJob; 28 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileList; 29 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileListBBoxLatLon; 30 | 31 | public class DownloadConfigurationBBoxLatLon 32 | extends DownloadConfiguration 33 | { 34 | private double _minLat = 0.0; 35 | private double _minLon = 0.0; 36 | private double _maxLat = 0.0; 37 | private double _maxLon = 0.0; 38 | 39 | private static final String MIN_LAT = "MinLat"; 40 | private static final String MIN_LON = "MinLon"; 41 | private static final String MAX_LAT = "MaxLat"; 42 | private static final String MAX_LON = "MaxLon"; 43 | 44 | public static final String ID = "BBoxLatLon"; 45 | 46 | @Override 47 | public void save(Properties prop) 48 | { 49 | setTemplateProperty(prop, TYPE, ID); 50 | 51 | setTemplateProperty(prop, MIN_LAT, String.valueOf(_minLat)); 52 | setTemplateProperty(prop, MIN_LON, String.valueOf(_minLon)); 53 | setTemplateProperty(prop, MAX_LAT, String.valueOf(_maxLat)); 54 | setTemplateProperty(prop, MAX_LON, String.valueOf(_maxLon)); 55 | } 56 | 57 | @Override 58 | public void load(Properties prop) 59 | { 60 | _minLat = Double.parseDouble(prop.getProperty(MIN_LAT, "0.0")); 61 | _minLon = Double.parseDouble(prop.getProperty(MIN_LON, "0.0")); 62 | _maxLat = Double.parseDouble(prop.getProperty(MAX_LAT, "0.0")); 63 | _maxLon = Double.parseDouble(prop.getProperty(MAX_LON, "0.0")); 64 | } 65 | 66 | /** 67 | * Getter for minLat 68 | * @return the minLat 69 | */ 70 | public final double getMinLat() 71 | { 72 | return _minLat; 73 | } 74 | 75 | /** 76 | * Setter for minLat 77 | * @param minLat the minLat to set 78 | */ 79 | public final void setMinLat(double minLat) 80 | { 81 | _minLat = minLat; 82 | } 83 | 84 | /** 85 | * Getter for minLon 86 | * @return the minLon 87 | */ 88 | public final double getMinLon() 89 | { 90 | return _minLon; 91 | } 92 | 93 | /** 94 | * Setter for minLon 95 | * @param minLon the minLon to set 96 | */ 97 | public final void setMinLon(double minLon) 98 | { 99 | _minLon = minLon; 100 | } 101 | 102 | /** 103 | * Getter for maxLat 104 | * @return the maxLat 105 | */ 106 | public final double getMaxLat() 107 | { 108 | return _maxLat; 109 | } 110 | 111 | /** 112 | * Setter for maxLat 113 | * @param maxLat the maxLat to set 114 | */ 115 | public final void setMaxLat(double maxLat) 116 | { 117 | _maxLat = maxLat; 118 | } 119 | 120 | /** 121 | * Getter for maxLon 122 | * @return the maxLon 123 | */ 124 | public final double getMaxLon() 125 | { 126 | return _maxLon; 127 | } 128 | 129 | /** 130 | * Setter for maxLon 131 | * @param maxLon the maxLon to set 132 | */ 133 | public final void setMaxLon(double maxLon) 134 | { 135 | _maxLon = maxLon; 136 | } 137 | 138 | /** 139 | * @see org.openstreetmap.fma.jtiledownloader.config.DownloadConfiguration#getType() 140 | */ 141 | @Override 142 | public String getType() 143 | { 144 | return ID; 145 | } 146 | 147 | /** 148 | * @see org.openstreetmap.fma.jtiledownloader.config.DownloadConfiguration#getTileList(DownloadJob) 149 | */ 150 | @Override 151 | public TileList getTileList(DownloadJob downloadJob) 152 | { 153 | TileListBBoxLatLon tileList = new TileListBBoxLatLon(); 154 | 155 | tileList.setDownloadZoomLevels(Util.getOutputZoomLevelArray(downloadJob.getTileProvider(), downloadJob.getOutputZoomLevels())); 156 | 157 | tileList.setMinLat(getMinLat()); 158 | tileList.setMaxLat(getMaxLat()); 159 | tileList.setMinLon(getMinLon()); 160 | tileList.setMaxLon(getMaxLon()); 161 | 162 | tileList.calculateTileValuesXY(); 163 | 164 | return tileList; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/datatypes/DownloadJob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Sven Strickroth 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.datatypes; 23 | 24 | import java.io.FileInputStream; 25 | import java.io.FileOutputStream; 26 | import java.io.IOException; 27 | import java.util.Properties; 28 | 29 | import java.util.logging.Level; 30 | import java.util.logging.Logger; 31 | import org.openstreetmap.fma.jtiledownloader.Util; 32 | import org.openstreetmap.fma.jtiledownloader.config.DownloadConfiguration; 33 | import org.openstreetmap.fma.jtiledownloader.config.DownloadConfigurationSaverIf; 34 | 35 | public class DownloadJob 36 | implements DownloadConfigurationSaverIf 37 | { 38 | private static final Logger log = Logger.getLogger(DownloadJob.class.getName()); 39 | 40 | private Properties prop = new Properties(); 41 | 42 | private String _outputZoomLevels = ""; 43 | private String _tileServer = ""; 44 | private String _outputLocation = ""; 45 | private String _type = ""; 46 | 47 | private static final String OUTPUT_ZOOM_LEVEL = "OutputZoomLevel"; 48 | private static final String TILE_SERVER = "TileServer"; 49 | private static final String OUTPUTLOCATION = "OutputLocation"; 50 | 51 | public static final String TYPE = "Type"; 52 | 53 | public DownloadJob() 54 | {} 55 | 56 | /** 57 | * constructor setting propertyFileName 58 | * 59 | * @param propertyFileName 60 | */ 61 | public DownloadJob(String propertyFileName) 62 | { 63 | loadFromFile(propertyFileName); 64 | } 65 | 66 | public void saveToFile(String propertyFileName) 67 | { 68 | setTemplateProperty(prop, OUTPUT_ZOOM_LEVEL, _outputZoomLevels); 69 | setTemplateProperty(prop, TILE_SERVER, _tileServer); 70 | setTemplateProperty(prop, OUTPUTLOCATION, _outputLocation); 71 | try 72 | { 73 | prop.storeToXML(new FileOutputStream(propertyFileName), null); 74 | } 75 | catch (IOException e) 76 | { 77 | log.log(Level.SEVERE, "Error saving job to file " + propertyFileName, e); 78 | } 79 | } 80 | 81 | private void loadFromFile(String fileName) 82 | { 83 | try 84 | { 85 | prop.loadFromXML(new FileInputStream(fileName)); 86 | } 87 | catch (IOException e) 88 | { 89 | log.log(Level.SEVERE, "Error loading job from file " + fileName, e); 90 | } 91 | 92 | _type = prop.getProperty(TYPE, ""); 93 | _outputZoomLevels = prop.getProperty(OUTPUT_ZOOM_LEVEL, "12"); 94 | _tileServer = prop.getProperty(TILE_SERVER, ""); 95 | _outputLocation = prop.getProperty(OUTPUTLOCATION, "tiles"); 96 | } 97 | 98 | protected void setTemplateProperty(Properties prop, String key, String value) 99 | { 100 | log.log(Level.CONFIG, "setting property {0} to value {1}", new Object[]{key, value}); 101 | prop.setProperty(key, value); 102 | } 103 | 104 | /** 105 | * Getter for outputZoomLevel 106 | * @return the outputZoomLevel 107 | */ 108 | public final String getOutputZoomLevels() 109 | { 110 | return _outputZoomLevels; 111 | } 112 | 113 | /** 114 | * Setter for outputZoomLevel 115 | * @param outputZoomLevel the outputZoomLevel to set 116 | */ 117 | public final void setOutputZoomLevels(String outputZoomLevel) 118 | { 119 | _outputZoomLevels = outputZoomLevel; 120 | } 121 | 122 | /** 123 | * Getter for tileServer 124 | * @return the tileServer 125 | */ 126 | public final String getTileServer() 127 | { 128 | return _tileServer; 129 | } 130 | 131 | public final TileProviderIf getTileProvider() 132 | { 133 | return Util.getTileProvider(getTileServer()); 134 | } 135 | 136 | /** 137 | * Setter for tileServer 138 | * @param tileServer the tileServer to set 139 | */ 140 | public final void setTileServer(String tileServer) 141 | { 142 | _tileServer = tileServer; 143 | } 144 | 145 | /** 146 | * Getter for outputLocation 147 | * @return the outputLocation 148 | */ 149 | public final String getOutputLocation() 150 | { 151 | return _outputLocation; 152 | } 153 | 154 | /** 155 | * Setter for outputLocation 156 | * @param outputLocation the outputLocation to set 157 | */ 158 | public final void setOutputLocation(String outputLocation) 159 | { 160 | _outputLocation = outputLocation; 161 | } 162 | 163 | /** 164 | * Getter for type 165 | * @return the type 166 | */ 167 | public final String getType() 168 | { 169 | return _type; 170 | } 171 | 172 | /** 173 | * @see org.openstreetmap.fma.jtiledownloader.config.DownloadConfigurationSaverIf#saveDownloadConfig(org.openstreetmap.fma.jtiledownloader.config.DownloadConfiguration) 174 | */ 175 | public void saveDownloadConfig(DownloadConfiguration config) 176 | { 177 | config.save(prop); 178 | } 179 | 180 | public void loadDownloadConfig(DownloadConfiguration config) 181 | { 182 | config.load(prop); 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/views/main/NetworkPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.views.main; 23 | 24 | import java.awt.GridBagConstraints; 25 | import java.awt.GridBagLayout; 26 | import java.awt.Insets; 27 | 28 | import javax.swing.JCheckBox; 29 | import javax.swing.JLabel; 30 | import javax.swing.JPanel; 31 | import javax.swing.JPasswordField; 32 | import javax.swing.JTextField; 33 | import javax.swing.border.Border; 34 | import javax.swing.border.TitledBorder; 35 | 36 | import org.openstreetmap.fma.jtiledownloader.config.AppConfiguration; 37 | 38 | public class NetworkPanel 39 | extends JPanel 40 | { 41 | private static final long serialVersionUID = 1L; 42 | 43 | private JCheckBox _chkUseProxyServer = new JCheckBox("Use Proxy Server?"); 44 | private JLabel _labelProxyServer = new JLabel("Proxy Server:"); 45 | private JTextField _textProxyServer = new JTextField(); 46 | private JLabel _labelProxyPort = new JLabel("Proxy Port:"); 47 | private JTextField _textProxyPort = new JTextField(); 48 | private JCheckBox _chkAuthRequired = new JCheckBox("Authentication required?"); 49 | private JLabel _labelProxyUser = new JLabel("Proxy User:"); 50 | private JTextField _textProxyUser = new JTextField(); 51 | private JLabel _labelProxyPassword = new JLabel("Proxy Password:"); 52 | private JTextField _textProxyPassWord = new JPasswordField(); 53 | 54 | /** 55 | * 56 | */ 57 | public NetworkPanel() 58 | { 59 | super(); 60 | 61 | createNetworkPanel(); 62 | initializeNetworkPanel(); 63 | } 64 | 65 | private void createNetworkPanel() 66 | { 67 | setLayout(new GridBagLayout()); 68 | JPanel panelProxySettings = new JPanel(); 69 | 70 | GridBagConstraints constraintsProxySettings = new GridBagConstraints(); 71 | constraintsProxySettings.gridwidth = GridBagConstraints.REMAINDER; 72 | constraintsProxySettings.weightx = 1.0; 73 | constraintsProxySettings.fill = GridBagConstraints.HORIZONTAL; 74 | constraintsProxySettings.insets = new Insets(5, 5, 0, 5); 75 | 76 | panelProxySettings.setLayout(new GridBagLayout()); 77 | Border border = new TitledBorder("Proxy Settings"); 78 | panelProxySettings.setBorder(border); 79 | 80 | panelProxySettings.add(_chkUseProxyServer, constraintsProxySettings); 81 | panelProxySettings.add(_labelProxyServer, constraintsProxySettings); 82 | panelProxySettings.add(_textProxyServer, constraintsProxySettings); 83 | panelProxySettings.add(_labelProxyPort, constraintsProxySettings); 84 | panelProxySettings.add(_textProxyPort, constraintsProxySettings); 85 | panelProxySettings.add(_chkAuthRequired, constraintsProxySettings); 86 | panelProxySettings.add(_labelProxyUser, constraintsProxySettings); 87 | panelProxySettings.add(_textProxyUser, constraintsProxySettings); 88 | panelProxySettings.add(_labelProxyPassword, constraintsProxySettings); 89 | panelProxySettings.add(_textProxyPassWord, constraintsProxySettings); 90 | 91 | GridBagConstraints constraints = new GridBagConstraints(); 92 | constraints.gridwidth = GridBagConstraints.REMAINDER; 93 | constraints.weightx = 1.0; 94 | constraints.fill = GridBagConstraints.HORIZONTAL; 95 | constraints.insets = new Insets(10, 5, 0, 5); 96 | add(panelProxySettings, constraints); 97 | 98 | constraints.weighty = 1.0; 99 | add(new JPanel(), constraints); 100 | } 101 | 102 | /** 103 | * 104 | */ 105 | private void initializeNetworkPanel() 106 | { 107 | _chkUseProxyServer.setSelected(AppConfiguration.getInstance().getUseProxyServer()); 108 | _textProxyServer.setText(AppConfiguration.getInstance().getProxyServer()); 109 | _textProxyPort.setText(AppConfiguration.getInstance().getProxyServerPort()); 110 | _chkAuthRequired.setSelected(AppConfiguration.getInstance().isProxyServerRequiresAuthentitication()); 111 | _textProxyUser.setText(AppConfiguration.getInstance().getProxyServerUser()); 112 | _textProxyPassWord.setText(AppConfiguration.getInstance().getProxyServerPassword()); 113 | } 114 | 115 | /** 116 | * @return use proxy server? 117 | */ 118 | public boolean isUseProxyServer() 119 | { 120 | return _chkUseProxyServer.isSelected(); 121 | } 122 | 123 | /** 124 | * @return the proxy server address 125 | */ 126 | public String getProxyServer() 127 | { 128 | return _textProxyServer.getText().trim(); 129 | } 130 | 131 | /** 132 | * @return the proxy port 133 | */ 134 | public String getProxyServerPort() 135 | { 136 | return _textProxyPort.getText().trim(); 137 | } 138 | 139 | /** 140 | * @return use proxy auth? 141 | */ 142 | public boolean isUseProxyServerAuth() 143 | { 144 | return _chkAuthRequired.isSelected(); 145 | } 146 | 147 | /** 148 | * @return proxy username 149 | */ 150 | public String getProxyServerUser() 151 | { 152 | return _textProxyUser.getText().trim(); 153 | } 154 | 155 | /** 156 | * @return proxy password 157 | */ 158 | public String getProxyServerPassword() 159 | { 160 | return _textProxyPassWord.getText().trim(); 161 | } 162 | 163 | } 164 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/views/errortilelist/ErrorTileListView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.views.errortilelist; 23 | 24 | import java.awt.BorderLayout; 25 | import java.awt.Dimension; 26 | import java.awt.FlowLayout; 27 | import java.awt.HeadlessException; 28 | import java.awt.event.ActionEvent; 29 | import java.awt.event.ActionListener; 30 | import java.util.ArrayList; 31 | 32 | import java.util.logging.Level; 33 | import java.util.logging.Logger; 34 | import javax.swing.JButton; 35 | import javax.swing.JDialog; 36 | import javax.swing.JPanel; 37 | import javax.swing.JScrollPane; 38 | import javax.swing.JTable; 39 | import javax.swing.WindowConstants; 40 | import javax.swing.table.DefaultTableColumnModel; 41 | import javax.swing.table.TableColumn; 42 | import javax.swing.table.TableModel; 43 | 44 | import org.openstreetmap.fma.jtiledownloader.datatypes.TileDownloadError; 45 | 46 | public class ErrorTileListView 47 | extends JDialog 48 | { 49 | 50 | private static final String[] COL_HEADS = new String[] { "No", "Tile", "Error" }; 51 | private static final int[] COL_SIZE = new int[] { 30, 300, 80 }; 52 | 53 | private static final int VIEW_SIZE_X = 550; 54 | private static final int VIEW_SIZE_Y = 480; 55 | private static final String RETRY = "RETRY"; 56 | private static final String CLOSE = "CLOSE"; 57 | private static final long serialVersionUID = 1L; 58 | private final ArrayList _errorTileList; 59 | 60 | private JTable _errorTable; 61 | private JButton _close; 62 | private JButton _retry; 63 | 64 | private int _exitCode = CODE_CLOSE; 65 | public static final int CODE_CLOSE = 0; 66 | public static final int CODE_RETRY = 1; 67 | 68 | /** 69 | * @param errorTileList 70 | * @throws HeadlessException 71 | */ 72 | public ErrorTileListView(ArrayList errorTileList) throws HeadlessException 73 | { 74 | super(); 75 | setTitle("ErrorTileListView"); 76 | setModal(true); 77 | _errorTileList = errorTileList; 78 | 79 | setPreferredSize(new Dimension(VIEW_SIZE_X, VIEW_SIZE_Y)); 80 | setLayout(new BorderLayout()); 81 | setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 82 | 83 | initTable(); 84 | 85 | _close = new JButton("Close"); 86 | _close.setPreferredSize(new Dimension(100, 25)); 87 | _close.setActionCommand(CLOSE); 88 | _close.addActionListener(new MyActionListener()); 89 | 90 | _retry = new JButton("Retry"); 91 | _retry.setPreferredSize(new Dimension(100, 25)); 92 | _retry.setActionCommand(RETRY); 93 | _retry.addActionListener(new MyActionListener()); 94 | 95 | initializeView(); 96 | 97 | } 98 | 99 | /** 100 | * 101 | */ 102 | private void initTable() 103 | { 104 | DefaultTableColumnModel cm = new DefaultTableColumnModel(); 105 | for (int i = 0; i < COL_HEADS.length; ++i) 106 | { 107 | TableColumn col = new TableColumn(i, COL_SIZE[i]); 108 | col.setHeaderValue(COL_HEADS[i]); 109 | cm.addColumn(col); 110 | } 111 | 112 | TableModel tm = new ErrorTileListViewTableModel(_errorTileList); 113 | 114 | _errorTable = new JTable(tm, cm); 115 | _errorTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); 116 | 117 | } 118 | 119 | /** 120 | * 121 | */ 122 | private void initializeView() 123 | { 124 | JScrollPane scrollPane = new JScrollPane(_errorTable); 125 | scrollPane.setPreferredSize(new Dimension(VIEW_SIZE_X - 20, VIEW_SIZE_Y - 90)); 126 | scrollPane.getViewport().add(_errorTable, BorderLayout.CENTER); 127 | add(scrollPane); 128 | 129 | JPanel panelButtons = new JPanel(); 130 | panelButtons.add(_retry); 131 | panelButtons.add(_close); 132 | 133 | setLayout(new FlowLayout()); 134 | add(panelButtons); 135 | 136 | pack(); 137 | } 138 | 139 | /** 140 | * Getter for errorTileList 141 | * @return the errorTileList 142 | */ 143 | public ArrayList getErrorTileList() 144 | { 145 | return _errorTileList; 146 | } 147 | 148 | /** 149 | * Setter for exitCode 150 | * @param exitCode the exitCode to set 151 | */ 152 | public void setExitCode(int exitCode) 153 | { 154 | _exitCode = exitCode; 155 | } 156 | 157 | /** 158 | * Getter for exitCode 159 | * @return the exitCode 160 | */ 161 | public int getExitCode() 162 | { 163 | return _exitCode; 164 | } 165 | 166 | class MyActionListener 167 | implements ActionListener 168 | { 169 | 170 | /** 171 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) 172 | */ 173 | public void actionPerformed(ActionEvent e) 174 | { 175 | String actionCommand = e.getActionCommand(); 176 | log.log(Level.FINE, "button pressed -> {0}", actionCommand); 177 | 178 | if (actionCommand.equalsIgnoreCase(CLOSE)) 179 | { 180 | setExitCode(CODE_CLOSE); 181 | } 182 | if (actionCommand.equalsIgnoreCase(RETRY)) 183 | { 184 | setExitCode(CODE_RETRY); 185 | } 186 | _close.removeActionListener(this); 187 | _retry.removeActionListener(this); 188 | dispose(); 189 | } 190 | } 191 | 192 | private static final Logger log = Logger.getLogger(ErrorTileListView.class.getName()); 193 | } 194 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Wed Aug 19 14:06:06 CEST 2009 2 | eclipse.preferences.version=1 3 | formatter_profile=_JTileDownloader 4 | formatter_settings_version=11 5 | org.eclipse.jdt.ui.exception.name=e 6 | org.eclipse.jdt.ui.gettersetter.use.is=true 7 | org.eclipse.jdt.ui.javadoc=true 8 | org.eclipse.jdt.ui.keywordthis=false 9 | org.eclipse.jdt.ui.overrideannotation=true 10 | org.eclipse.jdt.ui.text.custom_code_templates= 11 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | import java.util.HashMap; 6 | import java.util.logging.Logger; 7 | 8 | import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; 9 | import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 10 | 11 | /** 12 | * {@link TileCache} implementation that stores all {@link Tile} objects in 13 | * memory up to a certain limit ({@link #getCacheSize()}). If the limit is 14 | * exceeded the least recently used {@link Tile} objects will be deleted. 15 | * 16 | * @author Jan Peter Stotz 17 | */ 18 | public class MemoryTileCache implements TileCache { 19 | 20 | protected static final Logger log = Logger.getLogger(MemoryTileCache.class.getName()); 21 | 22 | /** 23 | * Default cache size 24 | */ 25 | protected int cacheSize = 200; 26 | 27 | protected HashMap hashMap; 28 | 29 | /** 30 | * List of all tiles in their last recently used order 31 | */ 32 | protected final CacheLinkedListElement lruTiles = new CacheLinkedListElement(); 33 | 34 | public MemoryTileCache() { 35 | hashMap = new HashMap(cacheSize); 36 | } 37 | 38 | public void addTile(Tile tile) { 39 | CacheEntry entry = createCacheEntry(tile); 40 | hashMap.put(tile.getKey(), entry); 41 | lruTiles.addFirst(entry); 42 | if (hashMap.size() > cacheSize) 43 | removeOldEntries(); 44 | } 45 | 46 | public Tile getTile(TileSource source, int x, int y, int z) { 47 | CacheEntry entry = hashMap.get(Tile.getTileKey(source, x, y, z)); 48 | if (entry == null) 49 | return null; 50 | // We don't care about placeholder tiles and hourglass image tiles, the 51 | // important tiles are the loaded ones 52 | if (entry.tile.isLoaded()) 53 | lruTiles.moveElementToFirstPos(entry); 54 | return entry.tile; 55 | } 56 | 57 | /** 58 | * Removes the least recently used tiles 59 | */ 60 | protected void removeOldEntries() { 61 | synchronized (lruTiles) { 62 | try { 63 | while (lruTiles.getElementCount() > cacheSize) { 64 | removeEntry(lruTiles.getLastElement()); 65 | } 66 | } catch (Exception e) { 67 | log.warning(e.getMessage()); 68 | } 69 | } 70 | } 71 | 72 | protected void removeEntry(CacheEntry entry) { 73 | hashMap.remove(entry.tile.getKey()); 74 | lruTiles.removeEntry(entry); 75 | } 76 | 77 | protected CacheEntry createCacheEntry(Tile tile) { 78 | return new CacheEntry(tile); 79 | } 80 | 81 | /** 82 | * Clears the cache deleting all tiles from memory 83 | */ 84 | public void clear() { 85 | synchronized (lruTiles) { 86 | hashMap.clear(); 87 | lruTiles.clear(); 88 | } 89 | } 90 | 91 | public int getTileCount() { 92 | return hashMap.size(); 93 | } 94 | 95 | public int getCacheSize() { 96 | return cacheSize; 97 | } 98 | 99 | /** 100 | * Changes the maximum number of {@link Tile} objects that this cache holds. 101 | * 102 | * @param cacheSize 103 | * new maximum number of tiles 104 | */ 105 | public void setCacheSize(int cacheSize) { 106 | this.cacheSize = cacheSize; 107 | if (hashMap.size() > cacheSize) 108 | removeOldEntries(); 109 | } 110 | 111 | /** 112 | * Linked list element holding the {@link Tile} and links to the 113 | * {@link #next} and {@link #prev} item in the list. 114 | */ 115 | protected static class CacheEntry { 116 | Tile tile; 117 | 118 | CacheEntry next; 119 | CacheEntry prev; 120 | 121 | protected CacheEntry(Tile tile) { 122 | this.tile = tile; 123 | } 124 | 125 | public Tile getTile() { 126 | return tile; 127 | } 128 | 129 | public CacheEntry getNext() { 130 | return next; 131 | } 132 | 133 | public CacheEntry getPrev() { 134 | return prev; 135 | } 136 | 137 | } 138 | 139 | /** 140 | * Special implementation of a double linked list for {@link CacheEntry} 141 | * elements. It supports element removal in constant time - in difference to 142 | * the Java implementation which needs O(n). 143 | * 144 | * @author Jan Peter Stotz 145 | */ 146 | protected static class CacheLinkedListElement { 147 | protected CacheEntry firstElement = null; 148 | protected CacheEntry lastElement; 149 | protected int elementCount; 150 | 151 | public CacheLinkedListElement() { 152 | clear(); 153 | } 154 | 155 | public synchronized void clear() { 156 | elementCount = 0; 157 | firstElement = null; 158 | lastElement = null; 159 | } 160 | 161 | /** 162 | * Add the element to the head of the list. 163 | * 164 | * @param element element to be added 165 | */ 166 | public synchronized void addFirst(CacheEntry element) { 167 | if (elementCount == 0) { 168 | firstElement = element; 169 | lastElement = element; 170 | element.prev = null; 171 | element.next = null; 172 | } else { 173 | element.next = firstElement; 174 | firstElement.prev = element; 175 | element.prev = null; 176 | firstElement = element; 177 | } 178 | elementCount++; 179 | } 180 | 181 | /** 182 | * Removes the specified elemntent form the list. 183 | * 184 | * @param element 185 | * to be removed 186 | */ 187 | public synchronized void removeEntry(CacheEntry element) { 188 | if (element.next != null) { 189 | element.next.prev = element.prev; 190 | } 191 | if (element.prev != null) { 192 | element.prev.next = element.next; 193 | } 194 | if (element == firstElement) 195 | firstElement = element.next; 196 | if (element == lastElement) 197 | lastElement = element.prev; 198 | element.next = null; 199 | element.prev = null; 200 | elementCount--; 201 | } 202 | 203 | public synchronized void moveElementToFirstPos(CacheEntry entry) { 204 | if (firstElement == entry) 205 | return; 206 | removeEntry(entry); 207 | addFirst(entry); 208 | } 209 | 210 | public int getElementCount() { 211 | return elementCount; 212 | } 213 | 214 | public CacheEntry getLastElement() { 215 | return lastElement; 216 | } 217 | 218 | public CacheEntry getFirstElement() { 219 | return firstElement; 220 | } 221 | 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/cmdline/JTileDownloaderCommandLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * Copyright 2009, Sven Strickroth 4 | * 5 | * This file is part of JTileDownloader. 6 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 7 | * 8 | * JTileDownloader is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * JTileDownloader is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy (see file COPYING.txt) of the GNU 19 | * General Public License along with JTileDownloader. 20 | * If not, see . 21 | */ 22 | 23 | package org.openstreetmap.fma.jtiledownloader.cmdline; 24 | 25 | import java.util.HashMap; 26 | import java.util.ArrayList; 27 | 28 | import java.util.logging.Level; 29 | import java.util.logging.Logger; 30 | import org.openstreetmap.fma.jtiledownloader.TileListDownloader; 31 | import org.openstreetmap.fma.jtiledownloader.config.*; 32 | import org.openstreetmap.fma.jtiledownloader.datatypes.*; 33 | import org.openstreetmap.fma.jtiledownloader.listener.TileDownloaderListener; 34 | import org.openstreetmap.fma.jtiledownloader.tilelist.TileList; 35 | 36 | public class JTileDownloaderCommandLine 37 | implements TileDownloaderListener 38 | { 39 | private static final Logger log = Logger.getLogger(JTileDownloaderCommandLine.class.getName()); 40 | private static final String CMDLINE_DL = "DL"; 41 | 42 | private final HashMap _arguments; 43 | 44 | private DownloadJob _downloadJob; 45 | private TileList _tileList; 46 | private TileListDownloader _tld; 47 | private TileProviderIf _tileProvider; 48 | 49 | /** 50 | * @param arguments 51 | */ 52 | public JTileDownloaderCommandLine(HashMap arguments) 53 | { 54 | _arguments = arguments; 55 | } 56 | 57 | /** 58 | * 59 | */ 60 | public void start() 61 | { 62 | printStartUpMessage(); 63 | 64 | if (_arguments.containsKey(CMDLINE_DL)) 65 | { 66 | String propertyFile = _arguments.get(CMDLINE_DL); 67 | 68 | _downloadJob = new DownloadJob(propertyFile); 69 | 70 | _tileProvider = _downloadJob.getTileProvider(); 71 | 72 | handleDownloadTemplate(_downloadJob.getType()); 73 | } 74 | } 75 | 76 | /** 77 | * @param type 78 | */ 79 | private void handleDownloadTemplate(String type) 80 | { 81 | DownloadConfiguration _downloadTemplate = null; 82 | 83 | if (type.equalsIgnoreCase(DownloadConfigurationUrlSquare.ID)) 84 | { 85 | _downloadTemplate = new DownloadConfigurationUrlSquare(); 86 | } 87 | else if (type.equalsIgnoreCase(DownloadConfigurationBBoxLatLon.ID)) 88 | { 89 | _downloadTemplate = new DownloadConfigurationBBoxLatLon(); 90 | } 91 | else if (type.equalsIgnoreCase(DownloadConfigurationBBoxXY.ID)) 92 | { 93 | _downloadTemplate = new DownloadConfigurationBBoxXY(); 94 | } 95 | else if (type.equalsIgnoreCase(DownloadConfigurationGPX.ID)) 96 | { 97 | _downloadTemplate = new DownloadConfigurationGPX(); 98 | } 99 | else 100 | { 101 | log.severe("File contains an unknown format. Please specify a valid file!"); 102 | } 103 | 104 | if (_downloadTemplate != null) 105 | { 106 | _downloadJob.loadDownloadConfig(_downloadTemplate); 107 | 108 | _tileList = _downloadTemplate.getTileList(_downloadJob); 109 | 110 | startDownload(_tileProvider); 111 | } 112 | } 113 | 114 | /** 115 | * 116 | */ 117 | private void startDownload(TileProviderIf tileProvider) 118 | { 119 | _tld = new TileListDownloader(_downloadJob.getOutputLocation(), _tileList, tileProvider); 120 | _tld.setListener(this); 121 | if (_tileList.getTileListToDownload().size() > 0) 122 | { 123 | _tld.start(); 124 | } 125 | } 126 | 127 | /** 128 | * 129 | */ 130 | private void printStartUpMessage() 131 | { 132 | log.info("JTileDownloader Copyright (C) 2008 Friedrich Maier"); 133 | log.info("This program comes with ABSOLUTELY NO WARRANTY."); 134 | log.info("This is free software, and you are welcome to redistribute it"); 135 | log.info("under certain conditions"); 136 | log.info("See file COPYING.txt and README.txt for details."); 137 | log.info(""); 138 | log.info(""); 139 | } 140 | 141 | /** 142 | * @see org.openstreetmap.fma.jtiledownloader.listener.TileDownloaderListener#downloadComplete(int, java.util.ArrayList, int) 143 | */ 144 | public void downloadComplete(int errorCount, ArrayList errorTileList, int updatedTileCount) 145 | { 146 | log.log(Level.INFO, "updated {0} tiles", updatedTileCount); 147 | log.log(Level.INFO, "download completed with {0} errors", errorCount); 148 | } 149 | 150 | /** 151 | * @see org.openstreetmap.fma.jtiledownloader.listener.TileDownloaderListener#downloadedTile(int, int, java.lang.String, int, boolean) 152 | */ 153 | public void downloadedTile(int actCount, int maxCount, String path, int updatedCount, boolean updatedTile) 154 | { 155 | log.info("downloaded tile " + actCount + "/" + maxCount + " to " + path + ": updated flag is " + updatedTile); 156 | } 157 | 158 | /** 159 | * @param message 160 | */ 161 | public void waitResume(String message) 162 | { 163 | log.log(Level.INFO, "wait to resume: {0}", message); 164 | } 165 | 166 | /** 167 | * @param message 168 | */ 169 | public void waitWaitHttp500ErrorToResume(String message) 170 | { 171 | log.log(Level.WARNING, "http 500 error occured: {0}", message); 172 | } 173 | 174 | /** 175 | * @see org.openstreetmap.fma.jtiledownloader.listener.TileDownloaderListener#errorOccured(int, int, Tile) 176 | */ 177 | public void errorOccured(int actCount, int maxCount, Tile tile) 178 | { 179 | log.warning("Error downloading tile " + actCount + "/" + maxCount + " from " + tile); 180 | } 181 | 182 | /** 183 | * @see org.openstreetmap.fma.jtiledownloader.listener.TileDownloaderListener#downloadStopped(int, int) 184 | */ 185 | public void downloadStopped(int actCount, int maxCount) 186 | { 187 | log.info("Stopped download at tile " + actCount + "/" + maxCount); 188 | } 189 | 190 | /** 191 | * @see org.openstreetmap.fma.jtiledownloader.listener.TileDownloaderListener#setInfo(java.lang.String) 192 | */ 193 | public void setInfo(String message) 194 | { 195 | log.info(message); 196 | } 197 | 198 | /** 199 | * @see org.openstreetmap.fma.jtiledownloader.listener.TileDownloaderListener#downloadPaused(int, int) 200 | */ 201 | public void downloadPaused(int actCount, int maxCount) 202 | {} 203 | } 204 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/Tile.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | import java.awt.Graphics; 6 | import java.awt.Graphics2D; 7 | import java.awt.geom.AffineTransform; 8 | import java.awt.image.BufferedImage; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | 12 | import javax.imageio.ImageIO; 13 | 14 | import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; 15 | import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 16 | 17 | /** 18 | * Holds one map tile. Additionally the code for loading the tile image and 19 | * painting it is also included in this class. 20 | * 21 | * @author Jan Peter Stotz 22 | */ 23 | public class Tile { 24 | 25 | /** 26 | * Hourglass image that is displayed until a map tile has been loaded 27 | */ 28 | public static BufferedImage LOADING_IMAGE; 29 | public static BufferedImage ERROR_IMAGE; 30 | 31 | static { 32 | try { 33 | LOADING_IMAGE = ImageIO.read(JMapViewer.class.getResourceAsStream("images/hourglass.png")); 34 | ERROR_IMAGE = ImageIO.read(JMapViewer.class.getResourceAsStream("images/error.png")); 35 | } catch (Exception e1) { 36 | LOADING_IMAGE = null; 37 | ERROR_IMAGE = null; 38 | } 39 | } 40 | 41 | protected TileSource source; 42 | protected int xtile; 43 | protected int ytile; 44 | protected int zoom; 45 | protected BufferedImage image; 46 | protected String key; 47 | protected boolean loaded = false; 48 | protected boolean loading = false; 49 | public static final int SIZE = 256; 50 | 51 | /** 52 | * Creates a tile with empty image. 53 | * 54 | * @param source 55 | * @param xtile 56 | * @param ytile 57 | * @param zoom 58 | */ 59 | public Tile(TileSource source, int xtile, int ytile, int zoom) { 60 | super(); 61 | this.source = source; 62 | this.xtile = xtile; 63 | this.ytile = ytile; 64 | this.zoom = zoom; 65 | this.image = LOADING_IMAGE; 66 | this.key = getTileKey(source, xtile, ytile, zoom); 67 | } 68 | 69 | public Tile(TileSource source, int xtile, int ytile, int zoom, BufferedImage image) { 70 | this(source, xtile, ytile, zoom); 71 | this.image = image; 72 | } 73 | 74 | /** 75 | * Tries to get tiles of a lower or higher zoom level (one or two level 76 | * difference) from cache and use it as a placeholder until the tile has 77 | * been loaded. 78 | */ 79 | public void loadPlaceholderFromCache(TileCache cache) { 80 | BufferedImage tmpImage = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_RGB); 81 | Graphics2D g = (Graphics2D) tmpImage.getGraphics(); 82 | // g.drawImage(image, 0, 0, null); 83 | for (int zoomDiff = 1; zoomDiff < 5; zoomDiff++) { 84 | // first we check if there are already the 2^x tiles 85 | // of a higher detail level 86 | int zoom_high = zoom + zoomDiff; 87 | if (zoomDiff < 3 && zoom_high <= JMapViewer.MAX_ZOOM) { 88 | int factor = 1 << zoomDiff; 89 | int xtile_high = xtile << zoomDiff; 90 | int ytile_high = ytile << zoomDiff; 91 | double scale = 1.0 / factor; 92 | g.setTransform(AffineTransform.getScaleInstance(scale, scale)); 93 | int paintedTileCount = 0; 94 | for (int x = 0; x < factor; x++) { 95 | for (int y = 0; y < factor; y++) { 96 | Tile tile = cache.getTile(source, xtile_high + x, ytile_high + y, zoom_high); 97 | if (tile != null && tile.isLoaded()) { 98 | paintedTileCount++; 99 | tile.paint(g, x * SIZE, y * SIZE); 100 | } 101 | } 102 | } 103 | if (paintedTileCount == factor * factor) { 104 | image = tmpImage; 105 | return; 106 | } 107 | } 108 | 109 | int zoom_low = zoom - zoomDiff; 110 | if (zoom_low >= JMapViewer.MIN_ZOOM) { 111 | int xtile_low = xtile >> zoomDiff; 112 | int ytile_low = ytile >> zoomDiff; 113 | int factor = (1 << zoomDiff); 114 | double scale = factor; 115 | AffineTransform at = new AffineTransform(); 116 | int translate_x = (xtile % factor) * SIZE; 117 | int translate_y = (ytile % factor) * SIZE; 118 | at.setTransform(scale, 0, 0, scale, -translate_x, -translate_y); 119 | g.setTransform(at); 120 | Tile tile = cache.getTile(source, xtile_low, ytile_low, zoom_low); 121 | if (tile != null && tile.isLoaded()) { 122 | tile.paint(g, 0, 0); 123 | image = tmpImage; 124 | return; 125 | } 126 | } 127 | } 128 | } 129 | 130 | public TileSource getSource() { 131 | return source; 132 | } 133 | 134 | /** 135 | * @return tile number on the x axis of this tile 136 | */ 137 | public int getXtile() { 138 | return xtile; 139 | } 140 | 141 | /** 142 | * @return tile number on the y axis of this tile 143 | */ 144 | public int getYtile() { 145 | return ytile; 146 | } 147 | 148 | /** 149 | * @return zoom level of this tile 150 | */ 151 | public int getZoom() { 152 | return zoom; 153 | } 154 | 155 | public BufferedImage getImage() { 156 | return image; 157 | } 158 | 159 | public void setImage(BufferedImage image) { 160 | this.image = image; 161 | } 162 | 163 | public void loadImage(InputStream input) throws IOException { 164 | image = ImageIO.read(input); 165 | } 166 | 167 | /** 168 | * @return key that identifies a tile 169 | */ 170 | public String getKey() { 171 | return key; 172 | } 173 | 174 | public boolean isLoaded() { 175 | return loaded; 176 | } 177 | 178 | public void setLoaded(boolean loaded) { 179 | this.loaded = loaded; 180 | } 181 | 182 | public String getUrl() { 183 | return source.getTileUrl(zoom, xtile, ytile); 184 | } 185 | 186 | /** 187 | * Paints the tile-image on the {@link Graphics} g at the 188 | * position x/y. 189 | * 190 | * @param g 191 | * @param x 192 | * x-coordinate in g 193 | * @param y 194 | * y-coordinate in g 195 | */ 196 | public void paint(Graphics g, int x, int y) { 197 | if (image == null) 198 | return; 199 | g.drawImage(image, x, y, null); 200 | } 201 | 202 | @Override 203 | public String toString() { 204 | return "Tile " + key; 205 | } 206 | 207 | @Override 208 | public boolean equals(Object obj) { 209 | if (!(obj instanceof Tile)) 210 | return false; 211 | Tile tile = (Tile) obj; 212 | return (xtile == tile.xtile) && (ytile == tile.ytile) && (zoom == tile.zoom); 213 | } 214 | 215 | public static String getTileKey(TileSource source, int xtile, int ytile, int zoom) { 216 | return zoom + "/" + xtile + "/" + ytile + "@" + source.getName(); 217 | } 218 | 219 | } -------------------------------------------------------------------------------- /src/org/openstreetmap/fma/jtiledownloader/views/main/JTileDownloaderMainView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, Friedrich Maier 3 | * 4 | * This file is part of JTileDownloader. 5 | * (see http://wiki.openstreetmap.org/index.php/JTileDownloader) 6 | * 7 | * JTileDownloader is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * JTileDownloader is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy (see file COPYING.txt) of the GNU 18 | * General Public License along with JTileDownloader. 19 | * If not, see . 20 | */ 21 | 22 | package org.openstreetmap.fma.jtiledownloader.views.main; 23 | 24 | import java.awt.Toolkit; 25 | import java.awt.event.WindowAdapter; 26 | import java.awt.event.WindowEvent; 27 | 28 | import java.util.logging.Logger; 29 | import javax.swing.JFrame; 30 | import javax.swing.JTabbedPane; 31 | import javax.swing.event.ChangeEvent; 32 | import javax.swing.event.ChangeListener; 33 | 34 | import org.openstreetmap.fma.jtiledownloader.Constants; 35 | import org.openstreetmap.fma.jtiledownloader.config.AppConfiguration; 36 | 37 | public class JTileDownloaderMainView 38 | extends JFrame 39 | { 40 | private static final long serialVersionUID = 1L; 41 | private static final Logger log = Logger.getLogger(JTileDownloaderMainView.class.getName()); 42 | 43 | private MainPanel _mainPanel; 44 | private OptionsPanel _optionsPanel; 45 | private NetworkPanel _networkPanel; 46 | 47 | private UpdateTilesPanel _updateTilesPanel; 48 | 49 | public JTileDownloaderMainView() 50 | { 51 | super(); 52 | 53 | generateView(); 54 | 55 | } 56 | 57 | /** 58 | * 59 | */ 60 | private void generateView() 61 | { 62 | addWindowListener(new MainViewWindowListener()); 63 | setResizable(false); 64 | 65 | setTitle("JTileDownloader" + " Version: " + Constants.VERSION); 66 | 67 | _mainPanel = new MainPanel(getMainView(), AppConfiguration.getInstance().getInputPanelIndex()); 68 | 69 | _updateTilesPanel = new UpdateTilesPanel(_mainPanel); 70 | _optionsPanel = new OptionsPanel(); 71 | _networkPanel = new NetworkPanel(); 72 | 73 | JTabbedPane tabbedPane = new JTabbedPane(); 74 | tabbedPane.addTab("Main", _mainPanel); 75 | tabbedPane.addTab("Update Tiles", _updateTilesPanel); 76 | tabbedPane.addTab("Options", _optionsPanel); 77 | tabbedPane.addTab("Network", _networkPanel); 78 | tabbedPane.addTab("Info", new InfoPanel()); 79 | 80 | tabbedPane.addChangeListener(new TabChangeListener()); 81 | 82 | getContentPane().add(tabbedPane);//, constraints); 83 | 84 | pack(); 85 | center(); 86 | } 87 | 88 | /** 89 | * Centers the window on the screen 90 | */ 91 | protected void center() 92 | { 93 | setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - getWidth()) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - getHeight()) / 2); 94 | } 95 | 96 | protected final JTileDownloaderMainView getMainView() 97 | { 98 | return this; 99 | } 100 | 101 | class MainViewWindowListener 102 | extends WindowAdapter 103 | { 104 | /** 105 | * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event.WindowEvent) 106 | */ 107 | @Override 108 | public void windowClosing(WindowEvent e) 109 | { 110 | log.fine("WindowEvent windowClosing"); 111 | 112 | _mainPanel.saveAllConfigOptions(); 113 | updateAppConfig(); 114 | 115 | e.getWindow().dispose(); 116 | System.exit(0); 117 | } 118 | 119 | } 120 | 121 | class TabChangeListener 122 | implements ChangeListener 123 | { 124 | 125 | /** 126 | * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent) 127 | */ 128 | public void stateChanged(ChangeEvent e) 129 | { 130 | if (((JTabbedPane) e.getSource()).getSelectedIndex() == 1) 131 | { 132 | log.fine("changed to update tab"); 133 | // selected update tab 134 | getUpdateTilesPanel().setFolder(getMainPanel().getOutputfolder()); 135 | getUpdateTilesPanel().setTileServer(getMainPanel().getSelectedTileProvider().getName()); 136 | } 137 | updateAppConfig(); 138 | } 139 | } 140 | 141 | /** 142 | * Saves the selected AppConfigurations 143 | */ 144 | public void updateAppConfig() 145 | { 146 | AppConfiguration.getInstance().setUseProxyServer(_networkPanel.isUseProxyServer()); 147 | AppConfiguration.getInstance().setProxyServer(_networkPanel.getProxyServer()); 148 | AppConfiguration.getInstance().setProxyServerPort(_networkPanel.getProxyServerPort()); 149 | AppConfiguration.getInstance().setProxyServerRequiresAuthentitication(_networkPanel.isUseProxyServerAuth()); 150 | AppConfiguration.getInstance().setProxyServerUser(_networkPanel.getProxyServerUser()); 151 | AppConfiguration.getInstance().setProxyServerPassword(_networkPanel.getProxyServerPassword()); 152 | AppConfiguration.getInstance().setDownloadThreads(_optionsPanel.getDownloadThreads()); 153 | AppConfiguration.getInstance().setOverwriteExistingFiles(_optionsPanel.isOverwriteExistingFiles()); 154 | AppConfiguration.getInstance().setTileServer(_mainPanel.getSelectedTileProvider().getName()); 155 | AppConfiguration.getInstance().setLastZoom(_mainPanel.getOutputZoomLevelString()); 156 | AppConfiguration.getInstance().setOutputFolder(_mainPanel.getOutputfolder()); 157 | AppConfiguration.getInstance().setWaitAfterNrTiles(_optionsPanel.isWaitAfterNumberOfTiles()); 158 | AppConfiguration.getInstance().setWaitSeconds(_optionsPanel.getWaitSeconds()); 159 | AppConfiguration.getInstance().setWaitNrTiles(_optionsPanel.getWaitNrTiles()); 160 | AppConfiguration.getInstance().setMinimumAgeInDays(_optionsPanel.getMinimumAgeInDays()); 161 | AppConfiguration.getInstance().setSlippyMap_NoDownload(_optionsPanel.isSlippyMapNoDownload()); 162 | AppConfiguration.getInstance().setSlippyMap_SaveTiles(_optionsPanel.isSlippyMapSaveTiles()); 163 | AppConfiguration.getInstance().setTileSortingPolicy(_optionsPanel.getTileSortingPolicy()); 164 | AppConfiguration.getInstance().saveToFile(); 165 | } 166 | 167 | /** 168 | * Getter for mainPanel 169 | * @return the mainPanel 170 | */ 171 | public final MainPanel getMainPanel() 172 | { 173 | return _mainPanel; 174 | } 175 | 176 | /** 177 | * Getter for optionsPanel 178 | * @return the optionsPanel 179 | */ 180 | public final OptionsPanel getOptionsPanel() 181 | { 182 | return _optionsPanel; 183 | } 184 | 185 | /** 186 | * Getter for networkPanel 187 | * @return the networkPanel 188 | */ 189 | public final NetworkPanel getNetworkPanel() 190 | { 191 | return _networkPanel; 192 | } 193 | 194 | /** 195 | * Getter for updateTilesPanel 196 | * @return the updateTilesPanel 197 | */ 198 | public final UpdateTilesPanel getUpdateTilesPanel() 199 | { 200 | return _updateTilesPanel; 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /src/org/openstreetmap/gui/jmapviewer/JTileDownloaderTileLoader.java: -------------------------------------------------------------------------------- 1 | package org.openstreetmap.gui.jmapviewer; 2 | 3 | //License: GPL. Copyright 2008 by Jan Peter Stotz 4 | 5 | // Adapted for JTileDownloader by Sven Strickroth , 2010 6 | 7 | import java.io.ByteArrayInputStream; 8 | import java.io.ByteArrayOutputStream; 9 | import java.io.File; 10 | import java.io.FileInputStream; 11 | import java.io.FileOutputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | 15 | import java.util.logging.Logger; 16 | import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; 17 | import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 18 | import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 19 | import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 20 | 21 | /** 22 | * A {@link TileLoader} implementation that loads tiles from OSM via HTTP and 23 | * saves all loaded files in a directory located in the the temporary directory. 24 | * If a tile is present in this file cache it will not be loaded from OSM again. 25 | * 26 | * @author Jan Peter Stotz 27 | */ 28 | public class JTileDownloaderTileLoader 29 | extends OsmTileLoader 30 | { 31 | private static final Logger log = Logger.getLogger(JTileDownloaderTileLoader.class.getName()); 32 | 33 | protected String cacheDirBase; 34 | protected boolean noDownload = false; 35 | protected boolean saveTiles = false; 36 | 37 | public JTileDownloaderTileLoader(TileLoaderListener map, String cacheDirBase) 38 | { 39 | super(map); 40 | this.cacheDirBase = cacheDirBase; 41 | } 42 | 43 | @Override 44 | public Runnable createTileLoaderJob(final TileSource source, final int tilex, final int tiley, final int zoom) 45 | { 46 | return new FileLoadJob(source, tilex, tiley, zoom); 47 | } 48 | 49 | protected class FileLoadJob 50 | implements Runnable 51 | { 52 | InputStream input = null; 53 | 54 | int tilex, tiley, zoom; 55 | Tile tile; 56 | TileSource source; 57 | File tileCacheDir; 58 | File tileFile = null; 59 | 60 | public FileLoadJob(TileSource source, int tilex, int tiley, int zoom) 61 | { 62 | super(); 63 | this.source = source; 64 | this.tilex = tilex; 65 | this.tiley = tiley; 66 | this.zoom = zoom; 67 | } 68 | 69 | public void run() 70 | { 71 | TileCache cache = listener.getTileCache(); 72 | synchronized (cache) 73 | { 74 | tile = cache.getTile(source, tilex, tiley, zoom); 75 | if (tile == null || tile.isLoaded() || tile.loading) 76 | return; 77 | } 78 | tileCacheDir = new File(cacheDirBase); 79 | if (tileCacheDir.exists() && loadTileFromFile()) 80 | return; 81 | 82 | if (!noDownload) 83 | { 84 | try 85 | { 86 | Thread.sleep(500); 87 | 88 | byte[] buffer = loadTileInBuffer(loadTileFromOsm(tile).getInputStream()); 89 | if (buffer != null) 90 | { 91 | tile.loadImage(new ByteArrayInputStream(buffer)); 92 | tile.loading = false; 93 | listener.tileLoadingFinished(tile, true); 94 | if (saveTiles) 95 | { 96 | saveTileToFile(buffer); 97 | } 98 | } 99 | tile.setLoaded(true); 100 | return; 101 | } 102 | catch (Exception e) 103 | { 104 | // some error occoured 105 | } 106 | } 107 | 108 | tile.setImage(Tile.ERROR_IMAGE); 109 | tile.setLoaded(true); 110 | listener.tileLoadingFinished(tile, true); 111 | } 112 | 113 | protected byte[] loadTileInBuffer(InputStream input) throws IOException 114 | { 115 | ByteArrayOutputStream bout = new ByteArrayOutputStream(input.available()); 116 | byte[] buffer = new byte[2048]; 117 | boolean finished = false; 118 | do 119 | { 120 | int read = input.read(buffer); 121 | if (read >= 0) 122 | bout.write(buffer, 0, read); 123 | else 124 | finished = true; 125 | } 126 | while (!finished); 127 | input.close(); 128 | if (bout.size() == 0) 129 | return null; 130 | return bout.toByteArray(); 131 | } 132 | 133 | protected void saveTileToFile(byte[] rawData) 134 | { 135 | try 136 | { 137 | File folder = new File(tileCacheDir + "/" + tile.getZoom() + "/" + tile.getXtile()); 138 | if (!folder.exists()) 139 | { 140 | folder.mkdirs(); 141 | } 142 | FileOutputStream f = new FileOutputStream(new File(folder, tile.getYtile() + "." + source.getTileType())); 143 | f.write(rawData); 144 | f.close(); 145 | log.finest("Saved tile to file: " + tile); 146 | } 147 | catch (Exception e) 148 | { 149 | log.warning("Failed to save tile content: " + e.getLocalizedMessage()); 150 | } 151 | } 152 | 153 | protected boolean loadTileFromFile() 154 | { 155 | FileInputStream fin = null; 156 | try 157 | { 158 | tileFile = getTileFile(); 159 | fin = new FileInputStream(tileFile); 160 | if (fin.available() == 0) 161 | throw new IOException("File empty"); 162 | tile.loadImage(fin); 163 | fin.close(); 164 | log.finest("Loaded from file: " + tile); 165 | tile.setLoaded(true); 166 | listener.tileLoadingFinished(tile, true); 167 | return true; 168 | } 169 | catch (Exception e) 170 | { 171 | try 172 | { 173 | if (fin != null) 174 | { 175 | fin.close(); 176 | tileFile.delete(); 177 | } 178 | } 179 | catch (Exception e1) 180 | { 181 | } 182 | tileFile = null; 183 | } 184 | return false; 185 | } 186 | 187 | protected File getTileFile() 188 | { 189 | return new File(tileCacheDir + "/" + tile.getZoom() + "/" + tile.getXtile() + "/" + tile.getYtile() + "." + source.getTileType()); 190 | } 191 | 192 | } 193 | 194 | public String getCacheDirBase() 195 | { 196 | return cacheDirBase; 197 | } 198 | 199 | public void setTileCacheDir(String tileCacheDir) 200 | { 201 | File dir = new File(tileCacheDir); 202 | dir.mkdirs(); 203 | this.cacheDirBase = dir.getAbsolutePath(); 204 | } 205 | 206 | /** 207 | * @param noDownload 208 | */ 209 | public void setNoDownload(boolean noDownload) 210 | { 211 | this.noDownload = noDownload; 212 | } 213 | 214 | /** 215 | * Setter for saveTiles 216 | * @param saveTiles the saveTiles to set 217 | */ 218 | public void setSaveTiles(boolean saveTiles) 219 | { 220 | this.saveTiles = saveTiles; 221 | } 222 | 223 | } 224 | --------------------------------------------------------------------------------