org.openstreetmap.gui.jmapviewer
Class Tile

java.lang.Object
  extended by org.openstreetmap.gui.jmapviewer.Tile

public class Tile
extends java.lang.Object

Holds one map tile. Additionally the code for loading the tile image and painting it is also included in this class.


Field Summary
protected  boolean error
           
static java.awt.image.BufferedImage ERROR_IMAGE
           
protected  java.lang.String error_message
           
protected  java.awt.image.BufferedImage image
           
protected  java.lang.String key
           
protected  boolean loaded
           
protected  boolean loading
           
static java.awt.image.BufferedImage LOADING_IMAGE
          Hourglass image that is displayed until a map tile has been loaded
protected  java.util.Map<java.lang.String,java.lang.String> metadata
          TileLoader-specific tile metadata
protected  TileSource source
           
protected  int xtile
           
protected  int ytile
           
protected  int zoom
           
 
Constructor Summary
Tile(TileSource source, int xtile, int ytile, int zoom)
          Creates a tile with empty image.
Tile(TileSource source, int xtile, int ytile, int zoom, java.awt.image.BufferedImage image)
           
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compares this object with obj based on the fields xtile, ytile and zoom.
 java.lang.String getErrorMessage()
           
 java.awt.image.BufferedImage getImage()
           
 java.lang.String getKey()
           
 java.util.Map<java.lang.String,java.lang.String> getMetadata()
           
 TileSource getSource()
           
 java.lang.String getStatus()
           
static java.lang.String getTileKey(TileSource source, int xtile, int ytile, int zoom)
           
 java.lang.String getUrl()
           
 java.lang.String getValue(java.lang.String key)
           
 int getXtile()
           
 int getYtile()
           
 int getZoom()
           
 boolean hasError()
           
 int hashCode()
          Note that the hash code does not include the source.
 boolean isLoaded()
           
 boolean isLoading()
           
 void loadImage(java.io.InputStream input)
           
 void loadPlaceholderFromCache(TileCache cache)
          Tries to get tiles of a lower or higher zoom level (one or two level difference) from cache and use it as a placeholder until the tile has been loaded.
 void paint(java.awt.Graphics g, int x, int y)
          Paints the tile-image on the Graphics g at the position x/y.
 void putValue(java.lang.String key, java.lang.String value)
          Puts the given key/value pair to the metadata of the tile.
 void setError(java.lang.String message)
           
 void setImage(java.awt.image.BufferedImage image)
           
 void setLoaded(boolean loaded)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOADING_IMAGE

public static java.awt.image.BufferedImage LOADING_IMAGE
Hourglass image that is displayed until a map tile has been loaded


ERROR_IMAGE

public static java.awt.image.BufferedImage ERROR_IMAGE

source

protected TileSource source

xtile

protected int xtile

ytile

protected int ytile

zoom

protected int zoom

image

protected java.awt.image.BufferedImage image

key

protected java.lang.String key

loaded

protected boolean loaded

loading

protected boolean loading

error

protected boolean error

error_message

protected java.lang.String error_message

metadata

protected java.util.Map<java.lang.String,java.lang.String> metadata
TileLoader-specific tile metadata

Constructor Detail

Tile

public Tile(TileSource source,
            int xtile,
            int ytile,
            int zoom)
Creates a tile with empty image.

Parameters:
source -
xtile -
ytile -
zoom -

Tile

public Tile(TileSource source,
            int xtile,
            int ytile,
            int zoom,
            java.awt.image.BufferedImage image)
Method Detail

loadPlaceholderFromCache

public void loadPlaceholderFromCache(TileCache cache)
Tries to get tiles of a lower or higher zoom level (one or two level difference) from cache and use it as a placeholder until the tile has been loaded.


getSource

public TileSource getSource()

getXtile

public int getXtile()
Returns:
tile number on the x axis of this tile

getYtile

public int getYtile()
Returns:
tile number on the y axis of this tile

getZoom

public int getZoom()
Returns:
zoom level of this tile

getImage

public java.awt.image.BufferedImage getImage()

setImage

public void setImage(java.awt.image.BufferedImage image)

loadImage

public void loadImage(java.io.InputStream input)
               throws java.io.IOException
Throws:
java.io.IOException

getKey

public java.lang.String getKey()
Returns:
key that identifies a tile

isLoaded

public boolean isLoaded()

isLoading

public boolean isLoading()

setLoaded

public void setLoaded(boolean loaded)

getUrl

public java.lang.String getUrl()
                        throws java.io.IOException
Throws:
java.io.IOException

paint

public void paint(java.awt.Graphics g,
                  int x,
                  int y)
Paints the tile-image on the Graphics g at the position x/y.

Parameters:
g -
x - x-coordinate in g
y - y-coordinate in g

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Note that the hash code does not include the source. Therefore a hash based collection can only contain tiles of one source.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Compares this object with obj based on the fields xtile, ytile and zoom. The source field is ignored.

Overrides:
equals in class java.lang.Object

getTileKey

public static java.lang.String getTileKey(TileSource source,
                                          int xtile,
                                          int ytile,
                                          int zoom)

getStatus

public java.lang.String getStatus()

hasError

public boolean hasError()

getErrorMessage

public java.lang.String getErrorMessage()

setError

public void setError(java.lang.String message)

putValue

public void putValue(java.lang.String key,
                     java.lang.String value)
Puts the given key/value pair to the metadata of the tile. If value is null, the (possibly existing) key/value pair is removed from the meta data.

Parameters:
key -
value -

getValue

public java.lang.String getValue(java.lang.String key)

getMetadata

public java.util.Map<java.lang.String,java.lang.String> getMetadata()


JOSM