PageRenderTime 17ms CodeModel.GetById 5ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/EditAction.java

#
Java | 182 lines | 60 code | 17 blank | 105 comment | 0 complexity | b43b9b2d22b882089e5ef7b01ff07812 MD5 | raw file
  1/*
  2 * EditAction.java - jEdit action listener
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 1998, 1999, 2000, 2001 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
 25//{{{ Imports
 26import java.awt.event.ActionEvent;
 27import java.awt.event.ActionListener;
 28import java.awt.Component;
 29import org.gjt.sp.util.Log;
 30//}}}
 31
 32/**
 33 * Instead of subclassing EditAction directly, you should now write an
 34 * actions.xml file.
 35 *
 36 * @author Slava Pestov
 37 * @version $Id: EditAction.java 3916 2001-11-24 13:03:36Z spestov $
 38 */
 39public abstract class EditAction
 40{
 41	//{{{ EditAction constructor
 42	/**
 43	 * Creates a new edit action with the specified name.
 44	 * @param name The action name
 45	 */
 46	public EditAction(String name)
 47	{
 48		this.name = name;
 49	} //}}}
 50
 51	//{{{ getName() method
 52	/**
 53	 * Returns the internal name of this action.
 54	 */
 55	public String getName()
 56	{
 57		return name;
 58	} //}}}
 59
 60	//{{{ getLabel() method
 61	/**
 62	 * Returns the action's label. The default implementation returns the
 63	 * value of the property named by the action's internal name suffixed
 64	 * with <code>.label</code>.
 65	 */
 66	public String getLabel()
 67	{
 68		return jEdit.getProperty(name + ".label");
 69	} //}}}
 70
 71	//{{{ invoke() method
 72	/**
 73	 * Invokes the action.
 74	 * @param view The view
 75	 * @since jEdit 2.7pre2
 76	 */
 77	public abstract void invoke(View view);
 78	//}}}
 79
 80	//{{{ getView() method
 81	/**
 82	 * @deprecated Call <code>GUIUtilities.getView()</code> instead.
 83	 */
 84	public static View getView(Component comp)
 85	{
 86		// moved to GUIUtilities as it makes no sense being here.
 87		return GUIUtilities.getView(comp);
 88	} //}}}
 89
 90	//{{{ isToggle() method
 91	/**
 92	 * Returns if this edit action should be displayed as a check box
 93	 * in menus.
 94	 * @since jEdit 2.2pre4
 95	 */
 96	public boolean isToggle()
 97	{
 98		return false;
 99	} //}}}
100
101	//{{{ isSelected() method
102	/**
103	 * If this edit action is a toggle, returns if it is selected or not.
104	 * @param view The view
105	 * @since jEdit 3.2pre5
106	 */
107	public boolean isSelected(View view)
108	{
109		return false;
110	} //}}}
111
112	//{{{ noRepeat() method
113	/**
114	 * Returns if this edit action should not be repeated. Returns false
115	 * by default.
116	 * @since jEdit 2.7pre2
117	 */
118	public boolean noRepeat()
119	{
120		return false;
121	} //}}}
122
123	//{{{ noRecord() method
124	/**
125	 * Returns if this edit action should not be recorded. Returns false
126	 * by default.
127	 * @since jEdit 2.7pre2
128	 */
129	public boolean noRecord()
130	{
131		return false;
132	} //}}}
133
134	//{{{ getCode() method
135	/**
136	 * Returns the BeanShell code that will replay this action.
137	 * @since jEdit 2.7pre2
138	 */
139	public abstract String getCode();
140	//}}}
141
142	//{{{ toString() method
143	public String toString()
144	{
145		return name;
146	} //}}}
147
148	//{{{ Private members
149	private String name;
150	//}}}
151
152	//{{{ Wrapper class
153	/**
154	 * 'Wrap' EditActions in this class to turn them into AWT
155	 * ActionListeners, that can be attached to buttons, menu items, etc.
156	 */
157	public static class Wrapper implements ActionListener
158	{
159		public Wrapper(EditAction action)
160		{
161			this.action = action;
162		}
163
164		/**
165		 * Called when the user selects this action from a menu.
166		 * It passes the action through the
167		 * <code>InputHandler.executeAction()</code> method,
168		 * which performs any recording or repeating. It also
169		 * loads the action if necessary.
170		 *
171		 * @param evt The action event
172		 */
173		public void actionPerformed(ActionEvent evt)
174		{
175			// Let input handler do recording, repeating, etc
176			GUIUtilities.getView((Component)evt.getSource())
177				.getInputHandler().invokeAction(action);
178		}
179
180		private EditAction action;
181	} //}}}
182}