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]