1. /*
  2. * @(#)KeyEventPostProcessor.java 1.5 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt;
  8. import java.awt.event.KeyEvent;
  9. /**
  10. * A KeyEventPostProcessor cooperates with the current KeyboardFocusManager
  11. * in the final resolution of all unconsumed KeyEvents. KeyEventPostProcessors
  12. * registered with the current KeyboardFocusManager will receive KeyEvents
  13. * after the KeyEvents have been dispatched to and handled by their targets.
  14. * KeyEvents that would have been otherwise discarded because no Component in
  15. * the application currently owns the focus will also be forwarded to
  16. * registered KeyEventPostProcessors. This will allow applications to implement
  17. * features that require global KeyEvent post-handling, such as menu shortcuts.
  18. * <p>
  19. * Note that the KeyboardFocusManager itself implements KeyEventPostProcessor.
  20. * By default, the current KeyboardFocusManager will be the final
  21. * KeyEventPostProcessor in the chain. The current KeyboardFocusManager cannot
  22. * be completely deregistered as a KeyEventPostProcessor. However, if a
  23. * KeyEventPostProcessor reports that no further post-processing of the
  24. * KeyEvent should take place, the AWT will consider the event fully handled
  25. * and will take no additional action with regard to the event. (While it is
  26. * possible for client code to register the current KeyboardFocusManager as
  27. * a KeyEventPostProcessor one or more times, this is usually unnecessary and
  28. * not recommended.)
  29. *
  30. * @author David Mendenhall
  31. * @version 1.5, 12/19/03
  32. *
  33. * @see KeyboardFocusManager#addKeyEventPostProcessor
  34. * @see KeyboardFocusManager#removeKeyEventPostProcessor
  35. * @since 1.4
  36. */
  37. public interface KeyEventPostProcessor {
  38. /**
  39. * This method is called by the current KeyboardFocusManager, requesting
  40. * that this KeyEventPostProcessor perform any necessary post-processing
  41. * which should be part of the KeyEvent's final resolution. At the time
  42. * this method is invoked, typically the KeyEvent has already been
  43. * dispatched to and handled by its target. However, if no Component in
  44. * the application currently owns the focus, then the KeyEvent has not
  45. * been dispatched to any Component. Typically, KeyEvent post-processing
  46. * will be used to implement features which require global KeyEvent
  47. * post-handling, such as menu shortcuts. Note that if a
  48. * KeyEventPostProcessor wishes to dispatch the KeyEvent, it must use
  49. * <code>redispatchEvent</code> to prevent the AWT from recursively
  50. * requesting that this KeyEventPostProcessor perform post-processing
  51. * of the event again.
  52. * <p>
  53. * If an implementation of this method returns <code>false</code>, then the
  54. * KeyEvent is passed to the next KeyEventPostProcessor in the chain,
  55. * ending with the current KeyboardFocusManager. If an implementation
  56. * returns <code>true</code>, the KeyEvent is assumed to have been fully
  57. * handled (although this need not be the case), and the AWT will take no
  58. * further action with regard to the KeyEvent. If an implementation
  59. * consumes the KeyEvent but returns <code>false</code>, the consumed
  60. * event will still be passed to the next KeyEventPostProcessor in the
  61. * chain. It is important for developers to check whether the KeyEvent has
  62. * been consumed before performing any post-processing of the KeyEvent. By
  63. * default, the current KeyboardFocusManager will perform no post-
  64. * processing in response to a consumed KeyEvent.
  65. *
  66. * @param e the KeyEvent to post-process
  67. * @return <code>true</code> if the AWT should take no further action with
  68. * regard to the KeyEvent; <code>false</code> otherwise
  69. * @see KeyboardFocusManager#redispatchEvent
  70. */
  71. boolean postProcessKeyEvent(KeyEvent e);
  72. }