PageRenderTime 80ms CodeModel.GetById 74ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/EditAction.java

#
Java | 193 lines | 63 code | 18 blank | 112 comment | 0 complexity | 79beff06154794ce7e427bd9c2d8a3a0 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, 2002 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 4190 2002-05-26 05:43:53Z 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	//{{{ getMouseOverText() method
 72	/**
 73	 * Returns the text that should be shown when the mouse is placed over
 74	 * this action's menu item or tool bar button. Currently only used by
 75	 * the macro system.
 76	 * @since jEdit 4.0pre5
 77	 */
 78	public String getMouseOverText()
 79	{
 80		return null;
 81	} //}}}
 82
 83	//{{{ invoke() method
 84	/**
 85	 * Invokes the action.
 86	 * @param view The view
 87	 * @since jEdit 2.7pre2
 88	 */
 89	public abstract void invoke(View view);
 90	//}}}
 91
 92	//{{{ getView() method
 93	/**
 94	 * @deprecated Call <code>GUIUtilities.getView()</code> instead.
 95	 */
 96	public static View getView(Component comp)
 97	{
 98		// moved to GUIUtilities as it makes no sense being here.
 99		return GUIUtilities.getView(comp);
100	} //}}}
101
102	//{{{ isToggle() method
103	/**
104	 * Returns if this edit action should be displayed as a check box
105	 * in menus.
106	 * @since jEdit 2.2pre4
107	 */
108	public boolean isToggle()
109	{
110		return false;
111	} //}}}
112
113	//{{{ isSelected() method
114	/**
115	 * If this edit action is a toggle, returns if it is selected or not.
116	 * @param view The view
117	 * @since jEdit 3.2pre5
118	 */
119	public boolean isSelected(View view)
120	{
121		return false;
122	} //}}}
123
124	//{{{ noRepeat() method
125	/**
126	 * Returns if this edit action should not be repeated. Returns false
127	 * by default.
128	 * @since jEdit 2.7pre2
129	 */
130	public boolean noRepeat()
131	{
132		return false;
133	} //}}}
134
135	//{{{ noRecord() method
136	/**
137	 * Returns if this edit action should not be recorded. Returns false
138	 * by default.
139	 * @since jEdit 2.7pre2
140	 */
141	public boolean noRecord()
142	{
143		return false;
144	} //}}}
145
146	//{{{ getCode() method
147	/**
148	 * Returns the BeanShell code that will replay this action.
149	 * @since jEdit 2.7pre2
150	 */
151	public abstract String getCode();
152	//}}}
153
154	//{{{ toString() method
155	public String toString()
156	{
157		return name;
158	} //}}}
159
160	//{{{ Private members
161	private String name;
162	//}}}
163
164	//{{{ Wrapper class
165	/**
166	 * 'Wrap' EditActions in this class to turn them into AWT
167	 * ActionListeners, that can be attached to buttons, menu items, etc.
168	 */
169	public static class Wrapper implements ActionListener
170	{
171		public Wrapper(EditAction action)
172		{
173			this.action = action;
174		}
175
176		/**
177		 * Called when the user selects this action from a menu.
178		 * It passes the action through the
179		 * <code>InputHandler.executeAction()</code> method,
180		 * which performs any recording or repeating. It also
181		 * loads the action if necessary.
182		 *
183		 * @param evt The action event
184		 */
185		public void actionPerformed(ActionEvent evt)
186		{
187			// Let input handler do recording, repeating, etc
188			jEdit.getActiveView().getInputHandler().invokeAction(action);
189		}
190
191		private EditAction action;
192	} //}}}
193}