PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/ActionContext.java

#
Java | 169 lines | 74 code | 14 blank | 81 comment | 9 complexity | fac474821bcf0a3f6ef511d364742623 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 5291 2005-10-27 17:02:52Z ezust $
  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. actionNames = null;
  56. actionSets.addElement(actionSet);
  57. actionSet.context = this;
  58. String[] actions = actionSet.getActionNames();
  59. for(int i = 0; i < actions.length; i++)
  60. {
  61. /* Is it already there? */
  62. if (actionHash.containsKey(actions[i]))
  63. {
  64. /* Save it for plugin unloading time */
  65. Object oldAction = actionHash.get(actions[i]);
  66. overriddenActions.put(actions[i], oldAction);
  67. }
  68. actionHash.put(actions[i],actionSet);
  69. }
  70. } //}}}
  71. //{{{ removeActionSet() method
  72. /**
  73. * Removes an action set from the context.
  74. * @since jEdit 4.2pre1
  75. */
  76. public void removeActionSet(ActionSet actionSet)
  77. {
  78. actionNames = null;
  79. actionSets.removeElement(actionSet);
  80. actionSet.context = null;
  81. String[] actions = actionSet.getActionNames();
  82. for(int i = 0; i < actions.length; i++)
  83. {
  84. actionHash.remove(actions[i]);
  85. if (overriddenActions.containsKey(actions[i]))
  86. {
  87. Object oldAction = overriddenActions.remove(actions[i]);
  88. actionHash.put(actions[i], oldAction);
  89. }
  90. }
  91. } //}}}
  92. //{{{ getActionSets() method
  93. /**
  94. * Returns all registered action sets.
  95. * @since jEdit 4.2pre1
  96. */
  97. public ActionSet[] getActionSets()
  98. {
  99. ActionSet[] retVal = new ActionSet[actionSets.size()];
  100. actionSets.copyInto(retVal);
  101. return retVal;
  102. } //}}}
  103. //{{{ getAction() method
  104. /**
  105. * Returns the specified action.
  106. * @param name The action name
  107. * @since jEdit 4.2pre1
  108. */
  109. public EditAction getAction(String name)
  110. {
  111. ActionSet set = (ActionSet)actionHash.get(name);
  112. if(set == null)
  113. return null;
  114. else
  115. return set.getAction(name);
  116. } //}}}
  117. //{{{ getActionSetForAction() method
  118. /**
  119. * Returns the action set that contains the specified action.
  120. *
  121. * @param action The action
  122. * @since jEdit 4.2pre1
  123. */
  124. public ActionSet getActionSetForAction(String action)
  125. {
  126. return (ActionSet)actionHash.get(action);
  127. } //}}}
  128. //{{{ getActionNames() method
  129. /**
  130. * Returns all registered action names.
  131. */
  132. public String[] getActionNames()
  133. {
  134. if(actionNames == null)
  135. {
  136. List vec = new LinkedList();
  137. for(int i = 0; i < actionSets.size(); i++)
  138. ((ActionSet)actionSets.elementAt(i)).getActionNames(vec);
  139. actionNames = (String[])vec.toArray(
  140. new String[vec.size()]);
  141. Arrays.sort(actionNames,
  142. new MiscUtilities.StringICaseCompare());
  143. }
  144. return actionNames;
  145. } //}}}
  146. //{{{ Package-private members
  147. String[] actionNames;
  148. Hashtable actionHash = new Hashtable();
  149. /** A map of built-in actions that were overridden by plugins. */
  150. Hashtable overriddenActions = new Hashtable();
  151. //}}}
  152. //{{{ Private members
  153. private Vector actionSets = new Vector();
  154. //}}}
  155. }