I'm using the batik toolkit to create dynamic and interactive diagrams in my Swing application. The diagrams should mix typical SVG content with swing components, like a JButton, ChartPanel (from JFreeChart project). I assume that my diagram consists of a SVG background (presented by JSVGCanvas or potentially one of its superclasses) and components, which locations and sizes are specified relative to coordinate system of the background. By the way, due to performance reasons, some of my components are simply transparent JSVGCanvases. For example when I want to change quickly some small part of my SVG document (for example to rotate fast a small arrow symbol in a big complicated document), using single JSVGCanvas turned out to be totally ineffective. Instead I'm cutting out DOM fragment and creating separate SVG document out of it. It is a little tricky solution because i have to set <svg> tag viewbox attribute properly for the additional SVG Document, when i want my JSVGCanvas component to have a different location and size than my background JSVGCanvas.

I have already created my own tags such as <oc:component id="btn1" type="JButton" x="100" y="170" width="200" height="20"><oc:param name="caption" value="My Button"></oc:component>

I can see different approaches to implement SVG and Swing mix.

1. Using JLayeredPane with custom layout manager. It is my current approach, with which i'm not satisfied. In layout container we can set components' bounds in layoutContainer method, based on viewboxtransform of background canvas. The layered pane revalidate method is called in gvtRenderingCompleted or updateCompleted when the viewbox transform has changed. Off course it's a simplification, because components' bounds should be calculated according to their parent tags coordinate system.
The shortcoming of this solution is that we can't put JLayeredPane in JSVGScrollPane, so we have to implement all zoom and scrolling stuff on our own.
2. Using JSVGCanvas as container (add method) - it is similar to first solution, but it's potentially easier to use JSVGScrollPane.
3. Using batik extension mechanism. It would be the best solution because all positioning, zooming, scrolling, painting, printing and so on, would be supported directly by batik. Also i could partially cover swing components by SVG shapes.
Thierry Kormann in http://koala.ilog.fr/batik/mlists/batik-users/archives/msg01001.html suggests that it is possible, but i got stuck in event dispatching and repainting.
I have made bridges and dom extensions and MyComponentNode extending AbstractGraphicsNode.
For example i call JButton's paint from MyComponentNode's primitivePaint(..) method to paint button at specific place:


public void primitivePaint(Graphics2D g2d) {
 ...
 Graphics gForComponent = g2d.create();
 gForComponent.translate(button.getX(), button.getY());
 button.paint(gForComponent);
 ...
}

At MyComponentNodeBridge' createGraphicsNode method I register listener on graphics nodes mouse events. The code is:

 UserAgent ua = ctx.getUserAgent();
 if (ua != null) {
 EventDispatcher dispatcher = ua.getEventDispatcher();
 if (dispatcher != null) {
   dispatcher.addGraphicsNodeMouseListener(node.getMouseListener());
 }

I wanted to implement all methods of my mouseListener similar to:
button.dispatchEvent(new MouseEvent(button,
 evt.getID(),
 evt.getWhen(),
 evt.getModifiers(),
 x,
 y,
 evt.getClickCount(),
 false));

Well, it nearly works but the problem is that the JButton doesn't belong to Swing hierarchy so it won't repaint itself (for example to show that it's pressed down).

Has anyone succeeded in making graphics node in GVT Tree based on Swing Component, making it interactive when showed in JSVGCanvas?

I would also be grateful for any thoughts about advantages and disadvantages of above approaches (espacially in the context of memory and processor usage).

Thanks in advance.
Lukasz Matuszczak




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to