Index: src/wmsplugin/Grabber.java
===================================================================
--- src/wmsplugin/Grabber.java	(revision 15843)
+++ src/wmsplugin/Grabber.java	(working copy)
@@ -2,16 +2,16 @@
 
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.awt.image.BufferedImage;
-import java.awt.Graphics;
 import java.awt.Color;
 import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.image.BufferedImage;
 
+import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Bounds;
+import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.projection.Projection;
 import org.openstreetmap.josm.gui.MapView;
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.io.CacheFiles;
 
 abstract public class Grabber implements Runnable {
@@ -23,8 +23,7 @@
     protected GeorefImage image;
     protected CacheFiles cache;
 
-    Grabber(Bounds b, Projection proj, double pixelPerDegree, GeorefImage image,
-    MapView mv, WMSLayer layer, CacheFiles cache)
+    Grabber(Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache)
     {
         if (b.min != null && b.max != null && WMSPlugin.doOverlap)
         {
@@ -45,8 +44,8 @@
         else
             this.b = b;
 
-        this.proj = proj;
-        this.pixelPerDegree = pixelPerDegree;
+        this.proj = Main.main.proj;
+        this.pixelPerDegree = layer.pixelPerDegree;
         this.image = image;
         this.mv = mv;
         this.layer = layer;
Index: src/wmsplugin/WMSInfo.java
===================================================================
--- src/wmsplugin/WMSInfo.java	(revision 15843)
+++ src/wmsplugin/WMSInfo.java	(working copy)
@@ -11,20 +11,27 @@
 
     String name;
     String url;
+    String cookies;
     int prefid;
 
     public WMSInfo(String name, String url, int prefid) {
-        this.name=name; this.url=url; this.prefid=prefid;
+        this(name, url, null, prefid);
     }
 
+    public WMSInfo(String name, String url, String cookies, int prefid) {
+        this.name=name;
+        this.url=url;
+        this.cookies=cookies;
+        this.prefid=prefid;
+    }
 
     public void save() {
         Main.pref.put("wmsplugin.url." + prefid + ".name", name);
         Main.pref.put("wmsplugin.url." + prefid + ".url", url);
     }
-    public int compareTo(WMSInfo c)
+
+    public int compareTo(WMSInfo in)
     {
-        WMSInfo in = (WMSInfo)c;
         Integer i = name.compareTo(in.name);
         if(i == 0)
             i = url.compareTo(in.url);
Index: src/wmsplugin/WMSLayer.java
===================================================================
--- src/wmsplugin/WMSLayer.java	(revision 15843)
+++ src/wmsplugin/WMSLayer.java	(working copy)
@@ -58,22 +58,24 @@
     JCheckBoxMenuItem startstop = new JCheckBoxMenuItem(tr("Automatic downloading"), true);
     protected JCheckBoxMenuItem alphaChannel = new JCheckBoxMenuItem(new ToggleAlphaAction());
     protected String baseURL;
+    protected String cookies;
     protected final int serializeFormatVersion = 4;
 
     private ExecutorService executor = null;
 
     public WMSLayer() {
-        this(tr("Blank Layer"), null);
+        this(tr("Blank Layer"), null, null);
         initializeImages();
         mv = Main.map.mapView;
     }
 
-    public WMSLayer(String name, String baseURL) {
+    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;
         getPPD();
@@ -85,7 +87,7 @@
     public void destroy() {
         try {
             executor.shutdown();
-        // Might not be initalized, so catch NullPointer as well
+            // Might not be initalized, so catch NullPointer as well
         } catch(Exception x) {}
     }
 
@@ -127,15 +129,12 @@
 
     private Bounds XYtoBounds (int x, int y) {
         return new Bounds(
-            new LatLon( x * ImageSize / pixelPerDegree,
-                         y * ImageSize / pixelPerDegree),
-            new LatLon((x + 1) *  ImageSize / pixelPerDegree,
-                       (y + 1) * ImageSize / pixelPerDegree));
+            new LatLon(      x * ImageSize / pixelPerDegree,       y * ImageSize / pixelPerDegree),
+            new LatLon((x + 1) * ImageSize / pixelPerDegree, (y + 1) * ImageSize / pixelPerDegree));
     }
 
     private int modulo (int a, int b) {
-      if(a%b>=0)return a%b;
-      else return a%b+b;
+        return a % b >= 0 ? a%b : a%b+b;
     }
 
     protected Bounds bounds(){
@@ -179,10 +178,10 @@
                     img.downloadingStarted = true;
                     img.image = null;
                     img.flushedResizedCachedInstance();
-                    Grabber gr = WMSPlugin.getGrabber(baseURL, XYtoBounds(x,y), Main.main.proj, pixelPerDegree, img, mv, this);
+                    Grabber gr = WMSPlugin.getGrabber(XYtoBounds(x,y), img, mv, this);
                     executor.submit(gr);
+                }
             }
-        }
     }
 
     @Override public void visitBoundingBox(BoundingXYVisitor v) {
@@ -219,9 +218,9 @@
     public GeorefImage findImage(EastNorth eastNorth) {
         for(int x = 0; x<dax; ++x)
             for(int y = 0; y<day; ++y)
-                    if(images[x][y].image!=null && images[x][y].min!=null && images[x][y].max!=null)
-                        if(images[x][y].contains(eastNorth, dx, dy))
-                            return images[x][y];
+                if(images[x][y].image!=null && images[x][y].min!=null && images[x][y].max!=null)
+                    if(images[x][y].contains(eastNorth, dx, dy))
+                        return images[x][y];
         return null;
     }
 
@@ -293,8 +292,7 @@
             super(tr("Save WMS layer to file"), ImageProvider.get("save"));
         }
         public void actionPerformed(ActionEvent ev) {
-            File f = DiskAccessAction.createAndOpenSaveFileChooser(
-            tr("Save WMS layer"), ".wms");
+            File f = DiskAccessAction.createAndOpenSaveFileChooser(tr("Save WMS layer"), ".wms");
             try
             {
                 FileOutputStream fos = new FileOutputStream(f);
@@ -322,7 +320,7 @@
         }
         public void actionPerformed(ActionEvent ev) {
             JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true,
-            false, tr("Load WMS layer"));
+                    false, tr("Load WMS layer"));
             if(fc == null) return;
             File f = fc.getSelectedFile();
             if (f == null) return;
@@ -333,9 +331,9 @@
                 int sfv = ois.readInt();
                 if (sfv != serializeFormatVersion) {
                     JOptionPane.showMessageDialog(Main.parent,
-                        tr("Unsupported WMS file version; found {0}, expected {1}", sfv, serializeFormatVersion),
-                        tr("File Format Error"),
-                        JOptionPane.ERROR_MESSAGE);
+                            tr("Unsupported WMS file version; found {0}, expected {1}", sfv, serializeFormatVersion),
+                            tr("File Format Error"),
+                            JOptionPane.ERROR_MESSAGE);
                     return;
                 }
                 startstop.setSelected(false);
