Changeset 3777 in josm


Ignore:
Timestamp:
Jan 7, 2011 3:38:27 PM (2 years ago)
Author:
Upliner
Message:

Add ability to set tilecache directory

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r3725 r3777  
    1010import java.awt.Rectangle; 
    1111import java.awt.Toolkit; 
     12import java.io.File; 
    1213import java.io.IOException; 
    1314import java.util.ArrayList; 
     
    158159    public SlippyMapBBoxChooser() { 
    159160        super(); 
    160         try { 
    161             cachedLoader = new OsmFileCacheTileLoader(this); 
    162         } catch (SecurityException e) { 
    163             // set to null if a SecurityException was thrown 
    164             // while creating the cachedLoader 
    165             // 
    166             cachedLoader = null; 
    167         } 
     161        cachedLoader = null; 
     162        String cachePath = TMSLayer.PROP_TILECACHE_DIR.get(); 
     163        if (cachePath != null && !cachePath.isEmpty()) { 
     164            try { 
     165                cachedLoader = new OsmFileCacheTileLoader(this, new File(cachePath)); 
     166            } catch (IOException e) { 
     167            } 
     168        } 
     169 
    168170        uncachedLoader = new OsmTileLoader(this); 
    169171        setZoomContolsVisible(false); 
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r3774 r3777  
    1818import java.awt.geom.Rectangle2D; 
    1919import java.awt.image.ImageObserver; 
     20import java.io.File; 
    2021import java.io.IOException; 
    2122import java.net.URI; 
     
    4142import org.openstreetmap.gui.jmapviewer.MemoryTileCache; 
    4243import org.openstreetmap.gui.jmapviewer.OsmFileCacheTileLoader; 
     44import org.openstreetmap.gui.jmapviewer.OsmTileLoader; 
    4345import org.openstreetmap.gui.jmapviewer.TMSTileSource; 
    4446import org.openstreetmap.gui.jmapviewer.TemplatedTMSTileSource; 
     
    5860import org.openstreetmap.josm.data.preferences.BooleanProperty; 
    5961import org.openstreetmap.josm.data.preferences.IntegerProperty; 
     62import org.openstreetmap.josm.data.preferences.StringProperty; 
    6063import org.openstreetmap.josm.gui.MapView; 
    6164import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 
     
    8588    public static final BooleanProperty PROP_DRAW_DEBUG = new BooleanProperty(PREFERENCE_PREFIX + ".draw_debug", false); 
    8689    public static final BooleanProperty PROP_ADD_TO_SLIPPYMAP_CHOOSER = new BooleanProperty(PREFERENCE_PREFIX + ".add_to_slippymap_chooser", true); 
     90    public static final StringProperty PROP_TILECACHE_DIR; 
     91 
     92    static { 
     93        String defPath = null; 
     94        try { 
     95            defPath = OsmFileCacheTileLoader.getDefaultCacheDir().getAbsolutePath(); 
     96        } catch (SecurityException e) { 
     97        } 
     98        PROP_TILECACHE_DIR = new StringProperty(PREFERENCE_PREFIX + ".tileceche_path", defPath); 
     99    } 
    87100 
    88101    boolean debug = false; 
     
    257270 
    258271        clearTileCache(); 
    259         //tileloader = new OsmTileLoader(this); 
    260         tileLoader = new OsmFileCacheTileLoader(this); 
     272        String cachePath = TMSLayer.PROP_TILECACHE_DIR.get(); 
     273        tileLoader = null; 
     274        if (cachePath != null && !cachePath.isEmpty()) { 
     275            try { 
     276                tileLoader = new OsmFileCacheTileLoader(this, new File(cachePath)); 
     277            } catch (IOException e) { 
     278            } 
     279        } 
     280        if (tileLoader == null) { 
     281            tileLoader = new OsmTileLoader(this); 
     282        } 
    261283    } 
    262284 
  • trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java

    r3737 r3777  
    3737import javax.swing.JTabbedPane; 
    3838import javax.swing.JTable; 
     39import javax.swing.JTextField; 
    3940import javax.swing.SpinnerNumberModel; 
    4041import javax.swing.table.DefaultTableModel; 
     
    4344import org.openstreetmap.josm.Main; 
    4445import org.openstreetmap.josm.data.imagery.ImageryInfo; 
    45 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 
    4646import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 
    4747import org.openstreetmap.josm.data.imagery.OffsetBookmark; 
     48import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 
    4849import org.openstreetmap.josm.gui.layer.ImageryLayer; 
    4950import org.openstreetmap.josm.gui.layer.TMSLayer; 
     
    8384    private JSpinner maxZoomLvl; 
    8485    private JCheckBox addToSlippyMapChosser = new JCheckBox(); 
     86    private JTextField tilecacheDir = new JTextField(); 
    8587 
    8688    private JPanel buildCommonSettingsPanel(final PreferenceTabbedPane gui) { 
     
    191193 
    192194        tmsTab.add(new JLabel(tr("Auto zoom by default: ")), GBC.std()); 
    193         tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 
     195        tmsTab.add(GBC.glue(5, 0), GBC.std()); 
    194196        tmsTab.add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL)); 
    195197 
    196198        tmsTab.add(new JLabel(tr("Autoload tiles by default: ")), GBC.std()); 
    197         tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 
     199        tmsTab.add(GBC.glue(5, 0), GBC.std()); 
    198200        tmsTab.add(autoloadTiles, GBC.eol().fill(GBC.HORIZONTAL)); 
    199201 
    200202        tmsTab.add(new JLabel(tr("Min zoom lvl: ")), GBC.std()); 
    201         tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 
    202         tmsTab.add(this.minZoomLvl, GBC.eol().fill(GBC.HORIZONTAL)); 
     203        tmsTab.add(GBC.glue(5, 0), GBC.std()); 
     204        tmsTab.add(this.minZoomLvl, GBC.eol()); 
    203205 
    204206        tmsTab.add(new JLabel(tr("Max zoom lvl: ")), GBC.std()); 
    205         tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 
    206         tmsTab.add(this.maxZoomLvl, GBC.eol().fill(GBC.HORIZONTAL)); 
     207        tmsTab.add(GBC.glue(5, 0), GBC.std()); 
     208        tmsTab.add(this.maxZoomLvl, GBC.eol()); 
    207209 
    208210        tmsTab.add(new JLabel(tr("Add to slippymap chooser: ")), GBC.std()); 
    209         tmsTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 
     211        tmsTab.add(GBC.glue(5, 0), GBC.std()); 
    210212        tmsTab.add(addToSlippyMapChosser, GBC.eol().fill(GBC.HORIZONTAL)); 
    211213 
     214        tmsTab.add(new JLabel(tr("Tile cache directory: ")), GBC.std()); 
     215        tmsTab.add(GBC.glue(5, 0), GBC.std()); 
     216        tmsTab.add(tilecacheDir, GBC.eol().fill(GBC.HORIZONTAL)); 
     217 
    212218        return tmsTab; 
    213219    } 
    214220 
    215221    private void addSettingsSection(final JPanel p, String name, JPanel section) { 
     222        addSettingsSection(p, name, section, GBC.eol()); 
     223    } 
     224    private void addSettingsSection(final JPanel p, String name, JPanel section, GBC gbc) { 
    216225        final JLabel lbl = new JLabel(name); 
    217226        lbl.setFont(lbl.getFont().deriveFont(Font.BOLD)); 
    218227        p.add(lbl,GBC.std()); 
    219228        p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0)); 
    220         p.add(section,GBC.eol().insets(20,5,0,10)); 
     229        p.add(section, gbc.insets(20,5,0,10)); 
    221230    } 
    222231 
     
    227236        addSettingsSection(p, tr("Common Settings"), buildCommonSettingsPanel(gui)); 
    228237        addSettingsSection(p, tr("WMS Settings"), buildWMSSettingsPanel()); 
    229         addSettingsSection(p, tr("TMS Settings"), buildTMSSettingsPanel()); 
     238        addSettingsSection(p, tr("TMS Settings"), buildTMSSettingsPanel(), 
     239                GBC.eol().fill(GBC.HORIZONTAL)); 
    230240 
    231241        p.add(new JPanel(),GBC.eol().fill(GBC.BOTH)); 
     
    268278        this.maxZoomLvl.setValue(TMSLayer.getMaxZoomLvl(null)); 
    269279        this.minZoomLvl.setValue(TMSLayer.getMinZoomLvl(null)); 
     280        this.tilecacheDir.setText(TMSLayer.PROP_TILECACHE_DIR.get()); 
    270281    } 
    271282 
     
    293304        TMSLayer.setMaxZoomLvl((Integer)this.maxZoomLvl.getValue()); 
    294305        TMSLayer.setMinZoomLvl((Integer)this.minZoomLvl.getValue()); 
     306        TMSLayer.PROP_TILECACHE_DIR.put(this.tilecacheDir.getText()); 
    295307 
    296308        ImageryLayer.PROP_FADE_AMOUNT.put(this.fadeAmount.getValue()); 
Note: See TracChangeset for help on using the changeset viewer.