|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.media.tile.TileSet
public abstract class TileSet
A tileset stores information on a single logical set of tiles. It provides a clean interface for
the TileManager or other entities to retrieve individual tiles from the tile set and
encapsulates the potentially sophisticated process of extracting the tile image from a composite
tileset image.
Tiles are referenced by their tile id. The tile id is essentially the tile number, assuming the tile at the top-left of the image is tile id zero and tiles are numbered, in ascending order, left to right, top to bottom.
This class is serializable and will be serialized, so derived classes should be sure to mark
non-persistent fields as transient.
| Nested Class Summary | |
|---|---|
static interface |
TileSet.Colorizer
Used to assign colorizations to tiles that require them. |
| Field Summary | |
|---|---|
protected static Map<Tile.Key,SoftReference<Tile>> |
_atiles
A map containing weak references to all "active" tiles. |
protected static Throttle |
_cacheStatThrottle
Throttle our cache status logging to once every 300 seconds. |
protected String |
_imagePath
The path to the file containing the tile images. |
protected ImageProvider |
_improv
The entity from which we obtain our tile image. |
protected static Tile.Key |
_key
A key used to look things up in the cache without creating craploads of keys unduly. |
protected String |
_name
The tileset name. |
protected Colorization[] |
_zations
Colorizations to be applied to tiles created from this tileset. |
| Constructor Summary | |
|---|---|
TileSet()
|
|
| Method Summary | |
|---|---|
protected boolean |
checkTileIndex(int tileIndex)
Used to ensure that the specified tile index is valid. |
TileSet |
clone(Colorization[] zations)
Creates a copy of this tileset which will apply the supplied colorizations to its tileset image when creating tiles. |
TileSet |
clone(String imagePath)
Returns a new tileset that is a clone of this tileset with the image path updated to reference the given path. |
abstract Rectangle |
computeTileBounds(int tileIndex,
Rectangle bounds)
Computes and fills in the bounds for the specified tile based on the mechanism used by the derived class to do such things. |
protected Tile |
createTile()
Creates a blank tile of the appropriate type for this tileset. |
protected Colorization[] |
getColorizations(int tileIndex,
TileSet.Colorizer rizer)
Returns colorizations for the specified tile image. |
String |
getImagePath()
Returns the path to the composite image used by this tileset. |
String |
getName()
Returns the tileset name. |
BufferedImage |
getRawTileImage(int tileIndex)
Returns the raw (unprepared) image that would be used by the tile at the specified index. |
BufferedImage |
getRawTileSetImage()
Returns the entire, raw, uncut, unprepared tileset source image. |
Tile |
getTile(int tileIndex)
Equivalent to getTile(int,Colorizer) with a null Colorizer argument. |
Tile |
getTile(int tileIndex,
Colorization[] zations)
Creates a Tile object from this tileset corresponding to the specified tile id and
returns that tile. |
Tile |
getTile(int tileIndex,
TileSet.Colorizer rizer)
Creates a Tile object from this tileset corresponding to the specified tile id and
returns that tile. |
abstract int |
getTileCount()
Returns the number of tiles in the tileset. |
Mirage |
getTileMirage(int tileIndex)
Returns a prepared version of the image that would be used by the tile at the specified index. |
Mirage |
getTileMirage(int tileIndex,
Colorization[] zations)
Returns a prepared version of the image that would be used by the tile at the specified index. |
Mirage[] |
getTileMirages()
Returns prepared versions of the images that would be used for each of the tiles. |
protected void |
initTile(Tile tile,
int tileIndex,
Colorization[] zations)
Initializes the supplied tile. |
protected void |
reportCachePerformance()
Reports statistics detailing the image manager cache performance and the current size of the cached images. |
void |
setImagePath(String imagePath)
Sets the path to the image that will be used by this tileset. |
void |
setImageProvider(ImageProvider improv)
Configures this tileset with an image provider that it can use to load its tileset image. |
void |
setName(String name)
Specifies the tileset name. |
String |
toString()
|
protected void |
toString(StringBuilder buf)
Derived classes can override this, calling super.toString(buf) and then
appending additional information to the buffer. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected String _imagePath
protected String _name
protected transient Colorization[] _zations
protected transient ImageProvider _improv
protected static Map<Tile.Key,SoftReference<Tile>> _atiles
protected static Tile.Key _key
protected static Throttle _cacheStatThrottle
| Constructor Detail |
|---|
public TileSet()
| Method Detail |
|---|
public void setImageProvider(ImageProvider improv)
TileManager.
public String getName()
public void setName(String name)
public void setImagePath(String imagePath)
getTile(int).
public String getImagePath()
public abstract int getTileCount()
public TileSet clone(Colorization[] zations)
public TileSet clone(String imagePath)
throws CloneNotSupportedException
CloneNotSupportedException
public abstract Rectangle computeTileBounds(int tileIndex,
Rectangle bounds)
tileIndex - the index of the tile whose bounds are to be computed.bounds - the rectangle object into which to fill the bounds.
public Tile getTile(int tileIndex)
getTile(int,Colorizer) with a null Colorizer argument.
public Tile getTile(int tileIndex,
TileSet.Colorizer rizer)
Tile object from this tileset corresponding to the specified tile id and
returns that tile. A null tile will never be returned, but one with an error image may be
returned if a problem occurs loading the underlying tileset image.
tileIndex - the index of the tile in the tileset. Tile indexes start with zero as the
upper left tile and increase by one as the tiles move left to right and top to bottom over
the source image.rizer - an entity that will be used to obtain colorizations for tilesets that are
recolorizable. Passing null if the tileset is known not to be recolorizable is valid.
public Tile getTile(int tileIndex,
Colorization[] zations)
Tile object from this tileset corresponding to the specified tile id and
returns that tile. A null tile will never be returned, but one with an error image may be
returned if a problem occurs loading the underlying tileset image.
tileIndex - the index of the tile in the tileset. Tile indexes start with zero as the
upper left tile and increase by one as the tiles move left to right and top to bottom over
the source image.zations - colorizations to be applied to the tile image prior to returning it. These
may be null for uncolorized images.
public Mirage getTileMirage(int tileIndex)
Tile object when all
that is desired is access to the underlying image.
public Mirage[] getTileMirages()
Tile objects when all that is
desired is access to the underlying images.
public Mirage getTileMirage(int tileIndex,
Colorization[] zations)
Tile object when all
that is desired is access to the underlying image.
public BufferedImage getRawTileSetImage()
getTile(int)), or a tile mirage (getTileMirage(int)).
public BufferedImage getRawTileImage(int tileIndex)
getTileMirage(int) because that
prepares the image for display. Only use this if you're going to do further processing and
prepare the subsequent image for display onscreen.
protected Colorization[] getColorizations(int tileIndex,
TileSet.Colorizer rizer)
clone(Colorization[]),
however derived classes may have dynamic colorization policies that look up colorization
assignments from the supplied colorizer.
protected boolean checkTileIndex(int tileIndex)
protected Tile createTile()
protected void initTile(Tile tile,
int tileIndex,
Colorization[] zations)
super.initTile().
tile - the tile to initialize.tileIndex - the index of the tile.zations - the colorizations to be used when generating the tile image.public String toString()
toString in class Objectprotected void reportCachePerformance()
protected void toString(StringBuilder buf)
super.toString(buf) and then
appending additional information to the buffer.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||