Java Reference
In-Depth Information
Through its target object (the Canvas or Component subclass) as well as the SVG con-
tent itself, an SVGAnimator can obtain and generate events. For your application logic
to receive these events, it must implement a class that inherits the SVGEventListener
interface, which specifies methods for user events such as key-press events, key-
release events, pointer-press events, pointer-release events, and notifications when
the platform hides or shows the animation itself. You can process these events by
hand, but most of the time when you want to interact with events from an SVG image,
it will be to create an SVG-specific control. Fortunately, the NetBeans environment
provides some classes that do this for you, as I discuss later in the “Using NetBeans
with SVG Images” section.
Note JSR 226 defines a mechanism by which you can use the MMAPI to play an SVG image. It's
essentially the same as playing other video; get a Player instance with a locator that specifies an SVG
image, and then get a Control subinterface javax.microedition.media.control.SVGControl .
Using that Control instance, you can get an Item or Component object to add to your view hierarchy and
play the media normally. JSR 287 does not specify whether devices will continue to support the MMAPI
for SVG playback.
Modifying SVG Images
While it's less likely that you will want to write an application that creates SVG images
instead of displaying them, it's certainly possible, and the SVGAPI that JSR 287 defines
lets you do it. Because the SVGAPI provides support for the SVG DOM, it's entirely
possible for you to create an empty SVG image and add new objects to it. To do this,
you must have working knowledge of the XML DOM, the SVG DOM, and the SVG stan-
dard itself; all of that is largely outside the scope of this section. Here, I just sketch the
general principle so you know that it's something you can do if you find you have the
need. All of what I say in this section is only on JSR 287-enabled devices; JSR 226 does
not have many of the classes and some of the methods required if you want to work
directly with the SVG DOM.
Listing 16-15 shows pseudocode derived from JSR 287 that gives an example of modi-
fying an existing SVG image using an SVGAnimator to provide user events to application
logic. In turn, those user events cause the code to add new circles to the SVG image that
the application is displaying.
 
Search WWH ::




Custom Search