Changes between Version 9 and Version 10 of plugin


Ignore:
Timestamp:
Dec 7, 2010, 1:16:31 PM (13 years ago)
Author:
bpt
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • plugin

    v9 v10  
    11== Using plugins ==
    22
    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:
     3Click "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
     7JPsychomorph 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
     9These interfaces are part of the Facemorph library available here:
     10
     11 * http://users.aber.ac.uk/bpt/jpsychomorph/version4/facemorphlib.jar -- facemorphlib.jar
     12
     13Documentation 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
     19The Plugin interface supports just two methods, setup and cleanup:
     20
     21{{{
     22public interface Plugin {
     23     public boolean setup(PsychoMorphForm psychomorph);
     24     public boolean cleanup(PsychoMorphForm psychomorph);
     25}
     26}}}
     27
     28A 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
     32import Facemorph.psychomorph.Batchable;
     33import Facemorph.psychomorph.ImageZoomPanel;
     34import Facemorph.psychomorph.Plugin;
     35import Facemorph.psychomorph.PsychoMorphForm;
     36import java.awt.event.ActionEvent;
     37import java.awt.event.ActionListener;
     38import javax.swing.JMenu;
     39import javax.swing.JMenuItem;
     40import javax.swing.JOptionPane;
     41
     42public 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
     71To implement a Batchable plugin for JPsychoMorph you need to create a Java class that overrides the Facemorph.Batchable interface:
    972
    1073{{{
     
    1780}}}
    1881
    19 This interface is part of the Facemorph library available here:
    20 
    21  * http://users.aber.ac.uk/bpt/jpsychomorph/version4/facemorphlib.jar -- facemorphlib.jar
    22 
    23 Documentation for all the classes in the library is available here:
    24 
    25  * http://users.aber.ac.uk/bpt/jpsychomorph/version4/javadoc/ -- facemorphlib documentation
    2682
    2783The main method in the Batchable interface is ''process'', which will be called for each image in the batch.  The ''single'' parameter is true if the processing is '''not''' operating in batch mode, but on a single loaded image.  This is useful for things like pushing undo information on the stack, which you may not want to do in batch mode. The ImageZoomPanel allows access to the currently loaded Image and Template.