PageRenderTime 48ms CodeModel.GetById 24ms 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
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 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 3916 2001-11-24 13:03:36Z 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. //{{{ invoke() method
  66. /**
  67. * Invokes the action.
  68. * @param view The view
  69. * @since jEdit 2.7pre2
  70. */
  71. public abstract void invoke(View view);
  72. //}}}
  73. //{{{ getView() method
  74. /**
  75. * @deprecated Call <code>GUIUtilities.getView()</code> instead.
  76. */
  77. public static View getView(Component comp)
  78. {
  79. // moved to GUIUtilities as it makes no sense being here.
  80. return GUIUtilities.getView(comp);
  81. } //}}}
  82. //{{{ isToggle() method
  83. /**
  84. * Returns if this edit action should be displayed as a check box
  85. * in menus.
  86. * @since jEdit 2.2pre4
  87. */
  88. public boolean isToggle()
  89. {
  90. return false;
  91. } //}}}
  92. //{{{ isSelected() method
  93. /**
  94. * If this edit action is a toggle, returns if it is selected or not.
  95. * @param view The view
  96. * @since jEdit 3.2pre5
  97. */
  98. public boolean isSelected(View view)
  99. {
  100. return false;
  101. } //}}}
  102. //{{{ noRepeat() method
  103. /**
  104. * Returns if this edit action should not be repeated. Returns false
  105. * by default.
  106. * @since jEdit 2.7pre2
  107. */
  108. public boolean noRepeat()
  109. {
  110. return false;
  111. } //}}}
  112. //{{{ noRecord() method
  113. /**
  114. * Returns if this edit action should not be recorded. Returns false
  115. * by default.
  116. * @since jEdit 2.7pre2
  117. */
  118. public boolean noRecord()
  119. {
  120. return false;
  121. } //}}}
  122. //{{{ getCode() method
  123. /**
  124. * Returns the BeanShell code that will replay this action.
  125. * @since jEdit 2.7pre2
  126. */
  127. public abstract String getCode();
  128. //}}}
  129. //{{{ toString() method
  130. public String toString()
  131. {
  132. return name;
  133. } //}}}
  134. //{{{ Private members
  135. private String name;
  136. //}}}
  137. //{{{ Wrapper class
  138. /**
  139. * 'Wrap' EditActions in this class to turn them into AWT
  140. * ActionListeners, that can be attached to buttons, menu items, etc.
  141. */
  142. public static class Wrapper implements ActionListener
  143. {
  144. public Wrapper(EditAction action)
  145. {
  146. this.action = action;
  147. }
  148. /**
  149. * Called when the user selects this action from a menu.
  150. * It passes the action through the
  151. * <code>InputHandler.executeAction()</code> method,
  152. * which performs any recording or repeating. It also
  153. * loads the action if necessary.
  154. *
  155. * @param evt The action event
  156. */
  157. public void actionPerformed(ActionEvent evt)
  158. {
  159. // Let input handler do recording, repeating, etc
  160. GUIUtilities.getView((Component)evt.getSource())
  161. .getInputHandler().invokeAction(action);
  162. }
  163. private EditAction action;
  164. } //}}}
  165. }