Class WritableTiledImage

All Implemented Interfaces:
RenderedImage, WritableRenderedImage

public class WritableTiledImage extends TiledImage implements WritableRenderedImage
A writable version of TiledImage.
Since:
1.1
Version:
1.1
  • Field Details

    • observers

      private volatile TileObserver[] observers
      The observers, or null if none. This is a copy-on-write array: values are never modified after construction (new arrays are created). This field is declared volatile because it is read without synchronization by getWritableTile(int, int) and releaseWritableTile(int, int). Since this is a copy-on-write array, it is okay to omit synchronization for those methods but we still need the memory effect.
    • writables

      private final Map<Point,Integer> writables
      Indices of tiles taken for a write operation. Values are counter of calls to getWritableTile(int, int). All accesses to this map shall be synchronized on the map instance.
  • Constructor Details

    • WritableTiledImage

      public WritableTiledImage(Map<String,Object> properties, ColorModel colorModel, int width, int height, int minTileX, int minTileY, WritableRaster... tiles)
      Creates a new tiled image. The first tile in the given array must be the one located at the minimal tile indices. All tiles must have the same size and the same sample model and must be sorted in row-major fashion.
      Parameters:
      properties - image properties, or null if none.
      colorModel - the color model, or null if none.
      width - number of pixels along X axis in the whole rendered image.
      height - number of pixels along Y axis in the whole rendered image.
      minTileX - minimum tile index in the X direction.
      minTileY - minimum tile index in the Y direction.
      tiles - the tiles. Must contains at least one element. This array is not cloned.
  • Method Details

    • addTileObserver

      public void addTileObserver(TileObserver observer)
      Adds an observer to be notified when a tile is checked out for writing. If the observer is already present, it will receive multiple notifications.
      Specified by:
      addTileObserver in interface WritableRenderedImage
      Parameters:
      observer - the observer to notify.
    • removeTileObserver

      public void removeTileObserver(TileObserver observer)
      Removes an observer from the list of observers notified when a tile is checked out for writing. If the observer was not registered, nothing happens. If the observer was registered for multiple notifications, it will now be registered for one fewer.
      Specified by:
      removeTileObserver in interface WritableRenderedImage
      Parameters:
      observer - the observer to stop notifying.
    • getWritableTile

      public WritableRaster getWritableTile(int tileX, int tileY)
      Checks out a tile for writing. If the same tile is checked out many times before to be released, only the first checkout is notified to listeners.
      Specified by:
      getWritableTile in interface WritableRenderedImage
      Parameters:
      tileX - the x index of the tile.
      tileY - the y index of the tile.
      Returns:
      the specified tile as a writable tile.
    • releaseWritableTile

      public void releaseWritableTile(int tileX, int tileY)
      Relinquishes the right to write to a tile. If the tile goes from having one writer to having no writers, the values are inverse converted and written in the original image. If the caller continues to write to the tile, the results are undefined.
      Specified by:
      releaseWritableTile in interface WritableRenderedImage
      Parameters:
      tileX - the x index of the tile.
      tileY - the y index of the tile.
    • isTileWritable

      public boolean isTileWritable(int tileX, int tileY)
      Returns whether a tile is currently checked out for writing.
      Specified by:
      isTileWritable in interface WritableRenderedImage
      Parameters:
      tileX - the x index of the tile.
      tileY - the y index of the tile.
      Returns:
      true if specified tile is checked out for writing, false otherwise.
    • getWritableTileIndices

      public Point[] getWritableTileIndices()
      Returns the indices of all tiles checked out for writing. Returns null if none are checked out.
      Specified by:
      getWritableTileIndices in interface WritableRenderedImage
      Returns:
      indices of tiles that are checked out for writing, or null if none.
    • hasTileWriters

      public boolean hasTileWriters()
      Returns whether any tile is checked out for writing.
      Specified by:
      hasTileWriters in interface WritableRenderedImage
      Returns:
      true if any tiles are checked out for writing, or false otherwise.
    • setData

      public void setData(Raster data)
      Sets a region of the image to the contents of the given raster. The raster is assumed to be in the same coordinate space as this image. The operation is clipped to the bounds of this image.
      Specified by:
      setData in interface WritableRenderedImage
      Parameters:
      data - the values to write in this image.