Java Reference
In-Depth Information
SVGImage.INTERACTION_MODE_FOCUS_HIGHLIGHT : Indicates that the SVG image may
contain focus highlighting, and the user may change which element has focus
SVGImage.INTERACTION_MODE_IN_PLACE_TEXT_EDIT : Indicates that the SVG image may
contain in-place text editing (within a text field, for example)
SVGImage.INTERACTION_MODE_OTHER : Indicates that the implementation should
support other user interaction with the SVG image
In Listing 16-15, the keyPressed and run methods show you how to mutate an SVG
image. When you press a key while the SVGAnimator 's target component has focus, the
SVGAnimator invokes keyPressed , which creates a new circle element that it will add to the
target document later at the first thread-safe opportunity. Because the SVGAnimator uses
multiple threads, the code needs to synchronize the addition of the circle element with
the SVGAnimator ; the code adds the new circle to a vector and schedules the update using
invokeLater . The run method—which the Java VM invokes at the appropriate time—
actually adds any pending circles to the SVG document.
Generally speaking, the Document and SVGDocument classes let you interact with a spe-
cific SVG document; this example uses the Document method createElementNS to create an
individual circle to draw on the image. To use createElementNS correctly, you need to have
a pretty good grip of the SVG standard, because you use it to create primitives in the SVG
language. If you're going this route in your application, I suggest you carefully study the
W3C standards I cited previously.
Of course, with these classes you can also query a specific document's DOM; the run
method in Listing 16-15 does this to get the document element of the SVG XML, which by
the definition of SVG has a child for each shape in the image. You can change elements of
the DOM, too, using the Node interface that the SVGDocument inherits; run does this by
invoking appendChild , passing the new object createElementNS created.
Using NetBeans with SVG Images
The approach that the SVGAPI takes to providing SVG support is fine for many applica-
tions, but it's a little labor intensive, especially for things many application developers
would like to do, such as simply play an SVG animated image, show an SVG image as a
splash screen or wait screen, or use one as a menu. While you can certainly write code to
do this yourself—it's a matter of composing a Displayable that uses an SVGAnimator —it's
going to be code that you, your virtual neighbor, and a good deal many other Java ME
developers are going to be writing over and over again for the next few years. Fortunately,
there's a better way.
The Mobility Pack for the NetBeans IDE provides a small package, org.netbeans.
microedition.svg , which contains some utility classes for building SVG user interfaces.
These classes all extend the MIDP Canvas class, so you simply use the Display class's
setCurrent to display an instance of one. Even better, the classes are integrated with the
 
Search WWH ::




Custom Search