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)

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