I have developed many Java2D based applications, and have used many times SVG tools to draw the applications artwork, company logos, and many other things, for me this will change. For the first time ever since I know about SVG I am implementing a Java application that need to display and print a lot graphical content without using Java2D directly, this time I am using the Java library named Batik
Each Java2D developer needs to deal with many low level problems, like repainting only the part of the drawing that has changed, hit detection over elements of the drawing, the need to manage java.awt.Graphics current configuration (Font, colors, etc.) in order to do not affect other portions of the drawing (restoring it or creating new java.awt.Graphics instances before changing it). Using SVG I have been able to do the drawing with changes to the DOM model and Batik takes care of all the tedious work
The trick is in the usage of the JSVGCanvas Swing component. This component is able to display a SVG drawing and update it when the DOM changes. Hit detection is implemented using standard XML events with Java
Another advantage of this approach is that I have been able to reduce the implementation time because many of the reusable parts of the drawing, for example an icon of a ship, was drawn on a SVG compatible tool instead of using Java code to do it, bitmaps images are not a nice solution because they do not scale without loosing quality and frequently generate big documents when printed
If you have experience with XML based APIs and want to deliver your application faster, try this approach










Comments (0) |
Trackbacks (0)