PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms 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
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, 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. 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.util.Log;
  28. //}}}
  29. /**
  30. * Instead of subclassing EditAction directly, you should now write an
  31. * actions.xml file.
  32. *
  33. * @author Slava Pestov
  34. * @version $Id: EditAction.java 4190 2002-05-26 05:43:53Z spestov $
  35. */
  36. public abstract class EditAction
  37. {
  38. //{{{ EditAction constructor
  39. /**
  40. * Creates a new edit action with the specified name.
  41. * @param name The action name
  42. */
  43. public EditAction(String name)
  44. {
  45. this.name = name;
  46. } //}}}
  47. //{{{ getName() method
  48. /**
  49. * Returns the internal name of this action.
  50. */
  51. public String getName()
  52. {
  53. return name;
  54. } //}}}
  55. //{{{ getLabel() method
  56. /**
  57. * Returns the action's label. The default implementation returns the
  58. * value of the property named by the action's internal name suffixed
  59. * with <code>.label</code>.
  60. */
  61. public String getLabel()
  62. {
  63. return jEdit.getProperty(name + ".label");
  64. } //}}}
  65. //{{{ getMouseOverText() method
  66. /**
  67. * Returns the text that should be shown when the mouse is placed over
  68. * this action's menu item or tool bar button. Currently only used by
  69. * the macro system.
  70. * @since jEdit 4.0pre5
  71. */
  72. public String getMouseOverText()
  73. {
  74. return null;
  75. } //}}}
  76. //{{{ invoke() method
  77. /**
  78. * Invokes the action.
  79. * @param view The view
  80. * @since jEdit 2.7pre2
  81. */
  82. public abstract void invoke(View view);
  83. //}}}
  84. //{{{ getView() method
  85. /**
  86. * @deprecated Call <code>GUIUtilities.getView()</code> instead.
  87. */
  88. public static View getView(Component comp)
  89. {
  90. // moved to GUIUtilities as it makes no sense being here.
  91. return GUIUtilities.getView(comp);
  92. } //}}}
  93. //{{{ isToggle() method
  94. /**
  95. * Returns if this edit action should be displayed as a check box
  96. * in menus.
  97. * @since jEdit 2.2pre4
  98. */
  99. public boolean isToggle()
  100. {
  101. return false;
  102. } //}}}
  103. //{{{ isSelected() method
  104. /**
  105. * If this edit action is a toggle, returns if it is selected or not.
  106. * @param view The view
  107. * @since jEdit 3.2pre5
  108. */
  109. public boolean isSelected(View view)
  110. {
  111. return false;
  112. } //}}}
  113. //{{{ noRepeat() method
  114. /**
  115. * Returns if this edit action should not be repeated. Returns false
  116. * by default.
  117. * @since jEdit 2.7pre2
  118. */
  119. public boolean noRepeat()
  120. {
  121. return false;
  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. //{{{ getCode() method
  134. /**
  135. * Returns the BeanShell code that will replay this action.
  136. * @since jEdit 2.7pre2
  137. */
  138. public abstract String getCode();
  139. //}}}
  140. //{{{ toString() method
  141. public String toString()
  142. {
  143. return name;
  144. } //}}}
  145. //{{{ Private members
  146. private String name;
  147. //}}}
  148. //{{{ Wrapper class
  149. /**
  150. * 'Wrap' EditActions in this class to turn them into AWT
  151. * ActionListeners, that can be attached to buttons, menu items, etc.
  152. */
  153. public static class Wrapper implements ActionListener
  154. {
  155. public Wrapper(EditAction action)
  156. {
  157. this.action = action;
  158. }
  159. /**
  160. * Called when the user selects this action from a menu.
  161. * It passes the action through the
  162. * <code>InputHandler.executeAction()</code> method,
  163. * which performs any recording or repeating. It also
  164. * loads the action if necessary.
  165. *
  166. * @param evt The action event
  167. */
  168. public void actionPerformed(ActionEvent evt)
  169. {
  170. // Let input handler do recording, repeating, etc
  171. jEdit.getActiveView().getInputHandler().invokeAction(action);
  172. }
  173. private EditAction action;
  174. } //}}}
  175. }