org.netbeans.microedition.svg
Class SVGPlayer

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Canvas
          extended by org.netbeans.microedition.svg.SVGPlayer
All Implemented Interfaces:
javax.microedition.lcdui.CommandListener
Direct Known Subclasses:
SVGAnimatorWrapper, SVGForm

public class SVGPlayer
extends javax.microedition.lcdui.Canvas
implements javax.microedition.lcdui.CommandListener

This class encapsulates SVGAnimator and exposes some of its setters, so it can be used as a component in NetBeans Visual Designer. It also adds many utility methods which can be used to easily manipulate the underlying document of the animated SVG image.

Even though this class extends Canvas, the Canvas is utilized only for forwarding command actions from Canvas created by SVGAnimator.


Field Summary
static int BOTTOM
          Anchor point constants.
static int BOTTOM_LEFT
          Anchor point constants.
static int BOTTOM_RIGHT
          Anchor point constants.
static int CENTER
          Anchor point constants.
static int LEFT
          Anchor point constants.
static int PAUSED
          Animator is paused (i.e. when started again, the animation will continue from the paused state)
static int PLAYING
          Animator is running animation
static int RIGHT
          Anchor point constants.
static int STOPPED
          Animator is stopped (i.e. when started again, the animation will start from the beginning)
static int TOP
          Anchor point constants.
static int TOP_LEFT
          Anchor point constants.
static int TOP_RIGHT
          Anchor point constants.
 
Fields inherited from class javax.microedition.lcdui.Canvas
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, UP
 
Constructor Summary
SVGPlayer(javax.microedition.m2g.SVGImage svgImage, javax.microedition.lcdui.Display display)
          Creates a new instance of SvgAnimatorHelper.
 
Method Summary
 void addCommand(javax.microedition.lcdui.Command cmd)
          Adds command to the animation canvas (not this canvas)
 void commandAction(javax.microedition.lcdui.Command command, javax.microedition.lcdui.Displayable displayable)
          Implementation of CommandListener.commandAction() which forwards command action from Canvas created by SVGAnimator to the CommandListener assigned to this component
protected  float[] computeAnchorTranslate(org.w3c.dom.svg.SVGRect bbox, int anchor)
          Computes the translation needed to center the given rectangle about the desired anchor position.
protected  javax.microedition.m2g.SVGAnimator getAnimator()
          Gets SVGAnimator created in this player.
 int getAnimatorState()
          Returns state of the animation
protected  javax.microedition.lcdui.CommandListener getCommandListener()
          Gets command listener assigned to this displayable.
protected  javax.microedition.lcdui.Display getDisplay()
          Gets Display
 org.w3c.dom.Document getDocument()
           
 javax.microedition.m2g.SVGEventListener getSafeSVGEventListener()
          Gets user's "Safe" SVGEventListener which is being called in the document update thread.
 org.w3c.dom.svg.SVGRect getScreenBBox(java.lang.String id)
          Returns the screen bounding box for the desired element.
 org.w3c.dom.svg.SVGAnimationElement getSVGAnimationElementById(java.lang.String id)
          Gets SVGAnimationElement from the SVGImage used for this SVGPlayer.
 javax.microedition.lcdui.Canvas getSvgCanvas()
          Gets Canvas which was created by the SVGAnimator
 org.w3c.dom.svg.SVGElement getSVGElementById(java.lang.String id)
          Gets SVGElement from the SVGImage used for this SVGPlayer.
 javax.microedition.m2g.SVGEventListener getSVGEventListener()
          Gets user's SVGEventListener
 javax.microedition.m2g.SVGImage getSVGImage()
          Gets SVGImage used to create this SVGPlayer.
 org.w3c.dom.svg.SVGLocatableElement getSVGLocatableElementById(java.lang.String id)
          Gets SVGLocatableElement from the SVGImage used for this SVGPlayer.
 javax.microedition.lcdui.Ticker getTicker()
          Gets ticker from the animation canvas (not this canvas)
 float getTimeIncrement()
          Gets time increment of the animation.
 java.lang.String getTitle()
          Gets title from the animation canvas (not this canvas)
 void invokeAndWait(java.lang.Runnable runnable)
          Proxy call for SVGAnimator.invokeAndWait() method.
 void invokeAndWaitSafely(java.lang.Runnable runnable)
          Invokes the input Runnable in the document update thread and returns after the Runnable has completed.
 void invokeLater(java.lang.Runnable runnable)
          Proxy call for SVGAnimator.invokeLater() method.
 void invokeLaterSafely(java.lang.Runnable runnable)
          Schedule the input Runnable for execution in the update thread\ at a later time.
 boolean isResetAnimationWhenStopped()
          Should be animation reset whhen stopped
