PageRenderTime 41ms CodeModel.GetById 19ms app.highlight 8ms RepoModel.GetById 12ms app.codeStats 0ms

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

#
Java | 179 lines | 78 code | 23 blank | 78 comment | 2 complexity | 63d795164bb2e15ad65359b5ce4ff1b3 MD5 | raw file
  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
 20package org.gjt.sp.jedit;
 21
 22import java.util.Vector;
 23import org.gjt.sp.jedit.gui.OptionsDialog;
 24
 25/**
 26 * The interface between jEdit and a plugin.
 27 *
 28 * @author Slava Pestov
 29 * @version $Id: EditPlugin.java 3825 2001-10-02 13:54:14Z spestov $
 30 * @since jEdit 2.1pre1
 31 */
 32public abstract class EditPlugin
 33{
 34	/**
 35	 * Returns the plugin's class name.
 36	 *
 37	 * @since jEdit 2.5pre3
 38	 */
 39	public String getClassName()
 40	{
 41		return getClass().getName();
 42	}
 43
 44	/**
 45	 * Method called by jEdit to initialize the plugin.
 46	 * Actions and edit modes should be registered here, along
 47	 * with any EditBus paraphinalia.
 48	 * @since jEdit 2.1pre1
 49	 */
 50	public void start() {}
 51
 52	/**
 53	 * Method called by jEdit before exiting. Usually, nothing
 54	 * needs to be done here.
 55	 * @since jEdit 2.1pre1
 56	 */
 57	public void stop() {}
 58
 59	/**
 60	 * Method called every time a view is created to set up the
 61	 * Plugins menu. Menus and menu items should be loaded using the
 62	 * methods in the GUIUtilities class, and added to the vector.
 63	 * @param menuItems Add menus and menu items here
 64	 *
 65	 * @see GUIUtilities#loadMenu(String)
 66	 * @see GUIUtilities#loadMenuItem(String)
 67	 *
 68	 * @since jEdit 2.6pre5
 69	 */
 70	public void createMenuItems(Vector menuItems) {}
 71
 72	/**
 73	 * Method called every time the plugin options dialog box is
 74	 * displayed. Any option panes created by the plugin should be
 75	 * added here.
 76	 * @param optionsDialog The plugin options dialog box
 77	 *
 78	 * @see OptionPane
 79	 * @see OptionsDialog#addOptionPane(OptionPane)
 80	 *
 81	 * @since jEdit 2.1pre1
 82	 */
 83	public void createOptionPanes(OptionsDialog optionsDialog) {}
 84
 85	/**
 86	 * Returns the JAR file containing this plugin.
 87	 * @since jEdit 3.1pre5
 88	 */
 89	public EditPlugin.JAR getJAR()
 90	{
 91		return jar;
 92	}
 93
 94	/**
 95	 * A placeholder for a plugin that didn't load.
 96	 */
 97	public static class Broken extends EditPlugin
 98	{
 99		public String getClassName()
100		{
101			return clazz;
102		}
103
104		// package-private members
105		Broken(String clazz)
106		{
107			this.clazz = clazz;
108		}
109
110		// private members
111		private String clazz;
112	}
113
114	/**
115	 * A JAR file.
116	 */
117	public static class JAR
118	{
119		public String getPath()
120		{
121			return path;
122		}
123
124		public JARClassLoader getClassLoader()
125		{
126			return classLoader;
127		}
128
129		public ActionSet getActions()
130		{
131			return actions;
132		}
133
134		public void addPlugin(EditPlugin plugin)
135		{
136			plugin.jar = JAR.this;
137
138			plugin.start();
139
140			if(plugin instanceof EBPlugin)
141				EditBus.addToBus((EBPlugin)plugin);
142
143			plugins.addElement(plugin);
144		}
145
146		public EditPlugin[] getPlugins()
147		{
148			EditPlugin[] array = new EditPlugin[plugins.size()];
149			plugins.copyInto(array);
150			return array;
151		}
152
153		public JAR(String path, JARClassLoader classLoader)
154		{
155			this.path = path;
156			this.classLoader = classLoader;
157			plugins = new Vector();
158			actions = new ActionSet();
159		}
160
161		// package-private members
162		void getPlugins(Vector vector)
163		{
164			for(int i = 0; i < plugins.size(); i++)
165			{
166				vector.addElement(plugins.elementAt(i));
167			}
168		}
169
170		// private members
171		private String path;
172		private JARClassLoader classLoader;
173		private Vector plugins;
174		private ActionSet actions;
175	}
176
177	// private members
178	private EditPlugin.JAR jar;
179}