001// License: GPL. For details, see Readme.txt file.
002package org.openstreetmap.gui.jmapviewer.interfaces;
003
004import org.openstreetmap.gui.jmapviewer.JMapViewer;
005import org.openstreetmap.gui.jmapviewer.Tile;
006
007/**
008 * Implement this interface for creating your custom tile cache for
009 * {@link JMapViewer}.
010 *
011 * @author Jan Peter Stotz
012 */
013public interface TileCache {
014
015    /**
016     * Retrieves a tile from the cache if present, otherwise <code>null</code>
017     * will be returned.
018     *
019     * @param source
020     *            the tile source
021     * @param x
022     *            tile number on the x axis of the tile to be retrieved
023     * @param y
024     *            tile number on the y axis of the tile to be retrieved
025     * @param z
026     *            zoom level of the tile to be retrieved
027     * @return the requested tile or <code>null</code> if the tile is not
028     *         present in the cache
029     */
030    public Tile getTile(TileSource source, int x, int y, int z);
031
032    /**
033     * Adds a tile to the cache. How long after adding a tile can be retrieved
034     * via {@link #getTile(TileSource, int, int, int)} is unspecified and depends on the
035     * implementation.
036     *
037     * @param tile the tile to be added
038     */
039    public void addTile(Tile tile);
040
041    /**
042     * @return the number of tiles hold by the cache
043     */
044    public int getTileCount();
045
046    /**
047     * Clears the cache deleting all tiles from memory.
048     */
049    public void clear();
050}