protected  void paint(javax.microedition.lcdui.Graphics graphics)
          Dummy paint method - does nothing, because all the rendering is done by the canvas obtained from SVGAnimator
 void pause()
          Pauses the animation.
 void play()
          Starts the animation.
 void removeCommand(javax.microedition.lcdui.Command cmd)
          Removes command from the animation canvas (not this canvas)
 void reset()
          reset the animation, so it starts again from the beginning.
 void rotate(java.lang.String id, float angle)
          Rotates the element with the given id by the given angle.
 void rotate(org.w3c.dom.svg.SVGElement svgElement, float angle)
          Rotates the element with the given id by the given angle.
 void rotateAbout(java.lang.String id, float angle, int anchor)
          Rotates the element with the given id by the given angle about the desired anchor point.
 void rotateAbout(org.w3c.dom.svg.SVGLocatableElement svgLocatableElement, float angle, int anchor)
          Rotates the element with the given id by the given angle about the desired anchor point.
 void rotateAboutSafely(java.lang.String id, float angle, int anchor)
          Rotates the element with the given id by the given angle about the desired anchor point.
 void rotateSafely(java.lang.String id, float angle)
          Rotates the element with the given id by the given angle.
 void scale(java.lang.String id, float sx, float sy)
          Scales the element with the specified id by the given factor along the x and y axis.
 void scale(org.w3c.dom.svg.SVGElement svgElement, float sx, float sy)
          Scales the element with the specified id by the given factor along the x and y axis.
 void scaleAbout(java.lang.String id, float sx, float sy, int anchor)
          Scales the element with the given id about the desired anchor point.
 void scaleAbout(org.w3c.dom.svg.SVGLocatableElement svgLocatableElement, float sx, float sy, int anchor)
          Scales the element with the given id about the desired anchor point.
 void scaleAboutSafely(java.lang.String id, float sx, float sy, int anchor)
          Scales the element with the given id about the desired anchor point.
 void scaleSafely(java.lang.String id, float sx, float sy)
          Scales the element with the specified id by the given factor along the x and y axis.
 void screenTranslate(java.lang.String id, float tx, float ty)
          Translates the element with the specified id by the given amount, in the screen coordinate space.
 void screenTranslate(org.w3c.dom.svg.SVGLocatableElement svgLocatableElement, float tx, float ty)
          Translates the element with the specified id by the given amount, in the screen coordinate space.
 void screenTranslateSafely(java.lang.String id, float tx, float ty)
          Translates the element with the specified id by the given amount, in the screen coordinate space.
 void setCommandListener(javax.microedition.lcdui.CommandListener commandListener)
          Sets command listener to this displayable
 void setFloatTrait(java.lang.String id, java.lang.String traitName, float traitValue)
          Sets the desired trait on the element with the specified identifier.
 void setFloatTraitSafely(java.lang.String id, java.lang.String traitName, float traitValue)
          Sets the desired trait on the element with the specified identifier.
 void setFullScreenMode(boolean mode)
          sets fullscreen mode the animation canvas (not this canvas)
 void setResetAnimationWhenStopped(boolean reset)
          Sets
 void setRGBTrait(java.lang.String id, java.lang.String traitName, int rgb)
          Sets the desired RGB value on the element with the specified identifier.
 void setRGBTrait(java.lang.String id, java.lang.String traitName, int r, int g, int b)
          Sets the desired RGB value on the element with the specified identifier.
 void setRGBTraitSafely(java.lang.String id, java.lang.String traitName, int rgb)
          Sets the desired RGB value on the element with the specified identifier.
 void setRGBTraitSafely(java.lang.String id, java.lang.String traitName, int r, int g, int b)
          Sets the desired RGB value on the element with the specified identifier.
 void setSafeSVGEventListener(javax.microedition.m2g.SVGEventListener safeSvgEventListener)
          Sets a user's SVGEventListener to be called in the document update thread.
 void setStartAnimationImmediately(boolean startAnimation)
          When set to true, the animation starts immediatelly when the canvas with animation displayed on the screen
 void setSVGEventListener(javax.microedition.m2g.SVGEventListener svgEventListener)
          Sets a user's SVGEventListener to the SVGAnimator
 void setTicker(javax.microedition.lcdui.Ticker ticker)
          Sets ticker to the animation canvas (not this canvas)
 void setTimeIncrement(float timeIncrement)
          Sets time increment for the animation.
 void setTitle(java.lang.String s)
          Sets title to the animation canvas (not this canvas)
 void setTrait(java.lang.String id, java.lang.String traitName, java.lang.String traitValue)
          Sets the desired trait on the element with the specified identifier.
 void setTraitSafely(java.lang.String id, java.lang.String traitName, java.lang.String traitValue)
          Sets the desired trait on the element with the specified identifier.
 void startAnimation(java.lang.String elementId)
          Starts immediately animation on the given animation element.
 void startAnimation(java.lang.String elementId, float delay)
          Starts immediately animation on the given animation element.
 void startAnimationSafely(java.lang.String elementId)
          Starts immediately animation on the given animation element.
 void stop()
          Stops the animation.
 void stopAnimation(java.lang.String elementId)
          Stops animation on the given animation element.
 void stopAnimation(java.lang.String elementId, float delay)
          Stops animation on the given animation element, with given delay.
 void stopAnimationSafely(java.lang.String elementId)
          Stops animation on the given animation element.
 void translate(java.lang.String id, float tx, float ty)
          Translates the element with the specified id by the given amount, in user space.
 void translate(org.w3c.dom.svg.SVGElement svgElement, float tx, float ty)
          Translates the element with the specified id by the given amount, in user space.
 void translateSafely(java.lang.String id, float tx, float ty)
          Translates the element with the specified id by the given amount, in user space.
 
