PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/www/tags/NOV_07_2009/htdocs/42docs/users-guide/plugin-implement-quicknotepadplugin.html

#
HTML | 71 lines | 68 code | 3 blank | 0 comment | 0 complexity | f582957c0482d0cf67fbdc3fd8347ea1 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. <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="
  2. How 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>
  3. The major issues encountered when writing a plugin core class arise
  4. from the developer's decisions on what features the plugin will make
  5. available. These issues have implications for other plugin elements
  6. as well.
  7. </p><div class="itemizedlist"><ul type="disc"><li><p>
  8. Will the plugin provide for actions that the user can trigger using
  9. jEdit's menu items, toolbar buttons and keyboard shortcuts?
  10. </p></li><li><p>
  11. Will the plugin have its own visible interface?
  12. </p></li><li><p>
  13. Will the plugin have settings that the user can configure?
  14. </p></li><li><p>
  15. Will the plugin
  16. respond to any messages reflecting changes in the host
  17. application's state?
  18. </p></li></ul></div><p>
  19. Recall that the plugin core class must extend
  20. <a href="../api/org/gjt/sp/jedit/EditPlugin.html" target="_top">
  21. <tt class="classname">EditPlugin</tt></a>.
  22. In QuickNotepad's plugin core class, there are no special
  23. initialization or shutdown chores to perform, so we will not need
  24. a <tt class="function">start()</tt> or <tt class="function">stop()</tt> method.
  25. </p><p>
  26. The resulting plugin core class is lightweight and straightforward to implement:
  27. </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 {
  28. public static final String NAME = "quicknotepad";
  29. public static final String MENU = "quicknotepad.menu";
  30. public static final String PROPERTY_PREFIX
  31. = "plugin.QuickNotepadPlugin.";
  32. public static final String OPTION_PREFIX
  33. = "options.quicknotepad.";
  34. </pre></td></tr></table></div><p>
  35. First we define a few static
  36. <tt class="classname">String</tt> data members to enforce consistent syntax
  37. for the name of properties we will use throughout the plugin.
  38. </p></li><li><div class="informalexample"><table border="0" bgcolor="#E0E0E0"><tr><td><pre class="programlisting">
  39. public void createMenuItems(Vector menuItems) {
  40. menuItems.addElement(GUIUtilities.loadMenu(MENU));
  41. }</pre></td></tr></table></div><p>
  42. This implementation of
  43. the <a href="../api/org/gjt/sp/jedit/EditPlugin.html#createMenuItems(java.util.Vector)" target="_top">
  44. <tt class="classname">EditPlugin.createMenuItems()</tt></a> method
  45. is very typical.
  46. It uses a jEdit utility function to create the menu, taking the list
  47. of actions from the <tt class="filename">quicknotepad</tt> property, and
  48. the label from <tt class="filename">quotenotepad.label</tt>.
  49. </p><p>
  50. If the plugin only had a single menu item (for example, an item
  51. activating a dockable window), we would call
  52. <a href="../api/org/gjt/sp/jedit/GUIUtilities.html#loadMenuItem(java.lang.String)" target="_top">
  53. <tt class="function">GUIUtilities.loadMenuItem()</tt></a> instead of
  54. <a href="../api/org/gjt/sp/jedit/GUIUtilities.html#loadMenu(java.lang.String)" target="_top">
  55. <tt class="function">GUIUtilities.loadMenu()</tt></a>.
  56. </p></li><li><div class="informalexample"><table border="0" bgcolor="#E0E0E0"><tr><td><pre class="programlisting">public void createOptionPanes(OptionsDialog od) {
  57. od.addOptionPane(new QuickNotepadOptionPane());
  58. }
  59. }</pre></td></tr></table></div><p>
  60. This implementation of
  61. the <a href="../api/org/gjt/sp/jedit/EditPlugin.html#createOptionPanes(org.gjt.sp.jedit.gui.OptionsDialog)" target="_top">
  62. <tt class="classname">EditPlugin.createOptionPanes()</tt></a> method
  63. adds a new instance of <tt class="classname">QuickNotepadOptionPane</tt>
  64. to the given instance of the <span><b class="guimenuitem">Global Options</b></span>
  65. dialog box.
  66. </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">
  67. How 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>