Index: /trunk/data_nodist/wms-cache.xsd
===================================================================
--- /trunk/data_nodist/wms-cache.xsd	(revision 4183)
+++ /trunk/data_nodist/wms-cache.xsd	(revision 4183)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://josm.openstreetmap.de/wms-cache"
+	xmlns:tns="http://josm.openstreetmap.de/wms-cache" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
+	elementFormDefault="qualified" jaxb:version="2.0">
+	
+	<annotation>
+		<appinfo>
+			<jaxb:schemaBindings>
+				<jaxb:package name="org.openstreetmap.josm.data.imagery.types">
+				</jaxb:package>
+				<jaxb:nameXmlTransform>
+					<jaxb:typeName suffix="Type" />
+					<jaxb:elementName suffix="Type" />
+				</jaxb:nameXmlTransform>
+			</jaxb:schemaBindings>
+			<jaxb:globalBindings>
+				<jaxb:javaType name="java.util.Calendar" xmlType="date"
+					parseMethod="javax.xml.bind.DatatypeConverter.parseDate"
+					printMethod="org.openstreetmap.josm.data.imagery.WmsCache.printDate" />
+			</jaxb:globalBindings>
+		</appinfo>
+	</annotation>
+
+	<element name="wms-cache">
+		<complexType>
+			<sequence>
+				<element name="projection" type="tns:projection" minOccurs="0"
+					maxOccurs="unbounded" />
+			</sequence>
+			<attribute name="tileSize" type="int" use="required" />
+			<attribute name="totalFileSize" type="int" use="required"/>
+		</complexType>
+	</element>
+	
+	<complexType name="projection">
+		<sequence>
+			<element name="entry" type="tns:entry" minOccurs="0" maxOccurs="unbounded"/>
+		</sequence>
+		<attribute name="name" type="string"/>
+		<attribute name="cache-directory" type="string"/>
+	</complexType>
+
+	<complexType name="entry">
+		<sequence>
+			<element name="pixelPerDegree" type="double" />
+			<element name="east" type="double" />
+			<element name="north" type="double" />
+			<element name="lastUsed" type="date" />
+			<element name="lastModified" type="date" />
+			<element name="filename" type="string" />
+		</sequence>
+	</complexType>
+</schema>
Index: unk/src/org/openstreetmap/josm/data/imagery/wms-cache.xsd
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/imagery/wms-cache.xsd	(revision 4182)
+++ 	(revision )
@@ -1,55 +1,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://josm.openstreetmap.de/wms-cache"
-	xmlns:tns="http://josm.openstreetmap.de/wms-cache" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
-	elementFormDefault="qualified" jaxb:version="2.0">
-	
-	<annotation>
-		<appinfo>
-			<jaxb:schemaBindings>
-				<jaxb:package name="org.openstreetmap.josm.data.imagery.types">
-				</jaxb:package>
-				<jaxb:nameXmlTransform>
-					<jaxb:typeName suffix="Type" />
-					<jaxb:elementName suffix="Type" />
-				</jaxb:nameXmlTransform>
-			</jaxb:schemaBindings>
-			<jaxb:globalBindings>
-				<jaxb:javaType name="java.util.Calendar" xmlType="date"
-					parseMethod="javax.xml.bind.DatatypeConverter.parseDate"
-					printMethod="org.openstreetmap.josm.data.imagery.WmsCache.printDate" />
-			</jaxb:globalBindings>
-		</appinfo>
-	</annotation>
-
-	<element name="wms-cache">
-		<complexType>
-			<sequence>
-				<element name="projection" type="tns:projection" minOccurs="0"
-					maxOccurs="unbounded" />
-			</sequence>
-			<attribute name="tileSize" type="int" use="required" />
-			<attribute name="totalFileSize" type="int" use="required"/>
-		</complexType>
-	</element>
-	
-	<complexType name="projection">
-		<sequence>
-			<element name="entry" type="tns:entry" minOccurs="0" maxOccurs="unbounded"/>
-		</sequence>
-		<attribute name="name" type="string"/>
-		<attribute name="cache-directory" type="string"/>
-	</complexType>
-
-	<complexType name="entry">
-		<sequence>
-			<element name="pixelPerDegree" type="double" />
-			<element name="east" type="double" />
-			<element name="north" type="double" />
-			<element name="lastUsed" type="date" />
-			<element name="lastModified" type="date" />
-			<element name="filename" type="string" />
-		</sequence>
-	</complexType>
-</schema>
Index: /trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/Layer.java	(revision 4182)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/Layer.java	(revision 4183)
@@ -16,6 +16,8 @@
 import javax.swing.Action;
 import javax.swing.Icon;