Methods inherited from class javax.microedition.lcdui.Canvas
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotify, isDoubleBuffered, keyPressed, keyReleased, keyRepeated, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, showNotify, sizeChanged
 
Methods inherited from class javax.microedition.lcdui.Displayable
getHeight, getWidth, isShown
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOP_LEFT

public static final int TOP_LEFT
Anchor point constants.

See Also:
Constant Field Values

TOP

public static final int TOP
Anchor point constants.

See Also:
Constant Field Values

TOP_RIGHT

public static final int TOP_RIGHT
Anchor point constants.

See Also:
Constant Field Values

LEFT

public static final int LEFT
Anchor point constants.

See Also:
Constant Field Values

CENTER

public static final int CENTER
Anchor point constants.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Anchor point constants.

See Also:
Constant Field Values

BOTTOM_LEFT

public static final int BOTTOM_LEFT
Anchor point constants.

See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
Anchor point constants.

See Also:
Constant Field Values

BOTTOM_RIGHT

public static final int BOTTOM_RIGHT
Anchor point constants.

See Also:
Constant Field Values

STOPPED

public static final int STOPPED
Animator is stopped (i.e. when started again, the animation will start from the beginning)

See Also:
Constant Field Values

PAUSED

public static final int PAUSED
Animator is paused (i.e. when started again, the animation will continue from the paused state)

See Also:
Constant Field Values

PLAYING

public static final int PLAYING
Animator is running animation

See Also:
Constant Field Values
Constructor Detail

SVGPlayer

public SVGPlayer(javax.microedition.m2g.SVGImage svgImage,
                 javax.microedition.lcdui.Display display)
          throws java.lang.IllegalArgumentException
Creates a new instance of SvgAnimatorHelper. It requires SVGImage to be animated and display.

Please note, supplied SVGImage shouldn't be reused in other SVGAnimator.

Throws:
java.lang.IllegalArgumentException
Method Detail

getSvgCanvas

public javax.microedition.lcdui.Canvas getSvgCanvas()
Gets Canvas which was created by the SVGAnimator


getDocument

public org.w3c.dom.Document getDocument()

getSVGEventListener

public javax.microedition.m2g.SVGEventListener getSVGEventListener()
Gets user's SVGEventListener

