• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

A Simple Example

Listing 19.4 is a sample command-line application that will load an SVG document file into a DOM object, add a circle element at random coordinates, and then save the result back to file. If the file doesn't exist when the program is run, a new DOM object will be created. The application will also save a JPEG image of the SVG representation. The imports come from Java I/O (to allow loading and saving of the data), the W3C DOM namespace (which contains the interfaces for Document and Element objects), and various parts of the Batik Toolkit. The class has a DOM Document object as a member variable, along with a couple of values to give the height and width of the image we want to generate. The main() method simply creates a new instance of this class to start the process.

Listing 19.4. SimpleDOM.java

import java.io.*;

import org.w3c.dom.*;

import org.apache.batik.dom.svg.*;
import org.apache.batik.util.*;
import org.apache.batik.transcoder.*;
import org.apache.batik.transcoder.svg2svg.*;
import org.apache.batik.transcoder.image.*;

import org.apache.batik.dom.svg.*;

public class SimpleDOM {

    Document document;
    int WIDTH = 100;
    int HEIGHT = 100;

    public static void main(String[] args) {
        new SimpleDOM();
    }


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint