Hi Meves,
As far as I can tell this is working just the way it is supposed to. In particular it's important to understand that there are several levels of transform involved here. There is the transform from viewBox->window W/H and on top of that is the transform due to currentScale/Translate, which is manipulated by scroll and zoom. With the current code if you also reset currentScale/Trans you will get more or less what you want:
SVGSVGElement svg; svg=(SVGSVGElement)svgDocument.getRootElement(); svg.setAttribute("viewBox","30 30 30 30"); svg.setCurrentScale(1); SVGPoint pt = svg.getCurrentTranslate(); pt.setX(0); pt.setY(0);
However, it is important to be aware that there is a clip associated with viewBox and window W/H. This can be overcome by setting overflow to visible. However I think that what you really want to do is 'bite the bullet' and manipulate the currentScale/Translate to set the view where you want it.
Good luck!
Meves Kai (ext) wrote:
Hello again,
and thanks for the quick response. But I am already using the UpdateManager's thread to perform the change of the viewBox attribute. So that does not seem to be the problem. I found out, that the update is indeed done but not correctly and it seems to have something to do with the fact that I bound the update to the OnScrollAction and/or to the OnZoomAction. When I scroll (using SHIFT+LMB) it updates only the area that was visible before the operation. The rest of the windows remains in the canvas' background-color. Similar effect, when zooming out by using SHIFT+RMB: not the whole canvas is used for the new view - only the box what used to be the old viewport is being updated.
The idea for the application is, that the user should get additional
information (that is dynamically loaded from a server) when he scrolls or
zooms to a special area. To ensure, that he notices the added information,
the viewBox attribute is updated, so the updated information is completely
visible.
I pasted a small example below, which shows the problem or you can see where I am wrong. I also pasted a svg-file, that can be used with the example.
Thank you in Advance, Kai.
----Java Code---- import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import org.apache.batik.swing.JSVGCanvas; import org.apache.batik.bridge.UpdateManager; import org.apache.batik.swing.svg.SVGLoadEventDispatcherAdapter; import org.apache.batik.swing.svg.SVGLoadEventDispatcherEvent; import org.w3c.dom.events.EventListener; import org.w3c.dom.Element; import org.w3c.dom.events.Event; import org.w3c.dom.events.EventTarget; import org.w3c.dom.svg.SVGDocument;
public class CanvasScripting { public static void main(String[] args) { new CanvasScripting(); } JFrame frame; JSVGCanvas canvas; SVGDocument svgDocument; UpdateManager um;
public CanvasScripting() {
frame = new JFrame();
canvas = new JSVGCanvas();
canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
canvas.addSVGLoadEventDispatcherListener
(new SVGLoadEventDispatcherAdapter() {
public void svgLoadEventDispatchStarted
(SVGLoadEventDispatcherEvent e) {
svgDocument = canvas.getSVGDocument(); registerListeners();
um = canvas.getUpdateManager(); }
});
frame.addWindowListener(new WindowAdapter() {
public void windowOpened(WindowEvent e) {
canvas.setURI("doc.svg");
}
});
frame.getContentPane().add(canvas);
frame.setSize(800, 600);
canvas.setSize(700,550);
frame.show();
}
public void registerListeners() {
Element elt = svgDocument.getRootElement();
EventTarget t = (EventTarget)elt;
t.addEventListener("click", new OnClickAction(), false);
t.addEventListener("SVGScroll", new OnScrollAction(),
false);
t.addEventListener("SVGZoom", new OnZoomAction(), false);
}
public class OnClickAction implements EventListener{ public void handleEvent(Event evt) { um.getUpdateRunnableQueue().invokeLater(new Animation()); } } public class OnScrollAction implements EventListener { public void handleEvent(Event evt) { System.out.println("OnScrollAction"); um.getUpdateRunnableQueue().invokeLater(new Animation()); } } public class OnZoomAction implements EventListener { public void handleEvent(Event evt) { um.getUpdateRunnableQueue().invokeLater(new Animation()); } } public class Animation implements Runnable { public void run() { svgDocument.getRootElement().setAttribute("viewBox", "30 30 30 30"); } } }
----SVG File------
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg id="svg909" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"> <defs id="defs911" />
<rect
style="fill:#ffaac8;"
id="rect1"
width="50"
height="50"
x="0"
y="0" />
<rect
style="fill:#ff0000;"
id="rect1"
width="55"
height="55"
x="49"
y="49" /> </svg>
-----------------
-----Original Message----- From: Thomas DeWeese [mailto:[EMAIL PROTECTED] Sent: Montag, 15. November 2004 12:25 To: Batik Users Subject: Re: Resized viewBox Attribute
Hi Meves,
This should work. I suspect that you need to read the FAQ:
http://xml.apache.org/batik/faqs.html#faq-21
Meves Kai (ext) wrote:
Hi there,
I'm currently working with a document, that is displayed by a JSVGCanvas
and
gets modified by my application. There are some elements being added to
the
document by my application. I'm also changing the documents' viewBox attribute by myDoc.getRootElement().setAttribute("viewBox", ...) in order
to
see the added elements (they are placed outside the current viewBox). But the JSVGCanvas seems not to notice the change of the viewBox attribute.
The
Elements are added correctly and visible if they appear inside the old viewBox. When I reload the SVGDocument by JSVGCanvas.setSVGDocument(myDoc) all shows up correctly, but since the document is very large I don't want
to
reload the document every time I add some elements.
Am I doing something wrong or is a change of the viewBox attribute not supported?
Thank you in advance, Kai.
--------------------------------------------------------------------- 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]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]