You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by tk...@apache.org on 2002/02/13 14:00:32 UTC

cvs commit: xml-batik/sources/org/apache/batik/dom/events EventSupport.java

tkormann    02/02/13 05:00:31

  Modified:    sources/org/apache/batik/bridge
                        AbstractGraphicsNodeBridge.java
                        SVGSVGElementBridge.java SVGTextElementBridge.java
                        SVGUseElementBridge.java
               sources/org/apache/batik/dom/events EventSupport.java
  Log:
  - let bubbling phase happen inside all bridge
  - show stacktrace if an error occured inside a DOM listener
  
  Revision  Changes    Path
  1.11      +5 -3      xml-batik/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java
  
  Index: AbstractGraphicsNodeBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AbstractGraphicsNodeBridge.java	13 Feb 2002 09:51:01 -0000	1.10
  +++ AbstractGraphicsNodeBridge.java	13 Feb 2002 13:00:31 -0000	1.11
  @@ -39,7 +39,7 @@
    * </ul>
    *
    * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
  - * @version $Id: AbstractGraphicsNodeBridge.java,v 1.10 2002/02/13 09:51:01 tkormann Exp $
  + * @version $Id: AbstractGraphicsNodeBridge.java,v 1.11 2002/02/13 13:00:31 tkormann Exp $
    */
   public abstract class AbstractGraphicsNodeBridge extends AbstractSVGBridge
       implements GraphicsNodeBridge, ErrorConstants {
  @@ -153,10 +153,12 @@
               }
               node.setTransform(at);
               fireBridgeUpdateCompleted(be);
  +        } else {
  +            System.out.println("Unsupported attribute modification: "+attrName+
  +                               " on "+e.getLocalName());
           }
       }
   
  -
       /**
        * The listener class for 'DOMAttrModified' event.
        */
  @@ -171,7 +173,7 @@
            */
           public void handleEvent(Event evt) {
               if (evt.getTarget() != e) {
  -                throw new Error("handleEvent bad target");
  +                return;
               }
               handleDOMAttrModifiedEvent((MutationEvent)evt);
           }
  
  
  
  1.21      +67 -2     xml-batik/sources/org/apache/batik/bridge/SVGSVGElementBridge.java
  
  Index: SVGSVGElementBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGSVGElementBridge.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- SVGSVGElementBridge.java	11 Feb 2002 16:00:08 -0000	1.20
  +++ SVGSVGElementBridge.java	13 Feb 2002 13:00:31 -0000	1.21
  @@ -22,6 +22,10 @@
   import org.apache.batik.util.SVGConstants;
   
   import org.w3c.dom.Element;
  +import org.w3c.dom.events.Event;
  +import org.w3c.dom.events.EventListener;
  +import org.w3c.dom.events.EventTarget;
  +import org.w3c.dom.events.MutationEvent;
   import org.w3c.dom.svg.SVGElement;
   import org.w3c.dom.svg.SVGSVGElement;
   
  @@ -29,12 +33,27 @@
    * Bridge class for the &lt;svg> element.
    *
    * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
  - * @version $Id: SVGSVGElementBridge.java,v 1.20 2002/02/11 16:00:08 tkormann Exp $
  + * @version $Id: SVGSVGElementBridge.java,v 1.21 2002/02/13 13:00:31 tkormann Exp $
    */
   public class SVGSVGElementBridge extends AbstractSVGBridge
       implements GraphicsNodeBridge, ErrorConstants {
   
       /**
  +     * The element that has been handled by this bridge.
  +     */
  +    protected Element e;
  +
  +    /**
  +     * The graphics node constructed by this bridge.
  +     */
  +    protected GraphicsNode node;
  +
  +    /**
  +     * The bridge context to use for dynamic updates.
  +     */
  +    protected BridgeContext ctx;
  +
  +    /**
        * Constructs a new bridge for the &lt;svg> element.
        */
       public SVGSVGElementBridge() {}
  @@ -46,8 +65,11 @@
           return SVG_SVG_TAG;
       }
   
  +    /**
  +     * Returns a new instance of this bridge.
  +     */
       public Bridge getInstance(){
  -        return this;
  +        return new SVGSVGElementBridge();
       }
   
       /**
  @@ -189,6 +211,12 @@
   
           // bind the specified element and its associated graphics node if needed
           if (ctx.isDynamic()) {
  +            ((EventTarget)e).addEventListener("DOMAttrModified", 
  +                                              new DOMAttrModifiedEventListener(),
  +                                              false);
  +            this.e = e;
  +            this.node = node;
  +            this.ctx = ctx;
               ctx.bind(e, node);
           }
       }
  @@ -200,6 +228,43 @@
           return true;
       }
   
  +    // dynamic support
  +
  +    /**
  +     * Handles DOMAttrModified events.
  +     *
  +     * @param evt the DOM mutation event
  +     */
  +    protected void handleDOMAttrModifiedEvent(MutationEvent evt) {
  +        String attrName = evt.getAttrName();
  +
  +        BridgeUpdateEvent be = new BridgeUpdateEvent();
  +        fireBridgeUpdateStarting(be);
  +        System.out.println("Unsupported attribute modification: "+attrName+
  +                           " on "+e.getLocalName());
  +        fireBridgeUpdateCompleted(be);
  +    }
  +
  +
  +    /**
  +     * The listener class for 'DOMAttrModified' event.
  +     */
  +    protected class DOMAttrModifiedEventListener implements EventListener {
  +
  +        /**
  +         * Handles 'DOMAttrModfied' events and deleguates to the
  +         * 'handleDOMAttrModifiedEvent' method any changes to the
  +         * GraphicsNode if any.
  +         *
  +         * @param evt the DOM event
  +         */
  +        public void handleEvent(Event evt) {
  +            if (evt.getTarget() != e) {
  +                return;
  +            }
  +            handleDOMAttrModifiedEvent((MutationEvent)evt);
  +        }
  +    }
   
       /**
        * A viewport for a SVGSVGElement.
  
  
  
  1.47      +6 -4      xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java
  
  Index: SVGTextElementBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- SVGTextElementBridge.java	13 Feb 2002 09:51:01 -0000	1.46
  +++ SVGTextElementBridge.java	13 Feb 2002 13:00:31 -0000	1.47
  @@ -60,7 +60,7 @@
    * Bridge class for the &lt;text> element.
    *
    * @author <a href="bill.haneman@ireland.sun.com>Bill Haneman</a>
  - * @version $Id: SVGTextElementBridge.java,v 1.46 2002/02/13 09:51:01 tkormann Exp $
  + * @version $Id: SVGTextElementBridge.java,v 1.47 2002/02/13 13:00:31 tkormann Exp $
    */
   public class SVGTextElementBridge extends AbstractSVGBridge
       implements GraphicsNodeBridge, ErrorConstants {
  @@ -258,9 +258,11 @@
                       (e, SVG_TRANSFORM_ATTRIBUTE, s);
               }
               node.setTransform(at);
  -
  +            
               fireBridgeUpdateCompleted(be);
  -
  +        } else {
  +            System.out.println("Unsupported attribute modification: "+attrName+
  +                               " on "+e.getLocalName());
           }
       }
   
  @@ -279,7 +281,7 @@
            */
           public void handleEvent(Event evt) {
               if (evt.getTarget() != e) {
  -                throw new Error("handleEvent bad target");
  +                return;
               }
               handleDOMAttrModifiedEvent((MutationEvent)evt);
           }
  
  
  
  1.18      +69 -2     xml-batik/sources/org/apache/batik/bridge/SVGUseElementBridge.java
  
  Index: SVGUseElementBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGUseElementBridge.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SVGUseElementBridge.java	11 Feb 2002 16:00:08 -0000	1.17
  +++ SVGUseElementBridge.java	13 Feb 2002 13:00:31 -0000	1.18
  @@ -26,6 +26,10 @@
   import org.w3c.dom.NamedNodeMap;
   import org.w3c.dom.Node;
   import org.w3c.dom.css.ViewCSS;
  +import org.w3c.dom.events.Event;
  +import org.w3c.dom.events.EventListener;
  +import org.w3c.dom.events.EventTarget;
  +import org.w3c.dom.events.MutationEvent;
   import org.w3c.dom.svg.SVGSVGElement;
   import org.w3c.dom.svg.SVGSymbolElement;
   
  @@ -33,12 +37,27 @@
    * Bridge class for the &lt;use> element.
    *
    * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
  - * @version $Id: SVGUseElementBridge.java,v 1.17 2002/02/11 16:00:08 tkormann Exp $
  + * @version $Id: SVGUseElementBridge.java,v 1.18 2002/02/13 13:00:31 tkormann Exp $
    */
   public class SVGUseElementBridge extends AbstractSVGBridge
       implements GraphicsNodeBridge, ErrorConstants {
   
       /**
  +     * The element that has been handled by this bridge.
  +     */
  +    protected Element e;
  +
  +    /**
  +     * The graphics node constructed by this bridge.
  +     */
  +    protected GraphicsNode node;
  +
  +    /**
  +     * The bridge context to use for dynamic updates.
  +     */
  +    protected BridgeContext ctx;
  +
  +    /**
        * Constructs a new bridge for the &lt;use> element.
        */
       public SVGUseElementBridge() {}
  @@ -50,8 +69,11 @@
           return SVG_USE_TAG;
       }
   
  +    /**
  +     * Returns a new instance of this bridge.
  +     */
       public Bridge getInstance(){
  -        return this;
  +        return new SVGUseElementBridge();
       }
   
       /**
  @@ -211,6 +233,13 @@
   
           // bind the specified element and its associated graphics node if needed
           if (ctx.isDynamic()) {
  +            ((EventTarget)e).addEventListener("DOMAttrModified", 
  +                                              new DOMAttrModifiedEventListener(),
  +                                              false);
  +            this.e = e;
  +            this.node = node;
  +            this.ctx = ctx;
  +
               ctx.bind(e, node);
           }
       }
  @@ -220,5 +249,43 @@
        */
       public boolean isComposite() {
           return false;
  +    }
  +
  +    // dynamic support
  +
  +    /**
  +     * Handles DOMAttrModified events.
  +     *
  +     * @param evt the DOM mutation event
  +     */
  +    protected void handleDOMAttrModifiedEvent(MutationEvent evt) {
  +        String attrName = evt.getAttrName();
  +
  +        BridgeUpdateEvent be = new BridgeUpdateEvent();
  +        fireBridgeUpdateStarting(be);
  +        System.out.println("Unsupported attribute modification: "+attrName+
  +                           " on "+e.getLocalName());
  +        fireBridgeUpdateCompleted(be);
  +    }
  +
  +
  +    /**
  +     * The listener class for 'DOMAttrModified' event.
  +     */
  +    protected class DOMAttrModifiedEventListener implements EventListener {
  +
  +        /**
  +         * Handles 'DOMAttrModfied' events and deleguates to the
  +         * 'handleDOMAttrModifiedEvent' method any changes to the
  +         * GraphicsNode if any.
  +         *
  +         * @param evt the DOM event
  +         */
  +        public void handleEvent(Event evt) {
  +            if (evt.getTarget() != e) {
  +                return;
  +            }
  +            handleDOMAttrModifiedEvent((MutationEvent)evt);
  +        }
       }
   }
  
  
  
  1.6       +3 -3      xml-batik/sources/org/apache/batik/dom/events/EventSupport.java
  
  Index: EventSupport.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/events/EventSupport.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EventSupport.java	2 Aug 2001 17:58:00 -0000	1.5
  +++ EventSupport.java	13 Feb 2002 13:00:31 -0000	1.6
  @@ -19,7 +19,7 @@
    * @see NodeEventTarget
    * @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: EventSupport.java,v 1.5 2001/08/02 17:58:00 hillion Exp $
  + * @version $Id: EventSupport.java,v 1.6 2002/02/13 13:00:31 tkormann Exp $
    */
   public class EventSupport {
   
  @@ -220,8 +220,8 @@
   	for (int i=0; i < listeners.length; ++i) {
   	    try {
   		listeners[i].handleEvent(evt);
  -	    } catch (Throwable th) { 
  -		// <!> FIXME: should do something else
  +	    } catch (Throwable th) {
  +                th.printStackTrace(System.err);
   	    }
   	}
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org