The major issues encountered when writing a plugin core class arise from the developer's decisions on what features the plugin will make available. These issues have implications for other plugin elements as well.
Will the plugin provide for actions that the user can trigger using jEdit's menu items, toolbar buttons and keyboard shortcuts?
Will the plugin have its own visible interface?
Will the plugin have settings that the user can configure?
Will the plugin respond to any messages reflecting changes in the host application's state?
Recall that the plugin core class must extend EditPlugin. In QuickNotepad's plugin core class, there are no special initialization or shutdown chores to perform, so we will not need a start() or stop() method.
The resulting plugin core class is lightweight and straightforward to implement:
public class QuickNotepadPlugin extends EditPlugin { public static final String NAME = "quicknotepad"; public static final String MENU = "quicknotepad.menu"; public static final String PROPERTY_PREFIX = "plugin.QuickNotepadPlugin."; public static final String OPTION_PREFIX = "options.quicknotepad."; |
First we define a few static String data members to enforce consistent syntax for the name of properties we will use throughout the plugin.
public void createMenuItems(Vector menuItems) { menuItems.addElement(GUIUtilities.loadMenu(MENU)); } |
This implementation of the EditPlugin.createMenuItems() method is very typical. It uses a jEdit utility function to create the menu, taking the list of actions from the quicknotepad property, and the label from quotenotepad.label.
If the plugin only had a single menu item (for example, an item activating a dockable window), we would call GUIUtilities.loadMenuItem() instead of GUIUtilities.loadMenu().
public void createOptionPanes(OptionsDialog od) { od.addOptionPane(new QuickNotepadOptionPane()); } } |
This implementation of the EditPlugin.createOptionPanes() method adds a new instance of QuickNotepadOptionPane to the given instance of the Global Options dialog box.