Differences between revisions 4 and 5
Revision 4 as of 2005-09-29 20:48:16
Size: 1815
Editor: GaryBader
Comment: Fixed bug noticed by Joel Bader
Revision 5 as of 2009-02-12 01:03:30
Size: 1823
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 20: Line 20:
attachment:HelloWorld.java [[attachment:HelloWorld.java]]
Line 22: Line 22:
attachment:HelloWorld.jar [[attachment:HelloWorld.jar]]

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.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 

HelloWorld.java

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.

Hello_World_Plugin (last edited 2010-07-22 20:07:25 by merlot)

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux