Return-Path: Delivered-To: apmail-xml-batik-users-archive@www.apache.org Received: (qmail 97723 invoked from network); 13 Jan 2005 15:15:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 13 Jan 2005 15:15:30 -0000 Received: (qmail 39844 invoked by uid 500); 13 Jan 2005 15:14:15 -0000 Delivered-To: apmail-xml-batik-users-archive@xml.apache.org Received: (qmail 39818 invoked by uid 500); 13 Jan 2005 15:14:14 -0000 Mailing-List: contact batik-users-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: "Batik Users" Delivered-To: mailing list batik-users@xml.apache.org Received: (qmail 39782 invoked by uid 99); 13 Jan 2005 15:14:13 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from Unknown (HELO alfa.atrem.pl) (212.244.176.182) by apache.org (qpsmtpd/0.28) with ESMTP; Thu, 13 Jan 2005 07:14:11 -0800 Received: from alfa (localhost [127.0.0.1]) by alfa.atrem.pl (Postfix) with SMTP id BF2948A5 for ; Thu, 13 Jan 2005 17:40:01 +0100 (CET) Received: from KOM107 (unknown [212.244.176.178]) by alfa.atrem.pl (Postfix) with SMTP id 72B7783A for ; Thu, 13 Jan 2005 17:40:01 +0100 (CET) Message-ID: <002701c4f983$336c63f0$2b084d0a@ATREM.PL> From: "Lukasz Matuszczak" To: "Batik Users" Subject: Mix SVG with Swing - Swing GraphicsNode? Date: Thu, 13 Jan 2005 16:18:56 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-2"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 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 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: batik-users-unsubscribe@xml.apache.org For additional commands, e-mail: batik-users-help@xml.apache.org