Returns:
an instance of the user's SVGEventListener or null if there was no user SVGEvenetListener set.

setSVGEventListener

public void setSVGEventListener(javax.microedition.m2g.SVGEventListener svgEventListener)
Sets a user's SVGEventListener to the SVGAnimator

Parameters:
svgEventListener - user SVGEventListener or null if no listener should be set

getSafeSVGEventListener

public javax.microedition.m2g.SVGEventListener getSafeSVGEventListener()
Gets user's "Safe" SVGEventListener which is being called in the document update thread.

Returns:
an instance of the user's SVGEventListener being called in the document update thread, or null if there was no user SVGEvenetListener set.

setSafeSVGEventListener

public void setSafeSVGEventListener(javax.microedition.m2g.SVGEventListener safeSvgEventListener)
Sets a user's SVGEventListener to be called in the document update thread.

Parameters:
safeSvgEventListener - user SVGEventListener or null if no listener should be set

setTimeIncrement

public void setTimeIncrement(float timeIncrement)
Sets time increment for the animation. Proxy call for SVGAnimator.setTimeIncrement()

Parameters:
timeIncrement - the minimal time that should ellapse between frame rendering. In seconds. Should be greater than zero.
Throws:
java.lang.IllegalArgumentException - - if timeIncrement is less than or equal to zero.

getTimeIncrement

public float getTimeIncrement()
Gets time increment of the animation. Proxy call of SVGAnimator.getTimeIncrement().

Returns:
time increment in seconds.

pause

public void pause()
Pauses the animation. Proxy call for SVGAnimator.pause()


stop

public void stop()
Stops the animation. Proxy call for SVGAnimator.stop()


play

public void play()
Starts the animation. Proxy call for SVGAnimator.play()


reset

public void reset()
reset the animation, so it starts again from the beginning. Can be used in either when stopped/paused or playing state.


getAnimatorState

public int getAnimatorState()
Returns state of the animation

Returns:
STOPPED for stopped state, PAUSED for paused state and PLAYING when the animation is running.

invokeAndWait

public void invokeAndWait(java.lang.Runnable runnable)
                   throws java.lang.InterruptedException
Proxy call for SVGAnimator.invokeAndWait() method.

Parameters:
runnable - Runnable to be passed to SVGAnimator.invokeAndWait(runnable) method.
Throws:
java.lang.InterruptedException

invokeLater

public void invokeLater(java.lang.Runnable runnable)
Proxy call for SVGAnimator.invokeLater() method.

Parameters:
runnable - Runnable to be passed to SVGAnimator.invokeLater(runnable) method.

getTitle

public java.lang.String getTitle()
Gets title from the animation canvas (not this canvas)

Overrides:
getTitle in class javax.microedition.lcdui.Displayable
Returns:
title string

setTitle

public void setTitle(java.lang.String s)
Sets title to the animation canvas (not this canvas)

Overrides:
setTitle in class javax.microedition.lcdui.Displayable
Parameters:
s - title String

addCommand

public void addCommand(javax.microedition.lcdui.Command cmd)
Adds command to the animation canvas (not this canvas)

Overrides:
addCommand in class javax.microedition.lcdui.Displayable

removeCommand

public void removeCommand(javax.microedition.lcdui.Command cmd)
Removes command from the animation canvas (not this canvas)

Overrides:
removeCommand in class javax.microedition.lcdui.Displayable

getTicker

public javax.microedition.lcdui.Ticker getTicker()
Gets ticker from the animation canvas (not this canvas)

Overrides:
getTicker in class javax.microedition.lcdui.Displayable

setTicker

public void setTicker(javax.microedition.lcdui.Ticker ticker)
Sets ticker to the animation canvas (not this canvas)

Overrides:
setTicker in class javax.microedition.lcdui.Displayable

setFullScreenMode

public void setFullScreenMode(boolean mode)
sets fullscreen mode the animation canvas (not this canvas)

Overrides:
setFullScreenMode in class javax.microedition.lcdui.Canvas

setStartAnimationImmediately

public void setStartAnimationImmediately(boolean startAnimation)
When set to true, the animation starts immediatelly when the canvas with animation displayed on the screen


isResetAnimationWhenStopped

