PageRenderTime 30ms CodeModel.GetById 22ms app.highlight 6ms RepoModel.GetById 1ms 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
  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
 20package org.gjt.sp.jedit;
 21
 22import java.util.*;
 23
 24/**
 25 * A set of actions..
 26 * @author Slava Pestov
 27 * @version $Id: ActionSet.java 3825 2001-10-02 13:54:14Z spestov $
 28 * @since jEdit 4.0pre1
 29 */
 30public class ActionSet
 31{
 32	/**
 33	 * Creates a new action set.
 34	 * @since jEdit 4.0pre1
 35	 */
 36	public ActionSet()
 37	{
 38		this(null);
 39	}
 40
 41	/**
 42	 * Creates a new action set.
 43	 * @param label The label, shown in the shortcuts option pane
 44	 * @since jEdit 4.0pre1
 45	 */
 46	public ActionSet(String label)
 47	{
 48		this.label = label;
 49		actions = new Hashtable();
 50	}
 51
 52	/**
 53	 * Return the action source label.
 54	 * @since jEdit 4.0pre1
 55	 */
 56	public String getLabel()
 57	{
 58		return label;
 59	}
 60
 61	/**
 62	 * Sets the action source label.
 63	 * @param label The label
 64	 * @since jEdit 4.0pre1
 65	 */
 66	public void setLabel(String label)
 67	{
 68		this.label = label;
 69	}
 70
 71	/**
 72	 * Adds an action to the action set.
 73	 * @param action The action
 74	 * @since jEdit 4.0pre1
 75	 */
 76	public void addAction(EditAction action)
 77	{
 78		actions.put(action.getName(),action);
 79	}
 80
 81	/**
 82	 * Removes an action from the action set.
 83	 * @param name The action name
 84	 * @since jEdit 4.0pre1
 85	 */
 86	public void removeAction(String name)
 87	{
 88		actions.remove(name);
 89	}
 90
 91	/**
 92	 * Removes all actions from the action set.
 93	 * @since jEdit 4.0pre1
 94	 */
 95	public void removeAllActions()
 96	{
 97		actions.clear();
 98	}
 99
100	/**
101	 * Returns an action with the specified name.
102	 * @param name The action name
103	 * @since jEdit 4.0pre1
104	 */
105	public EditAction getAction(String name)
106	{
107		return (EditAction)actions.get(name);
108	}
109
110	/**
111	 * Returns the number of actions in the set.
112	 * @since jEdit 4.0pre1
113	 */
114	public int getActionCount()
115	{
116		return actions.size();
117	}
118
119	/**
120	 * Returns an array of all actions in this action set.
121	 * @since jEdit 4.0pre1
122	 */
123	public EditAction[] getActions()
124	{
125		EditAction[] retVal = new EditAction[actions.size()];
126		Enumeration enum = actions.elements();
127		int i = 0;
128		while(enum.hasMoreElements())
129		{
130			retVal[i++] = (EditAction)enum.nextElement();
131		}
132		return retVal;
133	}
134
135	/**
136	 * Returns if this action set contains the specified action.
137	 * @param action The action
138	 * @since jEdit 4.0pre1
139	 */
140	public boolean contains(EditAction action)
141	{
142		return actions.contains(action);
143	}
144
145	public String toString()
146	{
147		return label;
148	}
149
150	// package-private members
151	void getActions(Vector vec)
152	{
153		Enumeration enum = actions.elements();
154		int i = 0;
155		while(enum.hasMoreElements())
156			vec.addElement(enum.nextElement());
157	}
158
159	// private members
160	private String label;
161	private Hashtable actions;
162}