Java Reference
In-Depth Information
■
Note
The SVGAPI is big, especially if you take into account the APIs that the
javax.microedition.
vectorgraphics
package provides. Figure 16-4 shows only the relationships between the classes you're
likely to use when rendering SVG images.
As Figure 16-4 shows, the class and interface hierarchy is actually fairly flat for the
root-level classes and interfaces. Be aware of the following classes and interfaces:
•
ScalableGraphics
: The fundamental class for 2D vector rendering
•
ScalableImage
: Represents an image in vector format; the parent of the
SVGImage
class
•
SVGImage
: Represents an SVG image conforming to SVG Tiny 1.2
•
SVGAnimator
: Handles automatic rendering of updates in animated SVG images
using an
SVGImage
•
Document
: Represents an XML document
•
SVGDocument
: Represents an SVG document; a child of
Document
•
Element
: Represents a generic item in an SVG document's DOM; the parent to
individual SVG elements
•
Event
: Represents contextual information about a specific interface; the parent of
the SVG event classes
•
EventListener
: Represents a listener to events, specifying the
handleEvent
that the
SVGAPI framework uses to send an object events
Rendering SVG Images
You can use the SVGAPI to render an SVG image in one of two ways. The first way is easy
and best used for static images (those that do not require animation). The second is a little
more complex, because it requires you to do everything you'd do for the first way and then
a little more; however, in return, you get an object that manages an animated SVG image.
Rendering Static SVG Images
The first way is simple: create an
SVGImage
using some initial data to draw, and then draw
it by giving it to a
ScalableGraphics
instance. Listing 16-12 shows pseudocode for this way
to draw an SVG image.