@@ -354,9 +352,9 @@
                 // FIXME be more specific
                 ex.printStackTrace(System.out);
                 JOptionPane.showMessageDialog(Main.parent,
-                    tr("Error loading file"),
-                    tr("Error"),
-                    JOptionPane.ERROR_MESSAGE);
+                        tr("Error loading file"),
+                        tr("Error"),
+                        JOptionPane.ERROR_MESSAGE);
                 return;
             }
         }
Index: src/wmsplugin/Map_Rectifier_WMSmenuAction.java
===================================================================
--- src/wmsplugin/Map_Rectifier_WMSmenuAction.java	(revision 15843)
+++ src/wmsplugin/Map_Rectifier_WMSmenuAction.java	(working copy)
@@ -2,13 +2,12 @@
 
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.Transferable;
 import java.awt.GridBagLayout;
 import java.awt.Toolkit;
-
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
 import java.util.ArrayList;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -20,10 +19,9 @@
 import javax.swing.JRadioButton;
 import javax.swing.JTextField;
 
+import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.gui.ExtendedDialog;
-import org.openstreetmap.josm.gui.MapView;
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.tools.GBC;
 import org.openstreetmap.josm.tools.Shortcut;
 import org.openstreetmap.josm.tools.UrlLabel;
@@ -33,19 +31,19 @@
      * Class that bundles all required information of a rectifier service
      */
     public class rectifierService {
-        private String name;
-        private String url;
-        private String wmsUrl;
-        private Pattern urlRegEx;
-        private Pattern idValidator;
+        private final String name;
+        private final String url;
+        private final String wmsUrl;
+        private final Pattern urlRegEx;
+        private final Pattern idValidator;
         public JRadioButton btn;
         /**
-          * @param name: Name of the rectifing service
-          * @param url: URL to the service where users can register, upload, etc.
-          * @param wmsUrl: URL to the WMS server where JOSM will grab the images. Insert __s__ where the ID should be placed
-          * @param urlRegEx: a regular expression that determines if a given URL is one of the service and returns the WMS id if so
-          * @param idValidator: regular expression that checks if a given ID is syntactically valid
-          */
+         * @param name: Name of the rectifing service
+         * @param url: URL to the service where users can register, upload, etc.
+         * @param wmsUrl: URL to the WMS server where JOSM will grab the images. Insert __s__ where the ID should be placed
+         * @param urlRegEx: a regular expression that determines if a given URL is one of the service and returns the WMS id if so
+         * @param idValidator: regular expression that checks if a given ID is syntactically valid
+         */
         public rectifierService(String name, String url, String wmsUrl, String urlRegEx, String idValidator) {
             this.name = name;
             this.url = url;
@@ -61,18 +59,18 @@
 
     /**
      * List of available rectifier services. May be extended from the outside
-    */
+     */
     public ArrayList<rectifierService> services = new ArrayList<rectifierService>();
 
     public Map_Rectifier_WMSmenuAction() {
         super(tr("Rectified Image..."),
-            "OLmarker",
-            tr("Download Rectified Images From Various Services"),
-            Shortcut.registerShortcut("wms:rectimg",
-                tr("WMS: {0}", tr("Rectified Image...")),
-                KeyEvent.VK_R,
-                Shortcut.GROUP_NONE),
-            true
+                "OLmarker",
+                tr("Download Rectified Images From Various Services"),
+                Shortcut.registerShortcut("wms:rectimg",
+                        tr("WMS: {0}", tr("Rectified Image...")),
+                        KeyEvent.VK_R,
+                        Shortcut.GROUP_NONE),
+                        true
         );
 
         // Add default services
@@ -80,7 +78,7 @@
             new rectifierService("Metacarta Map Rectifier",
                 "http://labs.metacarta.com/rectifier/",
                 "http://labs.metacarta.com/rectifier/wms.cgi?id=__s__&srs=EPSG:4326"
-                    + "&Service=WMS&Version=1.1.0&Request=GetMap&format=image/png",
+                + "&Service=WMS&Version=1.1.0&Request=GetMap&format=image/png",
                 // This matches more than the "classic" WMS link, so users can pretty much
                 // copy any link as long as it includes the ID
                 "labs\\.metacarta\\.com/(?:.*?)(?:/|=)([0-9]+)(?:\\?|/|\\.|$)",
@@ -93,10 +91,10 @@
             new rectifierService("Geothings Map Warper",
                 "http://warper.geothings.net/",
                 "http://warper.geothings.net/maps/wms/__s__?request=GetMap&version=1.1.1"
-                    + "&styles=&format=image/png&srs=epsg:4326&exceptions=application/vnd.ogc.se_inimage",
+                + "&styles=&format=image/png&srs=epsg:4326&exceptions=application/vnd.ogc.se_inimage",
                 // This matches more than the "classic" WMS link, so users can pretty much
                 // copy any link as long as it includes the ID
-                "(?:mapwarper\\.net|warper\\.geothings\\.net/(?:.*?)/([0-9]+)(?:\\?|/|\\.|$)",
+                "(?:mapwarper\\.net|warper\\.geothings\\.net)/(?:.*?)/([0-9]+)(?:\\?|/|\\.|$)",
                 "^[0-9]+$")
         );
 
@@ -126,7 +124,7 @@
             // If the contents match, they will be inserted into the text field and the corresponding
             // service will be pre-selected.
             if(!clip.equals("") && tfWmsUrl.getText().equals("")
-                && (s.urlRegEx.matcher(clip).find() || s.idValidator.matcher(clip).matches())) {
+                    && (s.urlRegEx.matcher(clip).find() || s.idValidator.matcher(clip).matches())) {
                 serviceBtn.setSelected(true);
                 tfWmsUrl.setText(clip);
             }
@@ -147,10 +145,10 @@
         panel.add(tfWmsUrl, GBC.eol().fill(GBC.HORIZONTAL));
 
         ExtendedDialog diag = new ExtendedDialog(Main.parent,
-                            tr("Add Rectified Image"),
-                            panel,
-                            new String[] {tr("Add Rectified Image"), tr("Cancel")},
-                            new String[] {"OLmarker.png", "cancel.png"});
+                tr("Add Rectified Image"),
+                panel,
+                new String[] {tr("Add Rectified Image"), tr("Cancel")},
+                new String[] {"OLmarker.png", "cancel.png"});
 
         // This repeatedly shows the dialog in case there has been an error.
         // The loop is break;-ed if the users cancels
@@ -197,24 +195,34 @@
 
             // and display an error message. The while(true) ensures that the dialog pops up again
             JOptionPane.showMessageDialog(Main.parent,
-                tr("Couldn't match the entered link or id to the selected service. Please try again."),
-                tr("No valid WMS URL or id"),
-                JOptionPane.ERROR_MESSAGE);
+                    tr("Couldn't match the entered link or id to the selected service. Please try again."),
+                    tr("No valid WMS URL or id"),
+                    JOptionPane.ERROR_MESSAGE);
             diag.setVisible(true);
         }
     }
 
     /**
-     * Adds a WMS Layer with given title and UR:
+     * Adds a WMS Layer with given title and URL
      * @param title: Name of the layer as it will shop up in the layer manager
      * @param url: URL to the WMS server
+     * @param cookies: Cookies to send with each image request (Format: josm=is; very=cool)
      */
