org.apache.batik.svggen

Class DefaultCachedImageHandler

public abstract class DefaultCachedImageHandler extends Object implements CachedImageHandler, SVGSyntax, ErrorConstants

This class is a default implementation of the GenericImageHandler for handlers implementing a caching strategy.

See Also: SVGGraphics2D

Field Summary
protected ImageCacherimageCacher
Method Summary
BufferedImagebuildBufferedImage(Dimension size)
This method creates a BufferedImage of the right size and type for the derived class.
protected voidcacheBufferedImage(Element imageElement, BufferedImage buf, SVGGeneratorContext generatorContext)
ElementcreateElement(SVGGeneratorContext generatorContext)
Creates an Element which can refer to an image.
abstract voidencodeImage(BufferedImage buf, OutputStream os)
Derived classes should implement this method and encode the input BufferedImage as needed
abstract intgetBufferedImageType()
This template method should be overridden by derived classes to declare the image type they need for saving to file.
ImageCachergetImageCacher()
The image cache can be used by subclasses for efficient image storage
abstract StringgetRefPrefix()
Should return the prefix with wich the image reference should be pre-concatenated.
protected voidhandleEmptyImage(Element imageElement)
voidhandleHREF(Image image, Element imageElement, SVGGeneratorContext generatorContext)
The handler should set the xlink:href tag and the width and height attributes.
protected voidhandleHREF(RenderedImage image, Element imageElement, SVGGeneratorContext generatorContext)
This template method should set the xlink:href attribute on the input Element parameter
protected voidhandleHREF(RenderableImage image, Element imageElement, SVGGeneratorContext generatorContext)
This method will delegate to the handleHREF which uses a RenderedImage
AffineTransformhandleImage(Image image, Element imageElement, int x, int y, int width, int height, SVGGeneratorContext generatorContext)
The handler sets the xlink:href tag and returns a transform
AffineTransformhandleImage(RenderedImage image, Element imageElement, int x, int y, int width, int height, SVGGeneratorContext generatorContext)
The handler sets the xlink:href tag and returns a transform
AffineTransformhandleImage(RenderableImage image, Element imageElement, double x, double y, double width, double height, SVGGeneratorContext generatorContext)
The handler sets the xlink:href tag and returns a transform
protected AffineTransformhandleTransform(Element imageElement, double x, double y, double srcWidth, double srcHeight, double dstWidth, double dstHeight, SVGGeneratorContext generatorContext)
Determines the transformation needed to get the cached image to scale & position properly.
voidsetDOMTreeManager(DOMTreeManager domTreeManager)
This GenericImageHandler implementation does not need to interact with the DOMTreeManager.

Field Detail

imageCacher

protected ImageCacher imageCacher

Method Detail

buildBufferedImage

public BufferedImage buildBufferedImage(Dimension size)
This method creates a BufferedImage of the right size and type for the derived class.

cacheBufferedImage

protected void cacheBufferedImage(Element imageElement, BufferedImage buf, SVGGeneratorContext generatorContext)

createElement

public Element createElement(SVGGeneratorContext generatorContext)
Creates an Element which can refer to an image. Note that no assumptions should be made by the caller about the corresponding SVG tag. By default, an <image> tag is used, but the {@link CachedImageHandlerBase64Encoder}, for example, overrides this method to use a different tag.

encodeImage

public abstract void encodeImage(BufferedImage buf, OutputStream os)
Derived classes should implement this method and encode the input BufferedImage as needed

getBufferedImageType

public abstract int getBufferedImageType()
This template method should be overridden by derived classes to declare the image type they need for saving to file.

getImageCacher

public ImageCacher getImageCacher()
The image cache can be used by subclasses for efficient image storage

getRefPrefix

public abstract String getRefPrefix()
Should return the prefix with wich the image reference should be pre-concatenated.

handleEmptyImage

protected void handleEmptyImage(Element imageElement)

handleHREF

public void handleHREF(Image image, Element imageElement, SVGGeneratorContext generatorContext)
The handler should set the xlink:href tag and the width and height attributes.

handleHREF

protected void handleHREF(RenderedImage image, Element imageElement, SVGGeneratorContext generatorContext)
This template method should set the xlink:href attribute on the input Element parameter

handleHREF

protected void handleHREF(RenderableImage image, Element imageElement, SVGGeneratorContext generatorContext)
This method will delegate to the handleHREF which uses a RenderedImage

handleImage

public AffineTransform handleImage(Image image, Element imageElement, int x, int y, int width, int height, SVGGeneratorContext generatorContext)
The handler sets the xlink:href tag and returns a transform

handleImage

public AffineTransform handleImage(RenderedImage image, Element imageElement, int x, int y, int width, int height, SVGGeneratorContext generatorContext)
The handler sets the xlink:href tag and returns a transform

handleImage

public AffineTransform handleImage(RenderableImage image, Element imageElement, double x, double y, double width, double height, SVGGeneratorContext generatorContext)
The handler sets the xlink:href tag and returns a transform

handleTransform

protected AffineTransform handleTransform(Element imageElement, double x, double y, double srcWidth, double srcHeight, double dstWidth, double dstHeight, SVGGeneratorContext generatorContext)
Determines the transformation needed to get the cached image to scale & position properly. Sets x and y attributes on the element accordingly.

setDOMTreeManager

public void setDOMTreeManager(DOMTreeManager domTreeManager)
This GenericImageHandler implementation does not need to interact with the DOMTreeManager.
Copyright B) 2007 Apache Software Foundation. All Rights Reserved.