| org.geotools.image.DeferredPlanarImage
DeferredPlanarImage | final public class DeferredPlanarImage extends PlanarImage implements WritableRenderedImage,TileObserver,TileComputationListener(Code) | | A tiled image to be used by renderer when the actual image may take a while to compute. This
image wraps an arbitrary
, which may (or may not) be
some image expensive to compute. When a tile is requested (through a call to
DeferredPlanarImage.getTile but the tile is not available in the wrapped image, then this class returns some default
(usually black) tile and start the real tile computation in a background thread. When the
actual tile is available, this class fire a
TileObserver.tileUpdate tileUpdate event,
thus given a chance to a renderer to repaint again this image with the new tiles.
Simple example of use:
public class Renderer extends JPanel implements TileObserver {
private DeferredPlanarImage image;
public Renderer(RenderedImage toPaint) {
image = new DeferredPlanarImage(toPaint);
image.addTileObserver(this);
}
public void tileUpdate(WritableRenderedImage source,
int tileX, int tileY, boolean willBeWritable)
{
repaint();
}
public void paint(Graphics gr) {
((Graphics2D) gr).drawRenderedImage(image);
}
}
since: 2.3 version: $Id: DeferredPlanarImage.java 27862 2007-11-12 19:51:19Z desruisseaux $ author: Remi Eve author: Martin Desruisseaux |
Constructor Summary | |
public | DeferredPlanarImage(RenderedImage source) Constructs a new instance of
DeferredPlanarImage . |
Method Summary | |
public synchronized void | addTileObserver(TileObserver observer) Adds an observer. | public synchronized void | dispose() Provides a hint that this image will no longer be accessed from a reference in user space. | public synchronized Raster | getTile(int tileX, int tileY) Returns the specified tile, or a default one if the requested tile is not yet available.
If the requested tile is not immediately available, then an empty tile is returned and
a notification will be sent later through
TileObserver when the real tile will
be available.
Parameters: tileX - Tile X index. Parameters: tileY - Tile Y index. | public WritableRaster | getWritableTile(int tileX, int tileY) Checks out a tile for writing. | public synchronized Point[] | getWritableTileIndices() Returns an array of
Point objects indicating which tiles are
checked out for writing. | public boolean | hasTileWriters() Returns whether any tile is checked out for writing. | public boolean | isTileWritable(int tileX, int tileY) Returns whether a tile is currently checked out for writing. | public void | releaseWritableTile(int tileX, int tileY) Relinquishes the right to write to a tile. | public synchronized void | removeTileObserver(TileObserver observer) Removes an observer. | public void | setData(Raster r) Sets a rectangle of the image to the contents of the raster. | public void | tileCancelled(Object eventSource, TileRequest[] requests, PlanarImage image, int tileX, int tileY) Invoked when a tile computation has been cancelled. | public void | tileComputationFailure(Object eventSource, TileRequest[] requests, PlanarImage image, int tileX, int tileY, Throwable cause) Invoked when a tile computation failed. | public void | tileComputed(Object eventSource, TileRequest[] requests, PlanarImage image, int tileX, int tileY, Raster tile) Invoked when a tile has been computed. | public void | tileUpdate(WritableRenderedImage source, int tileX, int tileY, boolean willBeWritable) Invoked if the underlying image is writable and one of its tile changed. |
DeferredPlanarImage | public DeferredPlanarImage(RenderedImage source)(Code) | | Constructs a new instance of
DeferredPlanarImage .
Parameters: source - The source image. |
addTileObserver | public synchronized void addTileObserver(TileObserver observer)(Code) | | Adds an observer. This observer will be notified everytime a tile initially empty become
available. If the observer is already present, it will receive multiple notifications.
|
dispose | public synchronized void dispose()(Code) | | Provides a hint that this image will no longer be accessed from a reference in user space.
NOTE: this method dispose the image given to the constructor as well.
This is because
DeferredPlanarImage is used as a "view" of an other
image, and the user shouldn't know that he is not using directly the other image.
|
getTile | public synchronized Raster getTile(int tileX, int tileY)(Code) | | Returns the specified tile, or a default one if the requested tile is not yet available.
If the requested tile is not immediately available, then an empty tile is returned and
a notification will be sent later through
TileObserver when the real tile will
be available.
Parameters: tileX - Tile X index. Parameters: tileY - Tile Y index. The requested tile. |
getWritableTile | public WritableRaster getWritableTile(int tileX, int tileY)(Code) | | Checks out a tile for writing. Since
DeferredPlanarImage are not really
writable, this method throws an
UnsupportedOperationException .
|
getWritableTileIndices | public synchronized Point[] getWritableTileIndices()(Code) | | Returns an array of
Point objects indicating which tiles are
checked out for writing. Returns null if none are checked out.
|
hasTileWriters | public boolean hasTileWriters()(Code) | | Returns whether any tile is checked out for writing.
|
isTileWritable | public boolean isTileWritable(int tileX, int tileY)(Code) | | Returns whether a tile is currently checked out for writing.
|
releaseWritableTile | public void releaseWritableTile(int tileX, int tileY)(Code) | | Relinquishes the right to write to a tile. Since
DeferredPlanarImage are
not really writable, this method throws an
IllegalStateException (the state is
really illegal since
DeferredPlanarImage.getWritableTile should never have succeeded).
|
removeTileObserver | public synchronized void removeTileObserver(TileObserver observer)(Code) | | Removes an observer. If the observer was not registered, nothing happens.
If the observer was registered for multiple notifications, it will now be
registered for one fewer.
|
setData | public void setData(Raster r)(Code) | | Sets a rectangle of the image to the contents of the raster. Since
DeferredPlanarImage are not really writable, this method
throws an
UnsupportedOperationException .
|
tileCancelled | public void tileCancelled(Object eventSource, TileRequest[] requests, PlanarImage image, int tileX, int tileY)(Code) | | Invoked when a tile computation has been cancelled. The default implementation does nothing.
|
tileComputationFailure | public void tileComputationFailure(Object eventSource, TileRequest[] requests, PlanarImage image, int tileX, int tileY, Throwable cause)(Code) | | Invoked when a tile computation failed. Default implementation log a warning and lets the
program continue as usual. We are not throwing an exception since this failure will alter
the visual rendering, but will not otherwise harm the system.
|
tileComputed | public void tileComputed(Object eventSource, TileRequest[] requests, PlanarImage image, int tileX, int tileY, Raster tile)(Code) | | Invoked when a tile has been computed.
Parameters: eventSource - The caller of this method. Parameters: requests - The relevant tile computation requests as returned by the methodused to queue the tile. Parameters: image - The image for which tiles are being computed as specified to theTileScheduler. Parameters: tileX - The X index of the tile in the tile array. Parameters: tileY - The Y index of the tile in the tile array. Parameters: tile - The computed tile. |
tileUpdate | public void tileUpdate(WritableRenderedImage source, int tileX, int tileY, boolean willBeWritable)(Code) | | Invoked if the underlying image is writable and one of its tile changed.
This method forward the call to every registered listener.
|
|
|