← Revision 2 as of 2005-07-22 22:43:30
Size: 1820
Comment:
|
← Revision 3 as of 2005-07-22 22:44:11 →
Size: 1822
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 17: | Line 17: |
Here is a simple "Hello World" example as a Cytoscape plugin where a Java Swing utility class is used to display the message in a dialog window.
1 import javax.swing.JOptionPane;
2 import cytoscape.plugin.CytoscapePlugin;
3 import cytoscape.plugin.Cytoscape;
4
5 public class HelloWorldPlugin extends CytoscapePlugin {
6
7 public HelloWorldPlugin () {
8 String message = "Hello World!";
9 System.out.println(message);
10 // use the CytoscapeDesktop as parent for a Swing dialog
11 JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message);
12 }
13 }
14
attachment:HelloWorld.java
attachment:HelloWorld.jar
Looking at the Plugin
Imports:
1 import cytoscape.plugin.CytoscapePlugin;
2 import cytoscape.Cytoscape;
3
All plugins must extend the class cytoscape.plugin.CytoscapePlugin. The specific class that extends CytoscapePlugin doesn't need to stand alone; it can reference any number of other classes and libraries. This "main" class is simply Cytoscape's entry point to your code.
The static class cytoscape.Cytoscape provides access the data objects and utilities of the Cytoscape core. Here, the plugin gets a reference to a window created by Cytoscape for a parent of a new dialog window.
Methods:
1 public HelloWorldPlugin ()
2
- All plugins must have a default constructor (that is, a constructor with no arguments). Cytoscape will call this constructor to create an instance of your plugin class.
To load this plugin into Cytoscape, save the jar file at the above link to your local disk in the Cytoscape plugins folder. Then start Cytoscape which will then load the plugin from the jar. You should see the "Hello World" dialog appear above your main Cytoscape window.