Index: /trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java	(revision 3776)
+++ /trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java	(revision 3777)
@@ -10,4 +10,5 @@
 import java.awt.Rectangle;
 import java.awt.Toolkit;
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -158,12 +159,13 @@
     public SlippyMapBBoxChooser() {
         super();
-        try {
-            cachedLoader = new OsmFileCacheTileLoader(this);
-        } catch (SecurityException e) {
-            // set to null if a SecurityException was thrown
-            // while creating the cachedLoader
-            //
-            cachedLoader = null;
-        }
+        cachedLoader = null;
+        String cachePath = TMSLayer.PROP_TILECACHE_DIR.get();
+        if (cachePath != null && !cachePath.isEmpty()) {
+            try {
+                cachedLoader = new OsmFileCacheTileLoader(this, new File(cachePath));
+            } catch (IOException e) {
+            }
+        }
+
         uncachedLoader = new OsmTileLoader(this);
         setZoomContolsVisible(false);
Index: /trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 3776)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 3777)
@@ -18,4 +18,5 @@
 import java.awt.geom.Rectangle2D;
 import java.awt.image.ImageObserver;
+import java.io.File;
 import java.io.IOException;
 import java.net.URI;
@@ -41,4 +42,5 @@
 import org.openstreetmap.gui.jmapviewer.MemoryTileCache;
 import org.openstreetmap.gui.jmapviewer.OsmFileCacheTileLoader;
+import org.openstreetmap.gui.jmapviewer.OsmTileLoader;
 import org.openstreetmap.gui.jmapviewer.TMSTileSource;
 import org.openstreetmap.gui.jmapviewer.TemplatedTMSTileSource;
@@ -58,4 +60,5 @@
 import org.openstreetmap.josm.data.preferences.BooleanProperty;
 import org.openstreetmap.josm.data.preferences.IntegerProperty;
+import org.openstreetmap.josm.data.preferences.StringProperty;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
@@ -85,4 +88,14 @@
     public static final BooleanProperty PROP_DRAW_DEBUG = new BooleanProperty(PREFERENCE_PREFIX + ".draw_debug", false);
     public static final BooleanProperty PROP_ADD_TO_SLIPPYMAP_CHOOSER = new BooleanProperty(PREFERENCE_PREFIX + ".add_to_slippymap_chooser", true);
+    public static final StringProperty PROP_TILECACHE_DIR;
+
+    static {
+        String defPath = null;
+        try {
+            defPath = OsmFileCacheTileLoader.getDefaultCacheDir().getAbsolutePath();
+        } catch (SecurityException e) {
+        }
+        PROP_TILECACHE_DIR = new StringProperty(PREFERENCE_PREFIX + ".tileceche_path", defPath);
+    }
 
     boolean debug = false;
@@ -257,6 +270,15 @@
 
         clearTileCache();
-        //tileloader = new OsmTileLoader(this);
-        tileLoader = new OsmFileCacheTileLoader(this);
+        String cachePath = TMSLayer.PROP_TILECACHE_DIR.get();
+        tileLoader = null;
+        if (cachePath != null && !cachePath.isEmpty()) {
+            try {
+                tileLoader = new OsmFileCacheTileLoader(this, new File(cachePath));
+            } catch (IOException e) {
+            }
+        }
+        if (tileLoader == null) {
+            tileLoader = new OsmTileLoader(this);
+        }
     }
 
Index: /trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java	(revision 3776)
+++ /trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java	(revision 3777)
@@ -37,4 +37,5 @@
 import javax.swing.JTabbedPane;
 import javax.swing.JTable;
+import javax.swing.JTextField;
 import javax.swing.SpinnerNumberModel;
 import javax.swing.table.DefaultTableModel;
@@ -43,7 +44,7 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.imagery.ImageryInfo;
-import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
 import org.openstreetmap.josm.data.imagery.OffsetBookmark;
+import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
 import org.openstreetmap.josm.gui.layer.ImageryLayer;
 import org.openstreetmap.josm.gui.layer.TMSLayer;
