1 /*
   2  * Copyright (c) 2001, 2013, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * 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 @FunctionalInterface
  58 public interface KeyEventPostProcessor {
  59 
  60     /**
  61      * This method is called by the current KeyboardFocusManager, requesting
  62      * that this KeyEventPostProcessor perform any necessary post-processing
  63      * which should be part of the KeyEvent's final resolution. At the time
  64      * this method is invoked, typically the KeyEvent has already been
  65      * dispatched to and handled by its target. However, if no Component in
  66      * the application currently owns the focus, then the KeyEvent has not
  67      * been dispatched to any Component. Typically, KeyEvent post-processing
  68      * will be used to implement features which require global KeyEvent
  69      * post-handling, such as menu shortcuts. Note that if a
  70      * KeyEventPostProcessor wishes to dispatch the KeyEvent, it must use
  71      * <code>redispatchEvent</code> to prevent the AWT from recursively
  72      * requesting that this KeyEventPostProcessor perform post-processing
  73      * of the event again.
  74      * <p>
  75      * If an implementation of this method returns <code>false</code>, then the
  76      * KeyEvent is passed to the next KeyEventPostProcessor in the chain,
  77      * ending with the current KeyboardFocusManager. If an implementation
  78      * returns <code>true</code>, the KeyEvent is assumed to have been fully
  79      * handled (although this need not be the case), and the AWT will take no
  80      * further action with regard to the KeyEvent. If an implementation
  81      * consumes the KeyEvent but returns <code>false</code>, the consumed
  82      * event will still be passed to the next KeyEventPostProcessor in the
  83      * chain. It is important for developers to check whether the KeyEvent has
  84      * been consumed before performing any post-processing of the KeyEvent. By
  85      * default, the current KeyboardFocusManager will perform no post-
  86      * processing in response to a consumed KeyEvent.
  87      *
  88      * @param e the KeyEvent to post-process
  89      * @return <code>true</code> if the AWT should take no further action with
  90      *         regard to the KeyEvent; <code>false</code> otherwise
  91      * @see KeyboardFocusManager#redispatchEvent
  92      */
  93     boolean postProcessKeyEvent(KeyEvent e);
  94 }
--- EOF ---