jdk/src/share/classes/java/awt/KeyEventPostProcessor.java
changeset 2 90ce3da70b43
child 5506 202f599c92aa
equal deleted inserted replaced
0:fd16c54261b3 2:90ce3da70b43
       
     1 /*
       
     2  * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 package java.awt;
       
    26 
       
    27 import java.awt.event.KeyEvent;
       
    28 
       
    29 
       
    30 /**
       
    31  * A KeyEventPostProcessor cooperates with the current KeyboardFocusManager
       
    32  * in the final resolution of all unconsumed KeyEvents. KeyEventPostProcessors
       
    33  * registered with the current KeyboardFocusManager will receive KeyEvents
       
    34  * after the KeyEvents have been dispatched to and handled by their targets.
       
    35  * KeyEvents that would have been otherwise discarded because no Component in
       
    36  * the application currently owns the focus will also be forwarded to
       
    37  * registered KeyEventPostProcessors. This will allow applications to implement
       
    38  * features that require global KeyEvent post-handling, such as menu shortcuts.
       
    39  * <p>
       
    40  * Note that the KeyboardFocusManager itself implements KeyEventPostProcessor.
       
    41  * By default, the current KeyboardFocusManager will be the final
       
    42  * KeyEventPostProcessor in the chain. The current KeyboardFocusManager cannot
       
    43  * be completely deregistered as a KeyEventPostProcessor. However, if a
       
    44  * KeyEventPostProcessor reports that no further post-processing of the
       
    45  * KeyEvent should take place, the AWT will consider the event fully handled
       
    46  * and will take no additional action with regard to the event. (While it is
       
    47  * possible for client code to register the current KeyboardFocusManager as
       
    48  * a KeyEventPostProcessor one or more times, this is usually unnecessary and
       
    49  * not recommended.)
       
    50  *
       
    51  * @author David Mendenhall
       
    52  *
       
    53  * @see KeyboardFocusManager#addKeyEventPostProcessor
       
    54  * @see KeyboardFocusManager#removeKeyEventPostProcessor
       
    55  * @since 1.4
       
    56  */
       
    57 public interface KeyEventPostProcessor {
       
    58 
       
    59     /**
       
    60      * This method is called by the current KeyboardFocusManager, requesting
       
    61      * that this KeyEventPostProcessor perform any necessary post-processing
       
    62      * which should be part of the KeyEvent's final resolution. At the time
       
    63      * this method is invoked, typically the KeyEvent has already been
       
    64      * dispatched to and handled by its target. However, if no Component in
       
    65      * the application currently owns the focus, then the KeyEvent has not
       
    66      * been dispatched to any Component. Typically, KeyEvent post-processing
       
    67      * will be used to implement features which require global KeyEvent
       
    68      * post-handling, such as menu shortcuts. Note that if a
       
    69      * KeyEventPostProcessor wishes to dispatch the KeyEvent, it must use
       
    70      * <code>redispatchEvent</code> to prevent the AWT from recursively
       
    71      * requesting that this KeyEventPostProcessor perform post-processing
       
    72      * of the event again.
       
    73      * <p>
       
    74      * If an implementation of this method returns <code>false</code>, then the
       
    75      * KeyEvent is passed to the next KeyEventPostProcessor in the chain,
       
    76      * ending with the current KeyboardFocusManager. If an implementation
       
    77      * returns <code>true</code>, the KeyEvent is assumed to have been fully
       
    78      * handled (although this need not be the case), and the AWT will take no
       
    79      * further action with regard to the KeyEvent. If an implementation
       
    80      * consumes the KeyEvent but returns <code>false</code>, the consumed
       
    81      * event will still be passed to the next KeyEventPostProcessor in the
       
    82      * chain. It is important for developers to check whether the KeyEvent has
       
    83      * been consumed before performing any post-processing of the KeyEvent. By
       
    84      * default, the current KeyboardFocusManager will perform no post-
       
    85      * processing in response to a consumed KeyEvent.
       
    86      *
       
    87      * @param e the KeyEvent to post-process
       
    88      * @return <code>true</code> if the AWT should take no further action with
       
    89      *         regard to the KeyEvent; <code>false</code> otherwise
       
    90      * @see KeyboardFocusManager#redispatchEvent
       
    91      */
       
    92     boolean postProcessKeyEvent(KeyEvent e);
       
    93 }