Package org.pepsoft.util.swing
Interface TileProvider
public interface TileProvider
A provider of image tiles.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddTileListener(TileListener tileListener) Register a tile listener which will be notified if the contents of a tile change.Get the coordinates of the "main area of interest" of this tile provider, if any, in tile coordinates and disregarding the current zoom level.intgetTilePriority(int x, int y) Get the priority with which a specific tile should be rendered.intGet the width and height of tiles (which must be square) in pixels.intgetZoom()Get the zoom as an exponent of two.booleanisTilePresent(int x, int y) Determines, if possible, if there is a tile present at a specified location.booleanIndicates whether the tile provider implements zooming itself (whentrue) or whether the tile consumer should implement it (whenfalse).booleanPaint the tile at the specified tile coordinates to an image.voidremoveTileListener(TileListener tileListener) Remove a previously registered tile listener.voidsetZoom(int zoom) Set the zoom as an exponent of two.
-
Method Details
-
getTileSize
int getTileSize()Get the width and height of tiles (which must be square) in pixels. The size must be a power of two!- Returns:
- The size in pixels of a tile.
-
isTilePresent
boolean isTilePresent(int x, int y) Determines, if possible, if there is a tile present at a specified location.- Parameters:
x- The X coordinate (in tiles) to check for the presence of a tile.y- The Y coordinate (in tiles) to check for the presence of a tile.- Returns:
trueif there is a tile there.
-
paintTile
Paint the tile at the specified tile coordinates to an image. The X coordinate increases to the right and the Y coordinate increases towards the bottom. An image of the correct size (or larger) will be provided on which to paint the tile. The tile provider may be requested to paint the tile in a different location on the provided image than the top left corner.The provider must paint the tile completely. The image is guaranteed to support transparency and the provider may make parts or all of the tile transparent.
The provider may fail to paint the tile for some reason, for example because a dependency is not met, in which case it should return
falseand leave the image unaltered.- Parameters:
image- The image on which to paint the tilex- The X coordinate (in tiles) of the tile to paint.y- The Y coordinate (in tiles) of the tile to paint.dx- The X coordinate at which to paint the tile in the image.dy- The Y coordinate at which to paint the tile in the image.- Returns:
trueif the tile was painted;falseif it could not be painted for some reason.
-
getTilePriority
int getTilePriority(int x, int y) Get the priority with which a specific tile should be rendered. A tile consumer may choose to render higher priority tiles before lower priority tiles. It is entirely up to the tile provider which values to return, or even to always return the same value.- Parameters:
x- The X coordinate (in tiles) of the tile.y- The Y coordinate (in tiles) of the tile.- Returns:
- The priority of the specified tile.
-
getExtent
Rectangle getExtent()Get the coordinates of the "main area of interest" of this tile provider, if any, in tile coordinates and disregarding the current zoom level. Note that the tile provider is still free to provide tiles outside this area. If the tile provider has no distinguishable area of interest (because it is endless, for instance), it may return null.- Returns:
- The coordinates of the main area of interest of this tile provider.
-
addTileListener
Register a tile listener which will be notified if the contents of a tile change.- Parameters:
tileListener- The tile listener to register.
-
removeTileListener
Remove a previously registered tile listener.- Parameters:
tileListener- The tile listener to remove.
-
isZoomSupported
boolean isZoomSupported()Indicates whether the tile provider implements zooming itself (whentrue) or whether the tile consumer should implement it (whenfalse). In the latter casegetZoom()andsetZoom(int)will never be invoked.- Returns:
trueif the tile provider implements zooming.
-
getZoom
int getZoom()Get the zoom as an exponent of two. In other words the tiles will be displayed at a scale of 1:2^n, so that n=-1 means half size, n=0 means 1:1 and 1 means double size, etc.- Returns:
- The zoom as an exponent of two.
-
setZoom
void setZoom(int zoom) Set the zoom as an exponent of two. In other words the tiles will be displayed at a scale of 1:2^n, so that n=-1 means half size, n=0 means 1:1 and 1 means double size, etc.- Parameters:
zoom- The zoom as an exponent of two.
-