PageRenderTime 176ms CodeModel.GetById 158ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms


HTML | 71 lines | 68 code | 3 blank | 0 comment | 0 complexity | f582957c0482d0cf67fbdc3fd8347ea1 MD5 | raw file
 1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>The QuickNotepadPlugin Class</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="jEdit 4.2 User's Guide"><link rel="up" href="plugin-implement.html" title="Chapter 18. Implementing a Simple Plugin"><link rel="previous" href="plugin-load.html" title="
 3How Plugins are Loaded"><link rel="next" href="plugin-implement-editbus.html" title="The EditBus"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">The QuickNotepadPlugin Class</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="plugin-load.html">Prev</a> </td><th width="60%" align="center">Chapter 18. Implementing a Simple Plugin</th><td width="20%" align="right"> <a accesskey="n" href="plugin-implement-editbus.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="plugin-implement-quicknotepadplugin"></a>The QuickNotepadPlugin Class</h2></div></div><div></div></div><p>
 4    The major issues encountered when writing a plugin core class arise
 5    from the developer's decisions on what features the plugin will make
 6    available. These issues have implications for other plugin elements
 7    as well.
 8</p><div class="itemizedlist"><ul type="disc"><li><p>
 9    Will the plugin provide for actions that the user can trigger using
10    jEdit's menu items, toolbar buttons and keyboard shortcuts?
11  </p></li><li><p>
12    Will the plugin have its own visible interface?
13  </p></li><li><p>
14    Will the plugin have settings that the user can configure?
15  </p></li><li><p>
16    Will the plugin
17    respond to any messages reflecting changes in the host
18    application's state?
19  </p></li></ul></div><p>
20  Recall that the plugin core class must extend
21  <a href="../api/org/gjt/sp/jedit/EditPlugin.html" target="_top">
22  <tt class="classname">EditPlugin</tt></a>.
23  In QuickNotepad's plugin core class, there are no special
24  initialization or shutdown chores to perform, so we will not need
25  a <tt class="function">start()</tt> or <tt class="function">stop()</tt> method.
27  The resulting plugin core class is lightweight and straightforward to implement:
28</p><div class="itemizedlist"><ul type="disc"><li><div class="informalexample"><table border="0" bgcolor="#E0E0E0"><tr><td><pre class="programlisting">public class QuickNotepadPlugin extends EditPlugin {
29    public static final String NAME = "quicknotepad";
30    public static final String MENU = "";
31    public static final String PROPERTY_PREFIX
32        = "plugin.QuickNotepadPlugin.";
33    public static final String OPTION_PREFIX
34        = "options.quicknotepad.";
36  First we define a few static
37  <tt class="classname">String</tt> data members to enforce consistent syntax
38  for the name of properties we will use throughout the plugin.
39</p></li><li><div class="informalexample"><table border="0" bgcolor="#E0E0E0"><tr><td><pre class="programlisting">
40    public void createMenuItems(Vector menuItems) {
41        menuItems.addElement(GUIUtilities.loadMenu(MENU));
42    }</pre></td></tr></table></div><p>
43  This implementation of
44  the <a href="../api/org/gjt/sp/jedit/EditPlugin.html#createMenuItems(java.util.Vector)" target="_top">
45  <tt class="classname">EditPlugin.createMenuItems()</tt></a> method
46  is very typical.
47  It uses a jEdit utility function to create the menu, taking the list
48  of actions from the <tt class="filename">quicknotepad</tt> property, and
49  the label from <tt class="filename">quotenotepad.label</tt>.
51  If the plugin only had a single menu item (for example, an item
52  activating a dockable window), we would call
53  <a href="../api/org/gjt/sp/jedit/GUIUtilities.html#loadMenuItem(java.lang.String)" target="_top">
54  <tt class="function">GUIUtilities.loadMenuItem()</tt></a> instead of
55  <a href="../api/org/gjt/sp/jedit/GUIUtilities.html#loadMenu(java.lang.String)" target="_top">
56  <tt class="function">GUIUtilities.loadMenu()</tt></a>.
57</p></li><li><div class="informalexample"><table border="0" bgcolor="#E0E0E0"><tr><td><pre class="programlisting">public void createOptionPanes(OptionsDialog od) {
58        od.addOptionPane(new QuickNotepadOptionPane());
59    }
63  This implementation of
64  the <a href="../api/org/gjt/sp/jedit/EditPlugin.html#createOptionPanes(org.gjt.sp.jedit.gui.OptionsDialog)" target="_top">
65  <tt class="classname">EditPlugin.createOptionPanes()</tt></a> method
66  adds a new instance of <tt class="classname">QuickNotepadOptionPane</tt>
67  to the given instance of the <span><b class="guimenuitem">Global Options</b></span>
68  dialog box.
69</p></li></ul></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="plugin-load.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="plugin-implement.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="plugin-implement-editbus.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">
71How Plugins are Loaded </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> The EditBus</td></tr></table></div></body></html>