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