To paint in swing on top of a JSVGCanvas:
The only thing you need to do is to call PaintChildren in the paint method of the parent component to the JSVGCanvas, and then paint your overlay. The parent can be a JPanel, a JSVGScrollPane, a Viewport, etc. In the example provided the most relevant method is the paint(g), all other stuff is generic Batik canvas.
To do a swing paint() overlay, as adapted from the JSVGCanvas tutorial from the Baitk web site:
x-tad-biggerpublic class OverlayPanel extends JPanel {
JSVGCanvas svgCanvas = new JSVGCanvas();
boolean isVisible = false;
public void paint(java.awt.Graphics g) {
paintChildren(g); // give JSVGCanvas a chance to render
// before we draw the overlay
//Some overlay sample.
if (isVisible) { // in case the overlay should be drawn
// only if we have a SVG document.
// if you track the gvtRenderingCompleted, you
// can have a boolean to activate once the
// document is displayed.
g.setColor(java.awt.Color.RED);
g.fillrect(10,10,100,100);
}
//End of overlay sample.
}
//Some routine to load the SVG document
public setSVGDocument(String uri) {
try {
svgCanvas.setURI(f.toURL().toString());
isVisible = false;
} catch (IOException ex) {
ex.printStackTrace();
}
}
// Constructor that creates the listeners, and adds the
// JSVGCanvas to the panel.
public OverlayPanel() {
this.add(Center, svgCanvas);
// Set the JSVGCanvas listeners.
svgCanvas.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
label.setText(Document Loading...);
}
public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
label.setText(Document Loaded.);
}
});
svgCanvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
public void gvtBuildStarted(GVTTreeBuilderEvent e) {
label.setText(Build Started...);
}
public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
label.setText(Build Done.);
frame.pack();
}
});
svgCanvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
label.setText(Rendering Started...);
}
public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
label.setText();
isVisible = true; // Our document is visible.
// Please note that you may need to
// force a redraw of the swing component
// to make it paint after this stage.
}
});
}
/x-tad-bigger
On Feb 22, 2005, at 2:11 PM, Lasse Riis wrote:
Andres Toussaint wrote:
Hi:
Please define what do you mean by overlay.
Is it a Swing paint() layer on top of your SVG JSVGCanvas? Or is it another element of SVG on top of the first element?
I mean a Swing paint() layer
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]