Hi,
In response to your suggestion about overlaying new svg documents on
existing documents, I have tried
(a) option 1 - by creating a single svg document, containing all the svg
documents that I want to load. Visibility and opacity are set at the GVT
tree level.
However the resulting svg document was large and took some time to render
and not all the documents were required at startup.
Our aim is to allow the user to specify the svg image on the fly, load it
and render it over an existing svg document that is loaded at startup.
(b) option 2 - overlaying a new svg document on an existing document by
creating multiple SVG documents (based on the sample code [see below] from
Stephane Hillon on the subject of "multilayering SVG output with Batik dated
9/8/2001" with some modifications).
However I have the following problems
(1) zoom in (ctrl + right mouse button) only works on svgcanvas (ie the
initial document I loaded). The zoom does not work on svgcanvas_another
which is the other svg document I selected through the filechooser.
The same problem occurs for pan, zoom out etc. How could I rectify this so
that all layers register the zoom/pan/etc event and perform zoom/pan/etc
insync.
(2) tool tips work only on svgcanvas (the initial document I loaded). How
can I get it to work on all the other layers as well.
(3) How do I set the panels to be transparent so that the various layers
(svg documents) show through without setting the opacity in the svg file or
manipulating the elements in the DOM or GVT tree.
(4) is there anything critical missing in my code.
Thank you.
Regards
Leakha
(please see sample code below using multiple svg canvas)
***************************************
sample code for multi-layering of svg canvas based on stephane
***************************************
package rimis.apps.epss;
import java.awt.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.awt.event.*;
import java.io.*;
import java.awt.color.*;
import java.net.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*; //contains ResourceBundle, Locale
import java.util.zip.*;
import javax.swing.text.*;
import org.w3c.dom.*;
import org.w3c.dom.svg.*;
import org.w3c.dom.css.ViewCSS;
import org.w3c.dom.css.*;
import org.w3c.dom.svg.SVGDocument;
import org.apache.batik.swing.svg.*;
import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter;//SVG to SVG dom
import org.apache.batik.swing.svg.SVGDocumentLoaderEvent;
import org.apache.batik.swing.svg.SVGDocumentLoaderListener;
import org.apache.batik.swing.svg.GVTTreeBuilderAdapter;//SVG dom to
Graphics Vector Toolkit tree (GVT)
import org.apache.batik.swing.svg.GVTTreeBuilderEvent;
import org.apache.batik.swing.svg.GVTTreeBuilderListener;
import org.apache.batik.swing.gvt.GVTTreeRendererAdapter;//GVT to image
import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
import org.apache.batik.gvt.*;
import org.apache.batik.gvt.event.EventDispatcher;
//import org.apache.batik.util.UnitProcessor;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.util.gui.resource.*;
import org.apache.batik.util.*;
import org.apache.batik.util.gui.resource.ToolBarFactory;
import org.apache.batik.util.gui.resource.ActionMap;
import org.apache.batik.util.gui.resource.ResourceManager;
import org.apache.batik.transcoder.*;
import org.apache.batik.swing.gvt.*;
import org.apache.batik.dom.svg.SVGOMDocument;
import org.apache.batik.xml.XMLUtilities;
import org.apache.batik.dom.*;
import org.apache.batik.script.*;
import org.apache.batik.dom.svg.*;
import org.apache.batik.swing.svg.SVGUserAgent;
import org.apache.batik.bridge.*;
import org.apache.batik.transcoder.image.*;
import org.apache.batik.transcoder.*;
import org.apache.batik.ext.swing.JAffineTransformChooser;
import org.apache.batik.ext.*;
//public class showSVG implements SVGDocumentLoaderListener,
GVTTreeBuilderListener,GVTTreeRendererListener {
public class showSVG_updated {
protected JPanel panel = new JPanel(new BorderLayout());
protected JLabel statusbar = new JLabel("");
protected boolean turnoff = false;
protected JLabel hdr = new JLabel("Spatial View of Little River in
Warrangong");
protected RimisCanvas svgcanvas;
protected RimisCanvas svgcanvas_another;
protected Map listeners = new HashMap();
protected SVGDocument doc;
protected Vector layerstable;
protected AddAct docload;
protected boolean layervisible;
protected boolean cont;
protected AddAct owner;
protected JButton filechooser_button;
protected JPanel main_panel;
// protected Application application;
// protected SVGUserAgent useragent = new UserAgent();
protected SVGUserAgent useragent;
// public showSVG_updated(JFrame frame) {
public showSVG_updated(JFrame f) {
super();
JFrame frame = f;
main_panel = new JPanel(new BorderLayout());
filechooser_button = new JButton("File chooser");
filechooser_button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
JFileChooser fc = new JFileChooser(".");
int choice = fc.showOpenDialog(main_panel);
if (choice ==JFileChooser.APPROVE_OPTION){
File f = fc.getSelectedFile();
try{
svgcanvas_another.setURI(f.toURL().toString());
} catch (IOException ex){
ex.printStackTrace();
}
}
}
});
main_panel.add("North",filechooser_button);
svgcanvas = new RimisCanvas();
svgcanvas_another = new RimisCanvas();
JPanel p = new JPanel(new StackLayout());
p.add(svgcanvas);
p.add(svgcanvas_another);
svgcanvas.setBackground(new Color(0,0,0,0)); //***this line differs
from the solution proposed by Stephane
main_panel.add("Center",p);
frame.getContentPane().add(main_panel);
// panel.setBorder(new EtchedBorder (EtchedBorder.RAISED));
// panel.add("North",hdr);
// panel.add("South",statusbar);
// System.out.println("SVGCanvas value:"+svgcanvas);
/*******/
svgcanvas_another.addSVGDocumentLoaderListener(new
SVGDocumentLoaderAdapter() {
public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
System.out.println("in addsvgdocumentloader");
statusbar.setText("Document Loading....");
}
public void documentLoadingCompleted(SVGDocumentLoaderEvent e){
System.out.println("in addsvgdocumentcompleted");
}
public void documentLoadingCancelled(SVGDocumentLoaderEvent e){
statusbar.setText("Document Loading
Cancelled....");
System.out.println("loading cancelled");
}
public void documentLoadingFailed(SVGDocumentLoaderEvent e){
statusbar.setText("Document Loading
Failed....");
System.out.println("loading failed");
}
});
svgcanvas_another.addGVTTreeBuilderListener(new
GVTTreeBuilderAdapter(){
BridgeContext ctx ;
public void gvtBuildStarted(GVTTreeBuilderEvent e){
System.out.println("in addgvttreebuild");
statusbar.setText("Map Build Started....");
}
public void gvtBuildCompleted(GVTTreeBuilderEvent e){
System.out.println("in addgvttreebuildcompleted");
statusbar.setText("Build done.");
}
});
svgcanvas_another.addGVTTreeRendererListener(new
GVTTreeRendererAdapter(){
public void gvtRenderingPrepare(GVTTreeRendererEvent e){
System.out.println("in addgvttreecumentloader");
statusbar.setText("Rendering started...");
}
public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
System.out.println("in addgvttreecumentcompleted");
statusbar.setText("Rendering completed...");
}
});
svgcanvas.setURI("file:resources/svg/testbmu.svg");
}
public static class StackLayout implements LayoutManager {
public void addLayoutComponent(String name, Component comp) {
// nothing to do
}
public void layoutContainer(Container parent) {
Dimension dim = parent.getSize();
for (int i=0; i < parent.getComponentCount(); ++i) {
parent.getComponent(i).setBounds(0, 0, dim.width,
dim.height);
}
}
public Dimension minimumLayoutSize(Container parent) {
Dimension minSize = new Dimension(0, 0);
for (int i=0; i < parent.getComponentCount(); ++i) {
Dimension dim = parent.getComponent(i).getMinimumSize();
minSize.width = Math.max(minSize.width, dim.width);
minSize.height = Math.max(minSize.height, dim.height);
}
return minSize;
}
public Dimension preferredLayoutSize(Container parent) {
Dimension size = new Dimension(0, 0);
for (int i=0; i < parent.getComponentCount(); ++i) {
Dimension dim = parent.getComponent(i).getPreferredSize();
size.width = Math.max(size.width, dim.width);
size.height = Math.max(size.height, dim.height);
}
return size;
}
public void removeLayoutComponent(Component comp) {
// nothing to do
}
}
}
*******************************************************************
-----Original Message-----
From: Vincent Hardy [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 09, 2001 9:26 PM
To: Batik Users
Subject: Re: overlaying new svg documents on existing documents
Leakha,
Depending on what you want to do, I think you could:
a. Use a single SVG document with <image> elements and the opacity
you want on it.
b. Use multiple overlaid JSVGCanvas.
I hope this helps.
Vincent
[EMAIL PROTECTED] wrote:
>
> I would like to be able to overlay new svg documents on existing svg
> documents. Furthermore these documents have to be semi-transparent so
that
> all the layers are visible.
>
> Could you please suggest options on how I can achieve this.
>
> Thank you.
>
> Regards
> Leakha
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]