Java Reference
In-Depth Information
Listing 16-15. Creating and Populating an SVG Image
class MIDPSVGEditor implements SVGEventListener, Runnable {
private static final String svgNS = "http://www.w3.org/2000/svg";
private SVGDocument svgDocument;
private SVGAnimator svgAnimator;
private Vector addToTree = new Vector();
private int cx, cy;
public MIDPSVGEditor (SVGImage svgi) {
svgDocument = svgi.getDocument();
svgAnimator = SVGAnimator.createAnimator(svgi);
svgAnimator.setSVGEventListener(this);
}
public Object getTargetComponent() {
return svgAnimator.getTargetComponent();
}
public void pointerPressed(int x, int y) {
}
public void pointerReleased(int x, int y) {
cx = x;
cy = y;
}
public void keyPressed(int keyCode) {
SVGElement circle = svgDocument.createElementNS(svgNS, "circle");
circle.setFloatTrait("cx", (float)cx);
circle.setFloatTrait("cy", (float)cy);
synchronized (addToTree) {
addToTree.addElement(circle);
}
svgAnimator.invokeLater(this);
}
public void keyReleased(int keyCode) {
}
 
Search WWH ::




Custom Search