tkormann 02/04/22 10:08:56 Modified: sources/org/apache/batik/bridge BridgeContext.java BridgeEventSupport.java ScriptingEnvironment.java Added: sources/org/apache/batik/bridge FocusManager.java Log: - add a new class FocusManager that has the current element with focus - add support for DOMFocusIn and DOMFocusOut event type - bug fix in event dispatcher next, add support for DOMActivate event type Revision Changes Path 1.46 +17 -1 xml-batik/sources/org/apache/batik/bridge/BridgeContext.java Index: BridgeContext.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeContext.java,v retrieving revision 1.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- BridgeContext.java 22 Apr 2002 14:59:44 -0000 1.45 +++ BridgeContext.java 22 Apr 2002 17:08:55 -0000 1.46 @@ -66,7 +66,7 @@ * a SVG DOM tree such as the current viewport or the user agent. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: BridgeContext.java,v 1.45 2002/04/22 14:59:44 tkormann Exp $ + * @version $Id: BridgeContext.java,v 1.46 2002/04/22 17:08:55 tkormann Exp $ */ public class BridgeContext implements ErrorConstants, CSSContext { @@ -331,6 +331,13 @@ } /** + * Returns the focus manager. + */ + public FocusManager getFocusManager() { + return focusManager; + } + + /** * Sets the interpreter pool used to handle scripts to the * specified interpreter pool. * @param interpreterPool the interpreter pool @@ -729,6 +736,11 @@ protected CSSEngineListener cssPropertiesChangedListener; /** + * The EventListener that is responsible of managing DOM focus event. + */ + protected FocusManager focusManager; + + /** * Adds EventListeners to the DOM and CSSEngineListener to the * CSSEngine to handle any modifications on the DOM tree or style * properties and update the GVT tree in response. @@ -757,6 +769,8 @@ domCharacterDataModifiedListener, true); + focusManager = new FocusManager(document); + SVGOMDocument svgDocument = (SVGOMDocument)document; CSSEngine cssEngine = svgDocument.getCSSEngine(); cssPropertiesChangedListener = new CSSPropertiesChangedListener(); @@ -784,6 +798,8 @@ SVGOMDocument svgDocument = (SVGOMDocument)document; CSSEngine cssEngine = svgDocument.getCSSEngine(); cssEngine.removeCSSEngineListener(cssPropertiesChangedListener); + + focusManager.dispose(); } /** 1.31 +5 -9 xml-batik/sources/org/apache/batik/bridge/BridgeEventSupport.java Index: BridgeEventSupport.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeEventSupport.java,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- BridgeEventSupport.java 22 Apr 2002 14:24:57 -0000 1.30 +++ BridgeEventSupport.java 22 Apr 2002 17:08:55 -0000 1.31 @@ -49,20 +49,16 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; + import org.w3c.dom.events.DocumentEvent; import org.w3c.dom.events.Event; import org.w3c.dom.events.EventListener; import org.w3c.dom.events.EventTarget; import org.w3c.dom.events.MouseEvent; + import org.w3c.dom.svg.SVGElement; import org.w3c.dom.svg.SVGSVGElement; - // <!> FIXME: TO BE REMOVED - // <!> FIXME: TO BE REMOVED - // <!> FIXME: TO BE REMOVED - // <!> FIXME: TO BE REMOVED - // <!> FIXME: TO BE REMOVED - /** * A class to attach listeners on the <code>Document</code> to * call pieces of script when necessary and to attach a listener @@ -70,9 +66,9 @@ * * @author <a href="mailto:[EMAIL PROTECTED]>Christophe Jolif</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: BridgeEventSupport.java,v 1.30 2002/04/22 14:24:57 tkormann Exp $ + * @version $Id: BridgeEventSupport.java,v 1.31 2002/04/22 17:08:55 tkormann Exp $ */ -class BridgeEventSupport implements SVGConstants { +public class BridgeEventSupport implements SVGConstants { private BridgeEventSupport() {} @@ -350,7 +346,7 @@ Element target = context.getElement(node); // Lookup inside the text element children to see if the target // is a tspan or textPath - if (node instanceof TextNode) { + if (target != null && node instanceof TextNode) { TextNode textNode = (TextNode)node; List list = textNode.getTextRuns(); for (int i = 0 ; i < list.size(); i++) { 1.24 +5 -5 xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java Index: ScriptingEnvironment.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- ScriptingEnvironment.java 15 Apr 2002 10:16:12 -0000 1.23 +++ ScriptingEnvironment.java 22 Apr 2002 17:08:56 -0000 1.24 @@ -47,7 +47,7 @@ * This class contains the informations needed by the SVG scripting. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: ScriptingEnvironment.java,v 1.23 2002/04/15 10:16:12 hillion Exp $ + * @version $Id: ScriptingEnvironment.java,v 1.24 2002/04/22 17:08:56 tkormann Exp $ */ public class ScriptingEnvironment extends BaseScriptingEnvironment { @@ -329,10 +329,10 @@ // UI listeners if (elt.hasAttributeNS(null, "onfocusin")) { - target.addEventListener("focusin", focusinListener, false); + target.addEventListener("DOMFocusIn", focusinListener, false); } if (elt.hasAttributeNS(null, "onfocusout")) { - target.addEventListener("focusout", focusoutListener, false); + target.addEventListener("DOMFocusOut", focusoutListener, false); } if (elt.hasAttributeNS(null, "onactivate")) { target.addEventListener("activate", activateListener, false); @@ -408,8 +408,8 @@ } // UI listeners - target.removeEventListener("focusin", focusinListener, false); - target.removeEventListener("focusout", focusoutListener, false); + target.removeEventListener("DOMFocusIn", focusinListener, false); + target.removeEventListener("DOMFocusOut", focusoutListener, false); target.removeEventListener("activate", activateListener, false); target.removeEventListener("click", clickListener, false); target.removeEventListener("mousedown", mousedownListener, false); 1.1 xml-batik/sources/org/apache/batik/bridge/FocusManager.java Index: FocusManager.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.bridge; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.events.DocumentEvent; import org.w3c.dom.events.Event; import org.w3c.dom.events.EventListener; import org.w3c.dom.events.EventTarget; import org.w3c.dom.events.UIEvent; import org.w3c.dom.events.MouseEvent; /** * A class that manages focus on elements. Users of this class needs * to attached this EventListener with the 'mouseover' event type. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: FocusManager.java,v 1.1 2002/04/22 17:08:56 tkormann Exp $ */ public class FocusManager { /** * The element that has the focus so far. */ protected EventTarget lastFocusEventTarget; /** * The document. */ protected Document document; /** * The EventListener that tracks 'DOMFocusIn' events. */ protected EventListener domFocusInListener; /** * The EventListener that tracks 'DOMFocusOut' events. */ protected EventListener domFocusOutListener; /** * The EventListener that tracks 'mouseover' events. */ protected EventListener mouseoverListener; /** * The EventListener that tracks 'mouseout' events. */ protected EventListener mouseoutListener; /** * Constructs a new <tt>FocusManager</tt> for the specified document. * * @param doc the document */ public FocusManager(Document doc) { document = doc; EventTarget target = (EventTarget)doc; mouseoverListener = new MouseOverTacker(); target.addEventListener("mouseover", mouseoverListener, true); mouseoutListener = new MouseOutTacker(); target.addEventListener("mouseout", mouseoutListener, true); domFocusInListener = new DOMFocusInTracker(); target.addEventListener("DOMFocusIn", domFocusInListener, true); domFocusOutListener = new DOMFocusOutTracker(); target.addEventListener("DOMFocusOut", domFocusOutListener, true); } /** * Returns the current element that has the focus or null if any. */ public EventTarget getCurrentEventTarget() { return lastFocusEventTarget; } /** * Removes all listeners attached to the document and that manage focus. */ public void dispose() { EventTarget target = (EventTarget)document; target.removeEventListener("mouseover", mouseoverListener, true); target.removeEventListener("mouseout", mouseoutListener, true); target.removeEventListener("DOMFocusIn", domFocusInListener, true); target.removeEventListener("DOMFocusOut", domFocusOutListener, true); } /** * The class that is responsible for tracking 'DOMFocusIn' changes. */ protected class DOMFocusInTracker implements EventListener { public void handleEvent(Event evt) { if (lastFocusEventTarget != null && lastFocusEventTarget != evt.getTarget()) { fireDOMFocusOutEvent(lastFocusEventTarget); } lastFocusEventTarget = evt.getTarget(); } } /** * The class that is responsible for tracking 'DOMFocusOut' changes. */ protected class DOMFocusOutTracker implements EventListener { public void handleEvent(Event evt) { lastFocusEventTarget = null; } } /** * The class that is responsible to update the focus according to * 'mouseover' event. */ protected class MouseOverTacker implements EventListener { public void handleEvent(Event evt) { EventTarget target = evt.getTarget(); fireDOMFocusInEvent(target); } } /** * The class that is responsible to update the focus according to * 'mouseout' event. */ protected class MouseOutTacker implements EventListener { public void handleEvent(Event evt) { EventTarget target = evt.getTarget(); fireDOMFocusOutEvent(target); } } /** * Fires a 'DOMFocusIn' event to the specified target. * * @param target the event target */ protected void fireDOMFocusInEvent(EventTarget target) { DocumentEvent docEvt = (DocumentEvent)((Element)target).getOwnerDocument(); UIEvent uiEvt = (UIEvent)docEvt.createEvent("UIEvents"); uiEvt.initUIEvent("DOMFocusIn", true, false, null, 0); target.dispatchEvent(uiEvt); } /** * Fires a 'DOMFocusOut' event to the specified target. * * @param target the event target */ protected void fireDOMFocusOutEvent(EventTarget target) { DocumentEvent docEvt = (DocumentEvent)((Element)target).getOwnerDocument(); UIEvent uiEvt = (UIEvent)docEvt.createEvent("UIEvents"); uiEvt.initUIEvent("DOMFocusOut", true, false, null, 0); target.dispatchEvent(uiEvt); } /** * Fires a 'DOMActivate' event to the specified target. * * @param target the event target * @param detailArg the detailArg parameter of the event */ protected void fireDOMActivateEvent(EventTarget target, int detailArg) { DocumentEvent docEvt = (DocumentEvent)((Element)target).getOwnerDocument(); UIEvent uiEvt = (UIEvent)docEvt.createEvent("UIEvents"); uiEvt.initUIEvent("DOMActivate", true, true, null, detailArg); target.dispatchEvent(uiEvt); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]