net.xoetrope.optional.svg
Class XSvgIcon

java.lang.Object
  extended by net.xoetrope.optional.svg.XSvgIcon
All Implemented Interfaces:
com.tinyline.svg.ImageLoader, java.awt.image.ImageObserver, java.lang.Runnable, javax.swing.Icon

public class XSvgIcon
extends java.lang.Object
implements javax.swing.Icon, com.tinyline.svg.ImageLoader, java.awt.image.ImageObserver, java.lang.Runnable

Render the SVG image as an icon

Copyright (c) Xoetrope 2001-2006, see license.txt for more details

$Revision: 1.6 $


Field Summary
 SVGEventQueue eventQueue
          The events queue
 com.tinyline.svg.SVGRaster raster
          The SVG renderer
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
XSvgIcon()
          Constructs a new SVGCanvas instance.
XSvgIcon(java.lang.String uri, int w, int h)
          Constructs a new SVGCanvas instance.
 
Method Summary
 void alertError(java.lang.String s)
          StatusBar: shows an alert
 void alertInit(java.lang.String s)
          StatusBar: inits the bar
 void alertWait(java.lang.String s)
          StatusBar: shows a wait
 com.tinyline.tiny2d.TinyBitmap createTinyBitmap(byte[] imageData, int imageOffset, int imageLength)
          Creates a TinyBitmap which decodes the image stored in the specified byte array, and at the specified offset and length.
 com.tinyline.tiny2d.TinyBitmap createTinyBitmap(java.lang.String imgRef)
          Returns a TinyBitmap for the given image URL or path.
 com.tinyline.tiny2d.TinyBitmap createTinyBitmap(com.tinyline.tiny2d.TinyString uri)
          Returns a TinyBitmap for the given image URL or path.
 void flush()
          Flushes allocated resources
 int getIconHeight()
          Returns the icon's height.
 int getIconWidth()
          Returns the icon's width.
 java.awt.Dimension getMinimumSize()
          The minimum size of the canvas.
 java.awt.Dimension getPreferredSize()
          The preferred size of the canvas.
 void goURL(java.lang.String url)
          Loads and dispalys an SVG document from the given URL.
 boolean imageUpdate(java.awt.Image img, int flags, int x, int y, int width, int height)
          This method is called when information about an image which was previously requested using an asynchronous interface becomes available.
 boolean isImageComplete()
          Is the image completely loaded?
 com.tinyline.svg.SVGDocument loadSVG(java.io.InputStream is)
          Loads an SVGT document from the given InputStream.
 com.tinyline.svg.SVGDocument loadSVG(java.lang.String urlStr)
          Loads an SVGT document from the given URL.
 void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
          Draw the icon at the specified location.
 void run()
          Fetch the specified currentURL in a separate thread and plays it in the renderer.
 void start()
          Starts the SVG player thread
 void stop()
          Stops the SVG player thread
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

raster

public com.tinyline.svg.SVGRaster raster
The SVG renderer


eventQueue

public SVGEventQueue eventQueue
The events queue

Constructor Detail

XSvgIcon

public XSvgIcon()
Constructs a new SVGCanvas instance.


XSvgIcon

public XSvgIcon(java.lang.String uri,
                int w,
                int h)
Constructs a new SVGCanvas instance.

Parameters:
uri - the location of the svg file
w - The width of this canvas.
h - The height of this canvas.
Method Detail

createTinyBitmap

public com.tinyline.tiny2d.TinyBitmap createTinyBitmap(com.tinyline.tiny2d.TinyString uri)
Returns a TinyBitmap for the given image URL or path.

Specified by:
createTinyBitmap in interface com.tinyline.svg.ImageLoader
Parameters:
uri - The image URL or path.
Returns:
a TinyBitmap object which gets its pixel data from the specified URL or path.

isImageComplete

public boolean isImageComplete()
Is the image completely loaded?

Returns:
true if the image is fully loaded

createTinyBitmap

public com.tinyline.tiny2d.TinyBitmap createTinyBitmap(java.lang.String imgRef)
Returns a TinyBitmap for the given image URL or path.

Parameters:
imgRef - The image URL or path.
Returns:
a TinyBitmap object which gets its pixel data from the specified URL or path.

createTinyBitmap

public com.tinyline.tiny2d.TinyBitmap createTinyBitmap(byte[] imageData,
                                                       int imageOffset,
                                                       int imageLength)
Creates a TinyBitmap which decodes the image stored in the specified byte array, and at the specified offset and length.

Specified by:
createTinyBitmap in interface com.tinyline.svg.ImageLoader
Parameters:
imageData - an array of bytes, representing image data in a supported image format.
imageOffset - the offset of the beginning of the data in the array.
imageLength - the length of the data in the array.
Returns:
a TinyBitmap object.

start

public void start()
Starts the SVG player thread


stop

public void stop()
Stops the SVG player thread


run

public void run()
Fetch the specified currentURL in a separate thread and plays it in the renderer. If the user cancels it, the thread be changed from this thread.

Specified by:
run in interface java.lang.Runnable

goURL

public void goURL(java.lang.String url)
Loads and dispalys an SVG document from the given URL. External hyperlinks handling

Parameters:
url - the location of the svg file

imageUpdate

public boolean imageUpdate(java.awt.Image img,
                           int flags,
                           int x,
                           int y,
                           int width,
                           int height)
This method is called when information about an image which was previously requested using an asynchronous interface becomes available. Asynchronous interfaces are method calls such as getWidth(ImageObserver) and drawImage(img, x, y, ImageObserver) which take an ImageObserver object as an argument.

Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Parameters:
img - the image being observed.
flags - the image status flags.
x - the x coordinate.
y - the y coordinate.
width - the width.
height - the height.
Returns:
false if the infoflags indicate that the image is completely loaded; true otherwise.

getIconWidth

public int getIconWidth()
Returns the icon's width.

Specified by:
getIconWidth in interface javax.swing.Icon
Returns:
an int specifying the fixed width of the icon.

getIconHeight

public int getIconHeight()
Returns the icon's height.

Specified by:
getIconHeight in interface javax.swing.Icon
Returns:
an int specifying the fixed height of the icon.

paintIcon

public void paintIcon(java.awt.Component c,
                      java.awt.Graphics g,
                      int x,
                      int y)
Draw the icon at the specified location. Icon implementations may use the Component argument to get properties useful for painting, e.g. the foreground or background color.

Specified by:
paintIcon in interface javax.swing.Icon
Parameters:
c - the component displaying the icon
g - the graphics context
x - the x location
y - the y location

getMinimumSize

public java.awt.Dimension getMinimumSize()
The minimum size of the canvas.

Returns:
The minimum size of the canvas.

getPreferredSize

public java.awt.Dimension getPreferredSize()
The preferred size of the canvas.

Returns:
The preferred size of the canvas.

flush

public void flush()
Flushes allocated resources


loadSVG

public com.tinyline.svg.SVGDocument loadSVG(java.lang.String urlStr)
Loads an SVGT document from the given URL.

Parameters:
urlStr - The SVGT document URL or path.
Returns:
An SVGT document.

loadSVG

public com.tinyline.svg.SVGDocument loadSVG(java.io.InputStream is)
Loads an SVGT document from the given InputStream.

Parameters:
is - The InputStream.
Returns:
An SVGT document.

alertError

public void alertError(java.lang.String s)
StatusBar: shows an alert

Parameters:
s - the message

alertWait

public void alertWait(java.lang.String s)
StatusBar: shows a wait

Parameters:
s - the message

alertInit

public void alertInit(java.lang.String s)
StatusBar: inits the bar

Parameters:
s - the message