-    private void addWMSLayer(String title, String url) {
-        WMSLayer wmsLayer = new WMSLayer(title, url);
+    private void addWMSLayer(String title, String url, String cookies) {
+        WMSLayer wmsLayer = new WMSLayer(title, url, cookies);
         Main.main.addLayer(wmsLayer);
     }
 
     /**
+     * Adds a WMS Layer with given title and URL
+     * @param title: Name of the layer as it will shop up in the layer manager
+     * @param url: URL to the WMS server
+     */
+    private void addWMSLayer(String title, String url) {
+        addWMSLayer(title, url, "");
+    }
+
+    /**
      * Helper function that extracts a String from the Clipboard if available.
      * Returns an empty String otherwise
      * @return String Clipboard contents if available
Index: src/wmsplugin/WMSGrabber.java
===================================================================
--- src/wmsplugin/WMSGrabber.java	(revision 15843)
+++ src/wmsplugin/WMSGrabber.java	(working copy)
@@ -16,7 +16,6 @@
 import java.text.MessageFormat;
 import java.text.NumberFormat;
 import java.util.Locale;
-import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -25,7 +24,6 @@
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Bounds;
-import org.openstreetmap.josm.data.projection.Projection;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.io.CacheFiles;
 import org.openstreetmap.josm.io.ProgressInputStream;
@@ -33,13 +31,11 @@
 
 public class WMSGrabber extends Grabber {
     protected String baseURL;
-    private static Boolean shownWarning = false;
-    private boolean urlWithPatterns;
+    private final boolean urlWithPatterns;
 
-    WMSGrabber(String baseURL, Bounds b, Projection proj,
-            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
-        super(b, proj, pixelPerDegree, image, mv, layer, cache);
-        this.baseURL = baseURL;
+    WMSGrabber(Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
+        super(b, image, mv, layer, cache);
+        this.baseURL = layer.baseURL;
         /* URL containing placeholders? */
         urlWithPatterns = baseURL != null && baseURL.contains("{1}");
     }