public boolean isResetAnimationWhenStopped()
Should be animation reset whhen stopped


setResetAnimationWhenStopped

public void setResetAnimationWhenStopped(boolean reset)
Sets


getCommandListener

protected final javax.microedition.lcdui.CommandListener getCommandListener()
Gets command listener assigned to this displayable. Can be used by children classes


setCommandListener

public void setCommandListener(javax.microedition.lcdui.CommandListener commandListener)
Sets command listener to this displayable

Overrides:
setCommandListener in class javax.microedition.lcdui.Canvas

getDisplay

protected javax.microedition.lcdui.Display getDisplay()
Gets Display


getAnimator

protected javax.microedition.m2g.SVGAnimator getAnimator()
Gets SVGAnimator created in this player. Please use wisely :-)


getSVGImage

public final javax.microedition.m2g.SVGImage getSVGImage()
Gets SVGImage used to create this SVGPlayer.

Returns:
SVGImage used to create this object

getSVGElementById

public org.w3c.dom.svg.SVGElement getSVGElementById(java.lang.String id)
                                             throws java.lang.IllegalArgumentException
Gets SVGElement from the SVGImage used for this SVGPlayer.

Parameters:
id - an id of the svg element to be obtained
Returns:
SVGElement corresponding to the given id, or null if there is no such element or the element is not of SVGElement instance
Throws:
java.lang.IllegalArgumentException - if the supplied id is null

getSVGLocatableElementById

public org.w3c.dom.svg.SVGLocatableElement getSVGLocatableElementById(java.lang.String id)
                                                               throws java.lang.IllegalArgumentException
Gets SVGLocatableElement from the SVGImage used for this SVGPlayer.

Parameters:
id - an id of the svg element to be obtained
Returns:
SVGLocatableElement corresponding to the given id, or null if there is no such element or the element is not of SVGLocatableElement instance
Throws:
java.lang.IllegalArgumentException - if the supplied id is null

getSVGAnimationElementById

public org.w3c.dom.svg.SVGAnimationElement getSVGAnimationElementById(java.lang.String id)
                                                               throws java.lang.IllegalArgumentException
Gets SVGAnimationElement from the SVGImage used for this SVGPlayer.

Parameters:
id - an id of the animation element to be obtained
Returns:
SVGAnimationElement corresponding to the given id, or null if there is no such element or the element is not of SVGAnimationElement instance
Throws:
java.lang.IllegalArgumentException - if the supplied id is null

invokeLaterSafely

public void invokeLaterSafely(java.lang.Runnable runnable)
Schedule the input Runnable for execution in the update thread\ at a later time. In the case the animator is in stopped mode, the method invokes the runnable in a separate thread.

Parameters:
runnable - a runnable scheduled for invokation in update thread

invokeAndWaitSafely

public void invokeAndWaitSafely(java.lang.Runnable runnable)
Invokes the input Runnable in the document update thread and returns after the Runnable has completed. In the case SVGAnimator is in stopped mode or if the method is being called directly from the document update thread, the method invokes run() method on runnable directly.

Parameters:
runnable - a runnable scheduled for invokation in update thread

setTraitSafely

public void setTraitSafely(java.lang.String id,
                           java.lang.String traitName,
                           java.lang.String traitValue)
Sets the desired trait on the element with the specified identifier. If the element with given ID is not an instance of SVGElement, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
id - the id of the element whose trait value should be changed.
traitName - the name of the trait to change, e.g, "display"
traitValue - the value of the trait to set, e.g., "none"

setTrait

public void setTrait(java.lang.String id,
                     java.lang.String traitName,
                     java.lang.String traitValue)
Sets the desired trait on the element with the specified identifier. If the element with given ID is not an instance of SVGElement, the operation is not performed.

Note:This method needs to be called from the document update thread.

Parameters:
id - the id of the element whose trait value should be changed.
traitName - the name of the trait to change, e.g, "display"
traitValue - the value of the trait to set, e.g., "none"

setFloatTraitSafely

public void setFloatTraitSafely(java.lang.String id,
                                java.lang.String traitName,
                                float traitValue)
Sets the desired trait on the element with the specified identifier. If the element with given ID is not an instance of SVGElement, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
id - the id of the element whose trait value should be changed.
traitName - the name of the trait to change, e.g, "display"
traitValue - the value of the trait to set, e.g., "none"

