Changeset 22848 in osm for applications/editors/josm/plugins/slippymap/src
- Timestamp:
- 2010-08-29T09:52:54+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java
r22550 r22848 38 38 import org.openstreetmap.josm.actions.RenameLayerAction; 39 39 import org.openstreetmap.josm.data.Bounds; 40 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;41 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;42 40 import org.openstreetmap.josm.data.coor.LatLon; 43 41 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; … … 57 55 * 58 56 */ 59 public class SlippyMapLayer extends Layer implements PreferenceChangedListener,ImageObserver,57 public class SlippyMapLayer extends Layer implements ImageObserver, 60 58 TileLoaderListener { 61 59 boolean debug = false; … … 263 261 public void layerRemoved(Layer oldLayer) { 264 262 MapView.removeLayerChangeListener(this); 265 Main.pref.removePreferenceChangeListener(SlippyMapLayer.this);266 263 } 267 264 }); 268 265 } 269 266 }); 270 271 Main.pref.addPreferenceChangeListener(this);272 267 } 273 268 … … 879 874 } 880 875 881 int fontHeight = g.getFontMetrics().getHeight();882 883 876 g.setColor(Color.DARK_GRAY); 884 877 … … 962 955 ts.loadAllTiles(false); // make sure there are tile objects for all tiles 963 956 Tile clickedTile = null; 964 Point p1 = null, p2 = null;965 957 for (Tile t1 : ts.allTiles()) { 966 958 Tile t2 = tempCornerTile(t1); … … 1040 1032 return x * 45.0 / Math.pow(2.0, zoom - 3) - 180.0; 1041 1033 } 1042 1043 /*1044 * (non-Javadoc)1045 *1046 * @seeorg.openstreetmap.josm.data.Preferences.PreferenceChangedListener#1047 * preferenceChanged(java.lang.String, java.lang.String)1048 */1049 public void preferenceChanged(PreferenceChangeEvent event) {1050 if (event.getKey().startsWith(SlippyMapPreferences.PREFERENCE_PREFIX)) {1051 // System.err.println(this + ".preferenceChanged('" + key + "', '"1052 // + newValue + "') called");1053 // when fade background changed, no need to clear tile storage1054 // TODO move this code to SlippyMapPreferences class.1055 if (!event.getKey().equals(SlippyMapPreferences.PREFERENCE_FADE_BACKGROUND)) {1056 autoZoomPopup.setSelected(SlippyMapPreferences.getAutozoom());1057 }1058 if (event.getKey().equals(SlippyMapPreferences.PREFERENCE_TILE_SOURCE)) {1059 newTileStorage();1060 }1061 redraw();1062 }1063 }1064 1065 @Override1066 public void destroy() {1067 Main.pref.removePreferenceChangeListener(SlippyMapLayer.this);1068 }1069 1034 } -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPlugin.java
r19477 r22848 1 1 package org.openstreetmap.josm.plugins.slippymap; 2 2 3 import java.util.List; 4 3 5 import org.openstreetmap.josm.Main; 6 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 7 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 4 8 import org.openstreetmap.josm.gui.MapFrame; 5 9 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; … … 13 17 * 14 18 */ 15 public class SlippyMapPlugin extends Plugin 19 public class SlippyMapPlugin extends Plugin implements PreferenceChangedListener 16 20 { 17 21 public SlippyMapPlugin(PluginInformation info) 18 22 { 19 23 super(info); 24 Main.pref.addPreferenceChangeListener(this); 20 25 } 21 26 22 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) 27 @Override 28 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) 23 29 { 24 if (newFrame != null ){30 if (newFrame != null && SlippyMapPreferences.getMapSource() != SlippyMapPreferences.NO_DEFAULT_TILE_SOURCE) { 25 31 SlippyMapLayer smlayer; 26 32 smlayer = new SlippyMapLayer(); … … 40 46 } 41 47 48 /* 49 * (non-Javadoc) 50 * 51 * @seeorg.openstreetmap.josm.data.Preferences.PreferenceChangedListener# 52 * preferenceChanged(java.lang.String, java.lang.String) 53 */ 54 public void preferenceChanged(PreferenceChangeEvent event) { 55 if (!Main.isDisplayingMapView()) { 56 return; 57 } 58 List<SlippyMapLayer> layes = Main.map.mapView.getLayersOfType(SlippyMapLayer.class); 59 assert layes.size() <= 1; 60 SlippyMapLayer layer = layes.isEmpty()?null:layes.get(0); 61 62 if (event.getKey().equals(SlippyMapPreferences.PREFERENCE_TILE_SOURCE)) { 63 if (layer == null && SlippyMapPreferences.getMapSource() != SlippyMapPreferences.NO_DEFAULT_TILE_SOURCE) { 64 Main.map.mapView.addLayer(new SlippyMapLayer()); 65 } else if (layer != null && SlippyMapPreferences.getMapSource() == SlippyMapPreferences.NO_DEFAULT_TILE_SOURCE) { 66 Main.map.mapView.removeLayer(layer); 67 } else if (layer == null && SlippyMapPreferences.getMapSource() == SlippyMapPreferences.NO_DEFAULT_TILE_SOURCE) { 68 // Do nothing 69 } else { 70 layer.newTileStorage(); 71 } 72 } else if (event.getKey().startsWith(SlippyMapPreferences.PREFERENCE_PREFIX) && layer != null) { 73 // System.err.println(this + ".preferenceChanged('" + key + "', '" 74 // + newValue + "') called"); 75 // when fade background changed, no need to clear tile storage 76 // TODO move this code to SlippyMapPreferences class. 77 if (!event.getKey().equals(SlippyMapPreferences.PREFERENCE_FADE_BACKGROUND)) { 78 layer.autoZoomPopup.setSelected(SlippyMapPreferences.getAutozoom()); 79 } 80 layer.redraw(); 81 } 82 } 83 42 84 } -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferenceSetting.java
r19302 r22848 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import java.awt.event.ActionEvent; 6 import java.awt.event.ActionListener; 7 import java.util.ArrayList; 8 import java.util.List; 4 9 5 10 import javax.swing.Box; … … 11 16 import javax.swing.JSpinner; 12 17 import javax.swing.SpinnerNumberModel; 13 import java.awt.event.ActionListener;14 import java.awt.event.ActionEvent;15 import java.util.Collection;16 18 17 import org.openstreetmap.gui.jmapviewer.*; 18 import org.openstreetmap.gui.jmapviewer.interfaces.*; 19 20 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; 19 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 21 20 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 22 21 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; … … 34 33 */ 35 34 private JComboBox tileSourceCombo; 36 35 37 36 private JCheckBox autozoomActive = new JCheckBox(tr("autozoom")); 38 37 private JCheckBox autoloadTiles = new JCheckBox(tr("autoload tiles")); … … 40 39 private JSpinner minZoomLvl = new JSpinner(); 41 40 private JSlider fadeBackground = new JSlider(0, 100); 42 41 43 42 public void addGui(PreferenceTabbedPane gui) 44 43 { … … 47 46 //String description = tr("A plugin that adds to JOSM new layer. This layer could render external tiles."); 48 47 JPanel slippymapTab = gui.createPreferenceTab("slippymap.png", tr("SlippyMap"), tr("Settings for the SlippyMap plugin.")); 49 Collection<TileSource> allSources = SlippyMapPreferences.getAllMapSources(); 48 List<TileSource> allSources = new ArrayList<TileSource>(SlippyMapPreferences.getAllMapSources()); 49 allSources.add(0, SlippyMapPreferences.NO_DEFAULT_TILE_SOURCE); 50 50 //Collection<String> allSources = SlippyMapPreferences.getAllMapNames(); 51 51 tileSourceCombo = new JComboBox(allSources.toArray()); … … 55 55 slippymapTab.add(GBC.glue(5, 0), GBC.std()); 56 56 slippymapTab.add(tileSourceCombo, GBC.eol().fill(GBC.HORIZONTAL)); 57 57 58 58 slippymapTab.add(new JLabel(tr("Auto zoom: ")), GBC.std()); 59 59 slippymapTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 60 60 slippymapTab.add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL)); 61 61 62 62 slippymapTab.add(new JLabel(tr("Autoload Tiles: ")), GBC.std()); 63 63 slippymapTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 64 64 slippymapTab.add(autoloadTiles, GBC.eol().fill(GBC.HORIZONTAL)); 65 65 66 66 slippymapTab.add(new JLabel(tr("Min zoom lvl: ")), GBC.std()); 67 67 slippymapTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 68 68 slippymapTab.add(this.minZoomLvl, GBC.eol().fill(GBC.HORIZONTAL)); 69 69 70 70 slippymapTab.add(new JLabel(tr("Max zoom lvl: ")), GBC.std()); 71 71 slippymapTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); … … 75 75 slippymapTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 76 76 slippymapTab.add(this.fadeBackground, GBC.eol().fill(GBC.HORIZONTAL)); 77 77 78 78 slippymapTab.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 79 79 … … 128 128 this.fadeBackground.setValue(Math.round(SlippyMapPreferences.getFadeBackground()*100f)); 129 129 } 130 130 131 131 /** 132 132 * <p> … … 139 139 public boolean ok() 140 140 { 141 141 SlippyMapPreferences.setMapSource((TileSource)this.tileSourceCombo.getSelectedItem()); 142 142 SlippyMapPreferences.setAutozoom(this.autozoomActive.isSelected()); 143 143 SlippyMapPreferences.setAutoloadTiles(this.autoloadTiles.isSelected()); -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferences.java
r19887 r22848 1 1 package org.openstreetmap.josm.plugins.slippymap; 2 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import java.util.ArrayList; 6 import java.util.List; 7 import java.util.Map; 8 9 import org.openstreetmap.gui.jmapviewer.OsmTileSource; 10 import org.openstreetmap.gui.jmapviewer.OsmTileSource.AbstractOsmTileSource; 11 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 3 12 import org.openstreetmap.josm.Main; 4 import java.util.List;5 import java.util.ArrayList;6 import java.util.Collection;7 import java.util.Map;8 import org.openstreetmap.gui.jmapviewer.*;9 import org.openstreetmap.gui.jmapviewer.interfaces.*;10 13 11 14 /** … … 18 21 public class SlippyMapPreferences 19 22 { 23 public static final String NO_DEFAULT_TILE_SOURCE_NAME = "{%no_default%}"; 20 24 public static final String PREFERENCE_PREFIX = "slippymap"; 21 25 … … 35 39 public static final int DEFAULT_MIN_ZOOM = 2; 36 40 41 37 42 public static TileSource getMapSource() 38 43 { … … 42 47 public static TileSource getMapSource(String name) 43 48 { 49 if (NO_DEFAULT_TILE_SOURCE_NAME.equals(name)) { 50 return NO_DEFAULT_TILE_SOURCE; // User don't want to load slippy layer on startup 51 } 52 44 53 List<TileSource> sources = SlippyMapPreferences.getAllMapSources(); 45 TileSource source = sources.get(0); 54 46 55 if (name == null || "".equals(name)) { 47 name = source.getName(); 48 Main.pref.put(PREFERENCE_TILE_SOURCE, name); 49 } 56 Main.pref.put(PREFERENCE_TILE_SOURCE, sources.get(0).getName()); 57 return sources.get(0); 58 } 59 50 60 for (TileSource s : sources) { 51 if (!name.equals(s.getName())) 52 continue; 53 source = s; 54 break; 55 } 56 return source; 61 if (name.equals(s.getName())) 62 return s; 63 } 64 65 return sources.get(0); 57 66 } 58 67 59 68 public static void setMapSource(TileSource source) { 60 Main.pref.put(SlippyMapPreferences.PREFERENCE_TILE_SOURCE, source .getName());69 Main.pref.put(SlippyMapPreferences.PREFERENCE_TILE_SOURCE, source == NO_DEFAULT_TILE_SOURCE?NO_DEFAULT_TILE_SOURCE_NAME:source.getName()); 61 70 } 62 71 … … 236 245 } 237 246 247 public static TileSource NO_DEFAULT_TILE_SOURCE = new AbstractOsmTileSource(tr("(none)"), "") { 248 public TileUpdate getTileUpdate() { 249 return null; 250 } 251 }; 252 238 253 public static class Coastline extends OsmTileSource.AbstractOsmTileSource { 239 254 public Coastline() { … … 266 281 } 267 282 268 public int getMaxZoom() { 283 @Override 284 public int getMaxZoom() { 269 285 return 21; 270 286 } 271 287 272 public String getTilePath(int zoom, int tilex, int tiley) { 288 @Override 289 public String getTilePath(int zoom, int tilex, int tiley) { 273 290 return "z=" + zoom + "&x=" + tilex + "&y=" + tiley; 274 291 } … … 278 295 } 279 296 } 280 297 281 298 282 299 public static class HaitiImagery extends OsmTileSource.AbstractOsmTileSource { … … 285 302 } 286 303 287 public int getMaxZoom() { 304 @Override 305 public int getMaxZoom() { 288 306 return 21; 289 307 } 290 308 291 public String getTilePath(int zoom, int tilex, int tiley) { 309 @Override 310 public String getTilePath(int zoom, int tilex, int tiley) { 292 311 return "/" + zoom + "/" + tilex + "/" + tiley + ".png"; 293 312 }
Note:
See TracChangeset
for help on using the changeset viewer.