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_DB = "slippy_map_chooser.max_tiles";
|
---|
19 | private static final String KEY_MAX_TILES_REDUCE_BY = "slippy_map_chooser.max_tiles_reduce_by";
|
---|
20 | public static boolean DEBUG_MODE = false;
|
---|
21 |
|
---|
22 |
|
---|
23 | static int MAX_TILES_IN_DB = 200;
|
---|
24 | static int MAX_TILES_REDUCE_BY = 40;
|
---|
25 |
|
---|
26 | public SlippyMapChooserPlugin(){
|
---|
27 | // create the plugin folder
|
---|
28 | // iPluginFolder = getPluginDir();
|
---|
29 | // File pluginFolder = new File(iPluginFolder);
|
---|
30 | // if(!pluginFolder.exists())
|
---|
31 | // pluginFolder.mkdir();
|
---|
32 | //
|
---|
33 | // //init the logger
|
---|
34 | // Logger.setLogFile(iPluginFolder+"\\slippy_map_chooser.log");
|
---|
35 |
|
---|
36 | //Add this plugin to the preference changed listener list
|
---|
37 | Main.pref.listener.add(this);
|
---|
38 |
|
---|
39 | //load prefs
|
---|
40 | String maxTiles = Main.pref.get(KEY_MAX_TILES_IN_DB);
|
---|
41 | if(!maxTiles.equals("")){
|
---|
42 | preferenceChanged(KEY_MAX_TILES_IN_DB, maxTiles);
|
---|
43 | }else{
|
---|
44 | Main.pref.put(KEY_MAX_TILES_IN_DB, String.valueOf(MAX_TILES_IN_DB));
|
---|
45 | }
|
---|
46 |
|
---|
47 | String maxTilesReduce = Main.pref.get(KEY_MAX_TILES_REDUCE_BY);
|
---|
48 | if(!maxTilesReduce.equals("")){
|
---|
49 | preferenceChanged(KEY_MAX_TILES_REDUCE_BY, maxTilesReduce);
|
---|
50 | }else{
|
---|
51 | Main.pref.put(KEY_MAX_TILES_REDUCE_BY, String.valueOf(MAX_TILES_REDUCE_BY));
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | public void addDownloadSelection(List<DownloadSelection> list){
|
---|
57 | list.add(new SlippyMapChooser());
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | public void preferenceChanged(String key, String newValue) {
|
---|
62 | if(key.equals(KEY_MAX_TILES_IN_DB)){
|
---|
63 | try{
|
---|
64 | MAX_TILES_IN_DB = Integer.parseInt(newValue);
|
---|
65 | }catch(Exception e){
|
---|
66 | MAX_TILES_IN_DB = 1000;
|
---|
67 | }
|
---|
68 |
|
---|
69 | }else if(key.equals(KEY_MAX_TILES_REDUCE_BY)){
|
---|
70 | try{
|
---|
71 | MAX_TILES_REDUCE_BY = Integer.parseInt(newValue);
|
---|
72 | }catch(Exception e){
|
---|
73 | MAX_TILES_REDUCE_BY = 100;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | }
|
---|