PageRenderTime 23ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/ActionSet.java

#
Java | 162 lines | 70 code | 16 blank | 76 comment | 0 complexity | 9993681cfe4fe9cf492de8285c880e4e 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. * ActionSet.java - A set of actions
  3. * Copyright (C) 2001 Slava Pestov
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. package org.gjt.sp.jedit;
  20. import java.util.*;
  21. /**
  22. * A set of actions..
  23. * @author Slava Pestov
  24. * @version $Id: ActionSet.java 3825 2001-10-02 13:54:14Z spestov $
  25. * @since jEdit 4.0pre1
  26. */
  27. public class ActionSet
  28. {
  29. /**
  30. * Creates a new action set.
  31. * @since jEdit 4.0pre1
  32. */
  33. public ActionSet()
  34. {
  35. this(null);
  36. }
  37. /**
  38. * Creates a new action set.
  39. * @param label The label, shown in the shortcuts option pane
  40. * @since jEdit 4.0pre1
  41. */
  42. public ActionSet(String label)
  43. {
  44. this.label = label;
  45. actions = new Hashtable();
  46. }
  47. /**
  48. * Return the action source label.
  49. * @since jEdit 4.0pre1
  50. */
  51. public String getLabel()
  52. {
  53. return label;
  54. }
  55. /**
  56. * Sets the action source label.
  57. * @param label The label
  58. * @since jEdit 4.0pre1
  59. */
  60. public void setLabel(String label)
  61. {
  62. this.label = label;
  63. }
  64. /**
  65. * Adds an action to the action set.
  66. * @param action The action
  67. * @since jEdit 4.0pre1
  68. */
  69. public void addAction(EditAction action)
  70. {
  71. actions.put(action.getName(),action);
  72. }
  73. /**
  74. * Removes an action from the action set.
  75. * @param name The action name
  76. * @since jEdit 4.0pre1
  77. */
  78. public void removeAction(String name)
  79. {
  80. actions.remove(name);
  81. }
  82. /**
  83. * Removes all actions from the action set.
  84. * @since jEdit 4.0pre1
  85. */
  86. public void removeAllActions()
  87. {
  88. actions.clear();
  89. }
  90. /**
  91. * Returns an action with the specified name.
  92. * @param name The action name
  93. * @since jEdit 4.0pre1
  94. */
  95. public EditAction getAction(String name)
  96. {
  97. return (EditAction)actions.get(name);
  98. }
  99. /**
  100. * Returns the number of actions in the set.
  101. * @since jEdit 4.0pre1
  102. */
  103. public int getActionCount()
  104. {
  105. return actions.size();
  106. }
  107. /**
  108. * Returns an array of all actions in this action set.
  109. * @since jEdit 4.0pre1
  110. */
  111. public EditAction[] getActions()
  112. {
  113. EditAction[] retVal = new EditAction[actions.size()];
  114. Enumeration enum = actions.elements();
  115. int i = 0;
  116. while(enum.hasMoreElements())
  117. {
  118. retVal[i++] = (EditAction)enum.nextElement();
  119. }
  120. return retVal;
  121. }
  122. /**
  123. * Returns if this action set contains the specified action.
  124. * @param action The action
  125. * @since jEdit 4.0pre1
  126. */
  127. public boolean contains(EditAction action)
  128. {
  129. return actions.contains(action);
  130. }
  131. public String toString()
  132. {
  133. return label;
  134. }
  135. // package-private members
  136. void getActions(Vector vec)
  137. {
  138. Enumeration enum = actions.elements();
  139. int i = 0;
  140. while(enum.hasMoreElements())
  141. vec.addElement(enum.nextElement());
  142. }
  143. // private members
  144. private String label;
  145. private Hashtable actions;
  146. }