simtools.images.svg
Class SVGImageFactory

java.lang.Object
  extended by simtools.images.svg.SVGImageFactory
Direct Known Subclasses:
TestSVGImageFactory

public class SVGImageFactory
extends java.lang.Object

A factory to load SVG files and display them using a BufferedImage Once a given SVG file is loaded with a size definition or using the default one, the image is generated in a dedicated thread. The loading is performed using load method which provides as an input a callback defined by the FactoryListener interface. Thanks to this interface, the resulting image is provided to the caller when it is fully painted. If other callers require the same SVG file (with the same size) then the image is shared to avoid to recompute it. The caller is assumed to call the release method to free allocated ressources when possible If a user of the image needs to rescale it, then it shall call the scale method which will perform the update of the image using a listener dedicated thread. This thread will delay the computation so that if several rescalings are required (in a time less than this delay plus the time to do the computation) then only the last one is taken into account to avoid useless computations. It is assumed that the old image is first rescaled for intermediate updates and then will be painted to provide a real SVG update for the new size.

Author:
cazenave_c

Nested Class Summary
static interface SVGImageFactory.FactoryListener
          The listener for the image users
 
Field Summary
protected  java.util.HashMap factoryElements
          The elements managed by the the factory the key is computed according to the File providing the SVG the value is the SVGFileHolder which is in charge of generating all the images for this SVG
static int SCALE_DELAY
          The delay between two scale computations
 
Constructor Summary
SVGImageFactory()
          Create an instance of the factory
 
Method Summary
protected  FactoryTranscoder createFactoryTranscoder(ImageHolder ie)
          This method has to be overriden to provide a specialization of FactoryTranscoder
protected  SVGFileHolder createFileHolder(SVGImageFactory factory, java.io.File f)
          This method has to be overriden to provide a specialization of SVGFileHolder
 java.awt.image.BufferedImage get(java.io.File f)
          Load an SVG file and paint it into an image
 java.awt.image.BufferedImage get(java.io.File f, int w, int h)
          Load an SVG file and paint it into an image
protected  java.lang.Object getKey(java.io.File f)
          Generate a key for an SVG file used to store in the hastable the SVGFileHolder
 void load(java.io.File f, int w, int h, SVGImageFactory.FactoryListener l)
          Load an SVG file and paint it into an image
 void load(java.io.File f, SVGImageFactory.FactoryListener l)
          Load an SVG file and paint it into an image using the SVF default size
 java.io.File read(java.io.ObjectInputStream in, SVGImageFactory.FactoryListener l, FileSerializer serializer, java.io.File referenceFile)
          Read the image used by one listener
 void release(java.io.File f, SVGImageFactory.FactoryListener l)
          Release the image used by one listener
 void scale(java.io.File f, int w, int h, SVGImageFactory.FactoryListener l)
          Change the size of an SVG document
 void wipeOff()
          Clean factoryElements contents.
 void write(java.io.ObjectOutputStream out, java.io.File f, SVGImageFactory.FactoryListener l, FileSerializer serializer, java.io.File referenceFile)
          Save the image used by one listener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCALE_DELAY

public static int SCALE_DELAY
The delay between two scale computations


factoryElements

protected java.util.HashMap factoryElements
The elements managed by the the factory the key is computed according to the File providing the SVG the value is the SVGFileHolder which is in charge of generating all the images for this SVG

See Also:
getKey
Constructor Detail

SVGImageFactory

public SVGImageFactory()
Create an instance of the factory

Method Detail

wipeOff

public void wipeOff()
Clean factoryElements contents. All images for all SVG shapes will be regenerated.


load

public void load(java.io.File f,
                 SVGImageFactory.FactoryListener l)
Load an SVG file and paint it into an image using the SVF default size

Parameters:
f - the file to load
l - the listener to call back when the image is available

get

public java.awt.image.BufferedImage get(java.io.File f)
Load an SVG file and paint it into an image

Parameters:
f - the file to load

get

public java.awt.image.BufferedImage get(java.io.File f,
                                        int w,
                                        int h)
Load an SVG file and paint it into an image

Parameters:
f - the file to load
w - the image width in pixels (=-1 for the default value)
h - the image height in pixels (=-1 for the default value)

load

public void load(java.io.File f,
                 int w,
                 int h,
                 SVGImageFactory.FactoryListener l)
Load an SVG file and paint it into an image

Parameters:
f - the file to load
w - the image width in pixels (=-1 for the default value)
h - the image height in pixels (=-1 for the default value)
l - the listener to call back when the image is available

getKey

protected java.lang.Object getKey(java.io.File f)
Generate a key for an SVG file used to store in the hastable the SVGFileHolder

Parameters:
f - the file
Returns:
the key

release

public void release(java.io.File f,
                    SVGImageFactory.FactoryListener l)
Release the image used by one listener

Parameters:
f - the file
l - the user listener

write

public void write(java.io.ObjectOutputStream out,
                  java.io.File f,
                  SVGImageFactory.FactoryListener l,
                  FileSerializer serializer,
                  java.io.File referenceFile)
           throws java.io.IOException
Save the image used by one listener

Parameters:
out - the output stream
f - the file
l - the user listener
serializer - to serialize the file
referenceFile - used by the the file serializer
Throws:
java.io.IOException

read

public java.io.File read(java.io.ObjectInputStream in,
                         SVGImageFactory.FactoryListener l,
                         FileSerializer serializer,
                         java.io.File referenceFile)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Read the image used by one listener

Parameters:
in - the input stream
f - the file
l - the user listener
serializer - to serialize the file
referenceFile - used by the the file serializer
Throws:
java.io.IOException
java.lang.ClassNotFoundException

scale

public void scale(java.io.File f,
                  int w,
                  int h,
                  SVGImageFactory.FactoryListener l)
Change the size of an SVG document

Parameters:
f - the SVG file
w - the image width in pixels (=-1 for the default value)
h - the image height in pixels (=-1 for the default value)
l - the user listener

createFactoryTranscoder

protected FactoryTranscoder createFactoryTranscoder(ImageHolder ie)
This method has to be overriden to provide a specialization of FactoryTranscoder

Parameters:
ie - the transcoder constructor parameter
Returns:
a new FactoryTrancoder

createFileHolder

protected SVGFileHolder createFileHolder(SVGImageFactory factory,
                                         java.io.File f)
This method has to be overriden to provide a specialization of SVGFileHolder

Parameters:
factory - the holder constructor factory parameter
f - the holder constructor file parameter
Returns:
a new SVGFileHolder