Index: utils/josm/plugins/landsat/src/landsat/DownloadLandsatTask.java
===================================================================
--- utils/josm/plugins/landsat/src/landsat/DownloadLandsatTask.java	(revision 1566)
+++ 	(revision )
@@ -1,62 +1,0 @@
-package landsat;
-
-import static org.openstreetmap.josm.tools.I18n.tr;
-
-import java.io.IOException;
-
-import javax.swing.JCheckBox;
-
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.actions.DownloadAction;
-import org.openstreetmap.josm.actions.DownloadAction.DownloadTask;
-import org.openstreetmap.josm.gui.PleaseWaitRunnable;
-
-public class DownloadLandsatTask extends PleaseWaitRunnable implements DownloadTask {
-
-	private LandsatLayer landsatLayer;
-	private double minlat, minlon, maxlat, maxlon;
-	private JCheckBox checkBox = new JCheckBox(tr("Landsat background images"));
-
-	public DownloadLandsatTask(LandsatLayer landsatLayer) {
-		super(tr("Downloading data"));
-		this.landsatLayer = landsatLayer;
-	}
-
-	@Override public void realRun() throws IOException {
-		landsatLayer.grab(minlat,minlon,maxlat,maxlon);
-	}
-
-	@Override protected void finish() {
-		if (landsatLayer != null)
-			Main.main.addLayer(landsatLayer);
-	}
-
-	@Override protected void cancel() {
-	}
-
-
-	public void download(DownloadAction action, double minlat, double minlon, double maxlat, double maxlon) {
-		this.minlat=minlat;
-		this.minlon=minlon;
-		this.maxlat=maxlat;
-		this.maxlon=maxlon;
-		Main.worker.execute(this);
-	}
-
-	public JCheckBox getCheckBox() {
-		return checkBox;
-	}
-
-	public void setEnabled(boolean b) {
-		checkBox.setEnabled(b); 
-	}
-
-	public void setCheckBoxSelected(boolean b) {
-		checkBox.setSelected(b);
-	}
-
-	public String getPreferencesSuffix() {
-		return "landsat";
-	}
-
-}
Index: utils/josm/plugins/landsat/src/landsat/DownloadWMSTask.java
===================================================================
--- utils/josm/plugins/landsat/src/landsat/DownloadWMSTask.java	(revision 1567)
+++ utils/josm/plugins/landsat/src/landsat/DownloadWMSTask.java	(revision 1567)
@@ -0,0 +1,67 @@
+package landsat;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.io.IOException;
+
+import javax.swing.JCheckBox;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.DownloadAction;
+import org.openstreetmap.josm.actions.DownloadAction.DownloadTask;
+import org.openstreetmap.josm.gui.PleaseWaitRunnable;
+
+public class DownloadWMSTask extends PleaseWaitRunnable 
+		implements DownloadTask {
+
+	private WMSLayer wmsLayer;
+	private double minlat, minlon, maxlat, maxlon;
+	private JCheckBox checkBox;
+	String name;
+
+	public DownloadWMSTask(WMSLayer wmsLayer, String briefName,
+									String detailedName) {
+		super(tr("Downloading data"));
+   		checkBox = new JCheckBox(tr(detailedName));
+		this.wmsLayer = wmsLayer;
+		this.name=briefName;
+	}
+
+	@Override public void realRun() throws IOException {
+		wmsLayer.grab(minlat,minlon,maxlat,maxlon);
+	}
+
+	@Override protected void finish() {
+		if (wmsLayer != null)
+			Main.main.addLayer(wmsLayer);
+	}
+
+	@Override protected void cancel() {
+	}
+
+
+	public void download(DownloadAction action, double minlat, double minlon, double maxlat, double maxlon) {
+		this.minlat=minlat;
+		this.minlon=minlon;
+		this.maxlat=maxlat;
+		this.maxlon=maxlon;
+		Main.worker.execute(this);
+	}
+
+	public JCheckBox getCheckBox() {
+		return checkBox;
+	}
+
+	public void setEnabled(boolean b) {
+		checkBox.setEnabled(b); 
+	}
+
+	public void setCheckBoxSelected(boolean b) {
+		checkBox.setSelected(b);
+	}
+
+	public String getPreferencesSuffix() {
+		return name; 
+	}
+
+}
Index: utils/josm/plugins/landsat/src/landsat/LandsatAdjustAction.java
===================================================================
--- utils/josm/plugins/landsat/src/landsat/LandsatAdjustAction.java	(revision 1566)
+++ 	(revision )
@@ -1,92 +1,0 @@
-package landsat; 
-
-import static org.openstreetmap.josm.tools.I18n.tr;
-
-import java.awt.Cursor;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.gui.MapFrame;
-import org.openstreetmap.josm.actions.mapmode.MapMode;
-import org.openstreetmap.josm.data.coor.EastNorth;
-import org.openstreetmap.josm.tools.ImageProvider;
-import org.openstreetmap.josm.gui.layer.Layer;
-import org.openstreetmap.josm.gui.IconToggleButton;
-
-public class LandsatAdjustAction extends MapMode implements
-		MouseListener, MouseMotionListener{
-
-	LandsatImage selectedImage; 
-	boolean mouseDown;
-	EastNorth prevEastNorth;
-
-	public LandsatAdjustAction(MapFrame mapFrame) {
-		super("landsatAdjust", "movelandsat", 
-						"Adjust the position of the Landsat.", mapFrame, 
-						ImageProvider.getCursor("normal", "move"));
-	}
-
-	@Override public void enterMode() {
-		super.enterMode();
-		Main.map.mapView.addMouseListener(this);
-		Main.map.mapView.addMouseMotionListener(this);
-	}
-
-	@Override public void exitMode() {
-		super.exitMode();
-		Main.map.mapView.removeMouseListener(this);
-		Main.map.mapView.removeMouseMotionListener(this);
-	}
-
-	@Override public void mousePressed(MouseEvent e) {
-		if (e.getButton() != MouseEvent.BUTTON1)
-			return;
-
-		 for(Layer layer:Main.map.mapView.getAllLayers()) {
-			if (layer instanceof LandsatLayer) {
-				prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY());
-				selectedImage = ((LandsatLayer)layer).findImage(prevEastNorth);
-				if(selectedImage!=null){
-					Main.map.mapView.setCursor
-						(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
-				}
-			}
-		}
-	}
-
-	@Override public void mouseDragged(MouseEvent e) {
-			/*
-		if (e.getButton() != MouseEvent.BUTTON1)
-			return;
-			*/
-
-		if(selectedImage!=null) {
-			EastNorth eastNorth=
-					Main.map.mapView.getEastNorth(e.getX(),e.getY());
-			if(selectedImage.contains(eastNorth)) {
-				selectedImage.displace(eastNorth.east()-prevEastNorth.east(), 
-									eastNorth.north()-prevEastNorth.north());
-				prevEastNorth = eastNorth;
-			}
-			Main.map.mapView.repaint();
-		}
-	}
-
-	@Override public void mouseReleased(MouseEvent e) {
-		Main.map.mapView.repaint();
-		Main.map.mapView.setCursor(Cursor.getDefaultCursor());
-		selectedImage = null;	
-	}
-
-	public void mouseEntered(MouseEvent e) {
-	}
-	public void mouseExited(MouseEvent e) {
-	}
-	public void mouseMoved(MouseEvent e) {
-	}
-
-	@Override public void mouseClicked(MouseEvent e) {
-	}
-}
Index: utils/josm/plugins/landsat/src/landsat/LandsatImage.java
===================================================================
--- utils/josm/plugins/landsat/src/landsat/LandsatImage.java	(revision 1566)
+++ 	(revision )
@@ -1,150 +1,0 @@
-package landsat;
-
-import java.awt.Graphics;
-import java.awt.Image;
-import java.awt.Point;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.imageio.ImageIO;
-
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.coor.EastNorth;
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.gui.NavigatableComponent;
-
-public class LandsatImage
-{
-	String constURL;
-	Image theImage;
-	double grabbedScale;
-	EastNorth topLeft, bottomRight;
-	double dEast, dNorth;	
-	double minLat,minLon,maxLat,maxLon;
-
-	public LandsatImage(String constURL)
-	{
-		this.constURL = constURL;
-	}
-
-	public void grab(NavigatableComponent nc) throws IOException
-	{
-
-		EastNorth topLeft  = nc.getEastNorth(0,0);
-		grabbedScale =  nc.getScale();  // scale is enPerPixel
-
-		this.topLeft = topLeft;
-
-		try
-		{
-			URL url = getURL(nc);
-			doGrab(url);
-		}
-		catch(MalformedURLException e)
-		{
-			System.out.println("Illegal url. Error="+e);
-		}
-	}
-
-	public void grab(NavigatableComponent nc,double minlat,double minlon,
-			double maxlat,double maxlon) throws IOException
-			{
-		LatLon p = new LatLon(minlat,minlon),
-		p2 = new LatLon(maxlat,maxlon);
-
-		grabbedScale = nc.getScale(); // enPerPixel
-
-		topLeft = Main.proj.latlon2eastNorth(new LatLon(maxlat,minlon));
-		bottomRight = Main.proj.latlon2eastNorth
-		(new LatLon(minlat,maxlon));
-
-		int widthPx = (int)((bottomRight.east()-topLeft.east())/grabbedScale),
-		heightPx = (int)
-		((topLeft.north()-bottomRight.north()) / grabbedScale);
-
-		try
-		{
-			URL url =  doGetURL(p,p2,widthPx,heightPx);
-			doGrab(url);
-			this.minLat=minlat;
-			this.minLon=minlon;
-			this.maxLat=maxlat;
-			this.maxLon=maxlon;
-		}
-		catch(MalformedURLException e)
-		{
-			System.out.println("Illegal url. Error="+e);
-		}
-	}
-
-	private URL getURL(NavigatableComponent nc) throws MalformedURLException
-	{
-		double widthEN = nc.getWidth()*grabbedScale,
-		heightEN = nc.getHeight()*grabbedScale;
-		LatLon p = Main.proj.eastNorth2latlon(new EastNorth
-				(topLeft.east(), topLeft.north()-heightEN));
-		LatLon p2 = Main.proj.eastNorth2latlon(new EastNorth
-				(topLeft.east()+widthEN, topLeft.north()));
-		return doGetURL(p,p2,(int)(widthEN/grabbedScale),
-				(int)(heightEN/grabbedScale) );
-	}
-
-	private URL doGetURL(LatLon p, LatLon p2,int w, int h)
-	throws MalformedURLException
-	{
-		String str = constURL + "&bbox=" + p.lon() +"," + p.lat() + ","+
-		p2.lon()+","+p2.lat() + "&width=" + w
-		+ "&height=" + h;
-		return new URL(str);
-	}
-
-	private void doGrab (URL url) throws IOException
-	{
-		InputStream is = url.openStream();
-		theImage = ImageIO.read(is) ;
-		is.close();
-		Main.map.repaint();
-	}
-
-	public void displace (double dEast, double dNorth)
-	{
-	 	this.dEast += dEast;	
-	 	this.dNorth += dNorth;	
-	}
-
-	public boolean contains(EastNorth eastNorth)
-	{
-		double e1 = topLeft.east()+dEast, 
-			   e2 = bottomRight.east()+dEast,
-			   n1 = bottomRight.north()+dNorth,
-			   n2 = topLeft.north()+dNorth;
-
-		boolean b =  eastNorth.east()>=e1 && eastNorth.east()<=e2 &&
-				eastNorth.north()>=n1 && eastNorth.north()<=n2;
-		return b;
-	}
-
-	public void paint(Graphics g,NavigatableComponent nc) 
-	{
-		if(theImage!=null)
-		{
-			double zoomInFactor = grabbedScale / nc.getScale();
-
-			// Find the image x and y of the supplied bottom left
-			// This will be the difference in EastNorth units, divided by the
-			// grabbed scale in EastNorth/pixel.
-
-			int w = theImage.getWidth(null), h=theImage.getHeight(null);
-			EastNorth topLeftDisplaced  = 
-				new EastNorth(topLeft.east()+dEast, topLeft.north()+dNorth);
-			Point displacement = Main.map.mapView.getPoint(topLeftDisplaced);
-			g.drawImage(theImage,displacement.x,displacement.y,
-					(int)(displacement.x+w*zoomInFactor),
-					(int)(displacement.y+h*zoomInFactor),
-					0,0,w,h,null);
-		}
-	}
-
-}
Index: utils/josm/plugins/landsat/src/landsat/LandsatLayer.java
===================================================================
--- utils/josm/plugins/landsat/src/landsat/LandsatLayer.java	(revision 1566)
+++ 	(revision )
@@ -1,118 +1,0 @@
-package landsat;
-
-import static org.openstreetmap.josm.tools.I18n.tr;
-
-import java.awt.Component;
-import java.awt.Graphics;
-import java.awt.Toolkit;
-import java.io.IOException;
-import java.util.ArrayList;
-
-import javax.swing.Icon;
-import javax.swing.ImageIcon;
-import javax.swing.JMenuItem;
-import javax.swing.JSeparator;
-
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
-import org.openstreetmap.josm.data.projection.Projection;
-import org.openstreetmap.josm.gui.MapView;
-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.data.coor.EastNorth;
-
-/**
- * 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.
- */
-public class LandsatLayer extends Layer {
-
-	private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(LandsatPlugin.class.getResource("/images/wms.png")));
-
-	private final ArrayList<LandsatImage> landsatImages;
-
-	private final String url;
-
-
-	public LandsatLayer(String url) {
-		super(url.indexOf('/') != -1 ? url.substring(url.indexOf('/')+1) : url);
-
-		// to calculate the world dimension, we assume that the projection does
-		// not have problems with translating longitude to a correct scale.
-		// Next to that, the projection must be linear dependend on the lat/lon
-		// unprojected scale.
-		if (Projection.MAX_LON != 180)
-			throw new IllegalArgumentException(tr
-					("Wrong longitude transformation for tile manager. "+
-							"Can't operate on {0}",Main.proj));
-
-		this.url = url;
-		//landsatImage = new LandsatImage(url);
-		landsatImages = new ArrayList<LandsatImage>();
-	}
-
-	public void grab() throws IOException
-	{
-		MapView mv = Main.map.mapView;
-		LandsatImage landsatImage = new LandsatImage(url);
-		landsatImage.grab(mv);
-		landsatImages.add(landsatImage);
-	}
-
-	public void grab(double minlat,double minlon,double maxlat,double maxlon)
-	throws IOException
-	{
-		MapView mv = Main.map.mapView;
-		LandsatImage landsatImage = new LandsatImage(url);
-		landsatImage.grab(mv,minlat,minlon,maxlat,maxlon);
-		landsatImages.add(landsatImage);
-	}
-
-	@Override public Icon getIcon() {
-		return icon;
-	}
-
-	@Override public String getToolTipText() {
-		return tr("WMS layer: {0}", url);
-	}
-
-	@Override public boolean isMergable(Layer other) {
-		return false;
-	}
-
-	@Override public void mergeFrom(Layer from) {
-	}
-
-	@Override public void paint(Graphics g, final MapView mv) {
-		for(LandsatImage landsatImage : landsatImages) {
-			landsatImage.paint(g,mv);
-		}
-	}
-
-	@Override public void visitBoundingBox(BoundingXYVisitor v) {
-		// doesn't have a bounding box
-	}
-
-	@Override public Object getInfoComponent() {
-		return getToolTipText();
-	}
-
-	@Override public Component[] getMenuEntries() {
-		return new Component[]{
-				new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
-				new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
-				new JSeparator(),
-				new JMenuItem(new LayerListPopup.InfoAction(this))};
-	}
-
-	public LandsatImage findImage(EastNorth eastNorth)
-	{
-		for(LandsatImage landsatImage : landsatImages) {
-			if (landsatImage.contains(eastNorth))  {
-				return landsatImage;
-			}
-		}
-		return null;
-	}
-}
Index: utils/josm/plugins/landsat/src/landsat/OSGBImage.java
===================================================================
--- utils/josm/plugins/landsat/src/landsat/OSGBImage.java	(revision 1567)
+++ utils/josm/plugins/landsat/src/landsat/OSGBImage.java	(revision 1567)
@@ -0,0 +1,70 @@
+package landsat;
+
+import uk.me.jstott.jcoord.OSRef;
+import uk.me.jstott.jcoord.LatLng;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.gui.NavigatableComponent;
+
+public class OSGBImage extends WMSImage
+{
+	public OSGBImage(String constURL)
+	{
+		super(constURL);
+	}
+
+	public void grab(NavigatableComponent nc,double minlat,double minlon,
+			double maxlat,double maxlon) throws IOException
+	{
+		// To deal with the fact that grid refs and lat/lon don't align
+		OSRef bottomLeftGR = 
+				new LatLng(minlat,minlon).toOSRef(),
+			  topRightGR = 
+				new LatLng(maxlat,maxlon).toOSRef(),
+		 	topLeftGR = 
+				new LatLng(maxlat,minlon).toOSRef(),
+			  bottomRightGR = 
+				new LatLng(minlat,maxlon).toOSRef();
+
+		double w = Math.min(bottomLeftGR.getEasting(),
+								topLeftGR.getEasting()),
+			   s = Math.min(bottomLeftGR.getNorthing(),
+							   bottomRightGR.getNorthing()),
+			   e = Math.max(bottomRightGR.getEasting(),
+							   topRightGR.getEasting()),
+			   n = Math.max(topLeftGR.getNorthing(),
+							   topRightGR.getNorthing());
+
+		// Adjust topLeft and bottomRight due to messing around with
+		// projections
+		LatLng tl2 = new OSRef(w,n).toLatLng();
+		LatLng br2 = new OSRef(e,s).toLatLng();
+
+		topLeft = Main.proj.latlon2eastNorth
+					(new LatLon(tl2.getLat(),tl2.getLng() ));
+		bottomRight = Main.proj.latlon2eastNorth
+					(new LatLon(br2.getLat(),br2.getLng() ));
+
+		grabbedScale = nc.getScale(); // enPerPixel
+
+		int widthPx = (int)((bottomRight.east()-topLeft.east())/grabbedScale),
+			heightPx = (int)
+				((topLeft.north()-bottomRight.north()) / grabbedScale);
+
+		try
+		{
+			URL url =  doGetURL(w,s,e,n,widthPx,heightPx);
+			System.out.println("OSGB URL=" + url);
+			doGrab(url);
+		}
+		catch(MalformedURLException ex)
+		{
+			System.out.println("Illegal url. Error="+ex);
+		}
+	}
+}
Index: utils/josm/plugins/landsat/src/landsat/OSGBLayer.java
===================================================================
--- utils/josm/plugins/landsat/src/landsat/OSGBLayer.java	(revision 1567)
+++ utils/josm/plugins/landsat/src/landsat/OSGBLayer.java	(revision 1567)
@@ -0,0 +1,21 @@
+package landsat;
+
+import java.io.IOException;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.MapView;
+
+public class OSGBLayer extends WMSLayer {
+
+	public OSGBLayer(String constURL) {
+		super(constURL);
+	}
+
+	public void grab(double minlat,double minlon,double maxlat,double maxlon)
+	throws IOException {
+		MapView mv = Main.map.mapView;
+		OSGBImage npeImage = new OSGBImage(url);
+		npeImage.grab(mv,minlat,minlon,maxlat,maxlon);
+		wmsImages.add(npeImage);
+	}
+}
Index: utils/josm/plugins/landsat/src/landsat/WMSAdjustAction.java
===================================================================
--- utils/josm/plugins/landsat/src/landsat/WMSAdjustAction.java	(revision 1567)
+++ utils/josm/plugins/landsat/src/landsat/WMSAdjustAction.java	(revision 1567)
@@ -0,0 +1,92 @@
+package landsat; 
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.Cursor;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.MapFrame;
+import org.openstreetmap.josm.actions.mapmode.MapMode;
+import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.IconToggleButton;
+
+public class WMSAdjustAction extends MapMode implements
+		MouseListener, MouseMotionListener{
+
+	WMSImage selectedImage; 
+	boolean mouseDown;
+	EastNorth prevEastNorth;
+
+	public WMSAdjustAction(MapFrame mapFrame) {
+		super("landsatAdjust", "movelandsat", 
+						"Adjust the position of the WMS layer", mapFrame, 
+						ImageProvider.getCursor("normal", "move"));
+	}
+
+	@Override public void enterMode() {
+		super.enterMode();
+		Main.map.mapView.addMouseListener(this);
+		Main.map.mapView.addMouseMotionListener(this);
+	}
+
+	@Override public void exitMode() {
+		super.exitMode();
+		Main.map.mapView.removeMouseListener(this);
+		Main.map.mapView.removeMouseMotionListener(this);
+	}
+
+	@Override public void mousePressed(MouseEvent e) {
+		if (e.getButton() != MouseEvent.BUTTON1)
+			return;
+
+		 for(Layer layer:Main.map.mapView.getAllLayers()) {
+			if (layer instanceof WMSLayer) {
+				prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY());
+				selectedImage = ((WMSLayer)layer).findImage(prevEastNorth);
+				if(selectedImage!=null){
+					Main.map.mapView.setCursor
+						(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
+				}
+			}
+		}
+	}
+
+	@Override public void mouseDragged(MouseEvent e) {
+			/*
+		if (e.getButton() != MouseEvent.BUTTON1)
+			return;
+			*/
+
+		if(selectedImage!=null) {
+			EastNorth eastNorth=
+					Main.map.mapView.getEastNorth(e.getX(),e.getY());
+			if(selectedImage.contains(eastNorth)) {
+				selectedImage.displace(eastNorth.east()-prevEastNorth.east(), 
+									eastNorth.north()-prevEastNorth.north());
+				prevEastNorth = eastNorth;
+			}
+			Main.map.mapView.repaint();
+		}
+	}
+
+	@Override public void mouseReleased(MouseEvent e) {
+		Main.map.mapView.repaint();
+		Main.map.mapView.setCursor(Cursor.getDefaultCursor());
+		selectedImage = null;	
+	}
+
+	public void mouseEntered(MouseEvent e) {
+	}
+	public void mouseExited(MouseEvent e) {
+	}
+	public void mouseMoved(MouseEvent e) {
+	}
+
+	@Override public void mouseClicked(MouseEvent e) {
+	}
+}
Index: utils/josm/plugins/landsat/src/landsat/WMSImage.java
===================================================================
--- utils/josm/plugins/landsat/src/landsat/WMSImage.java	(revision 1567)
+++ utils/josm/plugins/landsat/src/landsat/WMSImage.java	(revision 1567)
@@ -0,0 +1,145 @@
+package landsat;
+
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Point;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.imageio.ImageIO;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.gui.NavigatableComponent;
+
+public class WMSImage
+{
+	String constURL;
+	protected Image theImage;
+	protected double grabbedScale;
+	protected EastNorth topLeft, bottomRight;
+	double dEast, dNorth;	
+
+	public WMSImage(String constURL)
+	{
+		this.constURL = constURL;
+	}
+
+	public void grab(NavigatableComponent nc) throws IOException
+	{
+
+		EastNorth topLeft  = nc.getEastNorth(0,0);
+		grabbedScale =  nc.getScale();  // scale is enPerPixel
+
+		this.topLeft = topLeft;
+
+		try
+		{
+			URL url = getURL(nc);
+			doGrab(url);
+		}
+		catch(MalformedURLException e)
+		{
+			System.out.println("Illegal url. Error="+e);
+		}
+	}
+
+	public void grab(NavigatableComponent nc,double minlat,double minlon,
+			double maxlat,double maxlon) throws IOException
+	{
+		LatLon p = new LatLon(minlat,minlon),
+				p2 = new LatLon(maxlat,maxlon);
+
+		grabbedScale = nc.getScale(); // enPerPixel
+
+		topLeft = Main.proj.latlon2eastNorth(new LatLon(maxlat,minlon));
+		bottomRight = Main.proj.latlon2eastNorth(new LatLon(minlat,maxlon));
+
+		int widthPx = (int)((bottomRight.east()-topLeft.east())/grabbedScale),
+		heightPx = (int)
+		((topLeft.north()-bottomRight.north()) / grabbedScale);
+
+		try
+		{
+			URL url =  doGetURL(p.lon(),p.lat(),
+									p2.lon(),p2.lat(),widthPx,heightPx);
+			doGrab(url);
+		}
+		catch(MalformedURLException e)
+		{
+			System.out.println("Illegal url. Error="+e);
+		}
+	}
+
+	private URL getURL(NavigatableComponent nc) throws MalformedURLException
+	{
+		double widthEN = nc.getWidth()*grabbedScale,
+		heightEN = nc.getHeight()*grabbedScale;
+		LatLon p = Main.proj.eastNorth2latlon(new EastNorth
+				(topLeft.east(), topLeft.north()-heightEN));
+		LatLon p2 = Main.proj.eastNorth2latlon(new EastNorth
+				(topLeft.east()+widthEN, topLeft.north()));
+		return doGetURL(p.lon(),p.lat(),p2.lon(),p2.lat(),
+						(int)(widthEN/grabbedScale),
+						(int)(heightEN/grabbedScale) );
+	}
+
+	protected URL doGetURL(double w,double s,double e,double n, int wi, 
+					int ht) throws MalformedURLException
+	{
+		String str = constURL + "&bbox=" + w +"," + s + ","+
+				e+","+n + "&width=" + wi + "&height=" + ht;
+		return new URL(str);
+	}
+
+	protected void doGrab (URL url) throws IOException
+	{
+		InputStream is = url.openStream();
+		theImage = ImageIO.read(is) ;
+		is.close();
+		Main.map.repaint();
+	}
+
+	public void displace (double dEast, double dNorth)
+	{
+	 	this.dEast += dEast;	
+	 	this.dNorth += dNorth;	
+	}
+
+	public boolean contains(EastNorth eastNorth)
+	{
+		double e1 = topLeft.east()+dEast, 
+			   e2 = bottomRight.east()+dEast,
+			   n1 = bottomRight.north()+dNorth,
+			   n2 = topLeft.north()+dNorth;
+
+		boolean b =  eastNorth.east()>=e1 && eastNorth.east()<=e2 &&
+				eastNorth.north()>=n1 && eastNorth.north()<=n2;
+		return b;
+	}
+
+	public void paint(Graphics g,NavigatableComponent nc) 
+	{
+		if(theImage!=null)
+		{
+			double zoomInFactor = grabbedScale / nc.getScale();
+
+			// Find the image x and y of the supplied bottom left
+			// This will be the difference in EastNorth units, divided by the
+			// grabbed scale in EastNorth/pixel.
+
+			int w = theImage.getWidth(null), h=theImage.getHeight(null);
+			EastNorth topLeftDisplaced  = 
+				new EastNorth(topLeft.east()+dEast, topLeft.north()+dNorth);
+			Point displacement = Main.map.mapView.getPoint(topLeftDisplaced);
+			g.drawImage(theImage,displacement.x,displacement.y,
+					(int)(displacement.x+w*zoomInFactor),
+					(int)(displacement.y+h*zoomInFactor),
+					0,0,w,h,null);
+		}
+	}
+
+}
Index: utils/josm/plugins/landsat/src/landsat/WMSLayer.java
===================================================================
--- utils/josm/plugins/landsat/src/landsat/WMSLayer.java	(revision 1567)
+++ utils/josm/plugins/landsat/src/landsat/WMSLayer.java	(revision 1567)
@@ -0,0 +1,118 @@
+package landsat;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Toolkit;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JSeparator;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
+import org.openstreetmap.josm.data.projection.Projection;
+import org.openstreetmap.josm.gui.MapView;
+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.data.coor.EastNorth;
+
+/**
+ * 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.
+ */
+public class WMSLayer extends Layer {
+
+	protected static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(LandsatPlugin.class.getResource("/images/wms.png")));
+
+	protected final ArrayList<WMSImage> wmsImages;
+
+	protected final String url;
+
+
+	public WMSLayer(String url) {
+		super(url.indexOf('/') != -1 ? url.substring(url.indexOf('/')+1) : url);
+
+		// to calculate the world dimension, we assume that the projection does
+		// not have problems with translating longitude to a correct scale.
+		// Next to that, the projection must be linear dependend on the lat/lon
+		// unprojected scale.
+		if (Projection.MAX_LON != 180)
+			throw new IllegalArgumentException(tr
+					("Wrong longitude transformation for tile manager. "+
+							"Can't operate on {0}",Main.proj));
+
+		this.url = url;
+		//wmsImage = new WMSImage(url);
+		wmsImages = new ArrayList<WMSImage>();
+	}
+
+	public void grab() throws IOException
+	{
+		MapView mv = Main.map.mapView;
+		WMSImage wmsImage = new WMSImage(url);
+		wmsImage.grab(mv);
+		wmsImages.add(wmsImage);
+	}
+
+	public void grab(double minlat,double minlon,double maxlat,double maxlon)
+	throws IOException
+	{
+		MapView mv = Main.map.mapView;
+		WMSImage wmsImage = new WMSImage(url);
+		wmsImage.grab(mv,minlat,minlon,maxlat,maxlon);
+		wmsImages.add(wmsImage);
+	}
+
+	@Override public Icon getIcon() {
+		return icon;
+	}
+
+	@Override public String getToolTipText() {
+		return tr("WMS layer: {0}", url);
+	}
+
+	@Override public boolean isMergable(Layer other) {
+		return false;
+	}
+
+	@Override public void mergeFrom(Layer from) {
+	}
+
+	@Override public void paint(Graphics g, final MapView mv) {
+		for(WMSImage wmsImage : wmsImages) {
+			wmsImage.paint(g,mv);
+		}
+	}
+
+	@Override public void visitBoundingBox(BoundingXYVisitor v) {
+		// doesn't have a bounding box
+	}
+
+	@Override public Object getInfoComponent() {
+		return getToolTipText();
+	}
+
+	@Override public Component[] getMenuEntries() {
+		return new Component[]{
+				new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
+				new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
+				new JSeparator(),
+				new JMenuItem(new LayerListPopup.InfoAction(this))};
+	}
+
+	public WMSImage findImage(EastNorth eastNorth)
+	{
+		for(WMSImage wmsImage : wmsImages) {
+			if (wmsImage.contains(eastNorth))  {
+				return wmsImage;
+			}
+		}
+		return null;
+	}
+}