setFloatTrait

public void setFloatTrait(java.lang.String id,
                          java.lang.String traitName,
                          float traitValue)
Sets the desired trait on the element with the specified identifier. If the element with given ID is not an instance of SVGElement, the operation is not performed.

Parameters:
id - the id of the element whose trait value should be changed.
traitName - the name of the trait to change, e.g, "display"
traitValue - the value of the trait to set, e.g., "none"

setRGBTraitSafely

public void setRGBTraitSafely(java.lang.String id,
                              java.lang.String traitName,
                              int rgb)
Sets the desired RGB value on the element with the specified identifier. If the element with given ID is not an instance of SVGElement, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
id - the id of the element whose trait value should be changed.
traitName - the name of the trait to change, e.g, "stroke" or "fill"
rgb - the color value as an int in the following format 0xXXRRGGBB. The high order byte is ignored. For example, 0xFFFF0000 specifies red.

setRGBTrait

public void setRGBTrait(java.lang.String id,
                        java.lang.String traitName,
                        int rgb)
Sets the desired RGB value on the element with the specified identifier. If the element with given ID is not an instance of SVGElement, the operation is not performed.

Parameters:
id - the id of the element whose trait value should be changed.
traitName - the name of the trait to change, e.g, "stroke" or "fill"
rgb - the color value as an int in the following format 0xXXRRGGBB. The high order byte is ignored. For example, 0xFFFF0000 specifies red.

setRGBTraitSafely

public void setRGBTraitSafely(java.lang.String id,
                              java.lang.String traitName,
                              int r,
                              int g,
                              int b)
Sets the desired RGB value on the element with the specified identifier. If the element with given ID is not an instance of SVGElement, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
id - the id of the element whose trait value should be changed.
traitName - the name of the trait to change, e.g, "fill"
r - the desired red component value, in the 0-255 interval
g - the desired green component value, in the 0-255 interval
b - the desired blue component value, in the 0-255 interval

setRGBTrait

public void setRGBTrait(java.lang.String id,
                        java.lang.String traitName,
                        int r,
                        int g,
                        int b)
Sets the desired RGB value on the element with the specified identifier. If the element with given ID is not an instance of SVGElement, the operation is not performed.

Parameters:
id - the id of the element whose trait value should be changed.
traitName - the name of the trait to change, e.g, "fill"
r - the desired red component value, in the 0-255 interval
g - the desired green component value, in the 0-255 interval
b - the desired blue component value, in the 0-255 interval

translateSafely

public void translateSafely(java.lang.String id,
                            float tx,
                            float ty)
Translates the element with the specified id by the given amount, in user space. If the element with given ID is not an instance of SVGElement, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
id - the id of the element whose trait value should be changed.
tx - the desired translation along the x-axis
ty - the desired translation along the y-axis

translate

public void translate(java.lang.String id,
                      float tx,
                      float ty)
Translates the element with the specified id by the given amount, in user space. If the element with given ID is not an instance of SVGElement, the operation is not performed.

Parameters:
id - the id of the element whose trait value should be changed.
tx - the desired translation along the x-axis
ty - the desired translation along the y-axis

translate

public void translate(org.w3c.dom.svg.SVGElement svgElement,
                      float tx,
                      float ty)
Translates the element with the specified id by the given amount, in user space.

Parameters:
svgElement - the element whose trait value should be changed. If null, the operation is not performed.
tx - the desired translation along the x-axis
ty - the desired translation along the y-axis

screenTranslateSafely

public void screenTranslateSafely(java.lang.String id,
                                  float tx,
                                  float ty)
Translates the element with the specified id by the given amount, in the screen coordinate space. If the element with given ID is not an instance of SVGLocatableElement, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
id - the id of the element whose trait value should be changed.
tx - the desired translation along the x-axis
ty - the desired translation along the y-axis

screenTranslate

public void screenTranslate(java.lang.String id,
                            float tx,
                            float ty)
Translates the element with the specified id by the given amount, in the screen coordinate space. If the element with given ID is not an instance of SVGLocatableElement, the operation is not performed.

