PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 179 lines | 78 code | 23 blank | 78 comment | 2 complexity | 63d795164bb2e15ad65359b5ce4ff1b3 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. * EditPlugin.java - Interface all plugins must implement
  3. * Copyright (C) 1999, 2000 Slava Pestov
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. package org.gjt.sp.jedit;
  20. import java.util.Vector;
  21. import org.gjt.sp.jedit.gui.OptionsDialog;
  22. /**
  23. * The interface between jEdit and a plugin.
  24. *
  25. * @author Slava Pestov
  26. * @version $Id: EditPlugin.java 3825 2001-10-02 13:54:14Z spestov $
  27. * @since jEdit 2.1pre1
  28. */
  29. public abstract class EditPlugin
  30. {
  31. /**
  32. * Returns the plugin's class name.
  33. *
  34. * @since jEdit 2.5pre3
  35. */
  36. public String getClassName()
  37. {
  38. return getClass().getName();
  39. }
  40. /**
  41. * Method called by jEdit to initialize the plugin.
  42. * Actions and edit modes should be registered here, along
  43. * with any EditBus paraphinalia.
  44. * @since jEdit 2.1pre1
  45. */
  46. public void start() {}
  47. /**
  48. * Method called by jEdit before exiting. Usually, nothing
  49. * needs to be done here.
  50. * @since jEdit 2.1pre1
  51. */
  52. public void stop() {}
  53. /**
  54. * Method called every time a view is created to set up the
  55. * Plugins menu. Menus and menu items should be loaded using the
  56. * methods in the GUIUtilities class, and added to the vector.
  57. * @param menuItems Add menus and menu items here
  58. *
  59. * @see GUIUtilities#loadMenu(String)
  60. * @see GUIUtilities#loadMenuItem(String)
  61. *
  62. * @since jEdit 2.6pre5
  63. */
  64. public void createMenuItems(Vector menuItems) {}
  65. /**
  66. * Method called every time the plugin options dialog box is
  67. * displayed. Any option panes created by the plugin should be
  68. * added here.
  69. * @param optionsDialog The plugin options dialog box
  70. *
  71. * @see OptionPane
  72. * @see OptionsDialog#addOptionPane(OptionPane)
  73. *
  74. * @since jEdit 2.1pre1
  75. */
  76. public void createOptionPanes(OptionsDialog optionsDialog) {}
  77. /**
  78. * Returns the JAR file containing this plugin.
  79. * @since jEdit 3.1pre5
  80. */
  81. public EditPlugin.JAR getJAR()
  82. {
  83. return jar;
  84. }
  85. /**
  86. * A placeholder for a plugin that didn't load.
  87. */
  88. public static class Broken extends EditPlugin
  89. {
  90. public String getClassName()
  91. {
  92. return clazz;
  93. }
  94. // package-private members
  95. Broken(String clazz)
  96. {
  97. this.clazz = clazz;
  98. }
  99. // private members
  100. private String clazz;
  101. }
  102. /**
  103. * A JAR file.
  104. */
  105. public static class JAR
  106. {
  107. public String getPath()
  108. {
  109. return path;
  110. }
  111. public JARClassLoader getClassLoader()
  112. {
  113. return classLoader;
  114. }
  115. public ActionSet getActions()
  116. {
  117. return actions;
  118. }
  119. public void addPlugin(EditPlugin plugin)
  120. {
  121. plugin.jar = JAR.this;
  122. plugin.start();
  123. if(plugin instanceof EBPlugin)
  124. EditBus.addToBus((EBPlugin)plugin);
  125. plugins.addElement(plugin);
  126. }
  127. public EditPlugin[] getPlugins()
  128. {
  129. EditPlugin[] array = new EditPlugin[plugins.size()];
  130. plugins.copyInto(array);
  131. return array;
  132. }
  133. public JAR(String path, JARClassLoader classLoader)
  134. {
  135. this.path = path;
  136. this.classLoader = classLoader;
  137. plugins = new Vector();
  138. actions = new ActionSet();
  139. }
  140. // package-private members
  141. void getPlugins(Vector vector)
  142. {
  143. for(int i = 0; i < plugins.size(); i++)
  144. {
  145. vector.addElement(plugins.elementAt(i));
  146. }
  147. }
  148. // private members
  149. private String path;
  150. private JARClassLoader classLoader;
  151. private Vector plugins;
  152. private ActionSet actions;
  153. }
  154. // private members
  155. private EditPlugin.JAR jar;
  156. }