net.xoetrope.optional.svg.svgsalamander
Class XSvgPainter

java.lang.Object
  extended by net.xoetrope.optional.svg.svgsalamander.XSvgPainter
All Implemented Interfaces:
com.kitfox.svg.app.PlayerThreadListener, HitTester, Painter

public class XSvgPainter
extends java.lang.Object
implements Painter, HitTester, com.kitfox.svg.app.PlayerThreadListener

A painter that renders an SVG image

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


Field Summary
protected  java.awt.Color bkColor
           
protected  com.kitfox.svg.SVGDiagram diagram
           
protected  int oldHeight
           
protected  int oldWidth
           
protected  double scaleX
           
protected  double scaleY
           
 
Constructor Summary
XSvgPainter(javax.swing.JComponent comp)
          Creates a new instance of XSvgPainter
 
Method Summary
 void componentResized()
          The component has been resize, so resize the svg
 boolean contains(int x, int y)
          Check to see if the coordinates are within the component's active area
 double getCurTime()
           
 com.kitfox.svg.SVGElement getElement(java.lang.String id)
           
 java.lang.String getSelectedId()
          Get the ID of the selected element
 void paint(java.awt.Graphics2D g, javax.swing.JComponent component, int width, int height)
          Paints on the given Graphics2D object some effect which may or may not be related to the given component.
 void play()
           
 void setAnimate(boolean state)
          Flag this painter as an animation painter
 void setBackground(java.awt.Color c)
           
 void setElementIds(java.lang.String[][] ids)
          Set the element id for elements like masks etc
 void setImage(java.net.URL imageURL)
          Set the image managed and rendered by this painter
 void setImage(java.net.URL imageURL, boolean clear)
          Set the image managed and rendered by this painter
 void setInsets(java.awt.Insets insets)
           
 void setMetadata(java.net.URL mdURL)
          Set the metadata URL
 void setup()
          Get the managed states in the svg diagram.
 boolean updateState(int itemIndex)
          Update the svg state to be consistent with the button's state
 void updateTime(double curTime, double timeStep, int playState)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

diagram

protected com.kitfox.svg.SVGDiagram diagram

oldWidth

protected int oldWidth

oldHeight

protected int oldHeight

bkColor

protected java.awt.Color bkColor

scaleX

protected double scaleX

scaleY

protected double scaleY
Constructor Detail

XSvgPainter

public XSvgPainter(javax.swing.JComponent comp)
Creates a new instance of XSvgPainter

Parameters:
comp - the target component
Method Detail

getSelectedId

public java.lang.String getSelectedId()
Get the ID of the selected element

Parameters:
returns - a comma separated list of ids

setAnimate

public void setAnimate(boolean state)
Flag this painter as an animation painter

Parameters:
state - true to animate

play

public void play()

getCurTime

public double getCurTime()

updateTime

public void updateTime(double curTime,
                       double timeStep,
                       int playState)
Specified by:
updateTime in interface com.kitfox.svg.app.PlayerThreadListener

setElementIds

public void setElementIds(java.lang.String[][] ids)
Set the element id for elements like masks etc

Parameters:
element - the element type/role
id - the SVG element id to use

setMetadata

public void setMetadata(java.net.URL mdURL)
Set the metadata URL

Parameters:
mdURL - the host component

setImage

public void setImage(java.net.URL imageURL)
Set the image managed and rendered by this painter

Parameters:
imageURL - the url of the svg

setImage

public void setImage(java.net.URL imageURL,
                     boolean clear)
Set the image managed and rendered by this painter

Parameters:
imageURL - the url of the svg
clear - true to clear the svg universe, if for instance the svg image has changed

paint

public void paint(java.awt.Graphics2D g,
                  javax.swing.JComponent component,
                  int width,
                  int height)

Paints on the given Graphics2D object some effect which may or may not be related to the given component. For example, BackgroundPainter will use the background property of the component and the width/height of the component to perform a fill rect. Most other Painters will disregard the component entirely, except to get the component width/height.

The Graphics2D object must be returned to the same state it started at by the end of the method. For example, if "setColor(c)" was called on the graphics object, it should be reset to the original color before the method returns.

Specified by:
paint in interface Painter
Parameters:
g - The Graphics2D object in which to paint
component - The JComponent that the Painter is delegate for. This must not be null.
width -
height -

setBackground

public void setBackground(java.awt.Color c)

contains

public boolean contains(int x,
                        int y)
Description copied from interface: HitTester
Check to see if the coordinates are within the component's active area

Specified by:
contains in interface HitTester
Parameters:
x - the x coordinate, in device coordinates
y - the y coordinate, in device coordinates
Returns:
true if the mouse/cursor is within the active area

updateState

public boolean updateState(int itemIndex)
Update the svg state to be consistent with the button's state

Parameters:
itemIndex - the item index or -1 to update all items
Returns:
true if the state has changed

setup

public void setup()
Get the managed states in the svg diagram. The diagram may include two types of managed elements. The first is managed by a helper class implementing the XSvgStateHelper interface, and the second manages the scaling of the component. The svg's metadata section may include a list of elements to scale, and these are managed directly by this painter.


componentResized

public void componentResized()
The component has been resize, so resize the svg


getElement

public com.kitfox.svg.SVGElement getElement(java.lang.String id)

setInsets

public void setInsets(java.awt.Insets insets)