Parameters:
id - the id of the element whose trait value should be changed.
tx - the desired translation along the x-axis
ty - the desired translation along the y-axis

screenTranslate

public void screenTranslate(org.w3c.dom.svg.SVGLocatableElement svgLocatableElement,
                            float tx,
                            float ty)
Translates the element with the specified id by the given amount, in the screen coordinate space.

Parameters:
svgLocatableElement - the element whose trait value should be changed. If null, the operation is not performed.
tx - the desired translation along the x-axis
ty - the desired translation along the y-axis

getScreenBBox

public org.w3c.dom.svg.SVGRect getScreenBBox(java.lang.String id)
Returns the screen bounding box for the desired element.

Parameters:
id - the id of the element whose bounding box is retrieved.
Returns:
found screen bounding box or null if the the element with given was not found or does not correspond to an instance SVGLocatableElement.

scaleSafely

public void scaleSafely(java.lang.String id,
                        float sx,
                        float sy)
Scales the element with the specified id by the given factor along the x and y axis. If the element with given ID is not an instance of SVGElement, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
id - the id of the element whose trait value should be changed.
sx - the desired scale factor along the x-axis
sy - the desired scale factor along the y-axis

scale

public void scale(java.lang.String id,
                  float sx,
                  float sy)
Scales the element with the specified id by the given factor along the x and y axis. If the element with given ID is not an instance of SVGElement, the operation is not performed.

Parameters:
id - the id of the element whose trait value should be changed.
sx - the desired scale factor along the x-axis
sy - the desired scale factor along the y-axis

scale

public void scale(org.w3c.dom.svg.SVGElement svgElement,
                  float sx,
                  float sy)
Scales the element with the specified id by the given factor along the x and y axis.

Parameters:
svgElement - element whose trait value should be changed. If null, the operation is not performed.
sx - the desired scale factor along the x-axis
sy - the desired scale factor along the y-axis

scaleAboutSafely

public void scaleAboutSafely(java.lang.String id,
                             float sx,
                             float sy,
                             int anchor)
Scales the element with the given id about the desired anchor point. If the element with given ID is not an instance of SVGLocatableElement, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
id - the id of the element whose trait value should be changed.
sx - the desired scale factor along the x-axis
sy - the desired scale factor along the y-axis
anchor - one of TOP_LEFT, TOP, TOP_RIGHT, LEFT, CENTER, RIGHT, BOTTOM_LEFT, BOTTOM, BOTTOM_RIGHT.

scaleAbout

public void scaleAbout(java.lang.String id,
                       float sx,
                       float sy,
                       int anchor)
Scales the element with the given id about the desired anchor point. If the element with given ID is not an instance of SVGLocatableElement, the operation is not performed.

Parameters:
id - the id of the element whose trait value should be changed.
sx - the desired scale factor along the x-axis
sy - the desired scale factor along the y-axis
anchor - one of TOP_LEFT, TOP, TOP_RIGHT, LEFT, CENTER, RIGHT, BOTTOM_LEFT, BOTTOM, BOTTOM_RIGHT.

scaleAbout

public void scaleAbout(org.w3c.dom.svg.SVGLocatableElement svgLocatableElement,
                       float sx,
                       float sy,
                       int anchor)
Scales the element with the given id about the desired anchor point.

Parameters:
svgLocatableElement - element whose trait value should be changed. If null the operation is not performed.
sx - the desired scale factor along the x-axis
sy - the desired scale factor along the y-axis
anchor - one of TOP_LEFT, TOP, TOP_RIGHT, LEFT, CENTER, RIGHT, BOTTOM_LEFT, BOTTOM, BOTTOM_RIGHT.

rotateSafely

public void rotateSafely(java.lang.String id,
                         float angle)
Rotates the element with the given id by the given angle. If the element with given ID is not an instance of SVGElement, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
id - the id of the element which should be rotated.
angle - the rotation angle, in degrees

rotate

public void rotate(java.lang.String id,
                   float angle)
Rotates the element with the given id by the given angle. If the element with given ID is not an instance of SVGElement, the operation is not performed.

Parameters:
id - the id of the element which should be rotated.
angle - the rotation angle, in degrees

rotate

public void rotate(org.w3c.dom.svg.SVGElement svgElement,
                   float angle)
