Index: trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 5260)
+++ trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 5261)
@@ -67,4 +67,5 @@
 import org.openstreetmap.josm.data.preferences.StringProperty;
 import org.openstreetmap.josm.data.projection.Projection;
+import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
@@ -124,6 +125,5 @@
     HashSet<Tile> tileRequestsOutstanding = new HashSet<Tile>();
     @Override
-    public synchronized void tileLoadingFinished(Tile tile, boolean success)
-    {
+    public synchronized void tileLoadingFinished(Tile tile, boolean success) {
         if (tile.hasError()) {
             success = false;
@@ -143,6 +143,5 @@
     
     @Override
-    public TileCache getTileCache()
-    {
+    public TileCache getTileCache() {
         return tileCache;
     }
@@ -189,6 +188,16 @@
     }
 
-    void clearTileCache(ProgressMonitor monitor)
-    {
+    /**
+     * Clears the tile cache.
+     * 
+     * If the current tileLoader is an instance of OsmTileLoader, a new 
+     * TmsTileClearController is created and passed to the according clearCache 
+     * method.
+     * 
+     * @param monitor 
+     * @see MemoryTileCache#clear()
+     * @see OsmFileCacheTileLoader#clearCache(org.openstreetmap.gui.jmapviewer.interfaces.TileSource, org.openstreetmap.gui.jmapviewer.OsmFileCacheTileLoader.TileClearController) 
+     */
+    void clearTileCache(ProgressMonitor monitor) {
         tileCache.clear();
         if (tileLoader instanceof OsmFileCacheTileLoader) {
@@ -217,12 +226,16 @@
     protected boolean showErrors;
 
-    void redraw()
-    {
+    /**
+     * Initiates a repaint of Main.map
+     * 
+     * @see Main#map
+     * @see MapFrame#repaint() 
+     */
+    void redraw() {
         needRedraw = true;
         Main.map.repaint();
     }
 
-    static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts)
-    {
+    static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts) {
         if(maxZoomLvl > MAX_ZOOM) {
             /*Main.debug("Max. zoom level should not be more than 30! Setting to 30.");*/
@@ -239,6 +252,5 @@
     }
 
-    public static int getMaxZoomLvl(TileSource ts)
-    {
+    public static int getMaxZoomLvl(TileSource ts) {
         return checkMaxZoomLvl(PROP_MAX_ZOOM_LVL.get(), ts);
     }
@@ -249,6 +261,5 @@
     }
 
-    static int checkMinZoomLvl(int minZoomLvl, TileSource ts)
-    {
+    static int checkMinZoomLvl(int minZoomLvl, TileSource ts) {
         if(minZoomLvl < MIN_ZOOM) {
             /*Main.debug("Min. zoom level should not be less than "+MIN_ZOOM+"! Setting to that.");*/
@@ -266,6 +277,5 @@
     }
 
-    public static int getMinZoomLvl(TileSource ts)
-    {
+    public static int getMinZoomLvl(TileSource ts) {
         return checkMinZoomLvl(PROP_MIN_ZOOM_LVL.get(), ts);
     }
@@ -317,4 +327,16 @@
     }
 
+    /**
+     * Creates and returns a new TileSource instance depending on the {@link ImageryType}
+     * of the passed ImageryInfo object.
+     * 
+     * If no appropriate TileSource is found, null is returned.
+     * Currently supported ImageryType are {@link ImageryType#TMS}, 
+     * {@link ImageryType#BING}, {@link ImageryType#SCANEX}.
+     * 
+     * @param info
+     * @return a new TileSource instance or null if no TileSource for the ImageryInfo/ImageryType could be found.
+     * @throws IllegalArgumentException 
+     */
     public static TileSource getTileSource(ImageryInfo info) throws IllegalArgumentException {
         if (info.getImageryType() == ImageryType.TMS) {
@@ -351,6 +373,5 @@
     }
 
-    private void initTileSource(TileSource tileSource)
-    {
+    private void initTileSource(TileSource tileSource) {
         this.tileSource = tileSource;
         attribution.initialize(tileSource);
@@ -624,6 +645,5 @@
     }
 
-    void zoomChanged()
-    {
+    void zoomChanged() {
         /*if (debug) {
             Main.debug("zoomChanged(): " + currentZoomLevel);
@@ -634,6 +654,5 @@
     }
 
-    int getMaxZoomLvl()
-    {
+    int getMaxZoomLvl() {
         if (info.getMaxZoom() != 0)
             return checkMaxZoomLvl(info.getMaxZoom(), tileSource);
@@ -642,6 +661,5 @@
     }
 
-    int getMinZoomLvl()
-    {
+    int getMinZoomLvl() {
         return getMinZoomLvl(tileSource);
     }
@@ -652,6 +670,5 @@
      * @return    true, if zoom increasing was successfull, false othervise
      */
-    public boolean zoomIncreaseAllowed()
-    {
+    public boolean zoomIncreaseAllowed() {
         boolean zia = currentZoomLevel < this.getMaxZoomLvl();
         /*if (debug) {
@@ -660,6 +677,6 @@
         return zia;
     }
-    public boolean increaseZoomLevel()
-    {
+    
+    public boolean increaseZoomLevel() {
         if (zoomIncreaseAllowed()) {
             currentZoomLevel++;
@@ -676,6 +693,5 @@
     }
 
-    public boolean setZoomLevel(int zoom)
-    {
+    public boolean setZoomLevel(int zoom) {
         if (zoom == currentZoomLevel) return true;
         if (zoom > this.getMaxZoomLvl()) return false;
@@ -691,8 +707,8 @@
      * @return    true, if zoom increasing was successfull, false othervise
      */
-    public boolean zoomDecreaseAllowed()
-    {
+    public boolean zoomDecreaseAllowed() {
         return currentZoomLevel > this.getMinZoomLvl();
     }
+    
     public boolean decreaseZoomLevel() {
         //int minZoom = this.getMinZoomLvl();
@@ -724,4 +740,5 @@
         return new Tile(tileSource, x, y, zoom);
     }
+    
     synchronized Tile getOrCreateTile(int x, int y, int zoom) {
         Tile tile = getTile(x, y, zoom);
@@ -746,6 +763,5 @@
     }
 
-    synchronized boolean loadTile(Tile tile, boolean force)
-    {
+    synchronized boolean loadTile(Tile tile, boolean force) {
         if (tile == null)
             return false;
@@ -803,4 +819,5 @@
         return !done;
     }
+    
     boolean imageLoaded(Image i) {
         if (i == null)
@@ -811,6 +828,13 @@
         return false;
     }
-    Image getLoadedTileImage(Tile tile)
-    {
+    
+    /**
+     * Returns the image for the given tile if both tile and image are loaded. 
+     * Otherwise returns  null.
+     * 
+     * @param tile the Tile for which the image should be returned
+     * @return  the image of the tile or null.
+     */
+    Image getLoadedTileImage(Tile tile) {
         if (!tile.isLoaded())
             return null;
@@ -821,6 +845,5 @@
     }
 
-    LatLon tileLatLon(Tile t)
-    {
+    LatLon tileLatLon(Tile t) {
         int zoom = t.getZoom();
         return new LatLon(tileSource.tileYToLat(t.getYtile(), zoom),
@@ -828,6 +851,5 @@
     }
 
-    Rectangle tileToRect(Tile t1)
-    {
+    Rectangle tileToRect(Tile t1) {
         /*
          * We need to get a box in which to draw, so advance by one tile in
@@ -847,6 +869,5 @@
     // 'border' is the screen cordinates that need to be drawn.
     //  We must not draw outside of it.
-    void drawImageInside(Graphics g, Image sourceImg, Rectangle source, Rectangle border)
-    {
+    void drawImageInside(Graphics g, Image sourceImg, Rectangle source, Rectangle border) {
         Rectangle target = source;
 
@@ -899,4 +920,5 @@
         }
     }
+    
     // This function is called for several zoom levels, not just
     // the current one.  It should not trigger any tiles to be
@@ -1018,4 +1040,5 @@
         return Main.map.mapView.getPoint(Main.getProjection().latlon2eastNorth(ll).add(getDx(), getDy()));
     }
+    
     private Point pixelPos(Tile t) {
         double lon = tileSource.tileXToLon(t.getXtile(), t.getZoom());
@@ -1023,7 +1046,9 @@
         return pixelPos(tmpLL);
     }
+    
     private LatLon getShiftedLatLon(EastNorth en) {
         return Main.getProjection().eastNorth2latlon(en.add(-getDx(), -getDy()));
     }
+    
     private Coordinate getShiftedCoord(EastNorth en) {
         LatLon ll = getShiftedLatLon(en);
@@ -1080,13 +1105,17 @@
             }
         }
+        
         boolean tooSmall() {
             return this.tilesSpanned() < 2.1;
         }
+        
         boolean tooLarge() {
             return this.tilesSpanned() > 10;
         }
+        
         boolean insane() {
             return this.tilesSpanned() > 100;
         }
+        
         double tilesSpanned() {
             return Math.sqrt(1.0 * this.size());
@@ -1103,14 +1132,13 @@
          * already in the tileCache.
          */
-        List<Tile> allExistingTiles()
-        {
+        List<Tile> allExistingTiles() {
             return this.__allTiles(false);
         }
-        List<Tile> allTilesCreate()
-        {
+        
+        List<Tile> allTilesCreate() {
             return this.__allTiles(true);
         }
-        private List<Tile> __allTiles(boolean create)
-        {
+        
+        private List<Tile> __allTiles(boolean create) {
             // Tileset is either empty or too large
             if (zoom == 0 || this.insane())
@@ -1132,6 +1160,6 @@
             return ret;
         }
-        private List<Tile> allLoadedTiles()
-        {
+        
+        private List<Tile> allLoadedTiles() {
             List<Tile> ret = new ArrayList<Tile>();
             for (Tile t : this.allExistingTiles()) {
@@ -1142,6 +1170,5 @@
         }
 
-        void loadAllTiles(boolean force)
-        {
+        void loadAllTiles(boolean force) {
             if (!autoLoad && !force)
                 return;
@@ -1151,6 +1178,5 @@
         }
 
-        void loadAllErrorTiles(boolean force)
-        {
+        void loadAllErrorTiles(boolean force) {
             if (!autoLoad && !force)
                 return;
@@ -1224,6 +1250,4 @@
     }
 
-    /**
-     */
     @Override
     public void paint(Graphics2D g, MapView mv, Bounds bounds) {
