PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/ActionContext.java

#
Java | 143 lines | 53 code | 12 blank | 78 comment | 5 complexity | 21ea0c15f202d734b3cf89dcf3854385 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * ActionContext.java - For code sharing between jEdit and VFSBrowser
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1998, 2003 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit;
  23. import java.util.*;
  24. /**
  25. * Manages a collection of action sets. There are two instances of this class
  26. * in jEdit:
  27. * <ul>
  28. * <li>{@link org.gjt.sp.jedit.jEdit#getActionContext()} - editor actions
  29. * <li>{@link org.gjt.sp.jedit.browser.VFSBrowser#getActionContext()} - browser
  30. * actions
  31. * </ul>
  32. *
  33. * @since jEdit 4.2pre1
  34. * @author Slava Pestov
  35. * @version $Id: ActionContext.java 4669 2003-05-01 02:21:27Z spestov $
  36. */
  37. public abstract class ActionContext
  38. {
  39. //{{{ invokeAction() method
  40. /**
  41. * Invokes the given action in response to a user-generated event.
  42. * @param evt The event
  43. * @param action The action
  44. * @since jEdit 4.2pre1
  45. */
  46. public abstract void invokeAction(EventObject evt, EditAction action);
  47. //}}}
  48. //{{{ addActionSet() method
  49. /**
  50. * Adds a new action set to the context.
  51. * @since jEdit 4.2pre1
  52. */
  53. public void addActionSet(ActionSet actionSet)
  54. {
  55. actionSets.addElement(actionSet);
  56. actionSet.context = this;
  57. String[] actions = actionSet.getActionNames();
  58. for(int i = 0; i < actions.length; i++)
  59. {
  60. actionHash.put(actions[i],actionSet);
  61. }
  62. } //}}}
  63. //{{{ removeActionSet() method
  64. /**
  65. * Removes an action set from the context.
  66. * @since jEdit 4.2pre1
  67. */
  68. public void removeActionSet(ActionSet actionSet)
  69. {
  70. actionSets.removeElement(actionSet);
  71. actionSet.context = null;
  72. String[] actions = actionSet.getActionNames();
  73. for(int i = 0; i < actions.length; i++)
  74. {
  75. actionHash.remove(actions[i]);
  76. }
  77. } //}}}
  78. //{{{ getActionSets() method
  79. /**
  80. * Returns all registered action sets.
  81. * @since jEdit 4.2pre1
  82. */
  83. public ActionSet[] getActionSets()
  84. {
  85. ActionSet[] retVal = new ActionSet[actionSets.size()];
  86. actionSets.copyInto(retVal);
  87. return retVal;
  88. } //}}}
  89. //{{{ getAction() method
  90. /**
  91. * Returns the specified action.
  92. * @param name The action name
  93. * @since jEdit 4.2pre1
  94. */
  95. public EditAction getAction(String name)
  96. {
  97. ActionSet set = (ActionSet)actionHash.get(name);
  98. if(set == null)
  99. return null;
  100. else
  101. return set.getAction(name);
  102. } //}}}
  103. //{{{ getActionSetForAction() method
  104. /**
  105. * Returns the action set that contains the specified action.
  106. *
  107. * @param action The action
  108. * @since jEdit 4.2pre1
  109. */
  110. public ActionSet getActionSetForAction(String action)
  111. {
  112. return (ActionSet)actionHash.get(action);
  113. } //}}}
  114. //{{{ getActionNames() method
  115. /**
  116. * Returns all registered action names.
  117. */
  118. public String[] getActionNames()
  119. {
  120. ArrayList vec = new ArrayList();
  121. for(int i = 0; i < actionSets.size(); i++)
  122. ((ActionSet)actionSets.elementAt(i)).getActionNames(vec);
  123. return (String[])vec.toArray(new String[vec.size()]);
  124. } //}}}
  125. //{{{ Package-private members
  126. Hashtable actionHash = new Hashtable();
  127. //}}}
  128. //{{{ Private members
  129. private Vector actionSets = new Vector();
  130. //}}}
  131. }