Index: WMSLayer.java =================================================================== --- WMSLayer.java (revision 17300) +++ WMSLayer.java (working copy) @@ -34,12 +34,14 @@ import org.openstreetmap.josm.gui.dialogs.LayerListDialog; import org.openstreetmap.josm.gui.dialogs.LayerListPopup; import org.openstreetmap.josm.gui.layer.Layer; +import org.openstreetmap.josm.io.CacheFiles; import org.openstreetmap.josm.tools.ImageProvider; /** * This is a layer that grabs the current screen from an WMS server. The data - * fetched this way is tiled and managerd to the disc to reduce server load. + * fetched this way is tiled and managed to the disc to reduce server load. */ +@SuppressWarnings("serial") public class WMSLayer extends Layer { protected static final Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png"))); @@ -70,33 +72,39 @@ mv = Main.map.mapView; } - public WMSLayer(String name, String baseURL, String cookies) { - super(name); - alphaChannel.setSelected(Main.pref.getBoolean("wmsplugin.alpha_channel")); - background = true; /* set global background variable */ - initializeImages(); - this.baseURL = baseURL; - this.cookies = cookies; - WMSGrabber.getProjection(baseURL, true); - mv = Main.map.mapView; - resolution = mv.getDist100PixelText(); - pixelPerDegree = getPPD(); - + public WMSLayer(String name, String baseURL, String cookies) { + super(name); + alphaChannel.setSelected(Main.pref.getBoolean("wmsplugin.alpha_channel")); + background = true; /* set global background variable */ + initializeImages(); + this.baseURL = baseURL; + this.cookies = cookies; + WMSGrabber.getProjection(baseURL, true); + mv = Main.map.mapView; + resolution = "PixelPerDegree: " + Double.toString(getPPD()) + " (add #PPD= to layer name to restore)"; + pixelPerDegree = getPPD(); executor = Executors.newFixedThreadPool(3); } - @Override - public void destroy() { - try { - executor.shutdown(); - // Might not be initalized, so catch NullPointer as well - } catch(Exception x) {} - } + @Override + public void destroy() { + try { + executor.shutdown(); + // Might not be initialized, so catch NullPointer as well + } catch(Exception x) {} + } - public double getPPD(){ - ProjectionBounds bounds = mv.getProjectionBounds(); - return mv.getWidth() / (bounds.max.east() - bounds.min.east()); - } + public double getPPD(){ + // quick hack to predefine the PixelDensity to reuse the cache + int codeIndex = getName().indexOf("#PPD="); + if (codeIndex != -1) { + double f = Double.valueOf(getName().substring(codeIndex+5)); + return f; + } + + ProjectionBounds bounds = mv.getProjectionBounds(); + return mv.getWidth() / (bounds.max.east() - bounds.min.east()); + } public void initializeImages() { images = new GeorefImage[dax][day]; @@ -200,23 +208,24 @@ return getToolTipText(); } - @Override public Component[] getMenuEntries() { - return new Component[]{ - new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)), - new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)), - new JSeparator(), - new JMenuItem(new LoadWmsAction()), - new JMenuItem(new SaveWmsAction()), - new JSeparator(), - startstop, - alphaChannel, - new JMenuItem(new changeResolutionAction()), - new JMenuItem(new reloadErrorTilesAction()), - new JMenuItem(new downloadAction()), - new JSeparator(), - new JMenuItem(new LayerListPopup.InfoAction(this)) - }; - } + @Override public Component[] getMenuEntries() { + return new Component[]{ + new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)), + new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)), + new JSeparator(), + new JMenuItem(new LoadWmsAction()), + new JMenuItem(new SaveWmsAction()), + new JMenuItem(new BookmarkWmsAction()), + new JSeparator(), + startstop, + alphaChannel, + new JMenuItem(new changeResolutionAction()), + new JMenuItem(new reloadErrorTilesAction()), + new JMenuItem(new downloadAction()), + new JSeparator(), + new JMenuItem(new LayerListPopup.InfoAction(this)) + }; + } public GeorefImage findImage(EastNorth eastNorth) { for(int x = 0; x + */ + public class BookmarkWmsAction extends AbstractAction { + public BookmarkWmsAction() { + super(tr("Set WMS Bookmark")); + } + public void actionPerformed(ActionEvent ev) { + int i = 0; + while (Main.pref.hasKey("wmsplugin.url."+i+".url")) { + i++; + } + String baseName; + // cut old parameter + int parameterIndex = getName().indexOf("#PPD="); + if (parameterIndex != -1) { + baseName = getName().substring(0,parameterIndex); + } + else { + baseName = getName(); + } + Main.pref.put("wmsplugin.url."+ i +".url",baseURL ); + Main.pref.put("wmsplugin.url."+String.valueOf(i)+".name", baseName + "#" + getPPD() ); + WMSPlugin.refreshMenu(); + } + } + }