org.w3c.dom.events.EventListener Java Examples

The following examples show how to use org.w3c.dom.events.EventListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebBrowserBoxController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
protected void clickLink() {
        EventListener listener = new EventListener() {
            public void handleEvent(Event ev) {
//                    ev.;
            }
        };
        Document doc = webEngine.getDocument();
        Element el = doc.getElementById("exit-app");
        ((EventTarget) el).addEventListener("click", listener, false);

        NodeList links = doc.getElementsByTagName("a");
        for (int i = 0; i < links.getLength(); ++i) {
//            Node node = links.item(i);
//            String link = links.item(i).toString();
//
//            EventListener listener = new EventListener() {
//                public void handleEvent(Event ev) {
////                    ev.;
//                }
//            };

        }
    }
 
Example #2
Source File: DocumentImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Register an event listener with this
 * Node. A listener may be independently registered as both Capturing and
 * Bubbling, but may only be registered once per role; redundant
 * registrations are ignored.
 * @param node node to add listener to
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void addEventListener(NodeImpl node, String type,
                                EventListener listener, boolean useCapture)
{
    // We can't dispatch to blank type-name, and of course we need
    // a listener to dispatch to
    if (type == null || type.equals("") || listener == null)
        return;

    // Each listener may be registered only once per type per phase.
    // Simplest way to code that is to zap the previous entry, if any.
    removeEventListener(node, type, listener, useCapture);

    List<LEntry> nodeListeners = getEventListeners(node);
    if(nodeListeners == null) {
        nodeListeners = new ArrayList<>();
        setEventListeners(node, nodeListeners);
    }
    nodeListeners.add(new LEntry(type, listener, useCapture));

    // Record active listener
    LCount lc = LCount.lookup(type);
    if (useCapture) {
        ++lc.captures;
        ++lc.total;
    }
    else {
        ++lc.bubbles;
        ++lc.total;
    }

}
 
Example #3
Source File: DocumentImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Deregister an event listener previously
 * registered with this Node.  A listener must be independently removed
 * from the Capturing and Bubbling roles. Redundant removals (of listeners
 * not currently registered for this role) are ignored.
 * @param node node to remove listener from
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void removeEventListener(NodeImpl node, String type,
                                   EventListener listener,
                                   boolean useCapture)
{
    // If this couldn't be a valid listener registration, ignore request
    if (type == null || type.equals("") || listener == null)
        return;
    List<LEntry> nodeListeners = getEventListeners(node);
    if (nodeListeners == null)
        return;

    // Note that addListener has previously ensured that
    // each listener may be registered only once per type per phase.
    // count-down is OK for deletions!
    for (int i = nodeListeners.size() - 1; i >= 0; --i) {
        LEntry le = nodeListeners.get(i);
        if (le.useCapture == useCapture && le.listener == listener &&
            le.type.equals(type)) {
            nodeListeners.remove(i);
            // Storage management: Discard empty listener lists
            if (nodeListeners.isEmpty())
                setEventListeners(node, null);

            // Remove active listener
            LCount lc = LCount.lookup(type);
            if (useCapture) {
                --lc.captures;
                --lc.total;
            }
            else {
                --lc.bubbles;
                --lc.total;
            }

            break;  // Found it; no need to loop farther.
        }
    }
}
 
Example #4
Source File: DocumentImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Register an event listener with this
 * Node. A listener may be independently registered as both Capturing and
 * Bubbling, but may only be registered once per role; redundant
 * registrations are ignored.
 * @param node node to add listener to
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void addEventListener(NodeImpl node, String type,
                                EventListener listener, boolean useCapture)
{
    // We can't dispatch to blank type-name, and of course we need
    // a listener to dispatch to
    if (type == null || type.equals("") || listener == null)
        return;

    // Each listener may be registered only once per type per phase.
    // Simplest way to code that is to zap the previous entry, if any.
    removeEventListener(node, type, listener, useCapture);

    List<LEntry> nodeListeners = getEventListeners(node);
    if(nodeListeners == null) {
        nodeListeners = new ArrayList<>();
        setEventListeners(node, nodeListeners);
    }
    nodeListeners.add(new LEntry(type, listener, useCapture));

    // Record active listener
    LCount lc = LCount.lookup(type);
    if (useCapture) {
        ++lc.captures;
        ++lc.total;
    }
    else {
        ++lc.bubbles;
        ++lc.total;
    }

}
 
