hi,

is anybody experience this:
when I update the reference element eg:gradient element it doesn't
update the referencing element.
for example I have rect element with fill attr point to gradientElement,
if I update the gradient element
property/child the update doesn't reflected by GVT.

is this gvt or brigde bug? or this is not bug. if this is bug, I will
fill proper bugzilla :)

I attached sample file.

work around:
when update the reference element, update also the referencing element
by setting/update any attribute

Regards
Tonny Kohar
http://www.kiyut.com
/*
 * GVTReferenceBug.java
 *
 * Created on September 25, 2003, 3:51 PM
 */

package kiyut.bug;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;

import org.apache.batik.dom.svg.*;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.swing.gvt.GVTTreeRendererAdapter;
import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter;
import org.apache.batik.swing.svg.SVGDocumentLoaderEvent;
import org.apache.batik.swing.svg.GVTTreeBuilderAdapter;
import org.apache.batik.swing.svg.GVTTreeBuilderEvent;
import org.apache.batik.util.*;

import org.w3c.dom.*;
import org.w3c.dom.css.*;
import org.w3c.dom.svg.*;

/**
 *
 * @author  tonny
 */
public class GVTReferenceBug {
    File file = null;
    SVGDocument doc;
    JSVGCanvas canvas;
    
    public static void main(String[] args) {
        GVTReferenceBug bug = new GVTReferenceBug(args);
        bug.run();
    }
    
    
    public GVTReferenceBug(String[] args) {
        if (args[0] == null) {
            System.out.println("Please enter the svg filename as argument");
            System.exit(1);
        }
        System.out.println(args[0]); //just checking args
        file = new File(args[0]);
    }
    
    public void run() {
        doc = loadSVGDocument(file);
        JFrame frame = createFrame();
        frame.pack();
        frame.setVisible(true);
    }
    
    public SVGDocument loadSVGDocument(File file) {
        try {
            String url = file.toURL().toString();
            String parser = XMLResourceDescriptor.getXMLParserClassName();
            SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
            SVGDocument svgDocument = f.createSVGDocument(url);
            return svgDocument;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    
    private JFrame createFrame() {
        ActionListener actionListener = new ActionListener() {
            public void actionPerformed(ActionEvent e) { buttonActionPerformed(e); }
        };
        
        JButton gradButton = new JButton("update gradient");
        gradButton.setActionCommand("grad_button");
        gradButton.addActionListener(actionListener);
        
        JButton rectButton = new JButton("update rect");
        rectButton.setActionCommand("rect_button");
        rectButton.addActionListener(actionListener);
        
        JPanel buttonPane = new JPanel();
        buttonPane.add(gradButton);
        buttonPane.add(rectButton);
                
        canvas = new JSVGCanvas();
        canvas.setPreferredSize(new Dimension(400,200));
        canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        canvas.setDoubleBufferedRendering(true);
        canvas.setSVGDocument(doc);
        
        // Set the JSVGCanvas listeners.
        canvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
            public void gvtBuildStarted(GVTTreeBuilderEvent e) {
                System.out.println("Build Started...");
            }
            public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
                System.out.println("Build Done.");
            }
        });

        canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
            public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
                System.out.println("Rendering Started...");
            }
            public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
                System.out.println("Rendering Done.");
            }
        });
        
        JPanel contentPane = new JPanel();
        contentPane.setLayout(new BorderLayout());
        contentPane.add(canvas,BorderLayout.CENTER);
        contentPane.add(buttonPane,BorderLayout.SOUTH);       
        
        JFrame frame = new JFrame();
        frame.setContentPane(contentPane);
        return frame;
    }
        
    private void buttonActionPerformed(ActionEvent e) {
        String command = e.getActionCommand();
        if (command.equalsIgnoreCase("grad_button")) {
            // add new gradient stop element with offset 80%, blue color, and opacity 1
            SVGStopElement stopElement = (SVGStopElement)doc.createElementNS(SVGConstants.SVG_NAMESPACE_URI,SVGConstants.SVG_STOP_TAG);
            stopElement.setAttribute(SVGConstants.SVG_OFFSET_ATTRIBUTE, "80%");
            stopElement.setAttribute(SVGConstants.SVG_STOP_COLOR_ATTRIBUTE, "blue");
            stopElement.setAttribute(SVGConstants.SVG_STOP_OPACITY_ATTRIBUTE, "1");
            
            // here is the bug it is not updating canvas, is it gvt or bridge problem?
            Element element = (Element)doc.getElementById("grad1");
            element.appendChild(stopElement);
            
            canvas.repaint();
            canvas.resetRenderingTransform();
            
        } else if (command.equalsIgnoreCase("rect_button")) {
            // bug on batik, update on defs element doesn't reflected on the reference element
            // unless reference element is also updated
            
            SVGRectElement element = (SVGRectElement)doc.getElementById("rect1");
            SVGStylable svgStylable = (SVGStylable)element;
            CSSStyleDeclaration cssStyle = svgStylable.getStyle();
            
            //make sure it is updated, by setting different value first & set back the value
            cssStyle.setProperty(SVGConstants.SVG_FILL_ATTRIBUTE, "black",""); 
            cssStyle.setProperty(SVGConstants.SVG_FILL_ATTRIBUTE, "url(#grad1)","");

            canvas.repaint();
            canvas.resetRenderingTransform();
        } 
    }
}

<<attachment: bug_gvt_reference.svg>>

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

Reply via email to