| 1 | // This code has been adapted and copied from code that has been written by Immanuel Scholz and others for JOSM.
|
|---|
| 2 | // License: GPL. Copyright 2007 by Tim Haussmann
|
|---|
| 3 |
|
|---|
| 4 | import java.util.List;
|
|---|
| 5 |
|
|---|
| 6 | import org.openstreetmap.josm.Main;
|
|---|
| 7 | import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
|
|---|
| 8 | import org.openstreetmap.josm.gui.download.DownloadSelection;
|
|---|
| 9 | import org.openstreetmap.josm.plugins.Plugin;
|
|---|
| 10 |
|
|---|
| 11 | /**
|
|---|
| 12 | * @author Tim Haussmann
|
|---|
| 13 | */
|
|---|
| 14 | public class SlippyMapChooserPlugin extends Plugin implements PreferenceChangedListener {
|
|---|
| 15 |
|
|---|
| 16 | static String iPluginFolder = "";
|
|---|
| 17 |
|
|---|
| 18 | private static final String KEY_MAX_TILES_IN_MEMORY = "slippy_map_chooser.max_tiles";
|
|---|
| 19 | private static final String KEY_ENABLE_FILE_CACHE = "slippy_map_chooser.file_cache";
|
|---|
| 20 |
|
|---|
| 21 | static int MAX_TILES_IN_MEMORY = 200;
|
|---|
| 22 | static boolean ENABLE_FILE_CACHE = true;
|
|---|
| 23 |
|
|---|
| 24 | public SlippyMapChooserPlugin() {
|
|---|
| 25 | // create the plugin folder
|
|---|
| 26 | // iPluginFolder = getPluginDir();
|
|---|
| 27 | // File pluginFolder = new File(iPluginFolder);
|
|---|
| 28 | // if(!pluginFolder.exists())
|
|---|
| 29 | // pluginFolder.mkdir();
|
|---|
| 30 | //
|
|---|
| 31 | // //init the logger
|
|---|
| 32 | // Logger.setLogFile(iPluginFolder+"\\slippy_map_chooser.log");
|
|---|
| 33 |
|
|---|
| 34 | // Add this plugin to the preference changed listener list
|
|---|
| 35 | Main.pref.listener.add(this);
|
|---|
| 36 |
|
|---|
| 37 | // load prefs
|
|---|
| 38 | String maxTiles = Main.pref.get(KEY_MAX_TILES_IN_MEMORY);
|
|---|
| 39 | if (!maxTiles.equals("")) {
|
|---|
| 40 | preferenceChanged(KEY_MAX_TILES_IN_MEMORY, maxTiles);
|
|---|
| 41 | } else {
|
|---|
| 42 | Main.pref.put(KEY_MAX_TILES_IN_MEMORY, Integer.toString(MAX_TILES_IN_MEMORY));
|
|---|
| 43 | }
|
|---|
| 44 | String enableFileCache = Main.pref.get(KEY_ENABLE_FILE_CACHE);
|
|---|
| 45 | if (!enableFileCache.equals("")) {
|
|---|
| 46 | preferenceChanged(KEY_ENABLE_FILE_CACHE, enableFileCache);
|
|---|
| 47 | } else {
|
|---|
| 48 | Main.pref.put(KEY_ENABLE_FILE_CACHE, Boolean.toString(ENABLE_FILE_CACHE));
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | public void addDownloadSelection(List<DownloadSelection> list) {
|
|---|
| 53 | list.add(new SlippyMapChooser());
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | public void preferenceChanged(String key, String newValue) {
|
|---|
| 57 | if (KEY_MAX_TILES_IN_MEMORY.equals(key)) {
|
|---|
| 58 | try {
|
|---|
| 59 | MAX_TILES_IN_MEMORY = Integer.parseInt(newValue);
|
|---|
| 60 | } catch (Exception e) {
|
|---|
| 61 | MAX_TILES_IN_MEMORY = 1000;
|
|---|
| 62 | }
|
|---|
| 63 | } else if (KEY_ENABLE_FILE_CACHE.equals(key)) {
|
|---|
| 64 | try {
|
|---|
| 65 | ENABLE_FILE_CACHE = Boolean.parseBoolean(newValue);
|
|---|
| 66 | } catch (Exception e) {
|
|---|
| 67 | MAX_TILES_IN_MEMORY = 1000;
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | }
|
|---|