charite.christo.strap
Class StrapHotswap
java.lang.Object
charite.christo.strap.StrapHotswap
- All Implemented Interfaces:
- ChRunnable, HasPanel, PaintHook, ProcessEv
public class StrapHotswap
- extends java.lang.Object
- implements HasPanel, ChRunnable, ProcessEv, PaintHook
HELP
The hotswap-dialog provides a comfortable environment for writing plugins.
PACKAGE:charite.christo.protein.
PACKAGE:charite.christo.strap.extensions.
The concept of class-hotswap has been published in PUBMED:16469097.
Quick start: Follow this short guide:
Activate the node "StrapExtension" in the tree.
Subsequently, press the button
BUTTON:StrapHotswap#BUT_LAB_New
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 WIKI:Source_code of the
new plugin is opened with a text editor.
The source is a minimal example for "StrapExtension".
To start press BUTTON:StrapHotswap#BUT_LAB_Apply.
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 WIKI:Compiler is automatically started. The result of successful compilation is a WIKI:Class_file.
However, if the compilation fails, the WIKI:Compilation_error 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 WIKI:Jar_files in the directories ~/.StrapAlign/plugins and ~/.StrapAlign/jars are included to the WIKI:Classpath_(Java).
Types of plugins:
Each plugin implements a certain WIKI:Java_interface 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 JAVADOC:StrapExtension or JAVADOC:ProteinParser.
When these nodes are expanded the classes which implement the interface become visible.
For example JAVADOC:ConsensusSequence is a plugin implementing
JAVADOC:StrapExtension whereas JAVADOC:ResidueSolventAccessibility is a plugin
implementing JAVADOC:ValueOfResidue.
When you select JAVADOC:ConsensusSequence in the tree the button
BUTTON:StrapHotswap#BUT_LAB_Apply becomes active.
On pressing this button an instance of this
selected plugin is created and an appropriate action performed.
The JAVADOC:ConsensusSequence implements JAVADOC: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 JAVADOC:ResidueSolventAccessibility implements
JAVADOC:ValueOfResidue.
Therefore it works in the context of a certain dialog. This dialog is
opened and JAVADOC: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.
- BUTTON:StrapHotswap#BUT_LAB_New
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 JAVADOC: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.
- BUTTON:StrapHotswap#BUT_LAB_Edit 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
JAVADOC: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
JAVADOC:StrapEvent. Events can be monitored (Debug-menu).
Customization:
ICON:IC_CUSTOM The preferred WIKI:Text_editor or WIKI:Integrated_development_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:
- JAVADOC:StrapAlign
The root object. It can be obtained with the method getProteinAlignment() from event- or protein-objects.
or with the static method JAVADOC:StrapAlign#getInstance().
- JAVADOC:StrapEvent
Events are broadcasted to inform all listeners when changes occur. See debug-menu.
- JAVADOC:Protein
Arrays are read only:
Some methods return arrays. Never change array elements in returned arrays. The following is wrong:
Protein p= ....;
byte[] aminoAcids=p.getResidueType();
aminoAcids[4]=(byte)'Y';
In order to change the 5th residue to Tyrosine write instead:
Protein 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 DIALOG:StrapPlugins
Publication: PUBMED:16469097
Fields inherited from interface charite.christo.ChRunnable |
APPEND, COLUMN_TITLE, DOWNLOAD_FINISHED, GET_PANEL, ICON, INTERPRET_LINE, IS_DRAG4XY, ITEM_TEXT, MODIFY_RENDERER_COMPONENT, PROGRESS, REPAINT_CURSOR, SAY_DOWNLOADING, SET_ICON_IMAGE, SET_TREE_VALUE, SHOW_IN_FRAME, TAB_TEXT, TIP_TEXT |
Method Summary |
void |
dispose()
|
javax.swing.JComponent |
getPanel(int options)
|
boolean |
paintHook(javax.swing.JComponent component,
java.awt.Graphics g,
boolean after)
|
void |
processEv(java.awt.AWTEvent ev)
|
java.lang.Object |
run(java.lang.String id,
java.lang.Object arg)
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
BUT_LAB_Apply
public static final java.lang.String BUT_LAB_Apply
- See Also:
- Constant Field Values
BUT_LAB_Edit
public static final java.lang.String BUT_LAB_Edit
- See Also:
- Constant Field Values
BUT_LAB_New
public static final java.lang.String BUT_LAB_New
- See Also:
- Constant Field Values
StrapHotswap
public StrapHotswap()
processEv
public void processEv(java.awt.AWTEvent ev)
- Specified by:
processEv
in interface ProcessEv
- See Also:
EvAdapter
paintHook
public boolean paintHook(javax.swing.JComponent component,
java.awt.Graphics g,
boolean after)
- Specified by:
paintHook
in interface PaintHook
after
- This method is called once before and once after super.paintComponent.
- Returns:
- means do not call super.paintComponent
run
public java.lang.Object run(java.lang.String id,
java.lang.Object arg)
- Specified by:
run
in interface ChRunnable
getPanel
public javax.swing.JComponent getPanel(int options)
- Specified by:
getPanel
in interface HasPanel
dispose
public void dispose()
'The most important classes are StrapAlign, Protein and StrapEvent.'