@@ -70,17 +66,16 @@
         }
     }
 
-    public static final NumberFormat
-        latLonFormat = new DecimalFormat("###0.0000000",
+    public static final NumberFormat latLonFormat = new DecimalFormat("###0.0000000",
             new DecimalFormatSymbols(Locale.US));
 
     protected URL getURL(double w, double s,double e,double n,
             int wi, int ht) throws MalformedURLException {
         String str = baseURL;
-        String bbox = latLonFormat.format(w) + "," +
-                      latLonFormat.format(s) + "," +
-                      latLonFormat.format(e) + "," +
-                      latLonFormat.format(n);
+        String bbox = latLonFormat.format(w) + ","
+                           + latLonFormat.format(s) + ","
+                           + latLonFormat.format(e) + ","
+                           + latLonFormat.format(n);
 
         if (urlWithPatterns) {
             String proj = Main.proj.toCode();
@@ -131,8 +126,10 @@
     protected BufferedImage grab(URL url) throws IOException {
         BufferedImage cached = cache.getImg(url.toString());
         if(cached != null) return cached;
-    
+
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+        if(layer.cookies != null && !layer.cookies.equals(""))
+            conn.setRequestProperty("Cookie", layer.cookies);
         conn.setConnectTimeout(Main.pref.getInteger("wmsplugin.timeout.connect", 30) * 1000);
         conn.setReadTimeout(Main.pref.getInteger("wmsplugin.timeout.read", 30) * 1000);
 
@@ -145,7 +142,7 @@
         InputStream is = new ProgressInputStream(conn, null);
         BufferedImage img = ImageIO.read(is);
         is.close();
-        
+
         cache.saveImg(url.toString(), img);
         return img;
     }
Index: src/wmsplugin/WMSDownloadAction.java
===================================================================
--- src/wmsplugin/WMSDownloadAction.java	(revision 15843)
+++ src/wmsplugin/WMSDownloadAction.java	(working copy)
@@ -6,13 +6,10 @@
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
-import org.openstreetmap.josm.gui.MapView;
-import org.openstreetmap.josm.gui.layer.Layer;
-import org.openstreetmap.josm.data.Bounds;
 
 public class WMSDownloadAction extends JosmAction {
 
-    private WMSInfo info;
+    private final WMSInfo info;
 
     public WMSDownloadAction(WMSInfo info) {
         super(info.name, "wmsmenu", tr("Download WMS tile from {0}",info.name), null, false);
@@ -23,13 +20,13 @@
     public void actionPerformed(ActionEvent e) {
         System.out.println(info.url);
 
-        WMSLayer wmsLayer = new WMSLayer(info.name, info.url);
+        WMSLayer wmsLayer = new WMSLayer(info.name, info.url, info.cookies);
         Main.main.addLayer(wmsLayer);
     }
 
     public static WMSLayer getLayer(WMSInfo info) {
         // FIXME: move this to WMSPlugin/WMSInfo/preferences.
-        WMSLayer wmsLayer = new WMSLayer(info.name, info.url);
+        WMSLayer wmsLayer = new WMSLayer(info.name, info.url, info.cookies);
         Main.main.addLayer(wmsLayer);
         return wmsLayer;
     }
Index: src/wmsplugin/YAHOOGrabber.java
===================================================================
--- src/wmsplugin/YAHOOGrabber.java	(revision 15843)
+++ src/wmsplugin/YAHOOGrabber.java	(working copy)
@@ -1,34 +1,29 @@
 package wmsplugin;
 
-import static org.openstreetmap.josm.tools.I18n.tr;
-
 import java.awt.image.BufferedImage;
-import java.awt.Image;
-import java.net.URL;
 import java.io.IOException;
+import java.net.URL;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.StringTokenizer;
 
 import javax.imageio.ImageIO;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Bounds;
-import org.openstreetmap.josm.data.projection.Projection;
-import org.openstreetmap.josm.io.CacheFiles;
 import org.openstreetmap.josm.gui.MapView;
+import org.openstreetmap.josm.io.CacheFiles;
 
 
 public class YAHOOGrabber extends WMSGrabber {
     protected String browserCmd;
 
-    YAHOOGrabber(String baseURL, Bounds b, Projection proj,
-            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
-        super("file:///" + WMSPlugin.getPrefsPath() + "ymap.html?"
-        , b, proj, pixelPerDegree, image, mv, layer, cache);
-        this.browserCmd = baseURL.replaceFirst("yahoo://", "");
+    YAHOOGrabber(Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
+        super(b, image, mv, layer, cache);
+        layer.baseURL = "file:///" + WMSPlugin.getPrefsPath() + "ymap.html?";
+        this.browserCmd = layer.baseURL.replaceFirst("yahoo://", "");
     }
 
+    @Override
     protected BufferedImage grab(URL url) throws IOException {
         String urlstring = url.toExternalForm();
         // work around a problem in URL removing 2 slashes
@@ -52,7 +47,7 @@
         } catch(IOException ioe) {
             throw new IOException( "Could not start browser. Please check that the executable path is correct.\n" + ioe.getMessage() );
         }
-        
+
         BufferedImage img = ImageIO.read(browser.getInputStream());
         cache.saveImg(urlstring, img);
         return img;
Index: src/wmsplugin/WMSPlugin.java
===================================================================
--- src/wmsplugin/WMSPlugin.java	(revision 15843)
+++ src/wmsplugin/WMSPlugin.java	(working copy)
@@ -5,30 +5,34 @@
 
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Map;
-import java.util.TreeSet;
 import java.util.TreeMap;
-import java.io.*;
+import java.util.TreeSet;
 
-import javax.swing.AbstractAction;
-import javax.swing.AbstractButton;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.plugins.Plugin;
+import org.openstreetmap.josm.actions.JosmAction;
+import org.openstreetmap.josm.data.Bounds;
+import org.openstreetmap.josm.gui.IconToggleButton;
 import org.openstreetmap.josm.gui.MainMenu;
 import org.openstreetmap.josm.gui.MapFrame;
-import org.openstreetmap.josm.gui.IconToggleButton;
+import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
 import org.openstreetmap.josm.io.CacheFiles;
 import org.openstreetmap.josm.io.MirroredInputStream;
-import org.openstreetmap.josm.actions.JosmAction;
-import org.openstreetmap.josm.data.Bounds;
-import org.openstreetmap.josm.data.projection.Projection;
-import org.openstreetmap.josm.gui.MapView;
+import org.openstreetmap.josm.plugins.Plugin;
 
 public class WMSPlugin extends Plugin {
     static CacheFiles cache = new CacheFiles("wmsplugin");
@@ -103,6 +107,7 @@
         int prefid = 0;
         String name = null;
         String url = null;
+        String cookies = "";
         int lastid = -1;
         for (String key : keys) {
             String[] elements = key.split("\\.");
@@ -119,14 +124,16 @@
                 name = prefs.get(key);
             else if (elements[3].equals("url"))
                 url = prefs.get(key);
+            else if (elements[3].equals("cookies"))
+                cookies = prefs.get(key);
             if (name != null && url != null)
-                wmsList.add(new WMSInfo(name, url, prefid));
+                wmsList.add(new WMSInfo(name, url, cookies, prefid));
         }
         String source = "http://svn.openstreetmap.org/applications/editors/josm/plugins/wmsplugin/sources.cfg";
         try
         {
             MirroredInputStream s = new MirroredInputStream(source,
-            Main.pref.getPreferencesDir() + "plugins/wmsplugin/", -1);
+                    Main.pref.getPreferencesDir() + "plugins/wmsplugin/", -1);
             InputStreamReader r;
             try
             {
@@ -199,18 +206,17 @@
         }
     }
 
-    public static Grabber getGrabber(String _baseURL, Bounds _b, Projection _proj,
-                     double _pixelPerDegree, GeorefImage _image, MapView _mv, WMSLayer _layer){
-        if(_baseURL.startsWith("yahoo://"))
-            return new YAHOOGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer, cache);
+    // baseURL, XYtoBounds(x,y), Main.main.proj, pixelPerDegree, img, mv, this
+    // Grabber gr = WMSPlugin.getGrabber(XYtoBounds(x,y), img, mv, this);
+    public static Grabber getGrabber(Bounds bounds, GeorefImage img, MapView mv, WMSLayer layer){
+        if(layer.baseURL.startsWith("yahoo://"))
+            return new YAHOOGrabber(bounds, img, mv, layer, cache);
         else
-            return new WMSGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer, cache);
+            return new WMSGrabber(bounds, img, mv, layer, cache);
+
         // OSBGrabber should be rewrite for thread support first
-        //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){
+        //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") )
         //  return new OSGBGrabber(_b, _proj, _pixelPerDegree,  _images, _mv, _layer);
-        //} else {
-        //  return new WMSGrabber(_b, _proj, _pixelPerDegree,  _images, _mv, _layer);
-        //}
     }
 
     private static void setEnabledAll(boolean isEnabled) {
@@ -219,14 +225,14 @@
 
             if(item != null) item.setEnabled(isEnabled);
         }
-               menuEnabled = isEnabled;
+        menuEnabled = isEnabled;
     }
 
     public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
         if (oldFrame==null && newFrame!=null) {
             setEnabledAll(true);
             Main.map.addMapMode(new IconToggleButton
-                        (new WMSAdjustAction(Main.map)));
+                    (new WMSAdjustAction(Main.map)));
         } else if (oldFrame!=null && newFrame==null ) {
             setEnabledAll(false);
         }