Example #5
Source File: DocumentImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Register an event listener with this
 * Node. A listener may be independently registered as both Capturing and
 * Bubbling, but may only be registered once per role; redundant
 * registrations are ignored.
 * @param node node to add listener to
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void addEventListener(NodeImpl node, String type,
                                EventListener listener, boolean useCapture)
{
    // We can't dispatch to blank type-name, and of course we need
    // a listener to dispatch to
    if (type == null || type.equals("") || listener == null)
        return;

    // Each listener may be registered only once per type per phase.
    // Simplest way to code that is to zap the previous entry, if any.
    removeEventListener(node, type, listener, useCapture);

    List<LEntry> nodeListeners = getEventListeners(node);
    if(nodeListeners == null) {
        nodeListeners = new ArrayList<>();
        setEventListeners(node, nodeListeners);
    }
    nodeListeners.add(new LEntry(type, listener, useCapture));

    // Record active listener
    LCount lc = LCount.lookup(type);
    if (useCapture) {
        ++lc.captures;
        ++lc.total;
    }
    else {
        ++lc.bubbles;
        ++lc.total;
    }

}
 
Example #6
Source File: XmlLocationAnnotator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public XmlLocationAnnotator(XMLReader xmlReader, Document dom) {
    super(xmlReader);

    // Add listener to DOM, so we know which node was added.
    EventListener modListener = new EventListener() {
        @Override
        public void handleEvent(Event e) {
            EventTarget target = ((MutationEvent) e).getTarget();
            elementStack.push((Element) target);
        }
    };
    ((EventTarget) dom).addEventListener("DOMNodeInserted", modListener, true);
}
 
Example #7
Source File: XmlLocationAnnotator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public XmlLocationAnnotator(XMLReader xmlReader, Document dom) {
    super(xmlReader);

    // Add listener to DOM, so we know which node was added.
    EventListener modListener = new EventListener() {
        @Override
        public void handleEvent(Event e) {
            EventTarget target = ((MutationEvent) e).getTarget();
            elementStack.push((Element) target);
        }
    };
    ((EventTarget) dom).addEventListener("DOMNodeInserted", modListener, true);
}
 
