Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.event;
027
028// PENDING_DOC_REVIEW
029/**
030 * An {@code EventDispatcher} represents an event dispatching and processing
031 * entity. It is used when an {@code Event} needs to be dispatched to the
032 * associated {@code EventTarget} through the {@code EventDispatchChain}
033 * specified by the target. Each {@code EventDispatcher} in the chain can
034 * influence the event path and the event itself. One {@code EventDispatcher}
035 * can appear in multiple chains.
036 * <p>
037 * The system defines two successive phases of event delivery. The first
038 * phase is called capturing phase and happens when when an event travels from
039 * the first element of the {@code EventDispatchChain} associated with the event
040 * target to its last element. If the event target is part of some hierarchy,
041 * the direction of the event in this phase usually corresponds with the
042 * direction from the root element of the hierarchy to the target. The second
043 * phase is called bubbling phase and happens in the reverse order to the first
044 * phase. So the event is returning back from the last element of the
045 * {@code EventDispatchChain} to its first element in this phase. Usually that
046 * corresponds to the direction from the event target back to the root in the
047 * event target's hierarchy.
048 * <p>
049 * Each {@code EventDispatcher} in an {@code EventDispatchChain} is responsible
050 * for forwarding the event to the rest of the chain during event dispatching.
051 * This forwarding happens in the {@code dispatchEvent} method and forms a chain
052 * of nested calls which allows one {@code EventDispatcher} to see the event
053 * during both dispatching phases in a single {@code dispatchEvent} call.
054 * <p>
055 * Template for {@code dispatchEvent} implementation.
056<PRE>
057public Event dispatchEvent(Event event, EventDispatchChain tail) {
058    // capturing phase, can handle / modify / substitute / divert the event
059
060    if (notHandledYet) {
061        // forward the event to the rest of the chain
062        event = tail.dispatchEvent(event);
063
064        if (event != null) {
065            // bubbling phase, can handle / modify / substitute / divert
066            // the event
067        }
068    }
069
070    return notHandledYet ? event : null;
071</PRE>
072}
073
074 */
075public interface EventDispatcher {
076    /**
077     * Dispatches the specified event by this {@code EventDispatcher}. Does
078     * any required event processing. Both the event and its further path can
079     * be modified in this method. If the event is not handled / consumed during
080     * the capturing phase, it should be dispatched to the rest of the chain
081     * ({@code event = tail.dispatch(event);}).
082     *
083     * @param event the event do dispatch
084     * @param tail the rest of the chain to dispatch event to
085     * @return the return event or {@code null} if the event has been handled /
086     *      consumed
087     */
088    Event dispatchEvent(Event event, EventDispatchChain tail);
089}