Rotates the element with the given id by the given angle.

Parameters:
svgElement - the element which should be rotated. If null, the operation is not performed.
angle - the rotation angle, in degrees

rotateAboutSafely

public void rotateAboutSafely(java.lang.String id,
                              float angle,
                              int anchor)
Rotates the element with the given id by the given angle about the desired anchor point. If the element with given ID is not an instance of SVGLocatableElement, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
id - the id of the element which should be rotated.
angle - the rotation angle, in degrees
anchor - the reference point about which to rotate the element.

rotateAbout

public void rotateAbout(java.lang.String id,
                        float angle,
                        int anchor)
Rotates the element with the given id by the given angle about the desired anchor point. If the element with given ID is not an instance of SVGLocatableElement, the operation is not performed.

Parameters:
id - the id of the element which should be rotated.
angle - the rotation angle, in degrees
anchor - the reference point about which to rotate the element.

rotateAbout

public void rotateAbout(org.w3c.dom.svg.SVGLocatableElement svgLocatableElement,
                        float angle,
                        int anchor)
Rotates the element with the given id by the given angle about the desired anchor point.

Parameters:
svgLocatableElement - the element which should be rotated. If null the operation is not performed.
angle - the rotation angle, in degrees
anchor - the reference point about which to rotate the element.

computeAnchorTranslate

protected float[] computeAnchorTranslate(org.w3c.dom.svg.SVGRect bbox,
                                         int anchor)
Computes the translation needed to center the given rectangle about the desired anchor position.

Parameters:
bbox - the object's bounding box, used to compute the translation.
anchor - the desired anchor position for the translation. For example, if anchor is "BOTTOM_RIGHT", the returned translation will move the bottom right of the bounding box to the coordinate system's origin.
Returns:
the translation. A float array of size two, with the x-axis translation at index 0 and the y-axis translation at index 1.

startAnimationSafely

public void startAnimationSafely(java.lang.String elementId)
Starts immediately animation on the given animation element. If the given id does not correspond to a valid animation element, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
elementId - id of the animation element on which the animation should be started

startAnimation

public void startAnimation(java.lang.String elementId)
Starts immediately animation on the given animation element. If the given id does not correspond to a valid animation element, the operation is not performed.

Parameters:
elementId - id of the animation element on which the animation should be started
Throws:
java.lang.IllegalArgumentException - if the elementID does not correspond to a valid SVGAnimationElement

startAnimation

public void startAnimation(java.lang.String elementId,
                           float delay)
Starts immediately animation on the given animation element. If the given id does not correspond to a valid animation element, the operation is not performed.

Parameters:
elementId - id of the animation element on which the animation should be started
delay - offset in seconds at which the animation should be started

stopAnimationSafely

public void stopAnimationSafely(java.lang.String elementId)
Stops animation on the given animation element. If the given id does not correspond to a valid animation element, the operation is not performed.

This method uses "safe" approach - i.e. when it runs in document update thread it runs directly in the thread, otherwise it is scheduled using SVGAnimator.invokeAndWait method.

Parameters:
elementId - id of the animation element on which the animation should be stopped

stopAnimation

public void stopAnimation(java.lang.String elementId)
Stops animation on the given animation element. If the given id does not correspond to a valid animation element, the operation is not performed.

Parameters:
elementId - id of the animation element on which the animation should be stopped

stopAnimation

public void stopAnimation(java.lang.String elementId,
                          float delay)
Stops animation on the given animation element, with given delay. Stops animation on the given animation element. If the given id does not correspond to a valid animation element, the operation is not performed.

Parameters:
elementId - id of the animation element on which the animation should be stopped
delay - offset in seconds at which the animation should be stopped

paint

protected void paint(javax.microedition.lcdui.Graphics graphics)
Dummy paint method - does nothing, because all the rendering is done by the canvas obtained from SVGAnimator

Specified by:
paint in class javax.microedition.lcdui.Canvas

commandAction

public void commandAction(javax.microedition.lcdui.Command command,
                          javax.microedition.lcdui.Displayable displayable)
Implementation of CommandListener.commandAction() which forwards command action from Canvas created by SVGAnimator to the CommandListener assigned to this component

Specified by:
commandAction in interface javax.microedition.lcdui.CommandListener