PageRenderTime 42ms CodeModel.GetById 33ms app.highlight 6ms 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
  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
 23package org.gjt.sp.jedit;
 24
 25import java.util.*;
 26
 27/**
 28 * Manages a collection of action sets. There are two instances of this class
 29 * in jEdit:
 30 * <ul>
 31 * <li>{@link org.gjt.sp.jedit.jEdit#getActionContext()} - editor actions
 32 * <li>{@link org.gjt.sp.jedit.browser.VFSBrowser#getActionContext()} - browser
 33 * actions
 34 * </ul>
 35 *
 36 * @since jEdit 4.2pre1
 37 * @author Slava Pestov
 38 * @version $Id: ActionContext.java 4669 2003-05-01 02:21:27Z spestov $
 39 */
 40public abstract class ActionContext
 41{
 42	//{{{ invokeAction() method
 43	/**
 44	 * Invokes the given action in response to a user-generated event.
 45	 * @param evt The event
 46	 * @param action The action
 47	 * @since jEdit 4.2pre1
 48	 */
 49	public abstract void invokeAction(EventObject evt, EditAction action);
 50	//}}}
 51
 52	//{{{ addActionSet() method
 53	/**
 54	 * Adds a new action set to the context.
 55	 * @since jEdit 4.2pre1
 56	 */
 57	public void addActionSet(ActionSet actionSet)
 58	{
 59		actionSets.addElement(actionSet);
 60		actionSet.context = this;
 61		String[] actions = actionSet.getActionNames();
 62		for(int i = 0; i < actions.length; i++)
 63		{
 64			actionHash.put(actions[i],actionSet);
 65		}
 66	} //}}}
 67
 68	//{{{ removeActionSet() method
 69	/**
 70	 * Removes an action set from the context.
 71	 * @since jEdit 4.2pre1
 72	 */
 73	public void removeActionSet(ActionSet actionSet)
 74	{
 75		actionSets.removeElement(actionSet);
 76		actionSet.context = null;
 77		String[] actions = actionSet.getActionNames();
 78		for(int i = 0; i < actions.length; i++)
 79		{
 80			actionHash.remove(actions[i]);
 81		}
 82	} //}}}
 83
 84	//{{{ getActionSets() method
 85	/**
 86	 * Returns all registered action sets.
 87	 * @since jEdit 4.2pre1
 88	 */
 89	public ActionSet[] getActionSets()
 90	{
 91		ActionSet[] retVal = new ActionSet[actionSets.size()];
 92		actionSets.copyInto(retVal);
 93		return retVal;
 94	} //}}}
 95
 96	//{{{ getAction() method
 97	/**
 98	 * Returns the specified action.
 99	 * @param name The action name
100	 * @since jEdit 4.2pre1
101	 */
102	public EditAction getAction(String name)
103	{
104		ActionSet set = (ActionSet)actionHash.get(name);
105		if(set == null)
106			return null;
107		else
108			return set.getAction(name);
109	} //}}}
110
111	//{{{ getActionSetForAction() method
112	/**
113	 * Returns the action set that contains the specified action.
114	 *
115	 * @param action The action
116	 * @since jEdit 4.2pre1
117	 */
118	public ActionSet getActionSetForAction(String action)
119	{
120		return (ActionSet)actionHash.get(action);
121	} //}}}
122
123	//{{{ getActionNames() method
124	/**
125	 * Returns all registered action names.
126	 */
127	public String[] getActionNames()
128	{
129		ArrayList vec = new ArrayList();
130		for(int i = 0; i < actionSets.size(); i++)
131			((ActionSet)actionSets.elementAt(i)).getActionNames(vec);
132
133		return (String[])vec.toArray(new String[vec.size()]);
134	} //}}}
135
136	//{{{ Package-private members
137	Hashtable actionHash = new Hashtable();
138	//}}}
139
140	//{{{ Private members
141	private Vector actionSets = new Vector();
142	//}}}
143}