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 package helloworld;
   2 
   3 import java.awt.event.ActionEvent;
   4 import javax.swing.JOptionPane;
   5 import cytoscape.Cytoscape;
   6 import cytoscape.plugin.CytoscapePlugin;
   7 import cytoscape.util.CytoscapeAction;
   8 
   9 
  10 /**
  11  * A menu item "Hello World" will appear at Plugins menu. Click on the menu
  12  * item, a message dialog will show up.
  13  */
  14 public class HelloWorldPlugin extends CytoscapePlugin {
  15 
  16         public HelloWorldPlugin() {
  17                 MyPluginMenuAction menuAction = new MyPluginMenuAction(this);
  18                 Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) menuAction);
  19         }
  20         
  21         public class MyPluginMenuAction extends CytoscapeAction {
  22 
  23                 public MyPluginMenuAction(HelloWorldPlugin myPlugin) {
  24                         super("Hello World");
  25                         setPreferredMenu("Plugins");
  26                 }
  27 
  28                 public void actionPerformed(ActionEvent e) {
  29                         JOptionPane.showMessageDialog(Cytoscape.getDesktop(),"Hello World is selected!");       
  30                 }
  31         }
  32 }
  33 

HelloWorldPlugin.java

helloworld.jar

Looking at the Plugin

Imports:

   1 import cytoscape.plugin.CytoscapePlugin;
   2 import cytoscape.Cytoscape;
   3 

Methods:

   1       public HelloWorldPlugin ()
   2 

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)

MoinMoin Appliance - Powered by TurnKey Linux