+import javax.swing.JOptionPane;
 import javax.swing.JSeparator;
 
+import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.GpxExportAction;
 import org.openstreetmap.josm.actions.SaveAction;
@@ -75,5 +77,4 @@
     static public final String NAME_PROP = Layer.class.getName() + ".name";
 
-
     /** keeps track of property change listeners */
     protected PropertyChangeSupport propertyChangeSupport;
@@ -308,5 +309,5 @@
 
     /**
-     *
+     * Check changed status of layer
      *
      * @return True if layer was changed since last paint
@@ -314,4 +315,22 @@
     public boolean isChanged() {
         return true;
+    }
+
+    /**
+     * allows to check whether a projection is supported or not
+     *
+     * @return True if projection is supported for this layer
+     */
+    public boolean isProjectionSupported(Projection proj) {
+        return true;
+    }
+
+    /**
+     * Specify user information about projections
+     *
+     * @return User readable text telling about supported projections
+     */
+    public String nameSupportedProjections() {
+        return tr("All projections are supported");
     }
 
@@ -370,5 +389,12 @@
     @Override
     public void projectionChanged(Projection oldValue, Projection newValue) {
-        // default implementation does nothing - override in subclasses
+        if(!isProjectionSupported(newValue)) {
+              JOptionPane.showMessageDialog(Main.parent,
+                  tr("The layer {0} does not support the new projection {1}.\n{2}\n"
+                  + "Change the projection again or remove the layer.",
+                      getName(), newValue.toCode(), nameSupportedProjections()),
+                      tr("Warning"),
+                      JOptionPane.WARNING_MESSAGE);
+        }
     }
 }
Index: /trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 4182)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 4183)
@@ -34,4 +34,5 @@
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
 import javax.swing.JPopupMenu;
 import javax.swing.SwingUtilities;
@@ -62,4 +63,7 @@
 import org.openstreetmap.josm.data.preferences.IntegerProperty;
 import org.openstreetmap.josm.data.preferences.StringProperty;
+import org.openstreetmap.josm.data.projection.Epsg4326;
+import org.openstreetmap.josm.data.projection.Mercator;
+import org.openstreetmap.josm.data.projection.Projection;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
@@ -314,4 +318,13 @@
     public TMSLayer(ImageryInfo info) {
         super(info);
+
+        if(!isProjectionSupported(Main.getProjection())) {
+              JOptionPane.showMessageDialog(Main.parent,
+                  tr("TMS layers do not support the projection {1}.\n{2}\n"
+                  + "Change the projection or remove the layer.",
+                      Main.getProjection().toCode(), nameSupportedProjections()),
+                      tr("Warning"),
+                      JOptionPane.WARNING_MESSAGE);
+        }
 
         setBackgroundLayer(true);
@@ -1311,3 +1324,13 @@
         return needRedraw;
     }
+
+    @Override
+    public boolean isProjectionSupported(Projection proj) {
+        return proj instanceof Mercator || proj instanceof Epsg4326;
+    }
+
+    @Override
+    public String nameSupportedProjections() {
+        return tr("EPSG:4326 and Mercator projection are supported");
+    }
 }
Index: /trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java	(revision 4182)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java	(revision 4183)
@@ -38,4 +38,5 @@
 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
 import org.openstreetmap.josm.data.ProjectionBounds;
+import org.openstreetmap.josm.data.projection.Projection;
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.imagery.GeorefImage;
@@ -107,5 +108,5 @@
     private int workingThreadCount;
     private boolean canceled;
-
+    private ArrayList<String> serverProjections = null;
 
     /** set to true if this layer uses an invalid base url */
