Class AbstractTiledOpImpl

All Implemented Interfaces:
ImageOp, Op<BufferedImage>
Direct Known Subclasses:
CropOpBitmapImpl, FixedScaleOpBitmapImpl, GridOp, ImageSourceOpBitmapImpl, OrthoRotateOpBitmapImpl, ScaleOpBitmapImpl, SolidColorOp, SourceOpBitmapImpl, SourceOpSVGImpl

public abstract class AbstractTiledOpImpl extends AbstractOpImpl
The abstract base class for ImageOps which support multiple tiles.
Since:
3.1.0
Author:
Joel Uckelman
  • Field Details

    • tileSize

      protected Dimension tileSize
      The standard size of this ImageOps tiles.
    • numXTiles

      protected int numXTiles
      The number of tiles along the x-axis.
    • numYTiles

      protected int numYTiles
      The number of tiles along the y-axis.
    • tiles

      protected ImageOp[] tiles
      The tiles already created, stored as y*numXTiles + x.
  • Constructor Details

    • AbstractTiledOpImpl

      public AbstractTiledOpImpl()
  • Method Details

    • fixTileSize

      protected void fixTileSize()
      Sets the tileSize which is used by getTileSize(), getTileHeight(), getTileWidth(), getNumXTiles(), getNumYTiles(), and all other tile methods.
    • getTileSize

      public Dimension getTileSize()
      Returns the standard size of the BufferedImage tiles which are returned by ImageOp.getTile(Point, ImageOpObserver). Tiles which are in the extreme right column will not have full width if the BufferedImage width is not an integral multiple of the tile width. Similarly, tiles in the bottom row will not have full height if the BufferedImage height is not an integral multiple of the tile height.
      Specified by:
      getTileSize in interface ImageOp
      Specified by:
      getTileSize in class AbstractOpImpl
      Returns:
      the size of BufferedImage tiles in pixels
      See Also:
    • getTileHeight

      public int getTileHeight()
      Returns the standard height of the BufferedImage tiles which are returned by ImageOp.getTile(Point, ImageOpObserver).
      Specified by:
      getTileHeight in interface ImageOp
      Specified by:
      getTileHeight in class AbstractOpImpl
      Returns:
      the height of BufferedImage tiles in pixels
      See Also:
    • getTileWidth

      public int getTileWidth()
      Returns the standard width of the BufferedImage tiles which are returned by ImageOp.getTile(Point, ImageOpObserver).
      Specified by:
      getTileWidth in interface ImageOp
      Specified by:
      getTileWidth in class AbstractOpImpl
      Returns:
      the width of BufferedImage tiles in pixels
      See Also:
    • getNumXTiles

      public int getNumXTiles()
      Returns the number of tiles along the x-axis. There will always be at least one column of tiles. The number of columns should equal (int) Math.ceil((double) getWidth() / getTileWidth()).
      Specified by:
      getNumXTiles in interface ImageOp
      Specified by:
      getNumXTiles in class AbstractOpImpl
      Returns:
      the number of tiles along the x-axis
    • getNumYTiles

      public int getNumYTiles()
      Returns the number of tiles along the y-axis. There will always be at least one row of tiles. The number of rows should equal (int) Math.ceil((double) getHeight() / getTileHeight()).
      Specified by:
      getNumYTiles in interface ImageOp
      Specified by:
      getNumYTiles in class AbstractOpImpl
      Returns:
      the number of tiles along the y-axis
    • getTileOp

      public ImageOp getTileOp(int tileX, int tileY)
      Returns the ImageOp which produces tile (tileX,tileY), creating it if necessary.
      Specified by:
      getTileOp in interface ImageOp
      Specified by:
      getTileOp in class AbstractOpImpl
      Parameters:
      tileX - the x position of the requested tile
      tileY - the y position of the requested tile
      Returns:
      the ImageOp for tile (tileX,tileY)
    • createTileOp

      protected abstract ImageOp createTileOp(int tileX, int tileY)
    • getTile

      public BufferedImage getTile(int tileX, int tileY, ImageOpObserver obs) throws CancellationException, InterruptedException, ExecutionException
      Calculates tile (tileX,tileY), and reports completion or failure to the specified ImageOpObserver. If a non-null observer is given, then the operation may be done asynchronously. If the observer is null, then this method will block on completion of the operation. Tiles are numbered from zero, so the tile in the upper-left corner of the main BufferedImage is (0,0). Note that tileX and tileY are indices into the tile array, not pixel locations.

      Warning: BufferedImages returned by this method must not be modified.

      Specified by:
      getTile in interface ImageOp
      Specified by:
      getTile in class AbstractOpImpl
      Parameters:
      tileX - the x position of the requested tile
      tileY - the y position of the requested tile
      obs - the observer to be notified on completion
      Returns:
      the resulting BufferedImage
      Throws:
      IndexOutOfBoundsException - unless 0 <= tileX < numXTiles and 0 <= tileY < numYTiles.
      CancellationException - if the operation was cancelled
      InterruptedException - if the operation was interrupted
      ExecutionException - if the operation failed
    • getFutureTile

      public Future<BufferedImage> getFutureTile(int tileX, int tileY, ImageOpObserver obs) throws ExecutionException
      Submits a request for tile (tileX,tileY), and returns a reference to that request. If a non-null observer is given, then the operation may be done asynchronously. If the observer is null, then this method will block on completion of the operation. Tiles are numbered from zero, so the tile in the upper-left corner of the main BufferedImage is (0,0). Note that tileX and tileY are indices into the tile array, not pixel locations.

      Warning: BufferedImages obtained from the Futures returned by this method must not be modified.

      Specified by:
      getFutureTile in interface ImageOp
      Specified by:
      getFutureTile in class AbstractOpImpl
      Parameters:
      tileX - the x position of the requested tile
      tileY - the y position of the requested tile
      obs - the observer to be notified on completion
      Returns:
      a Future for the resulting BufferedImage
      Throws:
      IndexOutOfBoundsException - unless 0 <= tileX < numXTiles and 0 <= tileY < numYTiles.
      ExecutionException - if the operation failed
    • getTileIndices

      public Point[] getTileIndices(Rectangle rect)
      Returns an array of Points representing the tiles intersecting the given Rectangle.
      Specified by:
      getTileIndices in interface ImageOp
      Specified by:
      getTileIndices in class AbstractOpImpl
      Parameters:
      rect - the rectangle
      Returns:
      the positions of the tiles hit by the rectangle
      Throws:
      IllegalArgumentException - if rect == null.