PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/EditAction.java

#
Java | 222 lines | 79 code | 19 blank | 124 comment | 2 complexity | 4550d9627ff1e8e7001b5bfe28cec56a 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. * EditAction.java - jEdit action listener
  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. package org.gjt.sp.jedit;
  23. //{{{ Imports
  24. import java.awt.event.ActionEvent;
  25. import java.awt.event.ActionListener;
  26. import java.awt.Component;
  27. import org.gjt.sp.jedit.gui.InputHandler;
  28. import org.gjt.sp.util.Log;
  29. //}}}
  30. /**
  31. * An action that can be bound to a menu item, tool bar button or keystroke.
  32. *
  33. * @see jEdit#getAction(String)
  34. * @see jEdit#getActionNames()
  35. * @see ActionSet
  36. *
  37. * @author Slava Pestov
  38. * @version $Id: EditAction.java 4670 2003-05-01 04:17:13Z spestov $
  39. */
  40. public abstract class EditAction
  41. {
  42. //{{{ EditAction constructor
  43. /**
  44. * Creates a new edit action with the specified name.
  45. * @param name The action name
  46. */
  47. public EditAction(String name)
  48. {
  49. this.name = name;
  50. } //}}}
  51. //{{{ getName() method
  52. /**
  53. * Returns the internal name of this action.
  54. */
  55. public String getName()
  56. {
  57. return name;
  58. } //}}}
  59. //{{{ getLabel() method
  60. /**
  61. * Returns the action's label. This returns the
  62. * value of the property named by {@link #getName()} suffixed
  63. * with <code>.label</code>.
  64. */
  65. public final String getLabel()
  66. {
  67. return jEdit.getProperty(name + ".label");
  68. } //}}}
  69. //{{{ getMouseOverText() method
  70. /**
  71. * Returns the action's mouse over message. This returns the
  72. * value of the property named by {@link #getName()} suffixed
  73. * with <code>.mouse-over</code>.
  74. */
  75. public final String getMouseOverText()
  76. {
  77. return jEdit.getProperty(name + ".mouse-over");
  78. } //}}}
  79. //{{{ invoke() method
  80. /**
  81. * Invokes the action.
  82. * @param view The view
  83. * @since jEdit 2.7pre2
  84. */
  85. public void invoke(View view)
  86. {
  87. } //}}}
  88. //{{{ getView() method
  89. /**
  90. * @deprecated Call <code>GUIUtilities.getView()</code> instead.
  91. */
  92. public static View getView(Component comp)
  93. {
  94. // moved to GUIUtilities as it makes no sense being here.
  95. return GUIUtilities.getView(comp);
  96. } //}}}
  97. //{{{ isToggle() method
  98. /**
  99. * Returns if this edit action should be displayed as a check box
  100. * in menus. This returns the
  101. * value of the property named by {@link #getName()} suffixed
  102. * with <code>.toggle</code>.
  103. *
  104. * @since jEdit 2.2pre4
  105. */
  106. public final boolean isToggle()
  107. {
  108. return jEdit.getBooleanProperty(name + ".toggle");
  109. } //}}}
  110. //{{{ isSelected() method
  111. /**
  112. * If this edit action is a toggle, returns if it is selected or not.
  113. * @param comp The component
  114. * @since jEdit 4.2pre1
  115. */
  116. public boolean isSelected(Component comp)
  117. {
  118. return false;
  119. } //}}}
  120. //{{{ noRepeat() method
  121. /**
  122. * Returns if this edit action should not be repeated. Returns false
  123. * by default.
  124. * @since jEdit 2.7pre2
  125. */
  126. public boolean noRepeat()
  127. {
  128. return false;
  129. } //}}}
  130. //{{{ noRecord() method
  131. /**
  132. * Returns if this edit action should not be recorded. Returns false
  133. * by default.
  134. * @since jEdit 2.7pre2
  135. */
  136. public boolean noRecord()
  137. {
  138. return false;
  139. } //}}}
  140. //{{{ noRememberLast() method
  141. /**
  142. * Returns if this edit action should not be remembered as the most
  143. * recently invoked action.
  144. * @since jEdit 4.2pre1
  145. */
  146. public boolean noRememberLast()
  147. {
  148. return false;
  149. } //}}}
  150. //{{{ getCode() method
  151. /**
  152. * Returns the BeanShell code that will replay this action.
  153. * @since jEdit 2.7pre2
  154. */
  155. public abstract String getCode();
  156. //}}}
  157. //{{{ toString() method
  158. public String toString()
  159. {
  160. return name;
  161. } //}}}
  162. //{{{ Private members
  163. private String name;
  164. //}}}
  165. //{{{ Wrapper class
  166. /**
  167. * 'Wrap' EditActions in this class to turn them into AWT
  168. * ActionListeners, that can be attached to buttons, menu items, etc.
  169. */
  170. public static class Wrapper implements ActionListener
  171. {
  172. /**
  173. * Creates a new action listener wrapper.
  174. * @since jEdit 4.2pre1
  175. */
  176. public Wrapper(ActionContext context, String actionName)
  177. {
  178. this.context = context;
  179. this.actionName = actionName;
  180. }
  181. /**
  182. * Called when the user selects this action from a menu.
  183. * It passes the action through the
  184. * {@link org.gjt.sp.jedit.gui.InputHandler#invokeAction(EditAction)}
  185. * method, which performs any recording or repeating.
  186. *
  187. * @param evt The action event
  188. */
  189. public void actionPerformed(ActionEvent evt)
  190. {
  191. EditAction action = context.getAction(actionName);
  192. if(action == null)
  193. {
  194. Log.log(Log.WARNING,this,"Unknown action: "
  195. + actionName);
  196. }
  197. else
  198. context.invokeAction(evt,action);
  199. }
  200. private ActionContext context;
  201. private String actionName;
  202. } //}}}
  203. }