@@ -142,5 +143,5 @@
 
         if(info.getUrl() != null) {
-            WMSGrabber.getProjection(info.getUrl(), true);
+            serverProjections = WMSGrabber.getServerProjections(info.getUrl(), true);
             startGrabberThreads();
             if(info.getImageryType() == ImageryType.WMS && !ImageryInfo.isUrlWithPatterns(info.getUrl())) {
@@ -913,3 +914,18 @@
     }
 
+    @Override
+    public boolean isProjectionSupported(Projection proj) {
+        return serverProjections == null || serverProjections.contains(proj.toCode().toUpperCase());
+    }
+
+    @Override
+    public String nameSupportedProjections() {
+        String res = "";
+        for(String p : serverProjections) {
+            if(!res.isEmpty())
+                res += ", ";
+            res += p;
+        }
+        return tr("Supported projections are: {1}", res);
+    }
 }
Index: /trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java	(revision 4182)
+++ /trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java	(revision 4183)
@@ -18,4 +18,5 @@
 import java.text.DecimalFormatSymbols;
 import java.text.NumberFormat;
+import java.util.ArrayList;
 import java.util.Locale;
 import java.util.regex.Matcher;
@@ -73,5 +74,25 @@
             int wi, int ht) throws MalformedURLException {
         String myProj = Main.getProjection().toCode();
-        if(Main.getProjection() instanceof Mercator) // don't use mercator code directly
+        String srs = "";
+        boolean useepsg = false;
+        try
+        {
+            Matcher m = Pattern.compile(".*srs=([a-z0-9:]+).*").matcher(baseURL.toUpperCase());
+            if(m.matches())
+            {
+                if(m.group(1).equals("EPSG:4326") && Main.getProjection() instanceof Mercator)
+                    useepsg = true;
+            } else if(Main.getProjection() instanceof Mercator) {
+                useepsg = true;
+                srs ="&srs=EPSG:4326";
+            } else {
+                srs ="&srs="+myProj;
+            }
+        }
+        catch(Exception ex)
+        {
+        }
+
+        if(useepsg) // don't use mercator code directly
         {
             LatLon sw = Main.getProjection().eastNorth2latlon(new EastNorth(w, s));
@@ -101,5 +122,5 @@
         } else {
             str += "bbox=" + bbox
-            + getProjection(baseURL, false)
+            + srs
             + "&width=" + wi + "&height=" + ht;
             if (!(baseURL.endsWith("&") || baseURL.endsWith("?"))) {
@@ -112,34 +133,37 @@
     }
 
-    static public String getProjection(String baseURL, Boolean warn)
+    static public ArrayList<String> getServerProjections(String baseURL, Boolean warn)
     {
-        String projname = Main.getProjection().toCode();
-        if(Main.getProjection() instanceof Mercator) {
-            projname = "EPSG:4326";
-        }
-        String res = "";
+        ArrayList<String> serverProjections = new ArrayList<String>();
         try
         {
-            Matcher m = Pattern.compile(".*srs=([a-z0-9:]+).*").matcher(baseURL.toLowerCase());
+            Matcher m = Pattern.compile(".*srs=([a-z0-9:]+).*").matcher(baseURL.toUpperCase());
             if(m.matches())
             {
-                projname = projname.toLowerCase();
-                if(!projname.equals(m.group(1)) && warn)
-                {
-                    JOptionPane.showMessageDialog(Main.parent,
-                            tr("The projection ''{0}'' in URL and current projection ''{1}'' mismatch.\n"
-                                    + "This may lead to wrong coordinates.",
-                                    m.group(1), projname),
-                                    tr("Warning"),
-                                    JOptionPane.WARNING_MESSAGE);
-                }
-            } else {
-                res ="&srs="+projname;
-            }
+                serverProjections.add(m.group(1));
+                if(m.group(1).equals("EPSG:4326"))
+                    serverProjections.add(new Mercator().toCode());
+            }
+            /* TODO: here should be an "else" code checking server capabilities */
         }
         catch(Exception e)
         {
         }
-        return res;
+        if(serverProjections.isEmpty())
+            return null;
+        if(warn)
+        {
+            String myProj = Main.getProjection().toCode().toUpperCase();
+            if(!serverProjections.contains(myProj))
+            {
+                JOptionPane.showMessageDialog(Main.parent,
+                        tr("The projection ''{0}'' in URL and current projection ''{1}'' mismatch.\n"
+                                + "This may lead to wrong coordinates.",
+                                serverProjections.get(0), myProj),
+                                tr("Warning"),
+                                JOptionPane.WARNING_MESSAGE);
+            }
+        }
+        return serverProjections;
     }
 