Example #8
Source File: DocumentImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/** NON-DOM INTERNAL: Constructor for Listener list Entry
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCaptue True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
LEntry(String type, EventListener listener, boolean useCapture)
{
    this.type = type;
    this.listener = listener;
    this.useCapture = useCapture;
}
 
Example #9
Source File: DocumentImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/** NON-DOM INTERNAL: Constructor for Listener list Entry
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCaptue True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
LEntry(String type, EventListener listener, boolean useCapture)
{
    this.type = type;
    this.listener = listener;
    this.useCapture = useCapture;
}
 
Example #10
Source File: DocumentImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Register an event listener with this
 * Node. A listener may be independently registered as both Capturing and
 * Bubbling, but may only be registered once per role; redundant
 * registrations are ignored.
 * @param node node to add listener to
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void addEventListener(NodeImpl node, String type,
                                EventListener listener, boolean useCapture)
{
    // We can't dispatch to blank type-name, and of course we need
    // a listener to dispatch to
    if (type == null || type.equals("") || listener == null)
        return;

    // Each listener may be registered only once per type per phase.
    // Simplest way to code that is to zap the previous entry, if any.
    removeEventListener(node, type, listener, useCapture);

    List<LEntry> nodeListeners = getEventListeners(node);
    if(nodeListeners == null) {
        nodeListeners = new ArrayList<>();
        setEventListeners(node, nodeListeners);
    }
    nodeListeners.add(new LEntry(type, listener, useCapture));

    // Record active listener
    LCount lc = LCount.lookup(type);
    if (useCapture) {
        ++lc.captures;
        ++lc.total;
    }
    else {
        ++lc.bubbles;
        ++lc.total;
    }

}
 
Example #11
Source File: DocumentImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Deregister an event listener previously
 * registered with this Node.  A listener must be independently removed
 * from the Capturing and Bubbling roles. Redundant removals (of listeners
 * not currently registered for this role) are ignored.
 * @param node node to remove listener from
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void removeEventListener(NodeImpl node, String type,
                                   EventListener listener,
                                   boolean useCapture)
{
    // If this couldn't be a valid listener registration, ignore request
    if (type == null || type.equals("") || listener == null)
        return;
    List<LEntry> nodeListeners = getEventListeners(node);
    if (nodeListeners == null)
        return;

    // Note that addListener has previously ensured that
    // each listener may be registered only once per type per phase.
    // count-down is OK for deletions!
    for (int i = nodeListeners.size() - 1; i >= 0; --i) {
        LEntry le = nodeListeners.get(i);
        if (le.useCapture == useCapture && le.listener == listener &&
            le.type.equals(type)) {
            nodeListeners.remove(i);
            // Storage management: Discard empty listener lists
            if (nodeListeners.isEmpty())
                setEventListeners(node, null);

            // Remove active listener
            LCount lc = LCount.lookup(type);
            if (useCapture) {
                --lc.captures;
                --lc.total;
            }
            else {
                --lc.bubbles;
                --lc.total;
            }

            break;  // Found it; no need to loop farther.
        }
    }
}
 
Example #12
Source File: DocumentImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** NON-DOM INTERNAL: Constructor for Listener list Entry
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCaptue True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
LEntry(String type, EventListener listener, boolean useCapture)
{
    this.type = type;
    this.listener = listener;
    this.useCapture = useCapture;
}
 
Example #13
Source File: DocumentImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Register an event listener with this
 * Node. A listener may be independently registered as both Capturing and
 * Bubbling, but may only be registered once per role; redundant
 * registrations are ignored.
 * @param node node to add listener to
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void addEventListener(NodeImpl node, String type,
                                EventListener listener, boolean useCapture)
{
    // We can't dispatch to blank type-name, and of course we need
    // a listener to dispatch to
    if (type == null || type.equals("") || listener == null)
        return;

    // Each listener may be registered only once per type per phase.
    // Simplest way to code that is to zap the previous entry, if any.
    removeEventListener(node, type, listener, useCapture);

    List<LEntry> nodeListeners = getEventListeners(node);
    if(nodeListeners == null) {
        nodeListeners = new ArrayList<>();
        setEventListeners(node, nodeListeners);
    }
    nodeListeners.add(new LEntry(type, listener, useCapture));

    // Record active listener
    LCount lc = LCount.lookup(type);
    if (useCapture) {
        ++lc.captures;
        ++lc.total;
    }
    else {
        ++lc.bubbles;
        ++lc.total;
    }

}
 
Example #14
Source File: DocumentImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Deregister an event listener previously
 * registered with this Node.  A listener must be independently removed
 * from the Capturing and Bubbling roles. Redundant removals (of listeners
 * not currently registered for this role) are ignored.
 * @param node node to remove listener from
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void removeEventListener(NodeImpl node, String type,
                                   EventListener listener,
                                   boolean useCapture)
{
    // If this couldn't be a valid listener registration, ignore request
    if (type == null || type.equals("") || listener == null)
        return;
    List<LEntry> nodeListeners = getEventListeners(node);
    if (nodeListeners == null)
        return;

    // Note that addListener has previously ensured that
    // each listener may be registered only once per type per phase.
    // count-down is OK for deletions!
    for (int i = nodeListeners.size() - 1; i >= 0; --i) {
        LEntry le = nodeListeners.get(i);
        if (le.useCapture == useCapture && le.listener == listener &&
            le.type.equals(type)) {
            nodeListeners.remove(i);
            // Storage management: Discard empty listener lists
            if (nodeListeners.isEmpty())
                setEventListeners(node, null);

            // Remove active listener
            LCount lc = LCount.lookup(type);
            if (useCapture) {
                --lc.captures;
                --lc.total;
            }
            else {
                --lc.bubbles;
                --lc.total;
            }

            break;  // Found it; no need to loop farther.
        }
    }
}
 
Example #15
Source File: DocumentImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/** NON-DOM INTERNAL: Constructor for Listener list Entry
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCaptue True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
LEntry(String type, EventListener listener, boolean useCapture)
{
    this.type = type;
    this.listener = listener;
    this.useCapture = useCapture;
}
 
Example #16
Source File: XmlLocationAnnotator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public XmlLocationAnnotator(XMLReader xmlReader, Document dom) {
    super(xmlReader);

    // Add listener to DOM, so we know which node was added.
    EventListener modListener = new EventListener() {
        @Override
        public void handleEvent(Event e) {
            EventTarget target = ((MutationEvent) e).getTarget();
            elementStack.push((Element) target);
        }
    };
    ((EventTarget) dom).addEventListener("DOMNodeInserted", modListener, true);
}
 
Example #17
Source File: DocumentImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Deregister an event listener previously
 * registered with this Node.  A listener must be independently removed
 * from the Capturing and Bubbling roles. Redundant removals (of listeners
 * not currently registered for this role) are ignored.
 * @param node node to remove listener from
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void removeEventListener(NodeImpl node, String type,
                                   EventListener listener,
                                   boolean useCapture)
{
    // If this couldn't be a valid listener registration, ignore request
    if (type == null || type.equals("") || listener == null)
        return;
    List<LEntry> nodeListeners = getEventListeners(node);
    if (nodeListeners == null)
        return;

    // Note that addListener has previously ensured that
    // each listener may be registered only once per type per phase.
    // count-down is OK for deletions!
    for (int i = nodeListeners.size() - 1; i >= 0; --i) {
        LEntry le = nodeListeners.get(i);
        if (le.useCapture == useCapture && le.listener == listener &&
            le.type.equals(type)) {
            nodeListeners.remove(i);
            // Storage management: Discard empty listener lists
            if (nodeListeners.isEmpty())
                setEventListeners(node, null);

            // Remove active listener
            LCount lc = LCount.lookup(type);
            if (useCapture) {
                --lc.captures;
                --lc.total;
            }
            else {
                --lc.bubbles;
                --lc.total;
            }

            break;  // Found it; no need to loop farther.
        }
    }
}
 
Example #18
Source File: DocumentImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/** NON-DOM INTERNAL: Constructor for Listener list Entry
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCaptue True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
LEntry(String type, EventListener listener, boolean useCapture)
{
    this.type = type;
    this.listener = listener;
    this.useCapture = useCapture;
}
 
Example #19
Source File: DocumentImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Register an event listener with this
 * Node. A listener may be independently registered as both Capturing and
 * Bubbling, but may only be registered once per role; redundant
 * registrations are ignored.
 * @param node node to add listener to
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void addEventListener(NodeImpl node, String type,
                                EventListener listener, boolean useCapture)
{
    // We can't dispatch to blank type-name, and of course we need
    // a listener to dispatch to
    if (type == null || type.equals("") || listener == null)
        return;

    // Each listener may be registered only once per type per phase.
    // Simplest way to code that is to zap the previous entry, if any.
    removeEventListener(node, type, listener, useCapture);

    List<LEntry> nodeListeners = getEventListeners(node);
    if(nodeListeners == null) {
        nodeListeners = new ArrayList<>();
        setEventListeners(node, nodeListeners);
    }
    nodeListeners.add(new LEntry(type, listener, useCapture));

    // Record active listener
    LCount lc = LCount.lookup(type);
    if (useCapture) {
        ++lc.captures;
        ++lc.total;
    }
    else {
        ++lc.bubbles;
        ++lc.total;
    }

}
 
Example #20
Source File: DocumentImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Deregister an event listener previously
 * registered with this Node.  A listener must be independently removed
 * from the Capturing and Bubbling roles. Redundant removals (of listeners
 * not currently registered for this role) are ignored.
 * @param node node to remove listener from
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void removeEventListener(NodeImpl node, String type,
                                   EventListener listener,
                                   boolean useCapture)
{
    // If this couldn't be a valid listener registration, ignore request
    if (type == null || type.equals("") || listener == null)
        return;
    List<LEntry> nodeListeners = getEventListeners(node);
    if (nodeListeners == null)
        return;

    // Note that addListener has previously ensured that
    // each listener may be registered only once per type per phase.
    // count-down is OK for deletions!
    for (int i = nodeListeners.size() - 1; i >= 0; --i) {
        LEntry le = nodeListeners.get(i);
        if (le.useCapture == useCapture && le.listener == listener &&
            le.type.equals(type)) {
            nodeListeners.remove(i);
            // Storage management: Discard empty listener lists
            if (nodeListeners.isEmpty())
                setEventListeners(node, null);

            // Remove active listener
            LCount lc = LCount.lookup(type);
            if (useCapture) {
                --lc.captures;
                --lc.total;
            }
            else {
                --lc.bubbles;
                --lc.total;
            }

            break;  // Found it; no need to loop farther.
        }
    }
}
 
Example #21
Source File: DocumentImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** NON-DOM INTERNAL: Constructor for Listener list Entry
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCaptue True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
LEntry(String type, EventListener listener, boolean useCapture)
{
    this.type = type;
    this.listener = listener;
    this.useCapture = useCapture;
}
 
Example #22
Source File: DocumentImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Register an event listener with this
 * Node. A listener may be independently registered as both Capturing and
 * Bubbling, but may only be registered once per role; redundant
 * registrations are ignored.
 * @param node node to add listener to
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void addEventListener(NodeImpl node, String type,
                                EventListener listener, boolean useCapture)
{
    // We can't dispatch to blank type-name, and of course we need
    // a listener to dispatch to
    if (type == null || type.equals("") || listener == null)
        return;

    // Each listener may be registered only once per type per phase.
    // Simplest way to code that is to zap the previous entry, if any.
    removeEventListener(node, type, listener, useCapture);

    List<LEntry> nodeListeners = getEventListeners(node);
    if(nodeListeners == null) {
        nodeListeners = new ArrayList<>();
        setEventListeners(node, nodeListeners);
    }
    nodeListeners.add(new LEntry(type, listener, useCapture));

    // Record active listener
    LCount lc = LCount.lookup(type);
    if (useCapture) {
        ++lc.captures;
        ++lc.total;
    }
    else {
        ++lc.bubbles;
        ++lc.total;
    }

}
 
Example #23
Source File: DocumentImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Deregister an event listener previously
 * registered with this Node.  A listener must be independently removed
 * from the Capturing and Bubbling roles. Redundant removals (of listeners
 * not currently registered for this role) are ignored.
 * @param node node to remove listener from
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void removeEventListener(NodeImpl node, String type,
                                   EventListener listener,
                                   boolean useCapture)
{
    // If this couldn't be a valid listener registration, ignore request
    if (type == null || type.equals("") || listener == null)
        return;
    List<LEntry> nodeListeners = getEventListeners(node);
    if (nodeListeners == null)
        return;

    // Note that addListener has previously ensured that
    // each listener may be registered only once per type per phase.
    // count-down is OK for deletions!
    for (int i = nodeListeners.size() - 1; i >= 0; --i) {
        LEntry le = nodeListeners.get(i);
        if (le.useCapture == useCapture && le.listener == listener &&
            le.type.equals(type)) {
            nodeListeners.remove(i);
            // Storage management: Discard empty listener lists
            if (nodeListeners.isEmpty())
                setEventListeners(node, null);

            // Remove active listener
            LCount lc = LCount.lookup(type);
            if (useCapture) {
                --lc.captures;
                --lc.total;
            }
            else {
                --lc.bubbles;
                --lc.total;
            }

            break;  // Found it; no need to loop farther.
        }
    }
}
 
Example #24
Source File: DocumentImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/** NON-DOM INTERNAL: Constructor for Listener list Entry
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCaptue True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
LEntry(String type, EventListener listener, boolean useCapture)
{
    this.type = type;
    this.listener = listener;
    this.useCapture = useCapture;
}
 
Example #25
Source File: DocumentImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Register an event listener with this
 * Node. A listener may be independently registered as both Capturing and
 * Bubbling, but may only be registered once per role; redundant
 * registrations are ignored.
 * @param node node to add listener to
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void addEventListener(NodeImpl node, String type,
                                EventListener listener, boolean useCapture)
{
    // We can't dispatch to blank type-name, and of course we need
    // a listener to dispatch to
    if (type == null || type.equals("") || listener == null)
        return;

    // Each listener may be registered only once per type per phase.
    // Simplest way to code that is to zap the previous entry, if any.
    removeEventListener(node, type, listener, useCapture);

    List<LEntry> nodeListeners = getEventListeners(node);
    if(nodeListeners == null) {
        nodeListeners = new ArrayList<>();
        setEventListeners(node, nodeListeners);
    }
    nodeListeners.add(new LEntry(type, listener, useCapture));

    // Record active listener
    LCount lc = LCount.lookup(type);
    if (useCapture) {
        ++lc.captures;
        ++lc.total;
    }
    else {
        ++lc.bubbles;
        ++lc.total;
    }

}
 
Example #26
Source File: DocumentImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Deregister an event listener previously
 * registered with this Node.  A listener must be independently removed
 * from the Capturing and Bubbling roles. Redundant removals (of listeners
 * not currently registered for this role) are ignored.
 * @param node node to remove listener from
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
@Override
protected void removeEventListener(NodeImpl node, String type,
                                   EventListener listener,
                                   boolean useCapture)
{
    // If this couldn't be a valid listener registration, ignore request
    if (type == null || type.equals("") || listener == null)
        return;
    List<LEntry> nodeListeners = getEventListeners(node);
    if (nodeListeners == null)
        return;

    // Note that addListener has previously ensured that
    // each listener may be registered only once per type per phase.
    // count-down is OK for deletions!
    for (int i = nodeListeners.size() - 1; i >= 0; --i) {
        LEntry le = nodeListeners.get(i);
        if (le.useCapture == useCapture && le.listener == listener &&
            le.type.equals(type)) {
            nodeListeners.remove(i);
            // Storage management: Discard empty listener lists
            if (nodeListeners.isEmpty())
                setEventListeners(node, null);

            // Remove active listener
            LCount lc = LCount.lookup(type);
            if (useCapture) {
                --lc.captures;
                --lc.total;
            }
            else {
                --lc.bubbles;
                --lc.total;
            }

            break;  // Found it; no need to loop farther.
        }
    }
}
 
Example #27
Source File: DocumentImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** NON-DOM INTERNAL: Constructor for Listener list Entry
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCaptue True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
LEntry(String type, EventListener listener, boolean useCapture)
{
    this.type = type;
    this.listener = listener;
    this.useCapture = useCapture;
}
 
Example #28
Source File: DocumentImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Deregister an event listener previously
 * registered with this Node.  A listener must be independently removed
 * from the Capturing and Bubbling roles. Redundant removals (of listeners
 * not currently registered for this role) are ignored.
 * @param node node to remove listener from
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
protected void removeEventListener(NodeImpl node, String type,
                                   EventListener listener,
                                   boolean useCapture)
{
    // If this couldn't be a valid listener registration, ignore request
    if (type == null || type.equals("") || listener == null)
        return;
    Vector nodeListeners = getEventListeners(node);
    if (nodeListeners == null)
        return;

    // Note that addListener has previously ensured that
    // each listener may be registered only once per type per phase.
    // count-down is OK for deletions!
    for (int i = nodeListeners.size() - 1; i >= 0; --i) {
        LEntry le = (LEntry) nodeListeners.elementAt(i);
        if (le.useCapture == useCapture && le.listener == listener &&
            le.type.equals(type)) {
            nodeListeners.removeElementAt(i);
            // Storage management: Discard empty listener lists
            if (nodeListeners.size() == 0)
                setEventListeners(node, null);

            // Remove active listener
            LCount lc = LCount.lookup(type);
            if (useCapture) {
                --lc.captures;
                --lc.total;
            }
            else {
                --lc.bubbles;
                --lc.total;
            }

            break;  // Found it; no need to loop farther.
        }
    }
}
 
Example #29
Source File: DocumentImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/** NON-DOM INTERNAL: Constructor for Listener list Entry
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCaptue True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
LEntry(String type, EventListener listener, boolean useCapture)
{
    this.type = type;
    this.listener = listener;
    this.useCapture = useCapture;
}
 
Example #30
Source File: DocumentImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Deregister an event listener previously
 * registered with this Node.  A listener must be independently removed
 * from the Capturing and Bubbling roles. Redundant removals (of listeners
 * not currently registered for this role) are ignored.
 * @param node node to remove listener from
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
protected void removeEventListener(NodeImpl node, String type,
                                   EventListener listener,
                                   boolean useCapture)
{
    // If this couldn't be a valid listener registration, ignore request
    if (type == null || type.equals("") || listener == null)
        return;
    Vector nodeListeners = getEventListeners(node);
    if (nodeListeners == null)
        return;

    // Note that addListener has previously ensured that
    // each listener may be registered only once per type per phase.
    // count-down is OK for deletions!
    for (int i = nodeListeners.size() - 1; i >= 0; --i) {
        LEntry le = (LEntry) nodeListeners.elementAt(i);
        if (le.useCapture == useCapture && le.listener == listener &&
            le.type.equals(type)) {
            nodeListeners.removeElementAt(i);
            // Storage management: Discard empty listener lists
            if (nodeListeners.size() == 0)
                setEventListeners(node, null);

            // Remove active listener
            LCount lc = LCount.lookup(type);
            if (useCapture) {
                --lc.captures;
                --lc.total;
            }
            else {
                --lc.bubbles;
                --lc.total;
            }

            break;  // Found it; no need to loop farther.
        }
    }
}