Write plugins by yourself
[Menu-bar>Plugins] The hotswap-dialog provides a comfortable environment for writing plugins.
The concept of class-hotswap has been published in 16469097.
Quick start: Follow this short guide:
Activate the node "StrapExtension" in the tree.
Subsequently, press the button
to create a new plugin of type "StrapExtension".
You will be asked for a name of your new plugin. You can accept the
suggested name. The of the
new plugin is opened with a text editor.
The source is a minimal example for "StrapExtension".
To start press
.
All, what the plugin is doing is that it tells in a message box how many proteins are currently loaded.
The program code can be modified and extended.
For example the text in the message box can be changed.
When the altered source code is saved to hard disk the is automatically started. The result of successful compilation is a .
However, if the compilation fails, the or is shown in the log panel. This panel is in another tab. you need to go back to the main tab.
The next time, the plugin is started, the new text will be seen in the message box.
Hotswapped classes modified by the user:
The Java source- and class-files of the hotswap plugins reside in the directory "~/.StrapAlign/hotswap".
In contrast to standard plugins hotswapped classes must not have a package statement.
JAR-files:
All in the directories ~/.StrapAlign/plugins and ~/.StrapAlign/jars are included to the .
Types of plugins:
Each plugin implements a certain which determins the purpose of the plugin.
The interfaces and plugins are shown in the graphical tree.
The proximal branches of the tree are the interfaces such as StrapExtension
or ProteinParser
.
When these nodes are expanded the classes which implement the interface become visible.
For example ConsensusSequence
is a plugin implementing
StrapExtension
whereas ResidueSolventAccessibility
is a plugin
implementing ValueOfResidue
.
When you select ConsensusSequence
in the tree the button
becomes active.
On pressing this button an instance of this
selected plugin is created and an appropriate action performed.
The ConsensusSequence
implements StrapExtension
and has
therefore a run() method. The specific action for this type of plugins is to call the run()-method.
On the other hand ResidueSolventAccessibility
implements
ValueOfResidue
.
Therefore it works in the context of a certain dialog. This dialog is
opened and ValueOfResidue
is selected within the
dialog.
Developing/changing plugins:
Innovative in STRAP is that plugins can be loaded, created and changed at runtime.
Plugins do not need to be re-instantiated after changing the Java-source.
This is possible because STRAP does not communicate directly with the object but with a proxy object.
The technique was inspired by the hotswap API by Paul Cody Johnston .
The buttons act on the class or interface that is selected in the tree by the user.
This button is used to create a new plugin. The tree node of the interface to be implemented must be selected.
The useer can chose a name of the new plugin.
A skeleton of a class implementing the selected interface is written to the directory StrapPlugins
and can be modified in
a text editor.
Whenever the text is saved to hard disk it is automatically compiled and compiler messages are displayed.
Source code of user
defined interfaces and classes is shown and and plugin code is loaded
into the text editor. As soon as the Java-file is saved STRAP tries to
compile the Java-file. When the compilation succeeds the changes take
effect immediately.
Debugging: In the "debuggin" menu
which resides in the "option" menu are some tools to find programming
errors in plugins. The standard outputs stderr and
stdout which are written with the Java-statements
System.out.println("hello world") or System.err.println("hello
world"), respectively, can be viewed. Classes implementing
StrapListener
are notified when the cursor moves, when
proteins are added or deleted or when the multiple sequence alignment
is altered. This information is carried in instances of
StrapEvent
. Events can be monitored:
Watch STRAP-events.
Customization:
The preferred or lopment_environment used for Java source texts can be specified with the customize button at the top bar.
Accessing data of the multiple sequence alignment by plugins:
For the communication with the STRAP-model four classes are usually sufficient:
Arrays are read only:
Some methods return arrays. Never change array elements in returned arrays. The following is wrong:
StrapProtein p= ....;
byte[] aminoAcids=p.getResidueType();
aminoAcids[4]=(byte)'Y';
In order to change the 5th residue to Tyrosine write instead:
StrapProtein p= ....;
p.setResidueType(4,(byte)'Y');
Using public methods of STRAP classes :
If possible, use documented methods description because they will be kept in future releases whereas un-documented methods may change in the future.
See Plugins
Publication: 16469097