Java Reference
In-Depth Information
An SVGAnimator instance can be in one of the following states:
Stopped : An SVGAnimator begins its life in the stopped state, and it does not draw
anything during this state. When it's in the other states, you can place an
SVGAnimator instance in the stopped state by invoking its stop method.
Playing : An SVGAnimator with a running update thread that is drawing to its compo-
nent is in the playing state. You can pause a playing SVGAnimator by invoking its
pause method, or stop it by invoking its stop method.
Paused : An SVGAnimator may be paused, during which time the animation is not
updating and not proceeding. You can resume playing an SVGAnimator by invoking
its play method while it's in the paused state, or stop it by invoking its stop method.
Listing 16-14 shows pseudocode that sets up an SVGAnimator and starts playback.
Listing 16-14. Playing an Animated SVG
SVGAnimator svgAnimator = null;
String mediaName = …;
Display display = …;
private void initAndStartSvgPlayer()
throws IOException {
InputStream in = getClass().getResourceAsStream(mediaName);
SVGImage svgImage = (SVGImage)ScalableImage.createImage(in, null);
svgAnimator = SVGAnimator.createAnimator(svgImage);
Canvas svgCanvas = (Canvas)svgAnimator.getTargetComponent();
svgImage.setViewportWidth(svgCanvas.getWidth());
svgImage.setViewportHeight(svgCanvas.getHeight());
display.setCurrent((Displayable)svgCanvas);
svgAnimator.play();
}
Because the SVGAnimator uses a separate thread to perform the animation, you can't
access the SVG image itself directly while the image is animating. Instead, if you need to
change the contents of the image (see the next section, “Modifying SVG Images”), you
should do so only using the SVGAnimator 's invokeAndWait or invokeLater method.
Note Rendering an SVG image does not use the same API and concepts that the MMAPI defines. This is a
shame, as a little work to extend the notions of data source and player would likely have made for a clean
interface. When working with media, don't confuse the SVGAPI with the MMAPI.
 
Search WWH ::




Custom Search