Articles
Index
A Colorful Vision of Java 2DTM
API Graphics
By Edward Ort
(December 1999)
Vincent Hardy is a colorful fellow, and not only because he claims
to have an interest in areas as diverse as graphic arts and badminton.
His recent book, Java 2DTM API Graphics,
published by
Sun Microsystems Press, is chock full of color graphics, as well
as many other examples of images and text that can be created and
manipulated with the Java 2D API. Vincent is a software
architect in Sun's .com/ready competency center. He's had
past experience in GUI and distributed software systems, especially
in the network management area.
I had a chance to ask Vincent about his experiences with the book
and the API.
Ed: Why this book? What stimulated you to write it?
Vincent: I wrote this book mainly because I really love graphics.
When I first ran into the Java 2D API specification (late '97), I found
that it promised an awesome set of new features (transparency,
anti-aliasing, great font support, etc...), it had a great architecture
(the Java 2D API is highly extensible) and it was extremely broad in scope.
I felt that this new API was very exciting and had great potential, but
I also realized that it could be a somewhat difficult subject to approach,
especially for the programmer with limited experience in graphics. For
example, it can be hard to fully understand the function of any given
feature--a ConvolveOp can appear cryptic, even in its definition, until
you understand that it can be used for blurring an image or sharpening it.
This is what prompted me to write the book--I wanted to provide an
in-depth exploration of the Java 2D API and illustrate the highly
sophisticated results it can produce. My goal was to explain how the
Java 2D API features can be used, combined and extended.
Ed: How were you able to incorporate your background and experiences
into the writing of the book?
Vincent: In my work at Sun, I used the Java 2D API for several projects
(especially for server side graphics, that is, for on the fly image generation).
I also worked on demos with the Java 2D team for JavaOneSM 1998
(animations) and gave two sessions on the Java 2D API at JavaOne 1999. These
opportunities gave me hands-on experience with the API and as a consequence,
I learned four big lessons.
First, I realized that the API delivers well for different kinds of
applications--it can be used for animations, client side or server side
graphics. Actually, this is not surprising because the API was designed
to be low level so that it would fit a broad range of different needs.
The second lesson I learned was a consequence of the first. Because the
API is low level, it is often useful to write a higher level abstraction
layer to fit the needs of a specific application. For example, if you are
writing an animation on top of the Java 2D API, it helps to create classes
that deal with animation-specific problems (such as, managing dirty areas,
repaints, sequence of transformations etc.).
I also discovered that if a feature is missing in the API, chances are
you can build on the API's extensible design to add it. For example, if you
want a different type of stroke to draw shapes, you can write your own
stroke and have it work with the rest of the API as well as any other
type of stroke. This was the third important lesson I learned.
Finally and perhaps most importantly, I came to truly enjoy working with
this API! I have enjoyed the very sophisticated output it can generate and
its extensible architecture.
I have worked to communicate my experience in my book, and this is
reflected in the book's three-part structure.
The first Part (about 200 pages) contains an in-depth explanation of the
Java 2D API. Because it is a sophisticated API, this part crescendos from
the basic concepts to the detailed design of the API, covering all of its
features.
The second Part (about 180 pages) introduces the Graphic Layers
Framework (GLF). I wrote the GLF for three reasons. The first being that
the GLF is an example of a higher level framework that takes advantage of
the Java 2D API but offers a programming model appropriate for a specific
purpose--creating graphical compositions. Secondly, the GLF contains a lot
of extensions of Java 2D classes, such as custom filters, custom paints and
custom composites. I thought it was important to show how to leverage the
API's extensible design. Finally, I wanted to provide an easy way to
experiment with the Java 2D API features. I think it helps having fun!
The third Part of the book (about 110 pages) shows how to combine the
features of the Java 2D API. All of the examples in this Part use the GLF
because it helps making the code more concise. Part Three provides food
for thought and I wanted to illustrate how the Java 2D API delivers highly
sophisticated features. Part 3 shows, for example, how to create various
types of shadow effects, borders or fancy text layouts. It also contains a
gallery of images all created with the API.
Ed: In writing the book did you find anything particularly challenging
or surprising?
Vincent: This was a very exciting project in many aspects. It was very
challenging simply due to the sheer amount of work it represented. The book
is about 500 pages long, and is the first four-color book in the Sun
Microsystems Java Series. We worked hard to assure that this book was
published in full color, as I believe it really adds to the message when
discussing a graphics API. There are at least 200 figures and over
100 code samples (in addition to the Graphic Layers Framework itself)
and the manuscript itself. This represents a lot of material to manage
and I found that handling it as a software development project
(with a design phase, a development phase, an editing phase--similar to
debugging--and a final release) worked pretty well,
Ed: Did you have a particular audience in mind (for example, a specific
level of Java programming expertise)?
Vincent: I have assumed that the reader would be comfortable with
JavaTM technology but not down to the most detailed level. In other words,
a proper knowledge of the language constructs (such as class, interface)
is required, but not of all the APIs (for example, AWT, reflection or Swing).
I did not assume any prior knowledge of computer graphics. However, the
book contains many bibliographical references for those readers
interested in the theory behind some of the Java 2D API features.
Ed: How have sales of the book gone so far?
Vincent: Great, thanks for asking! The sales are doing fine (the book
is on Fatbrain.com's bestseller list for example) and we are working
on a reprint right now.
Ed: What sort of feedback have you received about the book?
Vincent: People have told me they liked that the examples not only
show how to use a given feature but also illustrate what you can do
with it. I have made special efforts to make the examples visually
enticing and it seems that people like this :-)
Ed: What do users seem to find most difficult in using the Java 2D API
or the Graphics Layer Framework?
Vincent: It depends on the type of user. I think for people just
starting out with graphics, it is very important to spend time
understanding what the Java 2D API rendering model is, that is,
understanding the notions of graphics context, graphics context
attributes and graphic objects. It is simple, but the reader needs
to be comfortable with these notions to have a good experience with
the API. Otherwise, getting comfortable with AffineTransforms and
composition of AffineTransforms is key to fully enjoying the API.
For more advanced users who want to extend the Java 2D API features, it
is important to master the design of the new image classes, which separate
data storage, pixel access and color representation. Mastering these issues
makes implementing custom Paints, Composites or filters easier.
Ed: What's the most frequent question people ask you about the Java 2D
API?
Vincent: "What is it for and how does it relate to other graphics APIs
such as JavaTM Advanced Imaging (JAI) or Java 3DTM?" This is one the
question I get asked the most.
The Java 2D API is core to the Java 2 platform whereas JAI and Java 3D
are extensions to the platform. Java 3D is a 3D scene graph API and Java
Advanced Imaging supports using very large images, tiled images, and a
large set of imaging operators for commercial and technical imaging.
Ed: Where do you see support for graphics in the Java platform headed?
Vincent: Right now there is a big focus on performance and improvements
in printing. There is also work being done on font hinting. Besides the
Java 2D improvements, I think we will see the Java 2D API leveraged in
other areas of the Java platform.
Note that the performance work is based on a rearchitecture of the
implementation which will reduce software overhead and enable specific
hardware acceleration. Also, there is an expert group formed under the
Java Community Process which is working on an image I/O framework, and
that will likely be part of the platform in the future.
Ed: What improvements in graphics support should be made in the future?
Vincent: I think that adding more Paints, Composites and filters to the
core Java 2D reference implementation would be a good thing. Performance
is going to get even better. I believe the next challenge is to develop
a portable graphics format so that applications can share graphics easily
such as moving graphics from an authoring tool to a renderer. I think the
Scalable Vector Graphics effort going on at the W3C is very important.
Interestingly enough, SVG and the Java 2D API capabilities make a very
good match. However, SVG does contain some additional features (e.g.,
paints and filters), and it might be good to add them to the core
Java 2D API.
Ed: Do you have any plans for another book?
Vincent: Right now, my plan is to spend more time with my wife and
children and my main focus is on our family Christmas vacation. ;-)
Then I plan on updating my book to take the evolution of the Java 2D API
into account. I have no firm plans for another book as of now. But if
I write another one, it will be about graphics again!
About the Author
Edward Ort is a staff member of the Java Developer Connection. He has written extensively about
relational database technology and programming languages.
Reader Feedback
Tell us what you think of this article.