1. /*
  2. * @(#)KeyEventDispatcher.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 KeyEventDispatcher cooperates with the current KeyboardFocusManager in the
  11. * targeting and dispatching of all KeyEvents. KeyEventDispatchers registered
  12. * with the current KeyboardFocusManager will receive KeyEvents before they are
  13. * dispatched to their targets, allowing each KeyEventDispatcher to retarget
  14. * the event, consume it, dispatch the event itself, or make other changes.
  15. * <p>
  16. * Note that KeyboardFocusManager itself implements KeyEventDispatcher. By
  17. * default, the current KeyboardFocusManager will be the sink for all KeyEvents
  18. * not dispatched by the registered KeyEventDispatchers. The current
  19. * KeyboardFocusManager cannot be completely deregistered as a
  20. * KeyEventDispatcher. However, if a KeyEventDispatcher reports that it
  21. * dispatched the KeyEvent, regardless of whether it actually did so, the
  22. * KeyboardFocusManager will take no further action with regard to the
  23. * KeyEvent. (While it is possible for client code to register the current
  24. * KeyboardFocusManager as a KeyEventDispatcher one or more times, this is
  25. * usually unnecessary and not recommended.)
  26. *
  27. * @author David Mendenhall
  28. * @version 1.5, 12/19/03
  29. *
  30. * @see KeyboardFocusManager#addKeyEventDispatcher
  31. * @see KeyboardFocusManager#removeKeyEventDispatcher
  32. * @since 1.4
  33. */
  34. public interface KeyEventDispatcher {
  35. /**
  36. * This method is called by the current KeyboardFocusManager requesting
  37. * that this KeyEventDispatcher dispatch the specified event on its behalf.
  38. * This KeyEventDispatcher is free to retarget the event, consume it,
  39. * dispatch it itself, or make other changes. This capability is typically
  40. * used to deliver KeyEvents to Components other than the focus owner. This
  41. * can be useful when navigating children of non-focusable Windows in an
  42. * accessible environment, for example. Note that if a KeyEventDispatcher
  43. * dispatches the KeyEvent itself, it must use <code>redispatchEvent</code>
  44. * to prevent the current KeyboardFocusManager from recursively requesting
  45. * that this KeyEventDispatcher dispatch the event again.
  46. * <p>
  47. * If an implementation of this method returns <code>false</code>, then
  48. * the KeyEvent is passed to the next KeyEventDispatcher in the chain,
  49. * ending with the current KeyboardFocusManager. If an implementation
  50. * returns <code>true</code>, the KeyEvent is assumed to have been
  51. * dispatched (although this need not be the case), and the current
  52. * KeyboardFocusManager will take no further action with regard to the
  53. * KeyEvent. In such a case,
  54. * <code>KeyboardFocusManager.dispatchEvent</code> should return
  55. * <code>true</code> as well. If an implementation consumes the KeyEvent,
  56. * but returns <code>false</code>, the consumed event will still be passed
  57. * to the next KeyEventDispatcher in the chain. It is important for
  58. * developers to check whether the KeyEvent has been consumed before
  59. * dispatching it to a target. By default, the current KeyboardFocusManager
  60. * will not dispatch a consumed KeyEvent.
  61. *
  62. * @param e the KeyEvent to dispatch
  63. * @return <code>true</code> if the KeyboardFocusManager should take no
  64. * further action with regard to the KeyEvent; <code>false</code>
  65. * otherwise
  66. * @see KeyboardFocusManager#redispatchEvent
  67. */
  68. boolean dispatchKeyEvent(KeyEvent e);
  69. }