3 | | Click "Plugins -> Load Plugin" from the Transformer window menu bar. You should be presented with a file browser, select a jar file containing one or more Batchable classes. |
4 | | The plugin will add a new cascaded menu to the plugins menu, the cascaded menu will contain each "Batchable" class as both a single and a batch item on the "Plugins" sub menu. |
5 | | |
6 | | == Writing plugins == |
7 | | |
8 | | To implement a plugin for JPsychoMorph you need to create a Java class that overrides the Facemorph.Batchable interface: |
| 3 | Click "Plugins -> Load Plugin" from the Transformer window menu bar. You should be presented with a file browser, select a jar file containing one or more Batchable and/or Plugin classes. The plugin will add a new cascaded menu to the plugins menu, the cascaded menu will contain each "Batchable" class as both a single and a batch item on the "Plugins" sub menu. Any Plugin classes may make additional changes to the user interface, such as adding a new menu. |
| 4 | |
| 5 | == Writing Batchable and Plugin classes == |
| 6 | |
| 7 | JPsychomorph handles two plugin interfaces, the main one is Batchable, which allows single and batch processing of images. The second interface, Plugin, is more general, and simply supports a setup and cleanup method. The internal handling of these interface types is different. For Batchable classes a new instance of the class is created each time it is used (in batch or single mode). For Plugin classes a single instance is created on loading and the setup method is called, this instance persists until the programme closes or the plugin is unloaded. A single jar file can contain a mixture of Plugin and Batchable classes, and all will be loaded or unloaded together. If a class implements both interfaces, one instance will be created as the Plugin, and will persist until unloaded, another instance will be created each time for batch or single mode Batchable processing. Any implementing class for either of these classes should have an empty (or no) constructor, if they do not they will not be loaded. |
| 8 | |
| 9 | These interfaces are part of the Facemorph library available here: |
| 10 | |
| 11 | * http://users.aber.ac.uk/bpt/jpsychomorph/version4/facemorphlib.jar -- facemorphlib.jar |
| 12 | |
| 13 | Documentation for all the classes in the library is available here: |
| 14 | |
| 15 | * http://users.aber.ac.uk/bpt/jpsychomorph/version4/javadoc/ -- facemorphlib documentation |
| 16 | |
| 17 | === Writing Plugin classes === |
| 18 | |
| 19 | The Plugin interface supports just two methods, setup and cleanup: |
| 20 | |
| 21 | {{{ |
| 22 | public interface Plugin { |
| 23 | public boolean setup(PsychoMorphForm psychomorph); |
| 24 | public boolean cleanup(PsychoMorphForm psychomorph); |
| 25 | } |
| 26 | }}} |
| 27 | |
| 28 | A very simple example of a Plugin is given below, this simply adds a menu "Boo!" to the Psychomorph window, with one item "Boo!", which when pressed brings up a dialog saying, you guessed, "Boo!". |
| 29 | |
| 30 | {{{ |
| 31 | |
| 32 | import Facemorph.psychomorph.Batchable; |
| 33 | import Facemorph.psychomorph.ImageZoomPanel; |
| 34 | import Facemorph.psychomorph.Plugin; |
| 35 | import Facemorph.psychomorph.PsychoMorphForm; |
| 36 | import java.awt.event.ActionEvent; |
| 37 | import java.awt.event.ActionListener; |
| 38 | import javax.swing.JMenu; |
| 39 | import javax.swing.JMenuItem; |
| 40 | import javax.swing.JOptionPane; |
| 41 | |
| 42 | public class AddMenuTest extends JMenu implements Plugin { |
| 43 | PsychoMorphForm psychomorph; |
| 44 | |
| 45 | public boolean setup(PsychoMorphForm psychomorph) { |
| 46 | this.psychomorph = psychomorph; |
| 47 | JMenuItem anItem = new JMenuItem("Boo!"); |
| 48 | anItem.addActionListener(new ActionListener() { |
| 49 | public void actionPerformed(ActionEvent e) { |
| 50 | JOptionPane.showMessageDialog(AddMenuTest.this.psychomorph, "Boo!"); |
| 51 | } |
| 52 | }); |
| 53 | |
| 54 | setText("Boo!"); |
| 55 | add(anItem); |
| 56 | psychomorph.addMenu(this); |
| 57 | |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | public boolean cleanup(PsychoMorphForm psychomorph) { |
| 62 | psychomorph.removeMenu(this); |
| 63 | return true; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | }}} |
| 68 | |
| 69 | === Writing Batchable classes === |
| 70 | |
| 71 | To implement a Batchable plugin for JPsychoMorph you need to create a Java class that overrides the Facemorph.Batchable interface: |