Download jEdit 4.1 User's Guide
Transcript
Chapter 17. Implementing a Simple Plugin usually is quite short, providing only a single BeanShell expression used to create a visible plugin window. The following example from the QuickNotepad plugin illustrates the requirements of the data file: <?xml version="1.0"?> <!DOCTYPE DOCKABLES SYSTEM "dockables.dtd"> <DOCKABLES> <DOCKABLE NAME="quicknotepad"> new QuickNotepad(view, position); </DOCKABLE> </DOCKABLES> In this example, the <DOCKABLE> element has a single attribute, the dockable window’s identifier. This attribute is used to key a property where the window title is stored; see Section 17.4. The contents of the <DOCKABLE> element itself is a BeanShell expression that constructs a new QuickNotepad object. The view and position are predefined by the plugin API as the view in which the plugin window will reside, and the docking position of the plugin. A formal description of each element of the dockables.xml file can be found in the documentation of the DockableWindowManager class. 17.7. The QuickNotepad Class Here is where most of the features of the plugin will be implemented. To work with the dockable window API, the top level window will be a JPanel. The visible components reflect a simple layout. Inside the top-level panel we will place a scroll pane with a text area. Above the scroll pane we will place a panel containing a small tool bar and a label displaying the path of the current notepad file. We have identified three user actions that need implementation here: chooseFile(), saveFile(), and copyToBuffer(). As noted earlier, we also want the text area to change its appearance in immediate response to a change in user options settings. In order to do that, the window class must respond to a PropertiesChanged message from the EditBus. Unlike the EBPlugin class, the EBComponent interface does not deal with the component’s actual subscribing and unsubscribing to the EditBus. To accomplish this, we use a pair of methods inherited from the Java platform’s JComponent class that are called when the window is made visible, and when it is hidden. These two methods, 162