1. /*
  2. * @(#)Keymap.java 1.14 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing.text;
  11. import javax.swing.Action;
  12. import javax.swing.KeyStroke;
  13. /**
  14. * A collection of bindings of KeyStrokes to actions. The
  15. * bindings are basically name-value pairs that potentially
  16. * resolve in a hierarchy.
  17. *
  18. * @author Timothy Prinzing
  19. * @version 1.14 02/02/00
  20. */
  21. public interface Keymap {
  22. /**
  23. * Fetches the name of the set of key-bindings.
  24. *
  25. * @return the name
  26. */
  27. public String getName();
  28. /**
  29. * Fetches the default action to fire if a
  30. * key is typed (i.e. a KEY_TYPED KeyEvent is received)
  31. * and there is no binding for it. Typically this
  32. * would be some action that inserts text so that
  33. * the keymap doesn't require an action for each
  34. * possible key.
  35. *
  36. * @return the default action
  37. */
  38. public Action getDefaultAction();
  39. /**
  40. * Set the default action to fire if a key is typed.
  41. *
  42. * @param a the action
  43. */
  44. public void setDefaultAction(Action a);
  45. /**
  46. * Fetches the action appropriate for the given symbolic
  47. * event sequence. This is used by JTextController to
  48. * determine how to interpret key sequences. If the
  49. * binding is not resolved locally, an attempt is made
  50. * to resolve through the parent keymap, if one is set.
  51. *
  52. * @param key the key sequence
  53. * @returns the action associated with the key
  54. * sequence if one is defined, otherwise null
  55. */
  56. public Action getAction(KeyStroke key);
  57. /**
  58. * Fetches all of the keystrokes in this map that
  59. * are bound to some action.
  60. *
  61. * @return the list of keystrokes
  62. */
  63. public KeyStroke[] getBoundKeyStrokes();
  64. /**
  65. * Fetches all of the actions defined in this keymap.
  66. *
  67. * @return the list of actions
  68. */
  69. public Action[] getBoundActions();
  70. /**
  71. * Fetches the keystrokes that will result in
  72. * the given action.
  73. *
  74. * @param a the action
  75. * @return the list of keystrokes
  76. */
  77. public KeyStroke[] getKeyStrokesForAction(Action a);
  78. /**
  79. * Determines if the given key sequence is locally defined.
  80. *
  81. * @param key the key sequence
  82. * @return true if the key sequence is locally defined else false
  83. */
  84. public boolean isLocallyDefined(KeyStroke key);
  85. /**
  86. * Adds a binding to the keymap.
  87. *
  88. * @param key the key sequence
  89. * @param a the action
  90. */
  91. public void addActionForKeyStroke(KeyStroke key, Action a);
  92. /**
  93. * Removes a binding from the keymap.
  94. *
  95. * @param keys the key sequence
  96. */
  97. public void removeKeyStrokeBinding(KeyStroke keys);
  98. /**
  99. * Removes all bindings from the keymap.
  100. */
  101. public void removeBindings();
  102. /**
  103. * Fetches the parent keymap used to resolve key-bindings.
  104. *
  105. * @return the keymap
  106. */
  107. public Keymap getResolveParent();
  108. /**
  109. * Sets the parent keymap, which will be used to
  110. * resolve key-bindings.
  111. *
  112. * @param parent the parent keymap
  113. */
  114. public void setResolveParent(Keymap parent);
  115. }