@@ -83,4 +84,5 @@
     private JSpinner maxZoomLvl;
     private JCheckBox addToSlippyMapChosser = new JCheckBox();
+    private JTextField tilecacheDir = new JTextField();
 
     private JPanel buildCommonSettingsPanel(final PreferenceTabbedPane gui) {
@@ -191,32 +193,39 @@
 
         tmsTab.add(new JLabel(tr("Auto zoom by default: ")), GBC.std());
-        tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
+        tmsTab.add(GBC.glue(5, 0), GBC.std());
         tmsTab.add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL));
 
         tmsTab.add(new JLabel(tr("Autoload tiles by default: ")), GBC.std());
-        tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
+        tmsTab.add(GBC.glue(5, 0), GBC.std());
         tmsTab.add(autoloadTiles, GBC.eol().fill(GBC.HORIZONTAL));
 
         tmsTab.add(new JLabel(tr("Min zoom lvl: ")), GBC.std());
-        tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
-        tmsTab.add(this.minZoomLvl, GBC.eol().fill(GBC.HORIZONTAL));
+        tmsTab.add(GBC.glue(5, 0), GBC.std());
+        tmsTab.add(this.minZoomLvl, GBC.eol());
 
         tmsTab.add(new JLabel(tr("Max zoom lvl: ")), GBC.std());
-        tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
-        tmsTab.add(this.maxZoomLvl, GBC.eol().fill(GBC.HORIZONTAL));
+        tmsTab.add(GBC.glue(5, 0), GBC.std());
+        tmsTab.add(this.maxZoomLvl, GBC.eol());
 
         tmsTab.add(new JLabel(tr("Add to slippymap chooser: ")), GBC.std());
-        tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
+        tmsTab.add(GBC.glue(5, 0), GBC.std());
         tmsTab.add(addToSlippyMapChosser, GBC.eol().fill(GBC.HORIZONTAL));
 
+        tmsTab.add(new JLabel(tr("Tile cache directory: ")), GBC.std());
+        tmsTab.add(GBC.glue(5, 0), GBC.std());
+        tmsTab.add(tilecacheDir, GBC.eol().fill(GBC.HORIZONTAL));
+
         return tmsTab;
     }
 
     private void addSettingsSection(final JPanel p, String name, JPanel section) {
+        addSettingsSection(p, name, section, GBC.eol());
+    }
+    private void addSettingsSection(final JPanel p, String name, JPanel section, GBC gbc) {
         final JLabel lbl = new JLabel(name);
         lbl.setFont(lbl.getFont().deriveFont(Font.BOLD));
         p.add(lbl,GBC.std());
         p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0));
-        p.add(section,GBC.eol().insets(20,5,0,10));
+        p.add(section, gbc.insets(20,5,0,10));
     }
 
@@ -227,5 +236,6 @@
         addSettingsSection(p, tr("Common Settings"), buildCommonSettingsPanel(gui));
         addSettingsSection(p, tr("WMS Settings"), buildWMSSettingsPanel());
-        addSettingsSection(p, tr("TMS Settings"), buildTMSSettingsPanel());
+        addSettingsSection(p, tr("TMS Settings"), buildTMSSettingsPanel(),
+                GBC.eol().fill(GBC.HORIZONTAL));
 
         p.add(new JPanel(),GBC.eol().fill(GBC.BOTH));
@@ -268,4 +278,5 @@
         this.maxZoomLvl.setValue(TMSLayer.getMaxZoomLvl(null));
         this.minZoomLvl.setValue(TMSLayer.getMinZoomLvl(null));
+        this.tilecacheDir.setText(TMSLayer.PROP_TILECACHE_DIR.get());
     }
 
@@ -293,4 +304,5 @@
         TMSLayer.setMaxZoomLvl((Integer)this.maxZoomLvl.getValue());
         TMSLayer.setMinZoomLvl((Integer)this.minZoomLvl.getValue());
+        TMSLayer.PROP_TILECACHE_DIR.put(this.tilecacheDir.getText());
 
         ImageryLayer.PROP_FADE_AMOUNT.put(this.fadeAmount.getValue());
