org.pushingpixels.flamingo.api.svg
Class SvgBatikResizableIcon

java.lang.Object
  extended by org.apache.batik.bridge.UserAgentAdapter
      extended by org.pushingpixels.flamingo.api.svg.SvgBatikResizableIcon
All Implemented Interfaces:
Icon, org.apache.batik.bridge.UserAgent, AsynchronousLoading, ResizableIcon

public class SvgBatikResizableIcon
extends org.apache.batik.bridge.UserAgentAdapter
implements ResizableIcon, AsynchronousLoading

SVG-based implementation of ResizableIcon based on Apache Batik library.


Nested Class Summary
static class org.pushingpixels.flamingo.api.svg.SvgBatikIcon.BufferedImageTranscoder
          A transcoder that generates a BufferedImage.
 
Field Summary
protected  Map<String,BufferedImage> cachedImages
          Contains all precomputed images.
protected  int height
          The height of the rendered image.
protected  EventListenerList listenerList
          The listeners.
protected  List listeners
          The listeners.
protected  byte[] svgBytes
          SVG byte array.
protected  int width
          The width of the rendered image.
 
Fields inherited from class org.apache.batik.bridge.UserAgentAdapter
ctx, extensions, FEATURES
 
Method Summary
 void addAsynchronousLoadListener(AsynchronousLoadListener l)
          Adds listener on the asynchronous loading events.
 void addGVTTreeRendererListener(org.apache.batik.swing.gvt.GVTTreeRendererListener l)
          Adds a GVTTreeRendererListener to this GVTTreeRenderer.
protected static InputStream constructFromZipStream(InputStream zippedStream)
          Constructs an input stream with uncompressed contents from the specified input stream with compressed contents.
protected  void fireAsyncCompleted(Boolean event)
          Fires the asynchronous load event.
 void fireEvent(org.apache.batik.util.EventDispatcher.Dispatcher dispatcher, Object event)
          Fires event.
 int getIconHeight()
           
 int getIconWidth()
           
 byte[] getSvgBytes()
          Returns the SVG bytes of the loaded SVG image.
static SvgBatikResizableIcon getSvgIcon(InputStream inputStream, Dimension initialDim)
          Returns the icon for the specified input stream.
static SvgBatikResizableIcon getSvgIcon(URL location, Dimension initialDim)
          Returns the icon for the specified URL.
static SvgBatikResizableIcon getSvgzIcon(InputStream inputStream, Dimension initialDim)
          Returns the icon for the specified input stream.
static SvgBatikResizableIcon getSvgzIcon(URL location, Dimension initialDim)
          Returns the icon for the specified URL.
 Dimension2D getViewportSize()
          Returns the default size of this user agent.
 boolean isLoading()
          Returns indication whether the content is still loading.
 void paintIcon(Component c, Graphics g, int x, int y)
           
 void removeAsynchronousLoadListener(AsynchronousLoadListener l)
          Removes listener on the asynchronous loading events.
 void removeGVTTreeRendererListener(org.apache.batik.swing.gvt.GVTTreeRendererListener l)
          Removes a GVTTreeRendererListenerner from this GVTTreeRenderer.
protected  boolean renderGVTTree(int renderWidth, int renderHeight)
          Renders the GVT tree.
 void setDimension(Dimension dim)
          Changes the dimension of this icon.
 void setPreferredSize(Dimension dim)
          Sets the preferred size for this icon.
 
Methods inherited from class org.apache.batik.bridge.UserAgentAdapter
addStdFeatures, checkLoadExternalResource, checkLoadScript, deselectAll, displayError, displayError, displayMessage, getAlternateStyleSheet, getBolderFontWeight, getBrokenLinkDocument, getClientAreaLocationOnScreen, getDefaultFontFamily, getEventDispatcher, getExternalResourceSecurity, getLanguages, getLighterFontWeight, getMedia, getMediumFontSize, getPixelToMM, getPixelUnitToMillimeter, getScriptSecurity, getStandardBolderFontWeight, getStandardLighterFontWeight, getTransform, getUserStyleSheetURI, getXMLParserClassName, handleElement, hasFeature, isXMLParserValidating, openLink, registerExtension, runThread, setBridgeContext, setSVGCursor, setTextSelection, setTransform, showAlert, showConfirm, showPrompt, showPrompt, supportExtension
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.Icon
getIconHeight, getIconWidth, paintIcon
 

Field Detail

listenerList

protected EventListenerList listenerList
The listeners.


cachedImages

protected Map<String,BufferedImage> cachedImages
Contains all precomputed images.


width

protected int width
The width of the rendered image.


height

protected int height
The height of the rendered image.


svgBytes

protected byte[] svgBytes
SVG byte array.


listeners

protected List listeners
The listeners.

Method Detail

constructFromZipStream

protected static InputStream constructFromZipStream(InputStream zippedStream)
                                             throws IOException
Constructs an input stream with uncompressed contents from the specified input stream with compressed contents.

Parameters:
zippedStream - Input stream with compressed contents.
Returns:
Input stream with uncompressed contents.
Throws:
IOException - in case any I/O operation failed.

getSvgIcon

public static SvgBatikResizableIcon getSvgIcon(URL location,
                                               Dimension initialDim)
Returns the icon for the specified URL. The URL is assumed to point to uncompressed SVG contents.

Parameters:
location - Icon URL.
initialDim - Initial dimension of the icon.
Returns:
Icon instance.

getSvgIcon

public static SvgBatikResizableIcon getSvgIcon(InputStream inputStream,
                                               Dimension initialDim)
Returns the icon for the specified input stream. The stream is assumed to contain uncompressed SVG contents.

Parameters:
inputStream - Icon stream.
initialDim - Initial dimension of the icon.
Returns:
Icon instance.

getSvgzIcon

public static SvgBatikResizableIcon getSvgzIcon(URL location,
                                                Dimension initialDim)
Returns the icon for the specified URL. The URL is assumed to point to compressed SVG contents.

Parameters:
location - Icon URL.
initialDim - Initial dimension of the icon.
Returns:
Icon instance.

getSvgzIcon

public static SvgBatikResizableIcon getSvgzIcon(InputStream inputStream,
                                                Dimension initialDim)
Returns the icon for the specified input stream. The stream is assumed to contain compressed SVG contents.

Parameters:
inputStream - Icon stream.
initialDim - Initial dimension of the icon.
Returns:
Icon instance.

setDimension

public void setDimension(Dimension dim)
Description copied from interface: ResizableIcon
Changes the dimension of this icon.

Specified by:
setDimension in interface ResizableIcon
Parameters:
dim - New dimension for this icon.

addAsynchronousLoadListener

public void addAsynchronousLoadListener(AsynchronousLoadListener l)
Description copied from interface: AsynchronousLoading
Adds listener on the asynchronous loading events.

Specified by:
addAsynchronousLoadListener in interface AsynchronousLoading
Parameters:
l - Listener to add.

removeAsynchronousLoadListener

public void removeAsynchronousLoadListener(AsynchronousLoadListener l)
Description copied from interface: AsynchronousLoading
Removes listener on the asynchronous loading events.

Specified by:
removeAsynchronousLoadListener in interface AsynchronousLoading
Parameters:
l - Listener to remove.

renderGVTTree

protected boolean renderGVTTree(int renderWidth,
                                int renderHeight)
Renders the GVT tree.

Parameters:
renderWidth - Requested rendering width.
renderHeight - Requested rendering height.
Returns:
If true, the image is already computed and cached.

fireAsyncCompleted

protected void fireAsyncCompleted(Boolean event)
Fires the asynchronous load event.

Parameters:
event - Event object.

isLoading

public boolean isLoading()
Description copied from interface: AsynchronousLoading
Returns indication whether the content is still loading.

Specified by:
isLoading in interface AsynchronousLoading
Returns:
true if the content is still loading, false otherwise.

getIconWidth

public int getIconWidth()
Specified by:
getIconWidth in interface Icon

getIconHeight

public int getIconHeight()
Specified by:
getIconHeight in interface Icon

paintIcon

public void paintIcon(Component c,
                      Graphics g,
                      int x,
                      int y)
Specified by:
paintIcon in interface Icon

getViewportSize

public Dimension2D getViewportSize()
Returns the default size of this user agent.

Specified by:
getViewportSize in interface org.apache.batik.bridge.UserAgent
Overrides:
getViewportSize in class org.apache.batik.bridge.UserAgentAdapter

setPreferredSize

public void setPreferredSize(Dimension dim)
Sets the preferred size for this icon. The rendering is scheduled automatically.

Parameters:
dim - Preferred size.

getSvgBytes

public byte[] getSvgBytes()
Returns the SVG bytes of the loaded SVG image.

Returns:
SVG bytes of the loaded SVG image.

fireEvent

public void fireEvent(org.apache.batik.util.EventDispatcher.Dispatcher dispatcher,
                      Object event)
Fires event.

Parameters:
dispatcher - Event dispatcher.
event - Event data.

addGVTTreeRendererListener

public void addGVTTreeRendererListener(org.apache.batik.swing.gvt.GVTTreeRendererListener l)
Adds a GVTTreeRendererListener to this GVTTreeRenderer.

Parameters:
l - Listener to add.

removeGVTTreeRendererListener

public void removeGVTTreeRendererListener(org.apache.batik.swing.gvt.GVTTreeRendererListener l)
Removes a GVTTreeRendererListenerner from this GVTTreeRenderer.

Parameters:
l - Listener to remove.