org.jvnet.flamingo.svg
Class SvgBatikResizableIcon

java.lang.Object
  extended by org.apache.batik.bridge.UserAgentAdapter
      extended by org.jvnet.flamingo.svg.SvgBatikResizableIcon
All Implemented Interfaces:
javax.swing.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.

Author:
Kirill Grouchnikov.

Nested Class Summary
static class SvgBatikIcon.BufferedImageTranscoder
          A transcoder that generates a BufferedImage.
 
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.
 void fireEvent(org.apache.batik.util.EventDispatcher.Dispatcher dispatcher, java.lang.Object event)
          Fires event.
 int getIconHeight()
           
 int getIconWidth()
           
 byte[] getSvgBytes()
          Returns the SVG bytes of the loaded SVG image.
static SvgBatikResizableIcon getSvgIcon(java.io.InputStream inputStream, java.awt.Dimension initialDim)
          Returns the icon for the specified input stream.
static SvgBatikResizableIcon getSvgIcon(java.net.URL location, java.awt.Dimension initialDim)
          Returns the icon for the specified URL.
static SvgBatikResizableIcon getSvgzIcon(java.io.InputStream inputStream, java.awt.Dimension initialDim)
          Returns the icon for the specified input stream.
static SvgBatikResizableIcon getSvgzIcon(java.net.URL location, java.awt.Dimension initialDim)
          Returns the icon for the specified URL.
 java.awt.geom.Dimension2D getViewportSize()
          Returns the default size of this user agent.
 boolean isLoading()
          Returns indication whether the content is still loading.
 void paintIcon(java.awt.Component c, java.awt.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.
 void revertToOriginalDimension()
           
 void setDimension(java.awt.Dimension dim)
          Changes the dimension of this icon.
 void setHeight(int height)
           
 void setPreferredSize(java.awt.Dimension dim)
          Sets the preferred size for this icon.
 void setWidth(int width)
           
 
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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.Icon
getIconHeight, getIconWidth, paintIcon
 

Method Detail

getSvgIcon

public static SvgBatikResizableIcon getSvgIcon(java.net.URL location,
                                               java.awt.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(java.io.InputStream inputStream,
                                               java.awt.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(java.net.URL location,
                                                java.awt.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(java.io.InputStream inputStream,
                                                java.awt.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.

revertToOriginalDimension

public void revertToOriginalDimension()

setDimension

public void setDimension(java.awt.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.

setHeight

public void setHeight(int height)

setWidth

public void setWidth(int width)

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.

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 javax.swing.Icon

getIconHeight

public int getIconHeight()
Specified by:
getIconHeight in interface javax.swing.Icon

paintIcon

public void paintIcon(java.awt.Component c,
                      java.awt.Graphics g,
                      int x,
                      int y)
Specified by:
paintIcon in interface javax.swing.Icon

getViewportSize

public java.awt.geom.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(java.awt.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,
                      java.lang.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.