|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ngs.image.ImageSource com.ngs.image.source.DefaultThumbnailSource com.ngs.image.source.CompositeSource
public class CompositeSource
A CompositeSource allows for layering of discrete ImageSources into a single aggregate ImageSource.
The first layer of the CompositeSource becomes the destination for all subsequent layers to render to. Each layer is rendered to the output of all previous layers. Thus, the third layer is composited against the result of the fisrt and second layers. The fourt layer against the first, second, and third layers, etc.
In the event that you want to composite two multi-page sources that have
differing page counts, if either the source or destination image passed to
doComposite()
is null, the opposing image is returned.
This allows us to automate the process of setting the bottom layer as the
destination, as well as simply returning the destination if a source is null.
So long as ImageSources added as additional layers will return null
when asked for a page they do not contain, rendering will simply skip that
layer by returning the existing destination.
There is an opportunity for subclasses to compute an AffineTransform to use
prior to compositing. For instance, if you want all of source images scaled
to respect the bounds of the destination, override calculateTransform()
and return an AffineTransform that will perform the function you require.
Nested Class Summary | |
---|---|
protected static class |
CompositeSource.Compositable
|
Field Summary | |
---|---|
protected AffineTransform |
identity
An Identity AffineTransform. |
protected ArrayList<CompositeSource.Compositable> |
layers
|
Constructor Summary | |
---|---|
CompositeSource()
Creates a new CompositeSource with no sources to composite. |
|
CompositeSource(ImageSource bottom)
Creates a new CompositeSource with a specified ImageSource as the bottom layer (a.k.a. |
Method Summary | |
---|---|
void |
addLayer(ImageSource layer)
Adds the given ImageSource as the top layer, using a SRC_OVER AlphaComposite (the default for all Java2D Graphics2D renderings). |
void |
addLayer(ImageSource layer,
Composite mode)
Adds the given ImageSource as the top layer, using the specified Composite object to render. |
protected AffineTransform |
calculateTransform(BufferedImage src,
BufferedImage dst)
Hook function that allows subclasses to calculate AffineTransforms to be applied during the composite rendering. |
void |
dispose()
Releases all cached resources, and invokes dispose() on all ImageSource layers. |
protected BufferedImage |
doComposite(BufferedImage src,
BufferedImage dst,
Composite mode,
AffineTransform transform)
Composite src into dst using mode
and transform. |
BufferedImage |
getImage(int index)
Renders and retrieves the image at the current index, by compositing all added layers with the specified Composite methods. |
int |
getImageCount()
Returns the maximum number of images from any single Layer in this CompositeSource's stack. |
String |
getImageName()
Implements ImageSource |
CompositeSource.Compositable |
getLayer(int layer)
|
int |
getNumLayers()
|
boolean |
isLayerVisible(int layer)
|
void |
removeAllLayers()
Removes all layers, and disposes of them. |
void |
removeLayer(int layer)
|
void |
setLayerVisibility(int layer,
boolean visible)
|
Methods inherited from class com.ngs.image.source.DefaultThumbnailSource |
---|
getThumbnail |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected ArrayList<CompositeSource.Compositable> layers
protected AffineTransform identity
Constructor Detail |
---|
public CompositeSource()
public CompositeSource(ImageSource bottom)
bottom
- The lowest level in the composite stack.Method Detail |
---|
public void addLayer(ImageSource layer, Composite mode)
layer
- The ImageSource to add.mode
- The Composite to use when renderingpublic void addLayer(ImageSource layer)
layer
- The IMageSource to addpublic void removeLayer(int layer)
public void removeAllLayers()
public int getNumLayers()
public CompositeSource.Compositable getLayer(int layer)
public void setLayerVisibility(int layer, boolean visible)
public boolean isLayerVisible(int layer)
public BufferedImage getImage(int index)
getImage
in class DefaultThumbnailSource
index
- The index of the image in the ImageSource to composite.
protected AffineTransform calculateTransform(BufferedImage src, BufferedImage dst)
src
- The source image about to be composited.dst
- The destination image about to be composited.
identity
protected BufferedImage doComposite(BufferedImage src, BufferedImage dst, Composite mode, AffineTransform transform)
src
into dst
using mode
and transform.
src
- The source image to composite fromdst
- The destination image to composite intomode
- The Composite mode to employ.transform
- An AffineTransform that should be applied to src as it
is composited into dst.public int getImageCount()
getImageCount
in class DefaultThumbnailSource
public void dispose()
dispose
in class DefaultThumbnailSource
public String getImageName()
DefaultThumbnailSource
getImageName
in class DefaultThumbnailSource
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |